Skip to content

Commit

Permalink
Don't construct prototype if not needed (#2751)
Browse files Browse the repository at this point in the history
When the function is `async || arrow || method ` we don't need to construct the prototype (then drop it).
  • Loading branch information
HalidOdat committed Mar 27, 2023
1 parent 3586bf2 commit 7bec3e6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,25 +613,25 @@ pub(crate) fn create_function_object(
.configurable(true)
.build();

let prototype = JsObject::with_object_proto(context);
prototype
.define_property_or_throw(CONSTRUCTOR, constructor_property, context)
.expect("failed to define the constructor property of the function");

let prototype_property = PropertyDescriptor::builder()
.value(prototype)
.writable(true)
.enumerable(false)
.configurable(false)
.build();

constructor
.define_property_or_throw(utf16!("length"), length_property, context)
.expect("failed to define the length property of the function");
constructor
.define_property_or_throw(utf16!("name"), name_property, context)
.expect("failed to define the name property of the function");

if !r#async && !arrow && !method {
let prototype = JsObject::with_object_proto(context);
prototype
.define_property_or_throw(CONSTRUCTOR, constructor_property, context)
.expect("failed to define the constructor property of the function");

let prototype_property = PropertyDescriptor::builder()
.value(prototype)
.writable(true)
.enumerable(false)
.configurable(false)
.build();
constructor
.define_property_or_throw(PROTOTYPE, prototype_property, context)
.expect("failed to define the prototype property of the function");
Expand Down

0 comments on commit 7bec3e6

Please sign in to comment.