1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:07:35 +00:00

LibJS: Add ErrorTypes for Promise ownKeys trap invariant violations

This commit is contained in:
Linus Groh 2021-10-20 17:57:01 +01:00
parent ca09f20dcf
commit cf109533de
3 changed files with 65 additions and 3 deletions

View file

@ -152,6 +152,12 @@
"the type of each result list element is either String or Symbol") \
M(ProxyOwnPropertyKeysDuplicates, "Proxy handler's ownKeys trap violates invariant: " \
"the result list may not contain duplicate elements") \
M(ProxyOwnPropertyKeysSkippedNonconfigurableProperty, "Proxy handler's ownKeys trap violates invariant: " \
"cannot skip non-configurable property '{}'") \
M(ProxyOwnPropertyKeysNonExtensibleSkippedProperty, "Proxy handler's ownKeys trap violates invariant: " \
"cannot skip property '{}' of non-extensible object") \
M(ProxyOwnPropertyKeysNonExtensibleNewProperty, "Proxy handler's ownKeys trap violates invariant: " \
"cannot report new property '{}' of non-extensible object") \
M(ProxyPreventExtensionsReturn, "Proxy handler's preventExtensions trap violates " \
"invariant: cannot return true if the target object is extensible") \
M(ProxyRevoked, "An operation was performed on a revoked Proxy object") \

View file

@ -728,7 +728,7 @@ ThrowCompletionOr<MarkedValueList> ProxyObject::internal_own_property_keys() con
for (auto& key : target_nonconfigurable_keys) {
// a. If key is not an element of uncheckedResultKeys, throw a TypeError exception.
if (!unchecked_result_keys.contains_slow(key))
return vm.throw_completion<TypeError>(global_object, ErrorType::FixmeAddAnErrorString);
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyOwnPropertyKeysSkippedNonconfigurableProperty, key.to_string_without_side_effects());
// b. Remove key from uncheckedResultKeys.
unchecked_result_keys.remove_first_matching([&](auto& value) {
@ -744,7 +744,7 @@ ThrowCompletionOr<MarkedValueList> ProxyObject::internal_own_property_keys() con
for (auto& key : target_configurable_keys) {
// a. If key is not an element of uncheckedResultKeys, throw a TypeError exception.
if (!unchecked_result_keys.contains_slow(key))
return vm.throw_completion<TypeError>(global_object, ErrorType::FixmeAddAnErrorString);
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyOwnPropertyKeysNonExtensibleSkippedProperty, key.to_string_without_side_effects());
// b. Remove key from uncheckedResultKeys.
unchecked_result_keys.remove_first_matching([&](auto& value) {
@ -754,7 +754,7 @@ ThrowCompletionOr<MarkedValueList> ProxyObject::internal_own_property_keys() con
// 22. If uncheckedResultKeys is not empty, throw a TypeError exception.
if (!unchecked_result_keys.is_empty())
return vm.throw_completion<TypeError>(global_object, ErrorType::FixmeAddAnErrorString);
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyOwnPropertyKeysNonExtensibleNewProperty, unchecked_result_keys[0].to_string_without_side_effects());
// 23. Return trapResult.
return { move(trap_result) };