1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

LibJS: Implement Object.defineProperties()

This commit is contained in:
Linus Groh 2021-04-10 18:39:11 +02:00 committed by Andreas Kling
parent 275da6fcc9
commit da8a35a79e
6 changed files with 120 additions and 0 deletions

View file

@ -49,6 +49,7 @@ void ObjectConstructor::initialize(GlobalObject& global_object)
u8 attr = Attribute::Writable | Attribute::Configurable;
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.getOwnPropertyNames, get_own_property_names, 1, attr);
@ -250,6 +251,21 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property_)
return &object;
}
// 20.1.2.3 Object.defineProperties, https://tc39.es/ecma262/#sec-object.defineproperties
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_properties)
{
if (!vm.argument(0).is_object()) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, "Object argument");
return {};
}
auto& object = vm.argument(0).as_object();
auto properties = vm.argument(1);
object.define_properties(properties);
if (vm.exception())
return {};
return &object;
}
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is)
{
return Value(same_value(vm.argument(0), vm.argument(1)));