mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 05:57:41 +00:00
LibJS: Convert internal_prevent_extensions() to ThrowCompletionOr
This commit is contained in:
parent
9b4362f10a
commit
73bae7d779
12 changed files with 22 additions and 30 deletions
|
@ -1419,7 +1419,7 @@ public:
|
|||
virtual bool internal_set(JS::PropertyName const&, JS::Value, JS::Value) override;
|
||||
virtual bool internal_define_own_property(JS::PropertyName const&, JS::PropertyDescriptor const&) override;
|
||||
virtual bool internal_delete(JS::PropertyName const&) override;
|
||||
virtual bool internal_prevent_extensions() override;
|
||||
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
||||
virtual JS::MarkedValueList internal_own_property_keys() const override;
|
||||
)~~~");
|
||||
}
|
||||
|
@ -2293,7 +2293,7 @@ bool @class_name@::internal_delete(JS::PropertyName const& property_name)
|
|||
|
||||
// 3.9.5. [[PreventExtensions]], https://heycam.github.io/webidl/#legacy-platform-object-preventextensions
|
||||
scoped_generator.append(R"~~~(
|
||||
bool @class_name@::internal_prevent_extensions()
|
||||
JS::ThrowCompletionOr<bool> @class_name@::internal_prevent_extensions()
|
||||
{
|
||||
// 1. Return false.
|
||||
return false;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -52,7 +52,7 @@ JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_is_extensible() const
|
|||
return m_window_object->internal_is_extensible();
|
||||
}
|
||||
|
||||
bool ConsoleGlobalObject::internal_prevent_extensions()
|
||||
JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_prevent_extensions()
|
||||
{
|
||||
return m_window_object->internal_prevent_extensions();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
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_is_extensible() const override;
|
||||
virtual bool internal_prevent_extensions() override;
|
||||
virtual JS::ThrowCompletionOr<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;
|
||||
virtual bool internal_has_property(JS::PropertyName const& name) const override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue