diff options
author | Lars Knoll <[email protected]> | 2017-08-05 00:03:52 +0200 |
---|---|---|
committer | Lars Knoll <[email protected]> | 2017-08-08 18:58:37 +0000 |
commit | f284d73ccece0490b4a227c788b9415a59a38d9c (patch) | |
tree | 729d1b8ef68c941bdda322fa6dc3c17b62d1a69e /src/qml | |
parent | 68a717a9cd5a5b092268eaddd3552becc55c74ab (diff) |
Avoid creating a separate Scope in the ExecutionContextSaver
There's no reason this class should create a scope on it's own.
Change-Id: I93bddea8be42a908a1aca1bcb0ec867aae0d29f8
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/jsapi/qjsengine.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4globalobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 14 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 2 |
7 files changed, 17 insertions, 21 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index e4c150057a..1c7540778b 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -438,7 +438,7 @@ QJSValue QJSEngine::evaluate(const QString& program, const QString& fileName, in { QV4::ExecutionEngine *v4 = d->m_v4Engine; QV4::Scope scope(v4); - QV4::ExecutionContextSaver saver(scope); + QV4::ExecutionContextSaver saver(v4); QV4::ExecutionContext *ctx = v4->currentContext; if (ctx->d() != v4->rootContext()->d()) diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index da76da839b..4053eb4f09 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -234,7 +234,7 @@ bool ExecutionContext::deleteProperty(String *name) // Do a standard call with this execution context as the outer scope ReturnedValue ExecutionContext::call(Scope &scope, CallData *callData, Function *function, const FunctionObject *f) { - ExecutionContextSaver ctxSaver(scope); + ExecutionContextSaver ctxSaver(scope.engine); Scoped<CallContext> ctx(scope, newCallContext(function, callData)); if (f) @@ -254,7 +254,7 @@ ReturnedValue QV4::ExecutionContext::simpleCall(Scope &scope, CallData *callData { Q_ASSERT(function->canUseSimpleFunction()); - ExecutionContextSaver ctxSaver(scope); + ExecutionContextSaver ctxSaver(scope.engine); CallContext::Data *ctx = scope.engine->memoryManager->allocSimpleCallContext(); diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 344c38ee79..f09772115c 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -360,14 +360,11 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData) CHECK_STACK_LIMITS(v4); Scope scope(v4); - ExecutionContextSaver ctxSaver(scope); - Scoped<ScriptFunction> f(scope, static_cast<const ScriptFunction *>(that)); InternalClass *ic = f->classForConstructor(); ScopedObject proto(scope, ic->prototype); - ScopedObject obj(scope, v4->newObject(ic, proto)); - callData->thisObject = obj.asReturnedValue(); + callData->thisObject = v4->newObject(ic, proto); QV4::Function *v4Function = f->function(); Q_ASSERT(v4Function); @@ -382,7 +379,7 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData) if (Q_UNLIKELY(v4->hasException)) return Encode::undefined(); else if (!result->isObject()) - return obj.asReturnedValue(); + return callData->thisObject.asReturnedValue(); return result->asReturnedValue(); } @@ -393,12 +390,11 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData) return Encode::undefined(); CHECK_STACK_LIMITS(v4); - Scope scope(v4); - Scoped<ScriptFunction> f(scope, static_cast<const ScriptFunction *>(that)); - + const ScriptFunction *f = static_cast<const ScriptFunction *>(that); QV4::Function *v4Function = f->function(); Q_ASSERT(v4Function); + Scope scope(v4); ScopedContext c(scope, f->scope()); if (v4Function->canUseSimpleCall) return c->simpleCall(scope, callData, v4Function); diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index dab6de572d..69d9683eaa 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -344,7 +344,7 @@ ReturnedValue EvalFunction::evalCall(CallData *callData, bool directCall) const ExecutionEngine *v4 = engine(); Scope scope(v4); - ExecutionContextSaver ctxSaver(scope); + ExecutionContextSaver ctxSaver(scope.engine); ExecutionContext *currentContext = v4->currentContext; ExecutionContext *ctx = currentContext; diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index 7df723e9d0..f6cb6fda5d 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -401,19 +401,19 @@ struct ScopedProperty struct ExecutionContextSaver { - Scope scope; // this makes sure that a reference to context on the JS stack goes out of scope as soon as the context is not used anymore. + ExecutionEngine *engine; ExecutionContext *savedContext; - ExecutionContextSaver(const Scope &scope) - : scope(scope.engine) + ExecutionContextSaver(ExecutionEngine *engine) + : engine(engine) { - savedContext = scope.engine->currentContext; + savedContext = engine->currentContext; } ~ExecutionContextSaver() { - Q_ASSERT(scope.engine->jsStackTop > scope.engine->currentContext); - scope.engine->currentContext = savedContext; - scope.engine->current = savedContext->d(); + Q_ASSERT(engine->jsStackTop > engine->currentContext); + engine->currentContext = savedContext; + engine->current = savedContext->d(); } }; diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 019fa54fb0..b771978def 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -148,7 +148,7 @@ ReturnedValue Script::run() if (qmlContext.isUndefined()) { TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, vmFunction); - ExecutionContextSaver ctxSaver(valueScope); + ExecutionContextSaver ctxSaver(valueScope.engine); ContextStateSaver stateSaver(valueScope, scope); scope->d()->strictMode = vmFunction->isStrict(); scope->d()->v4Function = vmFunction; diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index a736fb9f9d..3b15157ff5 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1210,7 +1210,7 @@ void QQmlComponentPrivate::setInitialProperties(QV4::ExecutionEngine *engine, QV if (engine->hasException) return; - QV4::ExecutionContextSaver saver(scope); + QV4::ExecutionContextSaver saver(scope.engine); engine->pushContext(qmlContext); while (1) { |