@ -608,18 +608,11 @@ pub(crate) fn create_function_object(
. build ( ) ;
let function = if r#async {
let promise_capability = PromiseCapability ::new (
& context . intrinsics ( ) . constructors ( ) . promise ( ) . constructor ( ) ,
context ,
)
. expect ( "cannot fail per spec" ) ;
Function ::new (
FunctionKind ::Async {
code ,
environments : context . vm . environments . clone ( ) ,
home_object : None ,
promise_capability ,
class_object : None ,
} ,
context . realm ( ) . clone ( ) ,
@ -835,8 +828,7 @@ impl JsObject {
let context = & mut ContextCleanupGuard ::new ( context , realm , active_function ) ;
let ( code , mut environments , class_object , promise_cap , async_ , gen ) =
match function_object . kind ( ) {
let ( code , mut environments , class_object , async_ , gen ) = match function_object . kind ( ) {
FunctionKind ::Native {
function ,
constructor ,
@ -869,7 +861,6 @@ impl JsObject {
code ,
environments . clone ( ) ,
class_object . clone ( ) ,
None ,
false ,
false ,
)
@ -878,14 +869,12 @@ impl JsObject {
FunctionKind ::Async {
code ,
environments ,
promise_capability ,
class_object ,
..
} = > (
code . clone ( ) ,
environments . clone ( ) ,
class_object . clone ( ) ,
Some ( promise_capability . clone ( ) ) ,
true ,
false ,
) ,
@ -898,7 +887,6 @@ impl JsObject {
code . clone ( ) ,
environments . clone ( ) ,
class_object . clone ( ) ,
None ,
false ,
true ,
) ,
@ -911,7 +899,6 @@ impl JsObject {
code . clone ( ) ,
environments . clone ( ) ,
class_object . clone ( ) ,
None ,
true ,
true ,
) ,
@ -919,6 +906,14 @@ impl JsObject {
drop ( object ) ;
let promise_capability = ( async_ & & ! gen ) . then ( | | {
PromiseCapability ::new (
& context . intrinsics ( ) . constructors ( ) . promise ( ) . constructor ( ) ,
context ,
)
. expect ( "cannot fail per spec" )
} ) ;
std ::mem ::swap ( & mut environments , & mut context . vm . environments ) ;
let lexical_this_mode = code . this_mode = = ThisMode ::Lexical ;
@ -1023,7 +1018,7 @@ impl JsObject {
let mut frame = CallFrame ::new ( code )
. with_param_count ( param_count )
. with_arg_count ( arg_count ) ;
frame . promise_capability = promise_cap . clone ( ) ;
frame . promise_capability = promise_capability . clone ( ) ;
context . vm . push_frame ( frame ) ;
@ -1036,8 +1031,8 @@ impl JsObject {
std ::mem ::swap ( & mut environments , & mut context . vm . environments ) ;
std ::mem ::swap ( & mut context . vm . stack , & mut stack ) ;
if let Some ( promise_cap ) = promise_cap {
Ok ( promise_cap . promise ( ) . clone ( ) . into ( ) )
if let Some ( promise_capability ) = promise_capability {
Ok ( promise_capability . promise ( ) . clone ( ) . into ( ) )
} else if gen {
result ? ;
let proto = this_function_object