summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptprogram.cpp
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2011-01-28 09:10:31 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2011-01-31 13:14:38 (GMT)
commit307eceb786d3558b604c25353d67aed6ef9b0702 (patch)
tree64dde4977c8fd3f5000676d03444c16314f2ccca /src/script/api/qscriptprogram.cpp
parent884dc710553c44277504245dc908f96731da84ed (diff)
downloadQt-307eceb786d3558b604c25353d67aed6ef9b0702.zip
Qt-307eceb786d3558b604c25353d67aed6ef9b0702.tar.gz
Qt-307eceb786d3558b604c25353d67aed6ef9b0702.tar.bz2
Invalidate QScriptPrograms when engine is destroyed
If the engine is destroyed before the program, the program must be invalidated; otherwise the program destructor will access a stale engine pointer, which can cause a crash (it crashes on Symbian, but "only" gives a Valgrind warning on Linux for our autotests). We need to keep track of all associated programs, just like we already do for values and strings. This fix follows the exact same pattern, but uses a QSet to keep the patch minimal. No new tests, but the evaluateProgram() test runs successfully on Symbian now, and there are no more Valgrind warnings. Task-number: QTBUG-16987 Reviewed-by: Olivier Goffart (cherry picked from commit b127b1036ec75c625920a6c029b64a95e3702bf9)
Diffstat (limited to 'src/script/api/qscriptprogram.cpp')
-rw-r--r--src/script/api/qscriptprogram.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp
index da103bb..31af9a0 100644
--- a/src/script/api/qscriptprogram.cpp
+++ b/src/script/api/qscriptprogram.cpp
@@ -64,6 +64,7 @@ QScriptProgramPrivate::~QScriptProgramPrivate()
if (engine) {
QScript::APIShim shim(engine);
_executable.clear();
+ engine->unregisterScriptProgram(this);
}
}
@@ -78,7 +79,10 @@ JSC::EvalExecutable *QScriptProgramPrivate::executable(JSC::ExecState *exec,
if (_executable) {
if (eng == engine)
return _executable.get();
- _executable = 0;
+ // "Migrating" to another engine; clean up old state
+ QScript::APIShim shim(engine);
+ _executable.clear();
+ engine->unregisterScriptProgram(this);
}
WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider
= QScript::UStringSourceProviderWithFeedback::create(sourceCode, fileName, firstLineNumber, eng);
@@ -86,10 +90,19 @@ JSC::EvalExecutable *QScriptProgramPrivate::executable(JSC::ExecState *exec,
JSC::SourceCode source(provider, firstLineNumber); //after construction of SourceCode provider variable will be null.
_executable = JSC::EvalExecutable::create(exec, source);
engine = eng;
+ engine->registerScriptProgram(this);
isCompiled = false;
return _executable.get();
}
+void QScriptProgramPrivate::detachFromEngine()
+{
+ _executable.clear();
+ sourceId = -1;
+ isCompiled = false;
+ engine = 0;
+}
+
/*!
Constructs a null QScriptProgram.
*/
@@ -122,9 +135,6 @@ QScriptProgram::QScriptProgram(const QScriptProgram &other)
*/
QScriptProgram::~QScriptProgram()
{
- // Q_D(QScriptProgram);
- // if (d->engine && (d->ref == 1))
- // d->engine->unregisterScriptProgram(d);
}
/*!
@@ -132,9 +142,6 @@ QScriptProgram::~QScriptProgram()
*/
QScriptProgram &QScriptProgram::operator=(const QScriptProgram &other)
{
- // if (d_func() && d_func()->engine && (d_func()->ref == 1))
- // d_func()->engine->unregisterScriptProgram(d_func());
- // }
d_ptr = other.d_ptr;
return *this;
}