Skip to content

Commit

Permalink
fix: add error type for report error
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Oct 25, 2021
1 parent cba93ec commit 4005937
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bridge/bindings/qjs/js_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ void JSContext::reportError(JSValueConst error) {
if (!JS_IsError(m_ctx, error)) return;

JSValue messageValue = JS_GetPropertyStr(m_ctx, error, "message");
JSValue errorTypeValue = JS_GetPropertyStr(m_ctx, error, "name");
const char *title = JS_ToCString(m_ctx, messageValue);
const char *type = JS_ToCString(m_ctx, errorTypeValue);
const char *stack = nullptr;
JSValue stackValue = JS_GetPropertyStr(m_ctx, error, "stack");
if (!JS_IsUndefined(stackValue)) {
Expand All @@ -253,18 +255,20 @@ void JSContext::reportError(JSValueConst error) {
if (stack != nullptr) {
messageLength += strlen(stack);
char message[messageLength];
sprintf(message, "%s\n%s", title, stack);
sprintf(message, "%s: %s\n%s", type, title, stack);
_handler(contextId, message);
} else {
char message[messageLength];
sprintf(message, "%s", title);
sprintf(message, "%s: %s", type, title);
_handler(contextId, message);
}

JS_FreeValue(m_ctx, errorTypeValue);
JS_FreeValue(m_ctx, messageValue);
JS_FreeValue(m_ctx, stackValue);
JS_FreeCString(m_ctx, title);
JS_FreeCString(m_ctx, stack);
JS_FreeCString(m_ctx, type);
}

void JSContext::drainPendingPromiseJobs() {
Expand Down

0 comments on commit 4005937

Please sign in to comment.