Make QV4::Script GC safe
authorLars Knoll <lars.knoll@theqtcompany.com>
Tue, 28 Apr 2015 17:18:40 +0000 (19:18 +0200)
committerSimon Hausmann <simon.hausmann@theqtcompany.com>
Wed, 17 Jun 2015 07:40:05 +0000 (07:40 +0000)
Change-Id: I559458278cb6a0bbbc4da441034115aa4c72b058
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/jsruntime/qv4script.cpp
src/qml/jsruntime/qv4script_p.h

index aec5d73861c42289203d73514ded9ee339c3cf68..33efed8e70922e55285fbf6e4a0e43d1e110d251 100644 (file)
@@ -188,7 +188,7 @@ Heap::FunctionObject *QmlBindingWrapper::createQmlCallableForFunction(QQmlContex
 }
 
 Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *compilationUnit)
-    : line(0), column(0), scope(v4->rootContext()->d()), strictMode(false), inheritContext(true), parsed(false)
+    : line(0), column(0), scope(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false)
     , qml(v4, qml), vmFunction(0), parseAsBinding(true)
 {
     parsed = true;
@@ -214,7 +214,7 @@ void Script::parse()
 
     parsed = true;
 
-    ExecutionEngine *v4 = scope->engine;
+    ExecutionEngine *v4 = scope->engine();
     Scope valueScope(v4);
 
     MemoryManager::GCBlocker gcBlocker(v4->memoryManager);
@@ -285,7 +285,7 @@ ReturnedValue Script::run()
     if (!vmFunction)
         return Encode::undefined();
 
-    QV4::ExecutionEngine *engine = scope->engine;
+    QV4::ExecutionEngine *engine = scope->engine();
     QV4::Scope valueScope(engine);
 
     if (qml.isUndefined()) {
@@ -293,15 +293,14 @@ ReturnedValue Script::run()
 
         ExecutionContextSaver ctxSaver(valueScope, scope);
         ContextStateSaver stateSaver(valueScope, scope);
-        scope->strictMode = vmFunction->isStrict();
-        scope->lookups = vmFunction->compilationUnit->runtimeLookups;
-        scope->compilationUnit = vmFunction->compilationUnit;
+        scope->d()->strictMode = vmFunction->isStrict();
+        scope->d()->lookups = vmFunction->compilationUnit->runtimeLookups;
+        scope->d()->compilationUnit = vmFunction->compilationUnit;
 
         return vmFunction->code(engine, vmFunction->codeData);
     } else {
         ScopedObject qmlObj(valueScope, qml.value());
-        ScopedContext ctx(valueScope, scope);
-        ScopedFunctionObject f(valueScope, engine->memoryManager->alloc<QmlBindingWrapper>(ctx, vmFunction, qmlObj));
+        ScopedFunctionObject f(valueScope, engine->memoryManager->alloc<QmlBindingWrapper>(scope, vmFunction, qmlObj));
         ScopedCallData callData(valueScope);
         callData->thisObject = Primitive::undefinedValue();
         return f->call(callData);
@@ -376,11 +375,10 @@ ReturnedValue Script::qmlBinding()
 {
     if (!parsed)
         parse();
-    ExecutionEngine *v4 = scope->engine;
+    ExecutionEngine *v4 = scope->engine();
     Scope valueScope(v4);
     ScopedObject qmlObj(valueScope, qml.value());
-    ScopedContext ctx(valueScope, scope);
-    ScopedObject v(valueScope, v4->memoryManager->alloc<QmlBindingWrapper>(ctx, vmFunction, qmlObj));
+    ScopedObject v(valueScope, v4->memoryManager->alloc<QmlBindingWrapper>(scope, vmFunction, qmlObj));
     return v.asReturnedValue();
 }
 
index d2d2b89d16e70a44e243d93908edbfde1a0a81a0..59a589a624bf806a81f6c1183d8f8139fc00c06a 100644 (file)
@@ -111,11 +111,11 @@ struct Q_QML_EXPORT QmlBindingWrapper : FunctionObject {
 struct Q_QML_EXPORT Script {
     Script(ExecutionContext *scope, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0)
         : sourceFile(source), line(line), column(column), sourceCode(sourceCode)
-        , scope(scope->d()), strictMode(false), inheritContext(false), parsed(false)
+        , scope(scope), strictMode(false), inheritContext(false), parsed(false)
         , vmFunction(0), parseAsBinding(false) {}
     Script(ExecutionEngine *engine, Object *qml, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0)
         : sourceFile(source), line(line), column(column), sourceCode(sourceCode)
-        , scope(engine->rootContext()->d()), strictMode(false), inheritContext(true), parsed(false)
+        , scope(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false)
         , qml(engine, qml), vmFunction(0), parseAsBinding(true) {}
     Script(ExecutionEngine *engine, Object *qml, CompiledData::CompilationUnit *compilationUnit);
     ~Script();
@@ -123,8 +123,7 @@ struct Q_QML_EXPORT Script {
     int line;
     int column;
     QString sourceCode;
-    // ### GC
-    Heap::ExecutionContext *scope;
+    ExecutionContext *scope;
     bool strictMode;
     bool inheritContext;
     bool parsed;