mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
LibJS: Convert internal_is_extensible() to ThrowCompletionOr
This commit is contained in:
parent
8c81c84c18
commit
9b4362f10a
9 changed files with 18 additions and 22 deletions
|
@ -72,7 +72,7 @@ Object::~Object()
|
||||||
// 7.2.5 IsExtensible ( O ), https://tc39.es/ecma262/#sec-isextensible-o
|
// 7.2.5 IsExtensible ( O ), https://tc39.es/ecma262/#sec-isextensible-o
|
||||||
bool Object::is_extensible() const
|
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
|
// 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
|
// 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]].
|
// 1. Return O.[[Extensible]].
|
||||||
return m_is_extensible;
|
return m_is_extensible;
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
|
|
||||||
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const;
|
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const;
|
||||||
virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype);
|
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 bool internal_prevent_extensions();
|
||||||
virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const;
|
virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const;
|
||||||
virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&);
|
virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&);
|
||||||
|
|
|
@ -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
|
// 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& vm = this->vm();
|
||||||
auto& global_object = this->global_object();
|
auto& global_object = this->global_object();
|
||||||
|
@ -156,16 +156,14 @@ bool ProxyObject::internal_is_extensible() const
|
||||||
// 1. Let handler be O.[[ProxyHandler]].
|
// 1. Let handler be O.[[ProxyHandler]].
|
||||||
|
|
||||||
// 2. If handler is null, throw a TypeError exception.
|
// 2. If handler is null, throw a TypeError exception.
|
||||||
if (m_is_revoked) {
|
if (m_is_revoked)
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxyRevoked);
|
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyRevoked);
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Assert: Type(handler) is Object.
|
// 3. Assert: Type(handler) is Object.
|
||||||
// 4. Let target be O.[[ProxyTarget]].
|
// 4. Let target be O.[[ProxyTarget]].
|
||||||
|
|
||||||
// 5. Let trap be ? GetMethod(handler, "isExtensible").
|
// 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
|
// 6. If trap is undefined, then
|
||||||
if (!trap) {
|
if (!trap) {
|
||||||
|
@ -174,18 +172,16 @@ bool ProxyObject::internal_is_extensible() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target »)).
|
// 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).
|
// 8. Let targetResult be ? IsExtensible(target).
|
||||||
auto target_result = m_target.is_extensible();
|
auto target_result = m_target.is_extensible();
|
||||||
if (vm.exception())
|
if (auto* exception = vm.exception())
|
||||||
return {};
|
return throw_completion(exception->value());
|
||||||
|
|
||||||
// 9. If SameValue(booleanTrapResult, targetResult) is false, throw a TypeError exception.
|
// 9. If SameValue(booleanTrapResult, targetResult) is false, throw a TypeError exception.
|
||||||
if (trap_result != target_result) {
|
if (trap_result != target_result)
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxyIsExtensibleReturn);
|
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyIsExtensibleReturn);
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 10. Return booleanTrapResult.
|
// 10. Return booleanTrapResult.
|
||||||
return trap_result;
|
return trap_result;
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
|
|
||||||
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
|
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
|
||||||
virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) 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 bool internal_prevent_extensions() override;
|
||||||
virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const 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_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
|
||||||
|
|
|
@ -248,7 +248,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Return ? target.[[IsExtensible]]().
|
// 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
|
// 28.1.10 Reflect.ownKeys ( target ), https://tc39.es/ecma262/#sec-reflect.ownkeys
|
||||||
|
|
|
@ -133,7 +133,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_set_prototype_of(Object* pr
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/history.html#location-isextensible
|
// 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.
|
// 1. Return true.
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
virtual ~LocationObject() override;
|
virtual ~LocationObject() override;
|
||||||
|
|
||||||
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) 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 bool internal_prevent_extensions() override;
|
||||||
|
|
||||||
// FIXME: There should also be a custom [[GetPrototypeOf]], [[GetOwnProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]] and [[OwnPropertyKeys]],
|
// FIXME: There should also be a custom [[GetPrototypeOf]], [[GetOwnProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]] and [[OwnPropertyKeys]],
|
||||||
|
|
|
@ -47,7 +47,7 @@ JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_set_prototype_of(JS::O
|
||||||
return m_window_object->internal_set_prototype_of(prototype);
|
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();
|
return m_window_object->internal_is_extensible();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
|
|
||||||
virtual JS::ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
|
virtual JS::ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
|
||||||
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) 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 bool internal_prevent_extensions() override;
|
||||||
virtual Optional<JS::PropertyDescriptor> internal_get_own_property(JS::PropertyName const& name) const 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;
|
virtual bool internal_define_own_property(JS::PropertyName const& name, JS::PropertyDescriptor const& descriptor) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue