summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-07-06 23:53:34 +0300
committerLinus Groh <mail@linusgroh.de>2021-07-07 01:38:10 +0100
commitdd27490ee160f92aef4962e31ae7598ddd2fb26a (patch)
treeeb54b23a21052725a3e9a09b0f1fa5d21dde4bdd /Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
parentd57767865882854406fd489cd38bf34bf1216ddd (diff)
downloadserenity-dd27490ee160f92aef4962e31ae7598ddd2fb26a.zip
LibJS: Throw if the trap result of OwnPropertyKeys contains duplicates
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/ProxyObject.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
index 8216918fd8..803ba3dd74 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -798,13 +798,23 @@ MarkedValueList ProxyObject::internal_own_property_keys() const
return MarkedValueList { heap() };
// 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, ยซ String, Symbol ยป).
- auto trap_result = create_list_from_array_like(global_object, trap_result_array, [](auto value) -> Result<void, ErrorType> {
- if (!value.is_string() && !value.is_symbol())
- return ErrorType::ProxyOwnPropertyKeysNotStringOrSymbol;
- return {};
+ HashTable<StringOrSymbol> unique_keys;
+ auto trap_result = create_list_from_array_like(global_object, trap_result_array, [&](auto value) {
+ auto& vm = global_object.vm();
+ if (!value.is_string() && !value.is_symbol()) {
+ vm.throw_exception<TypeError>(global_object, ErrorType::ProxyOwnPropertyKeysNotStringOrSymbol);
+ return;
+ }
+ auto property_key = value.to_property_key(global_object);
+ VERIFY(!vm.exception());
+ unique_keys.set(property_key, AK::HashSetExistingEntryBehavior::Keep);
});
- // FIXME: 9. If trapResult contains any duplicate entries, throw a TypeError exception.
+ // 9. If trapResult contains any duplicate entries, throw a TypeError exception.
+ if (unique_keys.size() != trap_result.size()) {
+ vm.throw_exception<TypeError>(global_object, ErrorType::ProxyOwnPropertyKeysDuplicates);
+ return MarkedValueList { heap() };
+ }
// 10. Let extensibleTarget be ? IsExtensible(target).
auto extensible_target = m_target.is_extensible();