@@ -612,9 +612,11 @@ NAPIExceptionStatus napi_call_function(NAPIEnv env, NAPIValue thisValue, NAPIVal
612612 CHECK_JSC (env )
613613 }
614614 JSValueRef returnValue = NULL ;
615+ //内部可能会执行微任务,如果使用全局异常(env->lastException)会导致 微任务中的 napi 调用失败
616+ JSValueRef _exception = NULL ;
615617 if (!argc )
616618 {
617- returnValue = JSObjectCallAsFunction (env -> context , objectRef , thisObjectRef , 0 , NULL , & env -> lastException );
619+ returnValue = JSObjectCallAsFunction (env -> context , objectRef , thisObjectRef , 0 , NULL , & _exception );
618620 }
619621 else if (argc <= 8 )
620622 {
@@ -624,7 +626,7 @@ NAPIExceptionStatus napi_call_function(NAPIEnv env, NAPIValue thisValue, NAPIVal
624626 argumentArray [i ] = (JSValueRef )argv [i ];
625627 }
626628 returnValue =
627- JSObjectCallAsFunction (env -> context , objectRef , thisObjectRef , argc , argumentArray , & env -> lastException );
629+ JSObjectCallAsFunction (env -> context , objectRef , thisObjectRef , argc , argumentArray , & _exception );
628630 }
629631 else
630632 {
@@ -635,9 +637,10 @@ NAPIExceptionStatus napi_call_function(NAPIEnv env, NAPIValue thisValue, NAPIVal
635637 argumentArray [i ] = (JSValueRef )argv [i ];
636638 }
637639 returnValue =
638- JSObjectCallAsFunction (env -> context , objectRef , thisObjectRef , argc , argumentArray , & env -> lastException );
640+ JSObjectCallAsFunction (env -> context , objectRef , thisObjectRef , argc , argumentArray , & _exception );
639641 free (argumentArray );
640642 }
643+ env -> lastException = _exception ;
641644 CHECK_JSC (env )
642645
643646 if (result )
0 commit comments