Cleanup the ExecutionContextSaver
Always operate on the current context (as that's what we do in practice anyway). Change-Id: I4171207a7a86e69aa685754956c0764ac6e152a7 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
This commit is contained in:
parent
b5902bd43a
commit
7dab89a65e
|
@ -66,7 +66,7 @@ void Debugger::JavaScriptJob::run()
|
|||
{
|
||||
Scope scope(engine);
|
||||
|
||||
ExecutionContextSaver saver(scope, engine->currentContext());
|
||||
ExecutionContextSaver saver(scope);
|
||||
|
||||
if (frameNr > 0) {
|
||||
Value *savedContexts = scope.alloc(frameNr);
|
||||
|
|
|
@ -348,6 +348,7 @@ public:
|
|||
void enableProfiler();
|
||||
|
||||
Heap::ExecutionContext *pushGlobalContext();
|
||||
void pushContext(Heap::ExecutionContext *context);
|
||||
void pushContext(CallContext *context);
|
||||
Heap::ExecutionContext *popContext();
|
||||
|
||||
|
@ -441,13 +442,19 @@ public:
|
|||
void assertObjectBelongsToEngine(const Heap::Base &baseObject);
|
||||
};
|
||||
|
||||
inline void ExecutionEngine::pushContext(Heap::ExecutionContext *context)
|
||||
{
|
||||
Q_ASSERT(current && context);
|
||||
context->parent = current;
|
||||
current = context;
|
||||
}
|
||||
|
||||
inline void ExecutionEngine::pushContext(CallContext *context)
|
||||
{
|
||||
Q_ASSERT(current && context && context->d());
|
||||
context->d()->parent = current;
|
||||
current = context->d();
|
||||
pushContext(context->d());
|
||||
}
|
||||
|
||||
|
||||
inline Heap::ExecutionContext *ExecutionEngine::popContext()
|
||||
{
|
||||
Q_ASSERT(current->parent);
|
||||
|
@ -467,7 +474,7 @@ Heap::ExecutionContext::ExecutionContext(ExecutionEngine *engine, ContextType t)
|
|||
, strictMode(false)
|
||||
, lineNumber(-1)
|
||||
{
|
||||
engine->current = this;
|
||||
engine->pushContext(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -434,17 +434,19 @@ 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 = scope.engine->emptyClass;
|
||||
ScopedObject proto(scope, f->protoForConstructor());
|
||||
ScopedObject obj(scope, v4->newObject(ic, proto));
|
||||
|
||||
|
||||
ScopedContext context(scope, v4->currentContext());
|
||||
callData->thisObject = obj.asReturnedValue();
|
||||
Scoped<CallContext> ctx(scope, context->newCallContext(f, callData));
|
||||
|
||||
ExecutionContextSaver ctxSaver(scope, context);
|
||||
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
|
||||
|
||||
if (f->function()->compiledFunction->hasQmlDependencies())
|
||||
|
@ -466,12 +468,12 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData)
|
|||
CHECK_STACK_LIMITS(v4);
|
||||
|
||||
Scope scope(v4);
|
||||
ExecutionContextSaver ctxSaver(scope);
|
||||
|
||||
Scoped<ScriptFunction> f(scope, static_cast<const ScriptFunction *>(that));
|
||||
ScopedContext context(scope, v4->currentContext());
|
||||
|
||||
Scoped<CallContext> ctx(scope, context->newCallContext(f, callData));
|
||||
|
||||
ExecutionContextSaver ctxSaver(scope, context);
|
||||
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
|
||||
|
||||
if (f->function()->compiledFunction->hasQmlDependencies())
|
||||
|
@ -522,14 +524,14 @@ ReturnedValue SimpleScriptFunction::construct(const Managed *that, CallData *cal
|
|||
CHECK_STACK_LIMITS(v4);
|
||||
|
||||
Scope scope(v4);
|
||||
ExecutionContextSaver ctxSaver(scope);
|
||||
|
||||
Scoped<SimpleScriptFunction> f(scope, static_cast<const SimpleScriptFunction *>(that));
|
||||
|
||||
InternalClass *ic = scope.engine->emptyClass;
|
||||
ScopedObject proto(scope, f->protoForConstructor());
|
||||
callData->thisObject = v4->newObject(ic, proto);
|
||||
|
||||
ExecutionContextSaver ctxSaver(scope, v4->currentContext());
|
||||
|
||||
CallContext::Data ctx(v4);
|
||||
#ifndef QT_NO_DEBUG
|
||||
ctx.mm_data = 0; // make sure we don't run into the assertion in setVTable when allocating a context on the stack
|
||||
|
@ -564,9 +566,9 @@ ReturnedValue SimpleScriptFunction::call(const Managed *that, CallData *callData
|
|||
CHECK_STACK_LIMITS(v4);
|
||||
|
||||
Scope scope(v4);
|
||||
Scoped<SimpleScriptFunction> f(scope, static_cast<const SimpleScriptFunction *>(that));
|
||||
ExecutionContextSaver ctxSaver(scope);
|
||||
|
||||
ExecutionContextSaver ctxSaver(scope, v4->currentContext());
|
||||
Scoped<SimpleScriptFunction> f(scope, static_cast<const SimpleScriptFunction *>(that));
|
||||
|
||||
CallContext::Data ctx(v4);
|
||||
#ifndef QT_NO_DEBUG
|
||||
|
@ -625,7 +627,7 @@ ReturnedValue BuiltinFunction::call(const Managed *that, CallData *callData)
|
|||
CHECK_STACK_LIMITS(v4);
|
||||
|
||||
Scope scope(v4);
|
||||
ExecutionContextSaver ctxSaver(scope, v4->currentContext());
|
||||
ExecutionContextSaver ctxSaver(scope);
|
||||
|
||||
CallContext::Data ctx(v4);
|
||||
#ifndef QT_NO_DEBUG
|
||||
|
@ -649,7 +651,7 @@ ReturnedValue IndexedBuiltinFunction::call(const Managed *that, CallData *callDa
|
|||
CHECK_STACK_LIMITS(v4);
|
||||
|
||||
Scope scope(v4);
|
||||
ExecutionContextSaver ctxSaver(scope, v4->currentContext());
|
||||
ExecutionContextSaver ctxSaver(scope);
|
||||
|
||||
CallContext::Data ctx(v4);
|
||||
#ifndef QT_NO_DEBUG
|
||||
|
|
|
@ -339,10 +339,9 @@ ReturnedValue EvalFunction::evalCall(CallData *callData, bool directCall) const
|
|||
|
||||
ExecutionEngine *v4 = engine();
|
||||
Scope scope(v4);
|
||||
ExecutionContextSaver ctxSaver(scope);
|
||||
|
||||
ScopedContext parentContext(scope, v4->currentContext());
|
||||
ExecutionContextSaver ctxSaver(scope, parentContext);
|
||||
|
||||
ScopedContext ctx(scope, parentContext.getPointer());
|
||||
|
||||
if (!directCall) {
|
||||
|
|
|
@ -416,20 +416,11 @@ struct ExecutionContextSaver
|
|||
ExecutionEngine *engine;
|
||||
Value *savedContext;
|
||||
|
||||
ExecutionContextSaver(Scope &scope, ExecutionContext *context)
|
||||
: engine(context->d()->engine)
|
||||
ExecutionContextSaver(Scope &scope)
|
||||
: engine(scope.engine)
|
||||
, savedContext(scope.alloc(1))
|
||||
{
|
||||
savedContext->setM(context->d());
|
||||
#if QT_POINTER_SIZE == 4
|
||||
savedContext->setTag(QV4::Value::Managed_Type);
|
||||
#endif
|
||||
}
|
||||
ExecutionContextSaver(Scope &scope, Heap::ExecutionContext *context)
|
||||
: engine(context->engine)
|
||||
, savedContext(scope.alloc(1))
|
||||
{
|
||||
savedContext->setM(context);
|
||||
savedContext->setM(scope.engine->currentContext());
|
||||
#if QT_POINTER_SIZE == 4
|
||||
savedContext->setTag(QV4::Value::Managed_Type);
|
||||
#endif
|
||||
|
|
|
@ -117,6 +117,8 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData)
|
|||
CHECK_STACK_LIMITS(v4);
|
||||
|
||||
Scope scope(v4);
|
||||
ExecutionContextSaver ctxSaver(scope);
|
||||
|
||||
QV4::Function *f = This->function();
|
||||
if (!f)
|
||||
return QV4::Encode::undefined();
|
||||
|
@ -124,7 +126,6 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData)
|
|||
ScopedContext context(scope, v4->currentContext());
|
||||
Scoped<CallContext> ctx(scope, context->newCallContext(This, callData));
|
||||
|
||||
ExecutionContextSaver ctxSaver(scope, context);
|
||||
ScopedValue result(scope, Q_V4_PROFILE(v4, f));
|
||||
|
||||
return result->asReturnedValue();
|
||||
|
@ -237,7 +238,7 @@ ReturnedValue Script::run()
|
|||
if (qmlContext.isUndefined()) {
|
||||
TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, vmFunction);
|
||||
|
||||
ExecutionContextSaver ctxSaver(valueScope, scope);
|
||||
ExecutionContextSaver ctxSaver(valueScope);
|
||||
ContextStateSaver stateSaver(valueScope, scope);
|
||||
scope->d()->strictMode = vmFunction->isStrict();
|
||||
scope->d()->lookups = vmFunction->compilationUnit->runtimeLookups;
|
||||
|
|
|
@ -483,7 +483,7 @@ void MemoryManager::sweep(bool lastSweep)
|
|||
|
||||
// some execution contexts are allocated on the stack, make sure we clear their markBit as well
|
||||
if (!lastSweep) {
|
||||
Heap::ExecutionContext *ctx = engine()->current;
|
||||
Heap::ExecutionContext *ctx = engine()->currentContext();
|
||||
while (ctx) {
|
||||
ctx->clearMarkBit();
|
||||
ctx = ctx->parent;
|
||||
|
|
Loading…
Reference in New Issue