mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:17:35 +00:00
LibJS: Convert internal_set() to ThrowCompletionOr
This commit is contained in:
parent
6c2b974db2
commit
e5409c6ead
19 changed files with 66 additions and 69 deletions
|
@ -54,7 +54,7 @@ ThrowCompletionOr<Value> ArgumentsObject::internal_get(PropertyName const& prope
|
|||
}
|
||||
|
||||
// 10.4.4.4 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-arguments-exotic-objects-set-p-v-receiver
|
||||
bool ArgumentsObject::internal_set(PropertyName const& property_name, Value value, Value receiver)
|
||||
ThrowCompletionOr<bool> ArgumentsObject::internal_set(PropertyName const& property_name, Value value, Value receiver)
|
||||
{
|
||||
bool is_mapped = false;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
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<Value> internal_get(PropertyName const&, Value receiver) const override;
|
||||
virtual bool internal_set(PropertyName const&, Value value, Value receiver) override;
|
||||
virtual ThrowCompletionOr<bool> internal_set(PropertyName const&, Value value, Value receiver) override;
|
||||
virtual bool internal_delete(PropertyName const&) override;
|
||||
|
||||
// [[ParameterMap]]
|
||||
|
|
|
@ -105,9 +105,7 @@ bool Object::set(PropertyName const& property_name, Value value, ShouldThrowExce
|
|||
// 3. Assert: Type(Throw) is Boolean.
|
||||
|
||||
// 4. Let success be ? O.[[Set]](P, V, O).
|
||||
auto success = internal_set(property_name, value, this);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto success = TRY_OR_DISCARD(internal_set(property_name, value, this));
|
||||
|
||||
// 5. If success is false and Throw is true, throw a TypeError exception.
|
||||
if (!success && throw_exceptions == ShouldThrowExceptions::Yes) {
|
||||
|
@ -690,19 +688,23 @@ ThrowCompletionOr<Value> Object::internal_get(PropertyName const& property_name,
|
|||
}
|
||||
|
||||
// 10.1.9 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver
|
||||
bool Object::internal_set(PropertyName const& property_name, Value value, Value receiver)
|
||||
ThrowCompletionOr<bool> Object::internal_set(PropertyName const& property_name, Value value, Value receiver)
|
||||
{
|
||||
VERIFY(!value.is_empty());
|
||||
VERIFY(!receiver.is_empty());
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
VERIFY(property_name.is_valid());
|
||||
|
||||
// 2. Let ownDesc be ? O.[[GetOwnProperty]](P).
|
||||
auto own_descriptor = TRY_OR_DISCARD(internal_get_own_property(property_name));
|
||||
auto own_descriptor = TRY(internal_get_own_property(property_name));
|
||||
|
||||
// 3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).
|
||||
return ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor);
|
||||
auto success = ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
return success;
|
||||
}
|
||||
|
||||
// 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ), https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
|
||||
|
@ -721,7 +723,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
|
|||
// b. If parent is not null, then
|
||||
if (parent) {
|
||||
// i. Return ? parent.[[Set]](P, V, Receiver).
|
||||
return parent->internal_set(property_name, value, receiver);
|
||||
return TRY_OR_DISCARD(parent->internal_set(property_name, value, receiver));
|
||||
}
|
||||
// c. Else,
|
||||
else {
|
||||
|
|
|
@ -99,7 +99,7 @@ public:
|
|||
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&);
|
||||
virtual ThrowCompletionOr<bool> internal_has_property(PropertyName const&) const;
|
||||
virtual ThrowCompletionOr<Value> internal_get(PropertyName const&, Value receiver) const;
|
||||
virtual bool internal_set(PropertyName const&, Value value, Value receiver);
|
||||
virtual ThrowCompletionOr<bool> internal_set(PropertyName const&, Value value, Value receiver);
|
||||
virtual bool internal_delete(PropertyName const&);
|
||||
virtual MarkedValueList internal_own_property_keys() const;
|
||||
|
||||
|
|
|
@ -543,7 +543,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_get(PropertyName const& property_
|
|||
}
|
||||
|
||||
// 10.5.9 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver
|
||||
bool ProxyObject::internal_set(PropertyName const& property_name, Value value, Value receiver)
|
||||
ThrowCompletionOr<bool> ProxyObject::internal_set(PropertyName const& property_name, Value value, Value receiver)
|
||||
{
|
||||
VERIFY(!value.is_empty());
|
||||
VERIFY(!receiver.is_empty());
|
||||
|
@ -557,16 +557,14 @@ bool ProxyObject::internal_set(PropertyName const& property_name, Value value, V
|
|||
// 2. Let handler be O.[[ProxyHandler]].
|
||||
|
||||
// 3. 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);
|
||||
|
||||
// 4. Assert: Type(handler) is Object.
|
||||
// 5. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 6. Let trap be ? GetMethod(handler, "set").
|
||||
auto trap = TRY_OR_DISCARD(Value(&m_handler).get_method(global_object, vm.names.set));
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.set));
|
||||
|
||||
// 7. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -575,32 +573,28 @@ bool ProxyObject::internal_set(PropertyName const& property_name, Value value, V
|
|||
}
|
||||
|
||||
// 8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, V, Receiver »)).
|
||||
auto trap_result = TRY_OR_DISCARD(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name), value, receiver)).to_boolean();
|
||||
auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name), value, receiver)).to_boolean();
|
||||
|
||||
// 9. If booleanTrapResult is false, return false.
|
||||
if (!trap_result)
|
||||
return false;
|
||||
|
||||
// 10. 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));
|
||||
|
||||
// 11. If targetDesc is not undefined and targetDesc.[[Configurable]] is false, then
|
||||
if (target_descriptor.has_value() && !*target_descriptor->configurable) {
|
||||
// a. If IsDataDescriptor(targetDesc) is true and targetDesc.[[Writable]] is false, then
|
||||
if (target_descriptor->is_data_descriptor() && !*target_descriptor->writable) {
|
||||
// i. If SameValue(V, targetDesc.[[Value]]) is false, throw a TypeError exception.
|
||||
if (!same_value(value, *target_descriptor->value)) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxySetImmutableDataProperty);
|
||||
return {};
|
||||
}
|
||||
if (!same_value(value, *target_descriptor->value))
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxySetImmutableDataProperty);
|
||||
}
|
||||
// b. If IsAccessorDescriptor(targetDesc) is true, then
|
||||
if (target_descriptor->is_accessor_descriptor()) {
|
||||
// i. If targetDesc.[[Set]] is undefined, throw a TypeError exception.
|
||||
if (!*target_descriptor->set) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxySetNonConfigurableAccessor);
|
||||
return {};
|
||||
}
|
||||
if (!*target_descriptor->set)
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxySetNonConfigurableAccessor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
|
||||
virtual ThrowCompletionOr<bool> internal_has_property(PropertyName const&) const override;
|
||||
virtual ThrowCompletionOr<Value> internal_get(PropertyName const&, Value receiver) const override;
|
||||
virtual bool internal_set(PropertyName const&, Value value, Value receiver) override;
|
||||
virtual ThrowCompletionOr<bool> internal_set(PropertyName const&, Value value, Value receiver) override;
|
||||
virtual bool internal_delete(PropertyName const&) override;
|
||||
virtual MarkedValueList internal_own_property_keys() const override;
|
||||
|
||||
|
|
|
@ -39,9 +39,10 @@ void Reference::put_value(GlobalObject& global_object, Value value)
|
|||
if (!base_obj)
|
||||
return;
|
||||
|
||||
bool succeeded = base_obj->internal_set(m_name, value, get_this_value());
|
||||
if (vm.exception())
|
||||
auto succeeded_or_error = base_obj->internal_set(m_name, value, get_this_value());
|
||||
if (succeeded_or_error.is_error())
|
||||
return;
|
||||
auto succeeded = succeeded_or_error.release_value();
|
||||
if (!succeeded && m_strict) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::ReferenceNullishSetProperty, m_name, m_base_value.to_string_without_side_effects());
|
||||
return;
|
||||
|
|
|
@ -310,7 +310,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set)
|
|||
}
|
||||
|
||||
// 4. Return ? target.[[Set]](key, V, receiver).
|
||||
return Value(target.as_object().internal_set(key, value, receiver));
|
||||
return Value(TRY_OR_DISCARD(target.as_object().internal_set(key, value, receiver)));
|
||||
}
|
||||
|
||||
// 28.1.13 Reflect.setPrototypeOf ( target, proto ), https://tc39.es/ecma262/#sec-reflect.setprototypeof
|
||||
|
|
|
@ -336,7 +336,7 @@ public:
|
|||
}
|
||||
|
||||
// 10.4.5.5 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects-set-p-v-receiver
|
||||
virtual bool internal_set(PropertyName const& property_name, Value value, Value receiver) override
|
||||
virtual ThrowCompletionOr<bool> internal_set(PropertyName const& property_name, Value value, Value receiver) override
|
||||
{
|
||||
VERIFY(!value.is_empty());
|
||||
VERIFY(!receiver.is_empty());
|
||||
|
@ -356,8 +356,8 @@ public:
|
|||
if (!numeric_index.is_undefined()) {
|
||||
// i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
|
||||
integer_indexed_element_set<T>(*this, numeric_index, value);
|
||||
if (vm().exception())
|
||||
return {};
|
||||
if (auto* exception = vm().exception())
|
||||
return throw_completion(exception->value());
|
||||
|
||||
// ii. Return true.
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue