summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-02 15:27:37 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-03 20:14:03 +0100
commit9b6c09e2c4ff79714dfecb4a98222bec9cc72b71 (patch)
treea0e9c66142b925acabf679e99a28b3cc1c708cc3 /Userland/Libraries
parentfa2ac5b75990287d8a1b9e292d0ae4da4fda3f46 (diff)
downloadserenity-9b6c09e2c4ff79714dfecb4a98222bec9cc72b71.zip
LibJS: Convert is_extensible() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp17
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp40
5 files changed, 22 insertions, 48 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp
index 6075663a5a..29c764c31b 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp
@@ -143,7 +143,7 @@ bool GlobalEnvironment::can_declare_global_var(FlyString const& name) const
return {};
if (has_property)
return true;
- return global_object.is_extensible();
+ return TRY_OR_DISCARD(global_object.is_extensible());
}
// 9.1.1.4.16 CanDeclareGlobalFunction ( N ), https://tc39.es/ecma262/#sec-candeclareglobalfunction
@@ -152,7 +152,7 @@ bool GlobalEnvironment::can_declare_global_function(FlyString const& name) const
auto& global_object = m_object_record->binding_object();
auto existing_prop = TRY_OR_DISCARD(global_object.internal_get_own_property(name));
if (!existing_prop.has_value())
- return global_object.is_extensible();
+ return TRY_OR_DISCARD(global_object.is_extensible());
if (*existing_prop->configurable)
return true;
if (existing_prop->is_data_descriptor() && *existing_prop->writable && *existing_prop->enumerable)
@@ -168,9 +168,10 @@ void GlobalEnvironment::create_global_var_binding(FlyString const& name, bool ca
bool has_property = global_object.has_own_property(name);
if (vm.exception())
return;
- bool extensible = global_object.is_extensible();
- if (vm.exception())
+ auto extensible_or_error = global_object.is_extensible();
+ if (extensible_or_error.is_error())
return;
+ auto extensible = extensible_or_error.release_value();
if (!has_property && extensible) {
m_object_record->create_mutable_binding(m_object_record->global_object(), name, can_be_deleted);
if (vm.exception())
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index 26d2aeff45..873aea3079 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -68,9 +68,10 @@ Object::~Object()
// 7.2 Testing and Comparison Operations, https://tc39.es/ecma262/#sec-testing-and-comparison-operations
// 7.2.5 IsExtensible ( O ), https://tc39.es/ecma262/#sec-isextensible-o
-bool Object::is_extensible() const
+ThrowCompletionOr<bool> Object::is_extensible() const
{
- return TRY_OR_DISCARD(internal_is_extensible());
+ // 1. Return ? O.[[IsExtensible]]().
+ return internal_is_extensible();
}
// 7.3 Operations on Objects, https://tc39.es/ecma262/#sec-operations-on-objects
@@ -352,17 +353,13 @@ bool Object::set_integrity_level(IntegrityLevel level)
// 7.3.16 TestIntegrityLevel ( O, level ), https://tc39.es/ecma262/#sec-testintegritylevel
bool Object::test_integrity_level(IntegrityLevel level) const
{
- auto& vm = this->vm();
-
// 1. Assert: Type(O) is Object.
// 2. Assert: level is either sealed or frozen.
VERIFY(level == IntegrityLevel::Sealed || level == IntegrityLevel::Frozen);
// 3. Let extensible be ? IsExtensible(O).
- auto extensible = is_extensible();
- if (vm.exception())
- return {};
+ auto extensible = TRY_OR_DISCARD(is_extensible());
// 4. If extensible is true, return false.
// 5. NOTE: If the object is extensible, none of its properties are examined.
@@ -616,15 +613,11 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> Object::internal_get_own_propert
ThrowCompletionOr<bool> Object::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
{
VERIFY(property_name.is_valid());
- auto& vm = this->vm();
-
// 1. Let current be ? O.[[GetOwnProperty]](P).
auto current = TRY(internal_get_own_property(property_name));
// 2. Let extensible be ? IsExtensible(O).
- auto extensible = is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible = TRY(is_extensible());
// 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current).
return validate_and_apply_property_descriptor(this, property_name, extensible, property_descriptor, current);
diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h
index ccd29941b5..4a58db187d 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.h
+++ b/Userland/Libraries/LibJS/Runtime/Object.h
@@ -71,7 +71,7 @@ public:
// 7.2 Testing and Comparison Operations, https://tc39.es/ecma262/#sec-testing-and-comparison-operations
- bool is_extensible() const;
+ ThrowCompletionOr<bool> is_extensible() const;
// 7.3 Operations on Objects, https://tc39.es/ecma262/#sec-operations-on-objects
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
index ca844404e1..95ed61ff4f 100644
--- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
@@ -179,7 +179,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible)
auto argument = vm.argument(0);
if (!argument.is_object())
return Value(false);
- return Value(argument.as_object().is_extensible());
+ return Value(TRY_OR_DISCARD(argument.as_object().is_extensible()));
}
// 20.1.2.15 Object.isFrozen ( O ), https://tc39.es/ecma262/#sec-object.isfrozen
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
index d61dabc6e3..e5141b7865 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -76,9 +76,7 @@ ThrowCompletionOr<Object*> ProxyObject::internal_get_prototype_of() const
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyGetPrototypeOfReturn);
// 9. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// 10. If extensibleTarget is true, return handlerProto.
if (extensible_target)
@@ -128,9 +126,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_set_prototype_of(Object* prototype
return false;
// 10. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// 11. If extensibleTarget is true, return true.
if (extensible_target)
@@ -175,9 +171,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_is_extensible() const
auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target)).to_boolean();
// 8. Let targetResult be ? IsExtensible(target).
- auto target_result = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto target_result = TRY(m_target.is_extensible());
// 9. If SameValue(booleanTrapResult, targetResult) is false, throw a TypeError exception.
if (trap_result != target_result)
@@ -217,9 +211,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_prevent_extensions()
// 8. If booleanTrapResult is true, then
if (trap_result) {
// a. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// b. If extensibleTarget is true, throw a TypeError exception.
if (extensible_target)
@@ -278,9 +270,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyGetOwnDescriptorNonConfigurable);
// c. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// d. If extensibleTarget is false, throw a TypeError exception.
if (!extensible_target)
@@ -291,9 +281,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr
}
// 12. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// 13. Let resultDesc be ? ToPropertyDescriptor(trapResultObj).
auto result_desc = to_property_descriptor(global_object, trap_result);
@@ -370,9 +358,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_define_own_property(PropertyName c
auto target_descriptor = TRY(m_target.internal_get_own_property(property_name));
// 12. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// 14. Else, let settingConfigFalse be false.
bool setting_config_false = false;
@@ -457,9 +443,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_has_property(PropertyName const& p
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyHasExistingNonConfigurable);
// ii. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// iii. If extensibleTarget is false, throw a TypeError exception.
if (!extensible_target)
@@ -648,9 +632,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_delete(PropertyName const& propert
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyDeleteNonConfigurable);
// 13. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// 14. If extensibleTarget is false, throw a TypeError exception.
if (!extensible_target)
@@ -704,9 +686,7 @@ ThrowCompletionOr<MarkedValueList> ProxyObject::internal_own_property_keys() con
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyOwnPropertyKeysDuplicates);
// 10. Let extensibleTarget be ? IsExtensible(target).
- auto extensible_target = m_target.is_extensible();
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto extensible_target = TRY(m_target.is_extensible());
// 11. Let targetKeys be ? target.[[OwnPropertyKeys]]().
auto target_keys = TRY(m_target.internal_own_property_keys());