diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2011-02-07 13:53:59 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2011-02-08 10:02:46 (GMT) |
commit | 640436345645b6cf6ff3334399f33c9d1c089492 (patch) | |
tree | 296f5ad05bc90ab9446167173a53d357ba5f1640 /tests/auto/qscriptengine | |
parent | 4cc2c1d87a90279cd024768c905da013f037cea1 (diff) | |
download | Qt-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/auto/qscriptengine')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
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; |