LibJS: Prebake the empty object ({}) with a prototype

Instead of performing a prototype transition for every new object we
create via {}, prebake the object returned by Object::create_empty()
with a shape with ObjectPrototype as the prototype.

We also prebake the shape for the object assigned to the "prototype"
property of new ScriptFunction objects, since those are extremely
common and that code broke from this change anyway.

This avoid a large number of transitions and is a small speed-up on
test-js.
This commit is contained in:
Andreas Kling 2020-10-17 23:13:37 +02:00
parent 919fc7a814
commit d3dfd55472
Notes: sideshowbarker 2024-07-19 01:52:02 +09:00
5 changed files with 24 additions and 4 deletions

View file

@ -69,8 +69,8 @@ void ScriptFunction::initialize(GlobalObject& global_object)
auto& vm = this->vm();
Function::initialize(global_object);
if (!m_is_arrow_function) {
Object* prototype = Object::create_empty(global_object);
prototype->define_property_without_transition(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable);
Object* prototype = vm.heap().allocate<Object>(global_object, *global_object.new_script_function_prototype_object_shape());
prototype->define_property(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable);
define_property(vm.names.prototype, prototype, 0);
}
define_native_property(vm.names.length, length_getter, nullptr, Attribute::Configurable);