summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2011-02-07 13:53:59 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2011-02-08 10:02:46 (GMT)
commit640436345645b6cf6ff3334399f33c9d1c089492 (patch)
tree296f5ad05bc90ab9446167173a53d357ba5f1640 /tests
parent4cc2c1d87a90279cd024768c905da013f037cea1 (diff)
downloadQt-640436345645b6cf6ff3334399f33c9d1c089492.zip
Qt-640436345645b6cf6ff3334399f33c9d1c089492.tar.gz
Qt-640436345645b6cf6ff3334399f33c9d1c089492.tar.bz2
Don't crash when creating backtrace for built-in JS function (2nd try)
Commit 147df10403ba280b3f04c1e3d6c4b1cf386abe5d did not quite fix the issue; other places need the same checks. When the JIT is enabled, frames for built-in JS host calls (such as Array.prototype.forEach) are not fully initialized. In particular, the CodeBlock register of such frames is not set (see comment in JITCall.cpp). We need to check if the codeBlock is actually valid before we start using it. This fixes the crash(es) but not the problem of actually getting the arguments for such frames through the API. There's also a related problem when a QtScript function (newFunction()) is called as a callback of a built-in JS host function (QTBUG-17287). These problems will go away once JavaScriptCore is updated to a more recent version (4.8 at the earliest), since the native-vs-script frame handling has been unified. Task-number: QTBUG-17137 Reviewed-by: Olivier Goffart
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp31
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp16
2 files changed, 46 insertions, 1 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index dd21555..7915eb0 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -871,7 +871,36 @@ void tst_QScriptContext::backtrace_data()
QStringList expected;
expected << "<native>() at -1"
<< "<anonymous>(0, 0, 0) at testfile:3"
- << "forEach(0) at -1"
+ << QString::fromLatin1("forEach(%0) at -1")
+ // Because the JIT doesn't store the arguments in the frame
+ // for built-in functions, arguments are not available.
+ // Will work when the copy of JavaScriptCore is updated
+ // (QTBUG-16568).
+ .arg(qt_script_isJITEnabled()
+ ? ""
+ : "function () {\n result = bt();\n}")
+ << "<global>() at testfile:4";
+ QTest::newRow("js callback from built-in") << source << expected;
+ }
+
+ {
+ QString source = QString::fromLatin1(
+ "[10,20].forEach(\n"
+ " function() {\n"
+ " result = bt();\n"
+ "}); result");
+
+ QStringList expected;
+ expected << "<native>() at -1"
+ << "<anonymous>(20, 1, 10,20) at testfile:3"
+ << QString::fromLatin1("forEach(%0) at -1")
+ // Because the JIT doesn't store the arguments in the frame
+ // for built-in functions, arguments are not available.
+ // Will work when the copy of JavaScriptCore is updated
+ // (QTBUG-16568).
+ .arg(qt_script_isJITEnabled()
+ ? ""
+ : "function () {\n result = bt();\n}")
<< "<global>() at testfile:4";
QTest::newRow("js callback from built-in") << source << expected;
}
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index c3a0ba1..8de6fbc 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -164,6 +164,7 @@ private slots:
void translationContext_data();
void translationContext();
void translateScriptIdBased();
+ void translateFromBuiltinCallback();
void functionScopes();
void nativeFunctionScopes();
void evaluateProgram();
@@ -4725,6 +4726,21 @@ void tst_QScriptEngine::translateScriptIdBased()
QString::fromLatin1("qtn_foo_bar")); // Doesn't have plural
}
+void tst_QScriptEngine::translateFromBuiltinCallback()
+{
+ QScriptEngine eng;
+ eng.installTranslatorFunctions();
+
+ // Callback has no translation context.
+ eng.evaluate("function foo() { qsTr('foo'); }");
+
+ // Stack at translation time will be:
+ // qsTr, foo, forEach, global
+ // qsTr() needs to walk to the outer-most (global) frame before it finds
+ // a translation context, and this should not crash.
+ eng.evaluate("[10,20].forEach(foo)", "script.js");
+}
+
void tst_QScriptEngine::functionScopes()
{
QScriptEngine eng;