Selaa lähdekoodia

LibJS: Convert internal_is_extensible() to ThrowCompletionOr

Linus Groh 3 vuotta sitten
vanhempi
commit
9b4362f10a

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Object.cpp

@@ -72,7 +72,7 @@ Object::~Object()
 // 7.2.5 IsExtensible ( O ), https://tc39.es/ecma262/#sec-isextensible-o
 bool Object::is_extensible() const
 {
-    return internal_is_extensible();
+    return TRY_OR_DISCARD(internal_is_extensible());
 }
 
 // 7.3 Operations on Objects, https://tc39.es/ecma262/#sec-operations-on-objects
@@ -547,7 +547,7 @@ ThrowCompletionOr<bool> Object::internal_set_prototype_of(Object* new_prototype)
 }
 
 // 10.1.3 [[IsExtensible]] ( ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-isextensible
-bool Object::internal_is_extensible() const
+ThrowCompletionOr<bool> Object::internal_is_extensible() const
 {
     // 1. Return O.[[Extensible]].
     return m_is_extensible;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Object.h

@@ -93,7 +93,7 @@ public:
 
     virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const;
     virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype);
-    virtual bool internal_is_extensible() const;
+    virtual ThrowCompletionOr<bool> internal_is_extensible() const;
     virtual bool internal_prevent_extensions();
     virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const;
     virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&);

+ 9 - 13
Userland/Libraries/LibJS/Runtime/ProxyObject.cpp

@@ -148,7 +148,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_set_prototype_of(Object* prototype
 }
 
 // 10.5.3 [[IsExtensible]] ( ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-isextensible
-bool ProxyObject::internal_is_extensible() const
+ThrowCompletionOr<bool> ProxyObject::internal_is_extensible() const
 {
     auto& vm = this->vm();
     auto& global_object = this->global_object();
@@ -156,16 +156,14 @@ bool ProxyObject::internal_is_extensible() const
     // 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, "isExtensible").
-    auto trap = TRY_OR_DISCARD(Value(&m_handler).get_method(global_object, vm.names.isExtensible));
+    auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.isExtensible));
 
     // 6. If trap is undefined, then
     if (!trap) {
@@ -174,18 +172,16 @@ bool ProxyObject::internal_is_extensible() const
     }
 
     // 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. Let targetResult be ? IsExtensible(target).
     auto target_result = m_target.is_extensible();
-    if (vm.exception())
-        return {};
+    if (auto* exception = vm.exception())
+        return throw_completion(exception->value());
 
     // 9. If SameValue(booleanTrapResult, targetResult) is false, throw a TypeError exception.
-    if (trap_result != target_result) {
-        vm.throw_exception<TypeError>(global_object, ErrorType::ProxyIsExtensibleReturn);
-        return {};
-    }
+    if (trap_result != target_result)
+        return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyIsExtensibleReturn);
 
     // 10. Return booleanTrapResult.
     return trap_result;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ProxyObject.h

@@ -37,7 +37,7 @@ public:
 
     virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
     virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
-    virtual bool internal_is_extensible() const override;
+    virtual ThrowCompletionOr<bool> internal_is_extensible() const override;
     virtual 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;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ReflectObject.cpp

@@ -248,7 +248,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible)
     }
 
     // 2. Return ? target.[[IsExtensible]]().
-    return Value(target.as_object().internal_is_extensible());
+    return Value(TRY_OR_DISCARD(target.as_object().internal_is_extensible()));
 }
 
 // 28.1.10 Reflect.ownKeys ( target ), https://tc39.es/ecma262/#sec-reflect.ownkeys

+ 1 - 1
Userland/Libraries/LibWeb/Bindings/LocationObject.cpp

@@ -133,7 +133,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_set_prototype_of(Object* pr
 }
 
 // https://html.spec.whatwg.org/multipage/history.html#location-isextensible
-bool LocationObject::internal_is_extensible() const
+JS::ThrowCompletionOr<bool> LocationObject::internal_is_extensible() const
 {
     // 1. Return true.
     return true;

+ 1 - 1
Userland/Libraries/LibWeb/Bindings/LocationObject.h

@@ -22,7 +22,7 @@ public:
     virtual ~LocationObject() override;
 
     virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
-    virtual bool internal_is_extensible() const override;
+    virtual JS::ThrowCompletionOr<bool> internal_is_extensible() const override;
     virtual bool internal_prevent_extensions() override;
 
     // FIXME: There should also be a custom [[GetPrototypeOf]], [[GetOwnProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]] and [[OwnPropertyKeys]],

+ 1 - 1
Userland/Services/WebContent/ConsoleGlobalObject.cpp

@@ -47,7 +47,7 @@ JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_set_prototype_of(JS::O
     return m_window_object->internal_set_prototype_of(prototype);
 }
 
-bool ConsoleGlobalObject::internal_is_extensible() const
+JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_is_extensible() const
 {
     return m_window_object->internal_is_extensible();
 }

+ 1 - 1
Userland/Services/WebContent/ConsoleGlobalObject.h

@@ -25,7 +25,7 @@ public:
 
     virtual JS::ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
     virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
-    virtual bool internal_is_extensible() const override;
+    virtual JS::ThrowCompletionOr<bool> internal_is_extensible() const override;
     virtual bool internal_prevent_extensions() override;
     virtual Optional<JS::PropertyDescriptor> internal_get_own_property(JS::PropertyName const& name) const override;
     virtual bool internal_define_own_property(JS::PropertyName const& name, JS::PropertyDescriptor const& descriptor) override;