summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-06-16 20:52:30 +0100
committerLinus Groh <mail@linusgroh.de>2021-06-16 22:49:04 +0100
commit317b88a8c395bf34b0290eaddeefb6afe4b584ed (patch)
tree31c692bd8f27a30325f6367264f0eb153e3e4fac /Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
parent748918964592b2fb560ce08de47779b6d5db30da (diff)
downloadserenity-317b88a8c395bf34b0290eaddeefb6afe4b584ed.zip
LibJS: Replace Object's create_empty() with create() taking a prototype
This now matches the spec's OrdinaryObjectCreate() across the board: instead of implicitly setting the created object's prototype to %Object.prototype% and then in many cases setting it to a nullptr right away, it now has an 'Object* prototype' parameter with _no default value_. This makes the code easier to compare with the spec, very clear in terms of what prototype is being used as well as avoiding unnecessary shape transitions. Also fixes a couple of cases were we weren't setting the correct prototype. There's no reason to assume that the object would not be empty (as in having own properties), so let's follow our existing pattern of Type::create(...) and simply call it 'create'.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
index 99245c513e..d59659fce0 100644
--- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
@@ -62,10 +62,13 @@ ObjectConstructor::~ObjectConstructor()
// 20.1.1.1 Object ( [ value ] ), https://tc39.es/ecma262/#sec-object-value
Value ObjectConstructor::call()
{
- auto value = vm().argument(0);
+ auto& vm = this->vm();
+ auto& global_object = this->global_object();
+
+ auto value = vm.argument(0);
if (value.is_nullish())
- return Object::create_empty(global_object());
- return value.to_object(global_object());
+ return Object::create(global_object, global_object.object_prototype());
+ return value.to_object(global_object);
}
// 20.1.1.1 Object ( [ value ] ), https://tc39.es/ecma262/#sec-object-value
@@ -191,8 +194,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries)
if (vm.exception())
return {};
- auto* object = Object::create_empty(global_object);
- object->set_prototype(global_object.object_prototype());
+ auto* object = Object::create(global_object, global_object.object_prototype());
get_iterator_values(global_object, iterable, [&](Value iterator_value) {
if (vm.exception())
@@ -344,8 +346,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create)
return {};
}
- auto* object = Object::create_empty(global_object);
- object->set_prototype(prototype);
+ auto* object = Object::create(global_object, prototype);
if (!properties.is_undefined()) {
object->define_properties(properties);