summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-29 17:54:25 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-29 23:49:53 +0100
commit5da210125e1ae62278ddf708ad85b037f1891a81 (patch)
treea184dafd5fe0707a7a3890df0cd6a7f97294f902 /Userland
parent0e69a6e487a3d00b329e01bd21b5acfce9070765 (diff)
downloadserenity-5da210125e1ae62278ddf708ad85b037f1891a81.zip
LibJS: Convert internal_define_own_property() to ThrowCompletionOr
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArgumentsObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Array.cpp11
-rw-r--r--Userland/Libraries/LibJS/Runtime/Array.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp20
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp51
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ReflectObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.h6
-rw-r--r--Userland/Libraries/LibWeb/Bindings/Replaceable.h15
-rw-r--r--Userland/Services/WebContent/ConsoleGlobalObject.cpp2
-rw-r--r--Userland/Services/WebContent/ConsoleGlobalObject.h2
15 files changed, 60 insertions, 67 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp
index 4fc89d52ae..9edd408f31 100644
--- a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp
@@ -123,7 +123,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ArgumentsObject::internal_get_ow
}
// 10.4.4.2 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-arguments-exotic-objects-defineownproperty-p-desc
-bool ArgumentsObject::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& descriptor)
+ThrowCompletionOr<bool> ArgumentsObject::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& descriptor)
{
// 1. Let map be args.[[ParameterMap]].
auto& map = parameter_map();
@@ -146,9 +146,7 @@ bool ArgumentsObject::internal_define_own_property(PropertyName const& property_
}
// 5. Let allowed be ? OrdinaryDefineOwnProperty(args, P, newArgDesc).
- bool allowed = Object::internal_define_own_property(property_name, new_arg_desc);
- if (vm().exception())
- return false;
+ bool allowed = TRY(Object::internal_define_own_property(property_name, new_arg_desc));
// 6. If allowed is false, return false.
if (!allowed)
diff --git a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h
index 11e85076a5..947b374091 100644
--- a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h
+++ b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h
@@ -24,7 +24,7 @@ public:
Environment& environment() { return m_environment; }
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const override;
- virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
+ virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor 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_delete(PropertyName const&) override;
diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp
index af20cd0c4b..5133d13947 100644
--- a/Userland/Libraries/LibJS/Runtime/Array.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Array.cpp
@@ -24,7 +24,7 @@ Array* Array::create(GlobalObject& global_object, size_t length, Object* prototy
if (!prototype)
prototype = global_object.array_prototype();
auto* array = global_object.heap().allocate<Array>(global_object, *prototype);
- array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false });
+ (void)array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false });
return array;
}
@@ -168,7 +168,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> Array::internal_get_own_property
}
// 10.4.2.1 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-array-exotic-objects-defineownproperty-p-desc
-bool Array::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
+ThrowCompletionOr<bool> Array::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
{
auto& vm = this->vm();
@@ -178,7 +178,10 @@ bool Array::internal_define_own_property(PropertyName const& property_name, Prop
// 2. If P is "length", then
if (property_name.is_string() && property_name.as_string() == vm.names.length.as_string()) {
// a. Return ? ArraySetLength(A, Desc).
- return set_length(property_descriptor);
+ auto success = set_length(property_descriptor);
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
+ return success;
}
// 3. Else if P is an array index, then
@@ -195,7 +198,7 @@ bool Array::internal_define_own_property(PropertyName const& property_name, Prop
return false;
// h. Let succeeded be ! OrdinaryDefineOwnProperty(A, P, Desc).
- auto succeeded = Object::internal_define_own_property(property_name, property_descriptor);
+ auto succeeded = Object::internal_define_own_property(property_name, property_descriptor).release_value();
// i. If succeeded is false, return false.
if (!succeeded)
return false;
diff --git a/Userland/Libraries/LibJS/Runtime/Array.h b/Userland/Libraries/LibJS/Runtime/Array.h
index d8c432705c..a89b4ff5fc 100644
--- a/Userland/Libraries/LibJS/Runtime/Array.h
+++ b/Userland/Libraries/LibJS/Runtime/Array.h
@@ -39,7 +39,7 @@ public:
virtual ~Array() override;
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const override;
- virtual 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_delete(PropertyName const&) override;
virtual MarkedValueList internal_own_property_keys() const override;
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index 78da28bf89..bff0be6cd1 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -137,7 +137,7 @@ bool Object::create_data_property(PropertyName const& property_name, Value value
};
// 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
- return internal_define_own_property(property_name, new_descriptor);
+ return TRY_OR_DISCARD(internal_define_own_property(property_name, new_descriptor));
}
// 7.3.6 CreateMethodProperty ( O, P, V ), https://tc39.es/ecma262/#sec-createmethodproperty
@@ -159,7 +159,7 @@ bool Object::create_method_property(PropertyName const& property_name, Value val
};
// 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
- return internal_define_own_property(property_name, new_descriptor);
+ return TRY_OR_DISCARD(internal_define_own_property(property_name, new_descriptor));
}
// 7.3.7 CreateDataPropertyOrThrow ( O, P, V ), https://tc39.es/ecma262/#sec-createdatapropertyorthrow
@@ -213,9 +213,7 @@ bool Object::define_property_or_throw(PropertyName const& property_name, Propert
VERIFY(property_name.is_valid());
// 3. Let success be ? O.[[DefineOwnProperty]](P, desc).
- auto success = internal_define_own_property(property_name, property_descriptor);
- if (vm.exception())
- return {};
+ auto success = TRY_OR_DISCARD(internal_define_own_property(property_name, property_descriptor));
// 4. If success is false, throw a TypeError exception.
if (!success) {
@@ -600,18 +598,18 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> Object::internal_get_own_propert
}
// 10.1.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc
-bool Object::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
+ThrowCompletionOr<bool> Object::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
{
VERIFY(property_name.is_valid());
auto& vm = this->vm();
// 1. Let current be ? O.[[GetOwnProperty]](P).
- auto current = TRY_OR_DISCARD(internal_get_own_property(property_name));
+ auto current = TRY(internal_get_own_property(property_name));
// 2. Let extensible be ? IsExtensible(O).
auto extensible = is_extensible();
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current).
return validate_and_apply_property_descriptor(this, property_name, extensible, property_descriptor, current);
@@ -759,7 +757,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
auto value_descriptor = PropertyDescriptor { .value = value };
// iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
- return receiver.as_object().internal_define_own_property(property_name, value_descriptor);
+ return TRY_OR_DISCARD(receiver.as_object().internal_define_own_property(property_name, value_descriptor));
}
// e. Else,
else {
@@ -783,6 +781,8 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
// 7. Perform ? Call(setter, Receiver, « V »).
(void)vm.call(*setter, receiver, value);
+ if (vm.exception())
+ return {};
// 8. Return true.
return true;
diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h
index ef1daa4de0..a34cd26c23 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.h
+++ b/Userland/Libraries/LibJS/Runtime/Object.h
@@ -96,7 +96,7 @@ public:
virtual ThrowCompletionOr<bool> internal_is_extensible() const;
virtual ThrowCompletionOr<bool> internal_prevent_extensions();
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const;
- virtual 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 Value internal_get(PropertyName const&, Value receiver) const;
virtual bool internal_set(PropertyName const&, Value value, Value receiver);
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
index c345b3788f..cb77da735c 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -330,7 +330,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr
}
// 10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc
-bool ProxyObject::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
+ThrowCompletionOr<bool> ProxyObject::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
@@ -341,16 +341,14 @@ bool ProxyObject::internal_define_own_property(PropertyName const& property_name
// 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, "defineProperty").
- auto trap = TRY_OR_DISCARD(Value(&m_handler).get_method(global_object, vm.names.defineProperty));
+ auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.defineProperty));
// 7. If trap is undefined, then
if (!trap) {
@@ -362,19 +360,19 @@ bool ProxyObject::internal_define_own_property(PropertyName const& property_name
auto descriptor_object = from_property_descriptor(global_object, property_descriptor);
// 9. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, descObj »)).
- auto trap_result = TRY_OR_DISCARD(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name), descriptor_object)).to_boolean();
+ auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name), descriptor_object)).to_boolean();
// 10. If booleanTrapResult is false, return false.
if (!trap_result)
return false;
// 11. 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));
// 12. 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());
// 14. Else, let settingConfigFalse be false.
bool setting_config_false = false;
@@ -388,35 +386,28 @@ bool ProxyObject::internal_define_own_property(PropertyName const& property_name
// 15. If targetDesc is undefined, then
if (!target_descriptor.has_value()) {
// a. If extensibleTarget is false, throw a TypeError exception.
- if (!extensible_target) {
- vm.throw_exception<TypeError>(global_object, ErrorType::ProxyDefinePropNonExtensible);
- return {};
- }
+ if (!extensible_target)
+ return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyDefinePropNonExtensible);
+
// b. If settingConfigFalse is true, throw a TypeError exception.
- if (setting_config_false) {
- vm.throw_exception<TypeError>(global_object, ErrorType::ProxyDefinePropNonConfigurableNonExisting);
- return {};
- }
+ if (setting_config_false)
+ return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyDefinePropNonConfigurableNonExisting);
}
// 16. Else,
else {
// a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc, targetDesc) is false, throw a TypeError exception.
- if (!is_compatible_property_descriptor(extensible_target, property_descriptor, target_descriptor)) {
- vm.throw_exception<TypeError>(global_object, ErrorType::ProxyDefinePropIncompatibleDescriptor);
- return {};
- }
+ if (!is_compatible_property_descriptor(extensible_target, property_descriptor, target_descriptor))
+ return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyDefinePropIncompatibleDescriptor);
+
// b. If settingConfigFalse is true and targetDesc.[[Configurable]] is true, throw a TypeError exception.
- if (setting_config_false && *target_descriptor->configurable) {
- vm.throw_exception<TypeError>(global_object, ErrorType::ProxyDefinePropExistingConfigurable);
- return {};
- }
+ if (setting_config_false && *target_descriptor->configurable)
+ return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyDefinePropExistingConfigurable);
+
// c. If IsDataDescriptor(targetDesc) is true, targetDesc.[[Configurable]] is false, and targetDesc.[[Writable]] is true, then
if (target_descriptor->is_data_descriptor() && !*target_descriptor->configurable && *target_descriptor->writable) {
// i. If Desc has a [[Writable]] field and Desc.[[Writable]] is false, throw a TypeError exception.
- if (property_descriptor.writable.has_value() && !*property_descriptor.writable) {
- vm.throw_exception<TypeError>(global_object, ErrorType::ProxyDefinePropNonWritable);
- return {};
- }
+ if (property_descriptor.writable.has_value() && !*property_descriptor.writable)
+ return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyDefinePropNonWritable);
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.h b/Userland/Libraries/LibJS/Runtime/ProxyObject.h
index c410a15c39..e54025f47e 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.h
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.h
@@ -40,7 +40,7 @@ public:
virtual ThrowCompletionOr<bool> internal_is_extensible() const override;
virtual ThrowCompletionOr<bool> internal_prevent_extensions() override;
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const override;
- virtual 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 Value internal_get(PropertyName const&, Value receiver) const override;
virtual bool internal_set(PropertyName const&, Value value, Value receiver) override;
diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
index bec3c3c746..262d40f171 100644
--- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
@@ -122,7 +122,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::define_property)
return {};
// 4. Return ? target.[[DefineOwnProperty]](key, desc).
- return Value(target.as_object().internal_define_own_property(key, descriptor));
+ return Value(TRY_OR_DISCARD(target.as_object().internal_define_own_property(key, descriptor)));
}
// 28.1.4 Reflect.deleteProperty ( target, propertyKey ), https://tc39.es/ecma262/#sec-reflect.deleteproperty
diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.cpp b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
index 6002d27e7a..f5f8cea400 100644
--- a/Userland/Libraries/LibJS/Runtime/StringObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
@@ -108,7 +108,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> StringObject::internal_get_own_p
}
// 10.4.3.2 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-string-exotic-objects-defineownproperty-p-desc
-bool StringObject::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
+ThrowCompletionOr<bool> StringObject::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
{
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.h b/Userland/Libraries/LibJS/Runtime/StringObject.h
index b0ef348f2b..a8b5d10798 100644
--- a/Userland/Libraries/LibJS/Runtime/StringObject.h
+++ b/Userland/Libraries/LibJS/Runtime/StringObject.h
@@ -28,7 +28,7 @@ public:
private:
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const override;
- virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
+ virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
virtual MarkedValueList internal_own_property_keys() const override;
virtual bool is_string_object() const final { return true; }
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h
index 721b340aea..f9be919cd2 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.h
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h
@@ -254,7 +254,7 @@ public:
}
// 10.4.5.3 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects-defineownproperty-p-desc
- virtual bool internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor) override
+ virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor) override
{
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
@@ -295,8 +295,8 @@ public:
// vi. If Desc has a [[Value]] field, perform ? IntegerIndexedElementSet(O, numericIndex, Desc.[[Value]]).
if (property_descriptor.value.has_value()) {
integer_indexed_element_set<T>(*this, numeric_index, *property_descriptor.value);
- if (vm().exception())
- return {};
+ if (auto* exception = vm().exception())
+ return throw_completion(exception->value());
}
// vii. Return true.
diff --git a/Userland/Libraries/LibWeb/Bindings/Replaceable.h b/Userland/Libraries/LibWeb/Bindings/Replaceable.h
index 6617922fe9..fce41f813c 100644
--- a/Userland/Libraries/LibWeb/Bindings/Replaceable.h
+++ b/Userland/Libraries/LibWeb/Bindings/Replaceable.h
@@ -6,11 +6,12 @@
#pragma once
-#define REPLACEABLE_PROPERTY_SETTER(ObjectType, property) \
- auto this_value = vm.this_value(global_object); \
- if (!this_value.is_object() || !is<ObjectType>(this_value.as_object())) { \
- vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, #ObjectType); \
- return {}; \
- } \
- this_value.as_object().internal_define_own_property(#property, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true }); \
+#define REPLACEABLE_PROPERTY_SETTER(ObjectType, property) \
+ auto this_value = vm.this_value(global_object); \
+ if (!this_value.is_object() || !is<ObjectType>(this_value.as_object())) { \
+ vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, #ObjectType); \
+ return {}; \
+ } \
+ TRY_OR_DISCARD(this_value.as_object().internal_define_own_property( \
+ #property, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true })); \
return JS::js_undefined();
diff --git a/Userland/Services/WebContent/ConsoleGlobalObject.cpp b/Userland/Services/WebContent/ConsoleGlobalObject.cpp
index e835bc520d..59427ecaf2 100644
--- a/Userland/Services/WebContent/ConsoleGlobalObject.cpp
+++ b/Userland/Services/WebContent/ConsoleGlobalObject.cpp
@@ -65,7 +65,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> ConsoleGlobalObject::int
return Base::internal_get_own_property(property_name);
}
-bool ConsoleGlobalObject::internal_define_own_property(JS::PropertyName const& property_name, JS::PropertyDescriptor const& descriptor)
+JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_define_own_property(JS::PropertyName const& property_name, JS::PropertyDescriptor const& descriptor)
{
return m_window_object->internal_define_own_property(property_name, descriptor);
}
diff --git a/Userland/Services/WebContent/ConsoleGlobalObject.h b/Userland/Services/WebContent/ConsoleGlobalObject.h
index e0a54e43fe..ab03375236 100644
--- a/Userland/Services/WebContent/ConsoleGlobalObject.h
+++ b/Userland/Services/WebContent/ConsoleGlobalObject.h
@@ -28,7 +28,7 @@ public:
virtual JS::ThrowCompletionOr<bool> internal_is_extensible() const 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 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::Value internal_get(JS::PropertyName const&, JS::Value) const override;
virtual bool internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;