summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-29 00:13:41 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-29 23:49:53 +0100
commit73bae7d779ebbf14eec603d8619f4d5247a6e69a (patch)
tree85ef6f46da8ff1dd50d1295921fa0b211ac0970a /Userland/Libraries
parent9b4362f10a5a87470f43c1086717daa9ce04bb08 (diff)
downloadserenity-73bae7d779ebbf14eec603d8619f4d5247a6e69a.zip
LibJS: Convert internal_prevent_extensions() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp22
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ReflectObject.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Bindings/LocationObject.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Bindings/LocationObject.h2
9 files changed, 18 insertions, 26 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
index 6f4ab44266..e93430100a 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -206,7 +206,7 @@ void GlobalObject::initialize_global_object()
});
m_throw_type_error_function->define_direct_property_without_transition(vm.names.length, Value(0), 0);
m_throw_type_error_function->define_direct_property_without_transition(vm.names.name, js_string(vm, ""), 0);
- m_throw_type_error_function->internal_prevent_extensions();
+ (void)m_throw_type_error_function->internal_prevent_extensions();
// 10.2.4 AddRestrictedFunctionProperties ( F, realm ), https://tc39.es/ecma262/#sec-addrestrictedfunctionproperties
m_function_prototype->define_direct_accessor_without_transition(vm.names.caller, m_throw_type_error_function, m_throw_type_error_function, Attribute::Configurable);
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index 61a2ee4bb7..ce0a3b2836 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -301,9 +301,7 @@ bool Object::set_integrity_level(IntegrityLevel level)
VERIFY(level == IntegrityLevel::Sealed || level == IntegrityLevel::Frozen);
// 3. Let status be ? O.[[PreventExtensions]]().
- auto status = internal_prevent_extensions();
- if (vm.exception())
- return {};
+ auto status = TRY_OR_DISCARD(internal_prevent_extensions());
// 4. If status is false, return false.
if (!status)
@@ -554,7 +552,7 @@ ThrowCompletionOr<bool> Object::internal_is_extensible() const
}
// 10.1.4 [[PreventExtensions]] ( ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-preventextensions
-bool Object::internal_prevent_extensions()
+ThrowCompletionOr<bool> Object::internal_prevent_extensions()
{
// 1. Set O.[[Extensible]] to false.
m_is_extensible = false;
diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h
index eb9a1f0c03..fe2e63cca0 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.h
+++ b/Userland/Libraries/LibJS/Runtime/Object.h
@@ -94,7 +94,7 @@ public:
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const;
virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype);
virtual ThrowCompletionOr<bool> internal_is_extensible() const;
- virtual bool internal_prevent_extensions();
+ virtual ThrowCompletionOr<bool> internal_prevent_extensions();
virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const;
virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&);
virtual bool internal_has_property(PropertyName const&) const;
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
index a93b509610..34b7d1c923 100644
--- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
@@ -208,9 +208,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions)
auto argument = vm.argument(0);
if (!argument.is_object())
return argument;
- auto status = argument.as_object().internal_prevent_extensions();
- if (vm.exception())
- return {};
+ auto status = TRY_OR_DISCARD(argument.as_object().internal_prevent_extensions());
if (!status) {
// FIXME: Improve/contextualize error message
vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPreventExtensionsReturnedFalse);
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
index a3aa946465..64c959185c 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -188,7 +188,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_is_extensible() const
}
// 10.5.4 [[PreventExtensions]] ( ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-preventextensions
-bool ProxyObject::internal_prevent_extensions()
+ThrowCompletionOr<bool> ProxyObject::internal_prevent_extensions()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
@@ -196,16 +196,14 @@ bool ProxyObject::internal_prevent_extensions()
// 1. Let handler be O.[[ProxyHandler]].
// 2. If handler is null, throw a TypeError exception.
- if (m_is_revoked) {
- vm.throw_exception<TypeError>(global_object, ErrorType::ProxyRevoked);
- return {};
- }
+ if (m_is_revoked)
+ return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyRevoked);
// 3. Assert: Type(handler) is Object.
// 4. Let target be O.[[ProxyTarget]].
// 5. Let trap be ? GetMethod(handler, "preventExtensions").
- auto trap = TRY_OR_DISCARD(Value(&m_handler).get_method(global_object, vm.names.preventExtensions));
+ auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.preventExtensions));
// 6. If trap is undefined, then
if (!trap) {
@@ -214,20 +212,18 @@ bool ProxyObject::internal_prevent_extensions()
}
// 7. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, ยซ target ยป)).
- auto trap_result = TRY_OR_DISCARD(vm.call(*trap, &m_handler, &m_target)).to_boolean();
+ auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target)).to_boolean();
// 8. If booleanTrapResult is true, then
if (trap_result) {
// a. Let extensibleTarget be ? IsExtensible(target).
auto extensible_target = m_target.is_extensible();
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// b. If extensibleTarget is true, throw a TypeError exception.
- if (extensible_target) {
- vm.throw_exception<TypeError>(global_object, ErrorType::ProxyPreventExtensionsReturn);
- return {};
- }
+ if (extensible_target)
+ return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyPreventExtensionsReturn);
}
// 9. Return booleanTrapResult.
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.h b/Userland/Libraries/LibJS/Runtime/ProxyObject.h
index faec553e70..aab0000d04 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.h
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.h
@@ -38,7 +38,7 @@ public:
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
virtual ThrowCompletionOr<bool> internal_is_extensible() const override;
- virtual bool internal_prevent_extensions() override;
+ virtual ThrowCompletionOr<bool> internal_prevent_extensions() override;
virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const override;
virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
virtual bool internal_has_property(PropertyName const&) const override;
diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
index e4b32240a2..ac2d057d17 100644
--- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
@@ -283,7 +283,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::prevent_extensions)
}
// 2. Return ? target.[[PreventExtensions]]().
- return Value(target.as_object().internal_prevent_extensions());
+ return Value(TRY_OR_DISCARD(target.as_object().internal_prevent_extensions()));
}
// 28.1.12 Reflect.set ( target, propertyKey, V [ , receiver ] ), https://tc39.es/ecma262/#sec-reflect.set
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
index df1b069154..a5946d2d90 100644
--- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
@@ -140,7 +140,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_is_extensible() const
}
// https://html.spec.whatwg.org/multipage/history.html#location-preventextensions
-bool LocationObject::internal_prevent_extensions()
+JS::ThrowCompletionOr<bool> LocationObject::internal_prevent_extensions()
{
// 1. Return false.
return false;
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h
index 39af96818c..7062c4ae25 100644
--- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h
+++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h
@@ -23,7 +23,7 @@ public:
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
virtual JS::ThrowCompletionOr<bool> internal_is_extensible() const override;
- virtual bool internal_prevent_extensions() override;
+ virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
// FIXME: There should also be a custom [[GetPrototypeOf]], [[GetOwnProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]] and [[OwnPropertyKeys]],
// but we don't have the infrastructure in place to implement them yet.