Skip to content

Commit

Permalink
fix: add misssing exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Jan 19, 2022
1 parent 733b6fd commit 44a8855
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bridge/bindings/qjs/dom/event_target.cc
Expand Up @@ -232,8 +232,9 @@ bool EventTargetInstance::internalDispatchEvent(EventInstance* eventInstance) {
JSValue columnValue = JS_NewUint32(m_ctx, 0);

JSValue args[]{messageValue, fileNameValue, lineNumberValue, columnValue, error};
JS_Call(m_ctx, handler, eventInstance->jsObject, 5, args);
JSValue returnValue = JS_Call(m_ctx, handler, eventInstance->jsObject, 5, args);
m_context->drainPendingPromiseJobs();
m_context->handleException(&returnValue);

JS_FreeValue(m_ctx, error);
JS_FreeValue(m_ctx, messageValue);
Expand Down
2 changes: 2 additions & 0 deletions bridge/bindings/qjs/dom/frame_request_callback_collection.cc
Expand Up @@ -22,6 +22,8 @@ void FrameCallback::fire(double highResTimeStamp) {
JSValue arguments[] = {JS_NewFloat64(m_ctx, highResTimeStamp)};

JSValue returnValue = JS_Call(m_ctx, m_callback, JS_UNDEFINED, 1, arguments);

context->drainPendingPromiseJobs();
JS_FreeValue(m_ctx, m_callback);

if (JS_IsException(returnValue)) {
Expand Down
9 changes: 6 additions & 3 deletions bridge/bindings/qjs/executing_context.cc
Expand Up @@ -135,10 +135,13 @@ ExecutionContext::~ExecutionContext() {
}
}

// Should free unhandled pending exceptions.
// Check if current context have unhandled exceptions.
JSValue exception = JS_GetException(m_ctx);
handleException(&exception);
JS_FreeValue(m_ctx, exception);
if (JS_IsObject(exception) || JS_IsException(exception)) {
// There must be bugs in native functions from call stack frame. Someone needs to fix it if throws.
reportError(exception);
assert_m(false, "Unhandled exception found when dispose JSContext.");
}

JS_FreeValue(m_ctx, globalObject);
JS_FreeContext(m_ctx);
Expand Down
4 changes: 3 additions & 1 deletion bridge/bindings/qjs/html_parser.cc
Expand Up @@ -141,7 +141,9 @@ void HTMLParser::parseProperty(ElementInstance* element, GumboElement* gumboElem
JSValue setAttributeFunc = JS_GetPropertyStr(ctx, element->jsObject, "setAttribute");
JSValue arguments[] = {key, value};

JS_Call(ctx, setAttributeFunc, element->jsObject, 2, arguments);
JSValue returnValue = JS_Call(ctx, setAttributeFunc, element->jsObject, 2, arguments);
context->drainPendingPromiseJobs();
context->handleException(&returnValue);

JS_FreeValue(ctx, setAttributeFunc);
JS_FreeValue(ctx, key);
Expand Down
2 changes: 2 additions & 0 deletions bridge/bindings/qjs/native_value.cc
Expand Up @@ -174,13 +174,15 @@ void anonymousAsyncCallback(void* callbackContext, NativeValue* nativeValue, int
JSValue value = nativeValueToJSValue(promiseContext->context, *nativeValue);
JSValue returnValue = JS_Call(context->ctx(), promiseContext->resolveFunc, context->global(), 1, &value);
context->drainPendingPromiseJobs();
context->handleException(&returnValue);
JS_FreeValue(context->ctx(), value);
JS_FreeValue(context->ctx(), returnValue);
} else if (errmsg != nullptr) {
JSValue error = JS_NewError(context->ctx());
JS_DefinePropertyValueStr(context->ctx(), error, "message", JS_NewString(context->ctx(), errmsg), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
JSValue returnValue = JS_Call(context->ctx(), promiseContext->rejectFunc, context->global(), 1, &error);
context->drainPendingPromiseJobs();
context->handleException(&returnValue);
JS_FreeValue(context->ctx(), error);
JS_FreeValue(context->ctx(), returnValue);
}
Expand Down
1 change: 0 additions & 1 deletion kraken/ios/kraken_bridge.xcframework

This file was deleted.

1 change: 0 additions & 1 deletion kraken/ios/quickjs.xcframework

This file was deleted.

0 comments on commit 44a8855

Please sign in to comment.