diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-10-29 17:08:28 -0400 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-31 07:50:30 +0200 |
commit | d1abf3d8ce91d1a060b1c06ac50d1c36367ca6e3 (patch) | |
tree | 6714e2814483c405dfdbaa5b75324781a5e32b37 | |
parent | 0f224779aaa881c57fc52b9b70aed648c9248d38 (diff) | |
download | serenity-d1abf3d8ce91d1a060b1c06ac50d1c36367ca6e3.zip |
LibJS: Convert ObjectConstructor to ThrowCompletionOr
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp | 208 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ObjectConstructor.h | 44 |
2 files changed, 119 insertions, 133 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 81137622b2..5ad4293a26 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -31,28 +31,28 @@ void ObjectConstructor::initialize(GlobalObject& global_object) define_direct_property(vm.names.prototype, global_object.object_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; - define_old_native_function(vm.names.defineProperty, define_property, 3, attr); - define_old_native_function(vm.names.defineProperties, define_properties, 2, attr); - define_old_native_function(vm.names.is, is, 2, attr); - define_old_native_function(vm.names.getOwnPropertyDescriptor, get_own_property_descriptor, 2, attr); - define_old_native_function(vm.names.getOwnPropertyDescriptors, get_own_property_descriptors, 1, attr); - define_old_native_function(vm.names.getOwnPropertyNames, get_own_property_names, 1, attr); - define_old_native_function(vm.names.getOwnPropertySymbols, get_own_property_symbols, 1, attr); - define_old_native_function(vm.names.getPrototypeOf, get_prototype_of, 1, attr); - define_old_native_function(vm.names.setPrototypeOf, set_prototype_of, 2, attr); - define_old_native_function(vm.names.isExtensible, is_extensible, 1, attr); - define_old_native_function(vm.names.isFrozen, is_frozen, 1, attr); - define_old_native_function(vm.names.isSealed, is_sealed, 1, attr); - define_old_native_function(vm.names.preventExtensions, prevent_extensions, 1, attr); - define_old_native_function(vm.names.freeze, freeze, 1, attr); - define_old_native_function(vm.names.fromEntries, from_entries, 1, attr); - define_old_native_function(vm.names.seal, seal, 1, attr); - define_old_native_function(vm.names.keys, keys, 1, attr); - define_old_native_function(vm.names.values, values, 1, attr); - define_old_native_function(vm.names.entries, entries, 1, attr); - define_old_native_function(vm.names.create, create, 2, attr); - define_old_native_function(vm.names.hasOwn, has_own, 2, attr); - define_old_native_function(vm.names.assign, assign, 2, attr); + define_native_function(vm.names.defineProperty, define_property, 3, attr); + define_native_function(vm.names.defineProperties, define_properties, 2, attr); + define_native_function(vm.names.is, is, 2, attr); + define_native_function(vm.names.getOwnPropertyDescriptor, get_own_property_descriptor, 2, attr); + define_native_function(vm.names.getOwnPropertyDescriptors, get_own_property_descriptors, 1, attr); + define_native_function(vm.names.getOwnPropertyNames, get_own_property_names, 1, attr); + define_native_function(vm.names.getOwnPropertySymbols, get_own_property_symbols, 1, attr); + define_native_function(vm.names.getPrototypeOf, get_prototype_of, 1, attr); + define_native_function(vm.names.setPrototypeOf, set_prototype_of, 2, attr); + define_native_function(vm.names.isExtensible, is_extensible, 1, attr); + define_native_function(vm.names.isFrozen, is_frozen, 1, attr); + define_native_function(vm.names.isSealed, is_sealed, 1, attr); + define_native_function(vm.names.preventExtensions, prevent_extensions, 1, attr); + define_native_function(vm.names.freeze, freeze, 1, attr); + define_native_function(vm.names.fromEntries, from_entries, 1, attr); + define_native_function(vm.names.seal, seal, 1, attr); + define_native_function(vm.names.keys, keys, 1, attr); + define_native_function(vm.names.values, values, 1, attr); + define_native_function(vm.names.entries, entries, 1, attr); + define_native_function(vm.names.create, create, 2, attr); + define_native_function(vm.names.hasOwn, has_own, 2, attr); + define_native_function(vm.names.assign, assign, 2, attr); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -114,55 +114,52 @@ static ThrowCompletionOr<Array*> get_own_property_keys(GlobalObject& global_obje } // 20.1.2.10 Object.getOwnPropertyNames ( O ), https://tc39.es/ecma262/#sec-object.getownpropertynames -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) { // 1. Return ? GetOwnPropertyKeys(O, string). - return TRY_OR_DISCARD(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::String)); + return TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::String)); } // 20.1.2.11 Object.getOwnPropertySymbols ( O ), https://tc39.es/ecma262/#sec-object.getownpropertysymbols -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols) { // 1. Return ? GetOwnPropertyKeys(O, symbol). - return TRY_OR_DISCARD(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::Symbol)); + return TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::Symbol)); } // 20.1.2.12 Object.getPrototypeOf ( O ), https://tc39.es/ecma262/#sec-object.getprototypeof -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of) { // 1. Let obj be ? ToObject(O). - auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); + auto* object = TRY(vm.argument(0).to_object(global_object)); // 2. Return ? obj.[[GetPrototypeOf]](). - return TRY_OR_DISCARD(object->internal_get_prototype_of()); + return TRY(object->internal_get_prototype_of()); } // 20.1.2.22 Object.setPrototypeOf ( O, proto ), https://tc39.es/ecma262/#sec-object.setprototypeof -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of) { auto proto = vm.argument(1); // 1. Set O to ? RequireObjectCoercible(O). - auto object = TRY_OR_DISCARD(require_object_coercible(global_object, vm.argument(0))); + auto object = TRY(require_object_coercible(global_object, vm.argument(0))); // 2. If Type(proto) is neither Object nor Null, throw a TypeError exception. - if (!proto.is_object() && !proto.is_null()) { - vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPrototypeWrongType); - return {}; - } + if (!proto.is_object() && !proto.is_null()) + return vm.throw_completion<TypeError>(global_object, ErrorType::ObjectPrototypeWrongType); // 3. If Type(O) is not Object, return O. if (!object.is_object()) return object; // 4. Let status be ? O.[[SetPrototypeOf]](proto). - auto status = TRY_OR_DISCARD(object.as_object().internal_set_prototype_of(proto.is_null() ? nullptr : &proto.as_object())); + auto status = TRY(object.as_object().internal_set_prototype_of(proto.is_null() ? nullptr : &proto.as_object())); // 5. If status is false, throw a TypeError exception. if (!status) { // FIXME: Improve/contextualize error message - vm.throw_exception<TypeError>(global_object, ErrorType::ObjectSetPrototypeOfReturnedFalse); - return {}; + return vm.throw_completion<TypeError>(global_object, ErrorType::ObjectSetPrototypeOfReturnedFalse); } // 6. Return O. @@ -170,69 +167,66 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of) } // 20.1.2.15 Object.isExtensible ( O ), https://tc39.es/ecma262/#sec-object.isextensible -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::is_extensible) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible) { auto argument = vm.argument(0); if (!argument.is_object()) return Value(false); - return Value(TRY_OR_DISCARD(argument.as_object().is_extensible())); + return Value(TRY(argument.as_object().is_extensible())); } // 20.1.2.16 Object.isFrozen ( O ), https://tc39.es/ecma262/#sec-object.isfrozen -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::is_frozen) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_frozen) { auto argument = vm.argument(0); if (!argument.is_object()) return Value(true); - return Value(TRY_OR_DISCARD(argument.as_object().test_integrity_level(Object::IntegrityLevel::Frozen))); + return Value(TRY(argument.as_object().test_integrity_level(Object::IntegrityLevel::Frozen))); } // 20.1.2.17 Object.isSealed ( O ), https://tc39.es/ecma262/#sec-object.issealed -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::is_sealed) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_sealed) { auto argument = vm.argument(0); if (!argument.is_object()) return Value(true); - return Value(TRY_OR_DISCARD(argument.as_object().test_integrity_level(Object::IntegrityLevel::Sealed))); + return Value(TRY(argument.as_object().test_integrity_level(Object::IntegrityLevel::Sealed))); } // 20.1.2.19 Object.preventExtensions ( O ), https://tc39.es/ecma262/#sec-object.preventextensions -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions) { auto argument = vm.argument(0); if (!argument.is_object()) return argument; - auto status = TRY_OR_DISCARD(argument.as_object().internal_prevent_extensions()); + auto status = TRY(argument.as_object().internal_prevent_extensions()); if (!status) { // FIXME: Improve/contextualize error message - vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPreventExtensionsReturnedFalse); - return {}; + return vm.throw_completion<TypeError>(global_object, ErrorType::ObjectPreventExtensionsReturnedFalse); } return argument; } // 20.1.2.6 Object.freeze ( O ), https://tc39.es/ecma262/#sec-object.freeze -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::freeze) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::freeze) { auto argument = vm.argument(0); if (!argument.is_object()) return argument; - auto status = TRY_OR_DISCARD(argument.as_object().set_integrity_level(Object::IntegrityLevel::Frozen)); - if (!status) { - vm.throw_exception<TypeError>(global_object, ErrorType::ObjectFreezeFailed); - return {}; - } + auto status = TRY(argument.as_object().set_integrity_level(Object::IntegrityLevel::Frozen)); + if (!status) + return vm.throw_completion<TypeError>(global_object, ErrorType::ObjectFreezeFailed); return argument; } // 20.1.2.7 Object.fromEntries ( iterable ), https://tc39.es/ecma262/#sec-object.fromentries -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::from_entries) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries) { - auto iterable = TRY_OR_DISCARD(require_object_coercible(global_object, vm.argument(0))); + auto iterable = TRY(require_object_coercible(global_object, vm.argument(0))); auto* object = Object::create(global_object, global_object.object_prototype()); - TRY_OR_DISCARD(get_iterator_values(global_object, iterable, [&](Value iterator_value) -> Optional<Completion> { + TRY(get_iterator_values(global_object, iterable, [&](Value iterator_value) -> Optional<Completion> { if (!iterator_value.is_object()) return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, String::formatted("Iterator value {}", iterator_value.to_string_without_side_effects())); @@ -249,36 +243,34 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::from_entries) } // 20.1.2.21 Object.seal ( O ), https://tc39.es/ecma262/#sec-object.seal -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::seal) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::seal) { auto argument = vm.argument(0); if (!argument.is_object()) return argument; - auto status = TRY_OR_DISCARD(argument.as_object().set_integrity_level(Object::IntegrityLevel::Sealed)); - if (!status) { - vm.throw_exception<TypeError>(global_object, ErrorType::ObjectSealFailed); - return {}; - } + auto status = TRY(argument.as_object().set_integrity_level(Object::IntegrityLevel::Sealed)); + if (!status) + return vm.throw_completion<TypeError>(global_object, ErrorType::ObjectSealFailed); return argument; } // 20.1.2.8 Object.getOwnPropertyDescriptor ( O, P ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptor -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor) { - auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); - auto key = TRY_OR_DISCARD(vm.argument(1).to_property_key(global_object)); - auto descriptor = TRY_OR_DISCARD(object->internal_get_own_property(key)); + auto* object = TRY(vm.argument(0).to_object(global_object)); + auto key = TRY(vm.argument(1).to_property_key(global_object)); + auto descriptor = TRY(object->internal_get_own_property(key)); return from_property_descriptor(global_object, descriptor); } // 20.1.2.9 Object.getOwnPropertyDescriptors ( O ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptors -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) { // 1. Let obj be ? ToObject(O). - auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); + auto* object = TRY(vm.argument(0).to_object(global_object)); // 2. Let ownKeys be ? obj.[[OwnPropertyKeys]](). - auto own_keys = TRY_OR_DISCARD(object->internal_own_property_keys()); + auto own_keys = TRY(object->internal_own_property_keys()); // 3. Let descriptors be ! OrdinaryObjectCreate(%Object.prototype%). auto* descriptors = Object::create(global_object, global_object.object_prototype()); @@ -288,7 +280,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) auto property_name = PropertyKey::from_value(global_object, key); // a. Let desc be ? obj.[[GetOwnProperty]](key). - auto desc = TRY_OR_DISCARD(object->internal_get_own_property(property_name)); + auto desc = TRY(object->internal_get_own_property(property_name)); // b. Let descriptor be ! FromPropertyDescriptor(desc). auto descriptor = from_property_descriptor(global_object, desc); @@ -303,75 +295,69 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) } // 20.1.2.4 Object.defineProperty ( O, P, Attributes ), https://tc39.es/ecma262/#sec-object.defineproperty -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::define_property) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property) { - if (!vm.argument(0).is_object()) { - vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, vm.argument(0).to_string_without_side_effects()); - return {}; - } - auto key = TRY_OR_DISCARD(vm.argument(1).to_property_key(global_object)); - auto descriptor = TRY_OR_DISCARD(to_property_descriptor(global_object, vm.argument(2))); - TRY_OR_DISCARD(vm.argument(0).as_object().define_property_or_throw(key, descriptor)); + if (!vm.argument(0).is_object()) + return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, vm.argument(0).to_string_without_side_effects()); + auto key = TRY(vm.argument(1).to_property_key(global_object)); + auto descriptor = TRY(to_property_descriptor(global_object, vm.argument(2))); + TRY(vm.argument(0).as_object().define_property_or_throw(key, descriptor)); return vm.argument(0); } // 20.1.2.3 Object.defineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-object.defineproperties -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::define_properties) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_properties) { auto object = vm.argument(0); auto properties = vm.argument(1); // 1. If Type(O) is not Object, throw a TypeError exception. - if (!object.is_object()) { - vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, "Object argument"); - return {}; - } + if (!object.is_object()) + return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, "Object argument"); // 2. Return ? ObjectDefineProperties(O, Properties). - return TRY_OR_DISCARD(object.as_object().define_properties(properties)); + return TRY(object.as_object().define_properties(properties)); } // 20.1.2.14 Object.is ( value1, value2 ), https://tc39.es/ecma262/#sec-object.is -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::is) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is) { return Value(same_value(vm.argument(0), vm.argument(1))); } // 20.1.2.18 Object.keys ( O ), https://tc39.es/ecma262/#sec-object.keys -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::keys) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) { - auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); - auto name_list = TRY_OR_DISCARD(object->enumerable_own_property_names(PropertyKind::Key)); + auto* object = TRY(vm.argument(0).to_object(global_object)); + auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Key)); return Array::create_from(global_object, name_list); } // 20.1.2.23 Object.values ( O ), https://tc39.es/ecma262/#sec-object.values -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::values) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) { - auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); - auto name_list = TRY_OR_DISCARD(object->enumerable_own_property_names(PropertyKind::Value)); + auto* object = TRY(vm.argument(0).to_object(global_object)); + auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Value)); return Array::create_from(global_object, name_list); } // 20.1.2.5 Object.entries ( O ), https://tc39.es/ecma262/#sec-object.entries -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::entries) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) { - auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); - auto name_list = TRY_OR_DISCARD(object->enumerable_own_property_names(PropertyKind::KeyAndValue)); + auto* object = TRY(vm.argument(0).to_object(global_object)); + auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::KeyAndValue)); return Array::create_from(global_object, name_list); } // 20.1.2.2 Object.create ( O, Properties ), https://tc39.es/ecma262/#sec-object.create -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::create) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create) { auto proto = vm.argument(0); auto properties = vm.argument(1); // 1. If Type(O) is neither Object nor Null, throw a TypeError exception. - if (!proto.is_object() && !proto.is_null()) { - vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPrototypeWrongType); - return {}; - } + if (!proto.is_object() && !proto.is_null()) + return vm.throw_completion<TypeError>(global_object, ErrorType::ObjectPrototypeWrongType); // 2. Let obj be ! OrdinaryObjectCreate(O). auto* object = Object::create(global_object, proto.is_null() ? nullptr : &proto.as_object()); @@ -379,7 +365,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::create) // 3. If Properties is not undefined, then if (!properties.is_undefined()) { // a. Return ? ObjectDefineProperties(obj, Properties). - return TRY_OR_DISCARD(object->define_properties(properties)); + return TRY(object->define_properties(properties)); } // 4. Return obj. @@ -387,23 +373,23 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::create) } // 20.1.2.13 Object.hasOwn ( O, P ), https://tc39.es/ecma262/#sec-object.hasown -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::has_own) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::has_own) { // 1. Let obj be ? ToObject(O). - auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); + auto* object = TRY(vm.argument(0).to_object(global_object)); // 2. Let key be ? ToPropertyKey(P). - auto key = TRY_OR_DISCARD(vm.argument(1).to_property_key(global_object)); + auto key = TRY(vm.argument(1).to_property_key(global_object)); // 3. Return ? HasOwnProperty(obj, key). - return Value(TRY_OR_DISCARD(object->has_own_property(key))); + return Value(TRY(object->has_own_property(key))); } // 20.1.2.1 Object.assign ( target, ...sources ), https://tc39.es/ecma262/#sec-object.assign -JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::assign) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::assign) { // 1. Let to be ? ToObject(target). - auto* to = TRY_OR_DISCARD(vm.argument(0).to_object(global_object)); + auto* to = TRY(vm.argument(0).to_object(global_object)); // 2. If only one argument was passed, return to. if (vm.argument_count() == 1) @@ -421,24 +407,24 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ObjectConstructor::assign) auto* from = MUST(next_source.to_object(global_object)); // ii. Let keys be ? from.[[OwnPropertyKeys]](). - auto keys = TRY_OR_DISCARD(from->internal_own_property_keys()); + auto keys = TRY(from->internal_own_property_keys()); // iii. For each element nextKey of keys, do for (auto& next_key : keys) { auto property_name = PropertyKey::from_value(global_object, next_key); // 1. Let desc be ? from.[[GetOwnProperty]](nextKey). - auto desc = TRY_OR_DISCARD(from->internal_get_own_property(property_name)); + auto desc = TRY(from->internal_get_own_property(property_name)); // 2. If desc is not undefined and desc.[[Enumerable]] is true, then if (!desc.has_value() || !*desc->enumerable) continue; // a. Let propValue be ? Get(from, nextKey). - auto prop_value = TRY_OR_DISCARD(from->get(property_name)); + auto prop_value = TRY(from->get(property_name)); // b. Perform ? Set(to, nextKey, propValue, true). - TRY_OR_DISCARD(to->set(property_name, prop_value, Object::ShouldThrowExceptions::Yes)); + TRY(to->set(property_name, prop_value, Object::ShouldThrowExceptions::Yes)); } } diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.h b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.h index a35a686648..6489ed562a 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.h +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.h @@ -25,28 +25,28 @@ public: private: virtual bool has_constructor() const override { return true; } - JS_DECLARE_OLD_NATIVE_FUNCTION(define_property); - JS_DECLARE_OLD_NATIVE_FUNCTION(define_properties); - JS_DECLARE_OLD_NATIVE_FUNCTION(is); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_own_property_descriptor); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_own_property_descriptors); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_own_property_names); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_own_property_symbols); - JS_DECLARE_OLD_NATIVE_FUNCTION(get_prototype_of); - JS_DECLARE_OLD_NATIVE_FUNCTION(set_prototype_of); - JS_DECLARE_OLD_NATIVE_FUNCTION(is_extensible); - JS_DECLARE_OLD_NATIVE_FUNCTION(is_frozen); - JS_DECLARE_OLD_NATIVE_FUNCTION(is_sealed); - JS_DECLARE_OLD_NATIVE_FUNCTION(prevent_extensions); - JS_DECLARE_OLD_NATIVE_FUNCTION(seal); - JS_DECLARE_OLD_NATIVE_FUNCTION(freeze); - JS_DECLARE_OLD_NATIVE_FUNCTION(from_entries); - JS_DECLARE_OLD_NATIVE_FUNCTION(keys); - JS_DECLARE_OLD_NATIVE_FUNCTION(values); - JS_DECLARE_OLD_NATIVE_FUNCTION(entries); - JS_DECLARE_OLD_NATIVE_FUNCTION(create); - JS_DECLARE_OLD_NATIVE_FUNCTION(has_own); - JS_DECLARE_OLD_NATIVE_FUNCTION(assign); + JS_DECLARE_NATIVE_FUNCTION(define_property); + JS_DECLARE_NATIVE_FUNCTION(define_properties); + JS_DECLARE_NATIVE_FUNCTION(is); + JS_DECLARE_NATIVE_FUNCTION(get_own_property_descriptor); + JS_DECLARE_NATIVE_FUNCTION(get_own_property_descriptors); + JS_DECLARE_NATIVE_FUNCTION(get_own_property_names); + JS_DECLARE_NATIVE_FUNCTION(get_own_property_symbols); + JS_DECLARE_NATIVE_FUNCTION(get_prototype_of); + JS_DECLARE_NATIVE_FUNCTION(set_prototype_of); + JS_DECLARE_NATIVE_FUNCTION(is_extensible); + JS_DECLARE_NATIVE_FUNCTION(is_frozen); + JS_DECLARE_NATIVE_FUNCTION(is_sealed); + JS_DECLARE_NATIVE_FUNCTION(prevent_extensions); + JS_DECLARE_NATIVE_FUNCTION(seal); + JS_DECLARE_NATIVE_FUNCTION(freeze); + JS_DECLARE_NATIVE_FUNCTION(from_entries); + JS_DECLARE_NATIVE_FUNCTION(keys); + JS_DECLARE_NATIVE_FUNCTION(values); + JS_DECLARE_NATIVE_FUNCTION(entries); + JS_DECLARE_NATIVE_FUNCTION(create); + JS_DECLARE_NATIVE_FUNCTION(has_own); + JS_DECLARE_NATIVE_FUNCTION(assign); }; } |