From 7bec3e6a8461ad316c10f95b1c438f0db366b316 Mon Sep 17 00:00:00 2001 From: Haled Odat Date: Mon, 27 Mar 2023 21:56:13 +0000 Subject: [PATCH] Don't construct prototype if not needed (#2751) When the function is `async || arrow || method ` we don't need to construct the prototype (then drop it). --- boa_engine/src/vm/code_block.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/boa_engine/src/vm/code_block.rs b/boa_engine/src/vm/code_block.rs index 0f41bc91b80..57108920555 100644 --- a/boa_engine/src/vm/code_block.rs +++ b/boa_engine/src/vm/code_block.rs @@ -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");