mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
LibJS: Convert internal_has_property() to ThrowCompletionOr
This commit is contained in:
parent
5da210125e
commit
d9895ec12d
10 changed files with 32 additions and 32 deletions
|
@ -1403,7 +1403,7 @@ public:
|
||||||
|
|
||||||
if (interface.extended_attributes.contains("CustomHasProperty")) {
|
if (interface.extended_attributes.contains("CustomHasProperty")) {
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
virtual bool internal_has_property(JS::PropertyName const&) const override;
|
virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyName const&) const override;
|
||||||
)~~~");
|
)~~~");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ bool Object::has_property(PropertyName const& property_name) const
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
// 3. Return ? O.[[HasProperty]](P).
|
// 3. Return ? O.[[HasProperty]](P).
|
||||||
return internal_has_property(property_name);
|
return TRY_OR_DISCARD(internal_has_property(property_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.3.12 HasOwnProperty ( O, P ), https://tc39.es/ecma262/#sec-hasownproperty
|
// 7.3.12 HasOwnProperty ( O, P ), https://tc39.es/ecma262/#sec-hasownproperty
|
||||||
|
@ -616,25 +616,30 @@ ThrowCompletionOr<bool> Object::internal_define_own_property(PropertyName const&
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10.1.7 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-hasproperty-p
|
// 10.1.7 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-hasproperty-p
|
||||||
bool Object::internal_has_property(PropertyName const& property_name) const
|
ThrowCompletionOr<bool> Object::internal_has_property(PropertyName const& property_name) const
|
||||||
{
|
{
|
||||||
|
auto& vm = this->vm();
|
||||||
|
|
||||||
// 1. Assert: IsPropertyKey(P) is true.
|
// 1. Assert: IsPropertyKey(P) is true.
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
// 2. Let hasOwn be ? O.[[GetOwnProperty]](P).
|
// 2. Let hasOwn be ? O.[[GetOwnProperty]](P).
|
||||||
auto has_own = TRY_OR_DISCARD(internal_get_own_property(property_name));
|
auto has_own = TRY(internal_get_own_property(property_name));
|
||||||
|
|
||||||
// 3. If hasOwn is not undefined, return true.
|
// 3. If hasOwn is not undefined, return true.
|
||||||
if (has_own.has_value())
|
if (has_own.has_value())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// 4. Let parent be ? O.[[GetPrototypeOf]]().
|
// 4. Let parent be ? O.[[GetPrototypeOf]]().
|
||||||
auto* parent = TRY_OR_DISCARD(internal_get_prototype_of());
|
auto* parent = TRY(internal_get_prototype_of());
|
||||||
|
|
||||||
// 5. If parent is not null, then
|
// 5. If parent is not null, then
|
||||||
if (parent) {
|
if (parent) {
|
||||||
// a. Return ? parent.[[HasProperty]](P).
|
// a. Return ? parent.[[HasProperty]](P).
|
||||||
return parent->internal_has_property(property_name);
|
auto result = parent->internal_has_property(property_name);
|
||||||
|
if (auto* exception = vm.exception())
|
||||||
|
return throw_completion(exception->value());
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Return false.
|
// 6. Return false.
|
||||||
|
|
|
@ -97,7 +97,7 @@ public:
|
||||||
virtual ThrowCompletionOr<bool> internal_prevent_extensions();
|
virtual ThrowCompletionOr<bool> internal_prevent_extensions();
|
||||||
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const;
|
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const;
|
||||||
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&);
|
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&);
|
||||||
virtual bool internal_has_property(PropertyName const&) const;
|
virtual ThrowCompletionOr<bool> internal_has_property(PropertyName const&) const;
|
||||||
virtual Value internal_get(PropertyName const&, Value receiver) const;
|
virtual Value internal_get(PropertyName const&, Value receiver) const;
|
||||||
virtual bool internal_set(PropertyName const&, Value value, Value receiver);
|
virtual bool internal_set(PropertyName const&, Value value, Value receiver);
|
||||||
virtual bool internal_delete(PropertyName const&);
|
virtual bool internal_delete(PropertyName const&);
|
||||||
|
|
|
@ -416,7 +416,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_define_own_property(PropertyName c
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10.5.7 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p
|
// 10.5.7 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p
|
||||||
bool ProxyObject::internal_has_property(PropertyName const& property_name) const
|
ThrowCompletionOr<bool> ProxyObject::internal_has_property(PropertyName const& property_name) const
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
auto& global_object = this->global_object();
|
auto& global_object = this->global_object();
|
||||||
|
@ -427,16 +427,14 @@ bool ProxyObject::internal_has_property(PropertyName const& property_name) const
|
||||||
// 2. Let handler be O.[[ProxyHandler]].
|
// 2. Let handler be O.[[ProxyHandler]].
|
||||||
|
|
||||||
// 3. If handler is null, throw a TypeError exception.
|
// 3. 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 {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Assert: Type(handler) is Object.
|
// 4. Assert: Type(handler) is Object.
|
||||||
// 5. Let target be O.[[ProxyTarget]].
|
// 5. Let target be O.[[ProxyTarget]].
|
||||||
|
|
||||||
// 6. Let trap be ? GetMethod(handler, "has").
|
// 6. Let trap be ? GetMethod(handler, "has").
|
||||||
auto trap = TRY_OR_DISCARD(Value(&m_handler).get_method(global_object, vm.names.has));
|
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.has));
|
||||||
|
|
||||||
// 7. If trap is undefined, then
|
// 7. If trap is undefined, then
|
||||||
if (!trap) {
|
if (!trap) {
|
||||||
|
@ -445,31 +443,27 @@ bool ProxyObject::internal_has_property(PropertyName const& property_name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P »)).
|
// 8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P »)).
|
||||||
auto trap_result = TRY_OR_DISCARD(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name))).to_boolean();
|
auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name))).to_boolean();
|
||||||
|
|
||||||
// 9. If booleanTrapResult is false, then
|
// 9. If booleanTrapResult is false, then
|
||||||
if (!trap_result) {
|
if (!trap_result) {
|
||||||
// a. Let targetDesc be ? target.[[GetOwnProperty]](P).
|
// a. Let targetDesc be ? target.[[GetOwnProperty]](P).
|
||||||
auto target_descriptor = TRY_OR_DISCARD(m_target.internal_get_own_property(property_name));
|
auto target_descriptor = TRY(m_target.internal_get_own_property(property_name));
|
||||||
|
|
||||||
// b. If targetDesc is not undefined, then
|
// b. If targetDesc is not undefined, then
|
||||||
if (target_descriptor.has_value()) {
|
if (target_descriptor.has_value()) {
|
||||||
// i. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
|
// i. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
|
||||||
if (!*target_descriptor->configurable) {
|
if (!*target_descriptor->configurable)
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxyHasExistingNonConfigurable);
|
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyHasExistingNonConfigurable);
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ii. Let extensibleTarget be ? IsExtensible(target).
|
// ii. Let extensibleTarget be ? IsExtensible(target).
|
||||||
auto extensible_target = m_target.is_extensible();
|
auto extensible_target = m_target.is_extensible();
|
||||||
if (vm.exception())
|
if (auto* exception = vm.exception())
|
||||||
return {};
|
return throw_completion(exception->value());
|
||||||
|
|
||||||
// iii. If extensibleTarget is false, throw a TypeError exception.
|
// iii. If extensibleTarget is false, throw a TypeError exception.
|
||||||
if (!extensible_target) {
|
if (!extensible_target)
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxyHasExistingNonExtensible);
|
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyHasExistingNonExtensible);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
virtual ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
virtual ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
||||||
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const override;
|
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const override;
|
||||||
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
|
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
|
||||||
virtual bool internal_has_property(PropertyName const&) const override;
|
virtual ThrowCompletionOr<bool> internal_has_property(PropertyName const&) const override;
|
||||||
virtual Value internal_get(PropertyName const&, Value receiver) const override;
|
virtual Value internal_get(PropertyName const&, Value receiver) const override;
|
||||||
virtual bool internal_set(PropertyName const&, Value value, Value receiver) override;
|
virtual bool internal_set(PropertyName const&, Value value, Value receiver) override;
|
||||||
virtual bool internal_delete(PropertyName const&) override;
|
virtual bool internal_delete(PropertyName const&) override;
|
||||||
|
|
|
@ -231,7 +231,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::has)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 3. Return ? target.[[HasProperty]](key).
|
// 3. Return ? target.[[HasProperty]](key).
|
||||||
return Value(target.as_object().internal_has_property(key));
|
return Value(TRY_OR_DISCARD(target.as_object().internal_has_property(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 28.1.9 Reflect.isExtensible ( target ), https://tc39.es/ecma262/#sec-reflect.isextensible
|
// 28.1.9 Reflect.isExtensible ( target ), https://tc39.es/ecma262/#sec-reflect.isextensible
|
||||||
|
|
|
@ -228,7 +228,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10.4.5.2 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects-hasproperty-p
|
// 10.4.5.2 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects-hasproperty-p
|
||||||
virtual bool internal_has_property(PropertyName const& property_name) const override
|
virtual ThrowCompletionOr<bool> internal_has_property(PropertyName const& property_name) const override
|
||||||
{
|
{
|
||||||
// 1. Assert: IsPropertyKey(P) is true.
|
// 1. Assert: IsPropertyKey(P) is true.
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
|
@ -4,12 +4,13 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/Completion.h>
|
||||||
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
||||||
#include <LibWeb/DOM/Element.h>
|
#include <LibWeb/DOM/Element.h>
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
bool CSSStyleDeclarationWrapper::internal_has_property(JS::PropertyName const& name) const
|
JS::ThrowCompletionOr<bool> CSSStyleDeclarationWrapper::internal_has_property(JS::PropertyName const& name) const
|
||||||
{
|
{
|
||||||
if (!name.is_string())
|
if (!name.is_string())
|
||||||
return Base::internal_has_property(name);
|
return Base::internal_has_property(name);
|
||||||
|
|
|
@ -70,9 +70,9 @@ JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_define_own_property(JS
|
||||||
return m_window_object->internal_define_own_property(property_name, descriptor);
|
return m_window_object->internal_define_own_property(property_name, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConsoleGlobalObject::internal_has_property(JS::PropertyName const& property_name) const
|
JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_has_property(JS::PropertyName const& property_name) const
|
||||||
{
|
{
|
||||||
return Object::internal_has_property(property_name) || m_window_object->internal_has_property(property_name);
|
return TRY(Object::internal_has_property(property_name)) || TRY(m_window_object->internal_has_property(property_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value ConsoleGlobalObject::internal_get(JS::PropertyName const& property_name, JS::Value receiver) const
|
JS::Value ConsoleGlobalObject::internal_get(JS::PropertyName const& property_name, JS::Value receiver) const
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
||||||
virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyName const& name) const override;
|
virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyName const& name) const override;
|
||||||
virtual JS::ThrowCompletionOr<bool> internal_define_own_property(JS::PropertyName const& name, JS::PropertyDescriptor const& descriptor) override;
|
virtual JS::ThrowCompletionOr<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;
|
virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyName const& name) const override;
|
||||||
virtual JS::Value internal_get(JS::PropertyName const&, JS::Value) const override;
|
virtual JS::Value internal_get(JS::PropertyName const&, JS::Value) const override;
|
||||||
virtual bool internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;
|
virtual bool internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;
|
||||||
virtual bool internal_delete(JS::PropertyName const& name) override;
|
virtual bool internal_delete(JS::PropertyName const& name) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue