Skip to content

Commit cc57e2f

Browse files
vyshnavsdeepakminggo
authored andcommitted
Added JS stack trace (#20168)
1 parent 3f26b75 commit cc57e2f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cocos/scripting/js-bindings/manual/ScriptingCore.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,28 @@ void ScriptingCore::reportError(JSContext *cx, const char *message, JSErrorRepor
940940
report->filename ? report->filename : "<no filename=\"filename\">",
941941
(unsigned int) report->lineno,
942942
message);
943+
944+
if (cx)
945+
{
946+
JS::RootedValue errorContext(cx);
947+
if (JS_GetPendingException(cx, &errorContext))
948+
{
949+
JS_ClearPendingException(cx);
950+
}
951+
952+
if (errorContext.isObject())
953+
{
954+
std::string stackStr = "";
955+
JS::RootedObject errObj(cx, errorContext.toObjectOrNull());
956+
JS::RootedValue stack(cx);
957+
if (JS_GetProperty(cx, errObj, "stack", &stack) && stack.isString())
958+
{
959+
JS::RootedString jsstackStr(cx, stack.toString());
960+
stackStr = JS_EncodeStringToUTF8(cx, jsstackStr);
961+
js_log("Stack: %s\n", stackStr.c_str());
962+
}
963+
}
964+
}
943965
}
944966

945967

0 commit comments

Comments
 (0)