Print JS stack trace when reporting exceptions.

Increase maximum logger message size.
Fix GC bug.

This was SVN commit r8063.
This commit is contained in:
Ykkrosh
2010-09-03 20:06:17 +00:00
parent 5cc04d44f8
commit 5e15a0279e
4 changed files with 39 additions and 7 deletions
+26 -1
View File
@@ -76,7 +76,7 @@ JSClass global_class = {
NULL, NULL, NULL, NULL
};
void ErrorReporter(JSContext* UNUSED(cx), const char* message, JSErrorReport* report)
void ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report)
{
// XXX Ugly hack: we want to compile code with 'use strict' and with JSOPTION_STRICT,
// but the latter causes the former to be reported as a useless expression, so
@@ -92,11 +92,28 @@ void ErrorReporter(JSContext* UNUSED(cx), const char* message, JSErrorReport* re
msg << report->filename;
msg << " line " << report->lineno << "\n";
}
msg << message;
// If there is an exception, then print its stack trace
jsval excn;
if (JS_GetPendingException(cx, &excn) && JSVAL_IS_OBJECT(excn))
{
jsval rval;
const char dumpStack[] = "this.stack.trimRight().replace(/^/mg, ' ')"; // indent each line
if (JS_EvaluateScript(cx, JSVAL_TO_OBJECT(excn), dumpStack, ARRAY_SIZE(dumpStack)-1, "(eval)", 1, &rval))
{
std::string stackTrace;
if (ScriptInterface::FromJSVal(cx, rval, stackTrace))
msg << "\n" << stackTrace;
}
}
if (isWarning)
LOGWARNING(L"%hs", msg.str().c_str());
else
LOGERROR(L"%hs", msg.str().c_str());
// When running under Valgrind, print more information in the error message
VALGRIND_PRINTF_BACKTRACE("->");
}
@@ -400,6 +417,14 @@ bool ScriptInterface::LocalRootScope::OK()
return m_OK;
}
void ScriptInterface::LocalRootScope::LeaveWithResult(jsval val)
{
if (m_OK)
JS_LeaveLocalRootScopeWithResult(m_cx, val);
m_OK = false;
}
jsval ScriptInterface::CallConstructor(jsval ctor)
{
// Constructing JS objects similarly to "new Foo" is non-trivial.