Skip to content

Commit b7e4c08

Browse files
committed
pesapi_call_function处理异常
1 parent d9513bb commit b7e4c08

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

unity/native_src/papi-quickjs/source/PapiQuickjsImpl.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,19 @@ pesapi_value pesapi_call_function(pesapi_env env, pesapi_value pfunc, pesapi_val
756756
for (int i = 0; i < argc; ++i) {
757757
js_argv[i] = *qjsValueFromPesapiValue(argv[i]);
758758
}
759-
JSValue* ret = allocValueInCurrentScope(ctx);
760-
*ret = JS_Call(ctx, *func, *thisObj, argc, js_argv);
761-
return pesapiValueFromQjsValue(ret);
759+
auto rt = JS_GetRuntime(ctx);
760+
JS_UpdateStackTop(rt);
761+
JSValue retOrEx = JS_Call(ctx, *func, *thisObj, argc, js_argv);
762+
if (JS_IsException(retOrEx)) {
763+
auto scope = getCurrentScope(ctx);
764+
scope->setCaughtException(JS_GetException(ctx));
765+
766+
return pesapi_create_undefined(env);
767+
} else {
768+
auto ret = allocValueInCurrentScope(ctx);
769+
*ret = retOrEx;
770+
return pesapiValueFromQjsValue(ret);
771+
}
762772
}
763773

764774
pesapi_value pesapi_eval(pesapi_env env, const uint8_t* code, size_t code_size, const char* path)

0 commit comments

Comments
 (0)