mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibJS: Add Object::define_property_without_transition() helper
This allows us to avoid transitioning in two common cases, saving some time during object construction.
This commit is contained in:
parent
21ac343211
commit
4c33209011
Notes:
sideshowbarker
2024-07-19 02:00:30 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4c332090114
3 changed files with 10 additions and 3 deletions
|
@ -415,6 +415,12 @@ bool Object::define_property(const StringOrSymbol& property_name, const Object&
|
|||
return define_property(property_name, value, attributes, throw_exceptions);
|
||||
}
|
||||
|
||||
bool Object::define_property_without_transition(const PropertyName& property_name, Value value, PropertyAttributes attributes, bool throw_exceptions)
|
||||
{
|
||||
TemporaryChange change(m_transitions_enabled, false);
|
||||
return define_property(property_name, value, attributes, throw_exceptions);
|
||||
}
|
||||
|
||||
bool Object::define_property(const PropertyName& property_name, Value value, PropertyAttributes attributes, bool throw_exceptions)
|
||||
{
|
||||
if (property_name.is_number())
|
||||
|
@ -753,10 +759,10 @@ bool Object::define_native_function(const StringOrSymbol& property_name, AK::Fun
|
|||
function_name = String::formatted("[{}]", property_name.as_symbol()->description());
|
||||
}
|
||||
auto* function = NativeFunction::create(global_object(), function_name, move(native_function));
|
||||
function->define_property("length", Value(length), Attribute::Configurable);
|
||||
function->define_property_without_transition("length", Value(length), Attribute::Configurable);
|
||||
if (vm().exception())
|
||||
return {};
|
||||
function->define_property("name", js_string(heap(), function_name), Attribute::Configurable);
|
||||
function->define_property_without_transition("name", js_string(heap(), function_name), Attribute::Configurable);
|
||||
if (vm().exception())
|
||||
return {};
|
||||
return define_property(property_name, function, attribute);
|
||||
|
|
|
@ -103,6 +103,7 @@ public:
|
|||
|
||||
virtual bool define_property(const StringOrSymbol& property_name, const Object& descriptor, bool throw_exceptions = true);
|
||||
bool define_property(const PropertyName&, Value value, PropertyAttributes attributes = default_attributes, bool throw_exceptions = true);
|
||||
bool define_property_without_transition(const PropertyName&, Value value, PropertyAttributes attributes = default_attributes, bool throw_exceptions = true);
|
||||
bool define_accessor(const PropertyName&, Function& getter_or_setter, bool is_getter, PropertyAttributes attributes = default_attributes, bool throw_exceptions = true);
|
||||
|
||||
bool define_native_function(const StringOrSymbol& property_name, AK::Function<Value(VM&, GlobalObject&)>, i32 length = 0, PropertyAttributes attributes = default_attributes);
|
||||
|
|
|
@ -69,7 +69,7 @@ void ScriptFunction::initialize(GlobalObject& global_object)
|
|||
Function::initialize(global_object);
|
||||
if (!m_is_arrow_function) {
|
||||
Object* prototype = Object::create_empty(global_object);
|
||||
prototype->define_property("constructor", this, Attribute::Writable | Attribute::Configurable);
|
||||
prototype->define_property_without_transition("constructor", this, Attribute::Writable | Attribute::Configurable);
|
||||
define_property("prototype", prototype, 0);
|
||||
}
|
||||
define_native_property("length", length_getter, nullptr, Attribute::Configurable);
|
||||
|
|
Loading…
Add table
Reference in a new issue