diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-05-06 09:23:59 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-07-22 13:49:11 +0200 |
commit | 9744e8bd423d528165f5e78704c6e017852b8e9a (patch) | |
tree | b1210199c698d3b09d80b9267d9aaab2b12ac5ab /src/qml/jsruntime/qv4context.cpp | |
parent | f3f31957b79c55f3e076473b0d4c41c8872535b3 (diff) |
Convert ExecutionContext to new storage scheme
Change-Id: I9fcc13da5360f37cef3149b114ed9263b9b74281
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4context.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 184 |
1 files changed, 92 insertions, 92 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 655df13e27..528ca97208 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -57,19 +57,19 @@ CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData { Q_ASSERT(function->function()); - CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(function, callData->argc))); - new (c) CallContext(engine, Type_CallContext); + CallContext *c = static_cast<CallContext *>(d()->engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(function, callData->argc))); + new (c) CallContext(d()->engine, Type_CallContext); c->function = function; c->realArgumentCount = callData->argc; - c->strictMode = function->strictMode(); - c->outer = function->scope(); + c->d()->strictMode = function->strictMode(); + c->d()->outer = function->scope(); c->activation = 0; - c->compilationUnit = function->function()->compilationUnit; - c->lookups = c->compilationUnit->runtimeLookups; + c->d()->compilationUnit = function->function()->compilationUnit; + c->d()->lookups = c->d()->compilationUnit->runtimeLookups; c->locals = (Value *)((quintptr(c + 1) + 7) & ~7); const CompiledData::Function *compiledFunction = function->function()->compiledFunction; @@ -77,31 +77,31 @@ CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData if (nLocals) std::fill(c->locals, c->locals + nLocals, Primitive::undefinedValue()); - c->callData = reinterpret_cast<CallData *>(c->locals + nLocals); - ::memcpy(c->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(Value)); + c->d()->callData = reinterpret_cast<CallData *>(c->locals + nLocals); + ::memcpy(c->d()->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(Value)); if (callData->argc < static_cast<int>(compiledFunction->nFormals)) - std::fill(c->callData->args + c->callData->argc, c->callData->args + compiledFunction->nFormals, Primitive::undefinedValue()); - c->callData->argc = qMax((uint)callData->argc, compiledFunction->nFormals); + std::fill(c->d()->callData->args + c->d()->callData->argc, c->d()->callData->args + compiledFunction->nFormals, Primitive::undefinedValue()); + c->d()->callData->argc = qMax((uint)callData->argc, compiledFunction->nFormals); return c; } WithContext *ExecutionContext::newWithContext(ObjectRef with) { - WithContext *w = new (engine->memoryManager) WithContext(engine, with); + WithContext *w = new (d()->engine->memoryManager) WithContext(d()->engine, with); return w; } CatchContext *ExecutionContext::newCatchContext(const StringRef exceptionVarName, const ValueRef exceptionValue) { - CatchContext *c = new (engine->memoryManager) CatchContext(engine, exceptionVarName, exceptionValue); + CatchContext *c = new (d()->engine->memoryManager) CatchContext(d()->engine, exceptionVarName, exceptionValue); return c; } CallContext *ExecutionContext::newQmlContext(FunctionObject *f, ObjectRef qml) { - CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(f, 0))); - new (c) CallContext(engine, qml, f); + CallContext *c = static_cast<CallContext *>(d()->engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(f, 0))); + new (c) CallContext(d()->engine, qml, f); return c; } @@ -112,17 +112,17 @@ void ExecutionContext::createMutableBinding(const StringRef name, bool deletable Scope scope(this); // find the right context to create the binding on - ScopedObject activation(scope, engine->globalObject); + ScopedObject activation(scope, d()->engine->globalObject); ExecutionContext *ctx = this; while (ctx) { - if (ctx->type >= Type_CallContext) { + if (ctx->d()->type >= Type_CallContext) { CallContext *c = static_cast<CallContext *>(ctx); if (!c->activation) - c->activation = engine->newObject()->getPointer(); + c->activation = d()->engine->newObject()->getPointer(); activation = c->activation; break; } - ctx = ctx->outer; + ctx = ctx->d()->outer; } if (activation->hasProperty(name)) @@ -143,10 +143,10 @@ GlobalContext::GlobalContext(ExecutionEngine *eng) WithContext::WithContext(ExecutionEngine *engine, ObjectRef with) : ExecutionContext(engine, Type_WithContext) { - callData = parent->callData; - outer = parent; - lookups = parent->lookups; - compilationUnit = parent->compilationUnit; + d()->callData = d()->parent->d()->callData; + d()->outer = d()->parent; + d()->lookups = d()->parent->d()->lookups; + d()->compilationUnit = d()->parent->d()->compilationUnit; withObject = with.getPointer(); } @@ -154,11 +154,11 @@ WithContext::WithContext(ExecutionEngine *engine, ObjectRef with) CatchContext::CatchContext(ExecutionEngine *engine, const StringRef exceptionVarName, const ValueRef exceptionValue) : ExecutionContext(engine, Type_CatchContext) { - strictMode = parent->strictMode; - callData = parent->callData; - outer = parent; - lookups = parent->lookups; - compilationUnit = parent->compilationUnit; + d()->strictMode = d()->parent->d()->strictMode; + d()->callData = d()->parent->d()->callData; + d()->outer = d()->parent; + d()->lookups = d()->parent->d()->lookups; + d()->compilationUnit = d()->parent->d()->compilationUnit; this->exceptionVarName = exceptionVarName; this->exceptionValue = exceptionValue; @@ -168,19 +168,19 @@ CallContext::CallContext(ExecutionEngine *engine, ObjectRef qml, FunctionObject : ExecutionContext(engine, Type_QmlContext) { this->function = function; - callData = reinterpret_cast<CallData *>(this + 1); - callData->tag = QV4::Value::_Integer_Type; - callData->argc = 0; - callData->thisObject = Primitive::undefinedValue(); + d()->callData = reinterpret_cast<CallData *>(this + 1); + d()->callData->tag = QV4::Value::_Integer_Type; + d()->callData->argc = 0; + d()->callData->thisObject = Primitive::undefinedValue(); - strictMode = true; - outer = function->scope(); + d()->strictMode = true; + d()->outer = function->scope(); activation = qml.getPointer(); if (function->function()) { - compilationUnit = function->function()->compilationUnit; - lookups = compilationUnit->runtimeLookups; + d()->compilationUnit = function->function()->compilationUnit; + d()->lookups = d()->compilationUnit->runtimeLookups; } locals = (Value *)(this + 1); @@ -214,17 +214,17 @@ bool ExecutionContext::deleteProperty(const StringRef name) { Scope scope(this); bool hasWith = false; - for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) { - if (ctx->type == Type_WithContext) { + for (ExecutionContext *ctx = this; ctx; ctx = ctx->d()->outer) { + if (ctx->d()->type == Type_WithContext) { hasWith = true; WithContext *w = static_cast<WithContext *>(ctx); if (w->withObject->hasProperty(name)) return w->withObject->deleteProperty(name); - } else if (ctx->type == Type_CatchContext) { + } else if (ctx->d()->type == Type_CatchContext) { CatchContext *c = static_cast<CatchContext *>(ctx); if (c->exceptionVarName->isEqualTo(name)) return false; - } else if (ctx->type >= Type_CallContext) { + } else if (ctx->d()->type >= Type_CallContext) { CallContext *c = static_cast<CallContext *>(ctx); FunctionObject *f = c->function; if (f->needsActivation() || hasWith) { @@ -235,50 +235,50 @@ bool ExecutionContext::deleteProperty(const StringRef name) } if (c->activation && c->activation->hasProperty(name)) return c->activation->deleteProperty(name); - } else if (ctx->type == Type_GlobalContext) { + } else if (ctx->d()->type == Type_GlobalContext) { GlobalContext *g = static_cast<GlobalContext *>(ctx); if (g->global->hasProperty(name)) return g->global->deleteProperty(name); } } - if (strictMode) + if (d()->strictMode) throwSyntaxError(QStringLiteral("Can't delete property %1").arg(name->toQString())); return true; } bool CallContext::needsOwnArguments() const { - return function->needsActivation() || callData->argc < static_cast<int>(function->formalParameterCount()); + return function->needsActivation() || d()->callData->argc < static_cast<int>(function->formalParameterCount()); } void ExecutionContext::markObjects(Managed *m, ExecutionEngine *engine) { ExecutionContext *ctx = static_cast<ExecutionContext *>(m); - if (ctx->outer) - ctx->outer->mark(engine); + if (ctx->d()->outer) + ctx->d()->outer->mark(engine); // ### shouldn't need these 3 lines - ctx->callData->thisObject.mark(engine); - for (int arg = 0; arg < ctx->callData->argc; ++arg) - ctx->callData->args[arg].mark(engine); + ctx->d()->callData->thisObject.mark(engine); + for (int arg = 0; arg < ctx->d()->callData->argc; ++arg) + ctx->d()->callData->args[arg].mark(engine); - if (ctx->type >= Type_CallContext) { + if (ctx->d()->type >= Type_CallContext) { QV4::CallContext *c = static_cast<CallContext *>(ctx); for (unsigned local = 0, lastLocal = c->function->varCount(); local < lastLocal; ++local) c->locals[local].mark(engine); if (c->activation) c->activation->mark(engine); c->function->mark(engine); - } else if (ctx->type == Type_WithContext) { + } else if (ctx->d()->type == Type_WithContext) { WithContext *w = static_cast<WithContext *>(ctx); w->withObject->mark(engine); - } else if (ctx->type == Type_CatchContext) { + } else if (ctx->d()->type == Type_CatchContext) { CatchContext *c = static_cast<CatchContext *>(ctx); c->exceptionVarName->mark(engine); c->exceptionValue.mark(engine); - } else if (ctx->type == Type_GlobalContext) { + } else if (ctx->d()->type == Type_GlobalContext) { GlobalContext *g = static_cast<GlobalContext *>(ctx); g->global->mark(engine); } @@ -287,25 +287,25 @@ void ExecutionContext::markObjects(Managed *m, ExecutionEngine *engine) void ExecutionContext::setProperty(const StringRef name, const ValueRef value) { Scope scope(this); - for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) { - if (ctx->type == Type_WithContext) { + for (ExecutionContext *ctx = this; ctx; ctx = ctx->d()->outer) { + if (ctx->d()->type == Type_WithContext) { ScopedObject w(scope, static_cast<WithContext *>(ctx)->withObject); if (w->hasProperty(name)) { w->put(name, value); return; } - } else if (ctx->type == Type_CatchContext && static_cast<CatchContext *>(ctx)->exceptionVarName->isEqualTo(name)) { + } else if (ctx->d()->type == Type_CatchContext && static_cast<CatchContext *>(ctx)->exceptionVarName->isEqualTo(name)) { static_cast<CatchContext *>(ctx)->exceptionValue = *value; return; } else { ScopedObject activation(scope, (Object *)0); - if (ctx->type >= Type_CallContext) { + if (ctx->d()->type >= Type_CallContext) { CallContext *c = static_cast<CallContext *>(ctx); if (c->function->function()) { uint index = c->function->function()->internalClass->find(name); if (index < UINT_MAX) { if (index < c->function->formalParameterCount()) { - c->callData->args[c->function->formalParameterCount() - index - 1] = *value; + c->d()->callData->args[c->function->formalParameterCount() - index - 1] = *value; } else { index -= c->function->formalParameterCount(); c->locals[index] = *value; @@ -314,12 +314,12 @@ void ExecutionContext::setProperty(const StringRef name, const ValueRef value) } } activation = c->activation; - } else if (ctx->type == Type_GlobalContext) { + } else if (ctx->d()->type == Type_GlobalContext) { activation = static_cast<GlobalContext *>(ctx)->global; } if (activation) { - if (ctx->type == Type_QmlContext) { + if (ctx->d()->type == Type_QmlContext) { activation->put(name, value); return; } else { @@ -332,12 +332,12 @@ void ExecutionContext::setProperty(const StringRef name, const ValueRef value) } } } - if (strictMode || name->equals(engine->id_this)) { + if (d()->strictMode || name->equals(d()->engine->id_this)) { ScopedValue n(scope, name.asReturnedValue()); throwReferenceError(n); return; } - engine->globalObject->put(name, value); + d()->engine->globalObject->put(name, value); } ReturnedValue ExecutionContext::getProperty(const StringRef name) @@ -346,13 +346,13 @@ ReturnedValue ExecutionContext::getProperty(const StringRef name) ScopedValue v(scope); name->makeIdentifier(); - if (name->equals(engine->id_this)) - return callData->thisObject.asReturnedValue(); + if (name->equals(d()->engine->id_this)) + return d()->callData->thisObject.asReturnedValue(); bool hasWith = false; bool hasCatchScope = false; - for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) { - if (ctx->type == Type_WithContext) { + for (ExecutionContext *ctx = this; ctx; ctx = ctx->d()->outer) { + if (ctx->d()->type == Type_WithContext) { ScopedObject w(scope, static_cast<WithContext *>(ctx)->withObject); hasWith = true; bool hasProperty = false; @@ -363,21 +363,21 @@ ReturnedValue ExecutionContext::getProperty(const StringRef name) continue; } - else if (ctx->type == Type_CatchContext) { + else if (ctx->d()->type == Type_CatchContext) { hasCatchScope = true; CatchContext *c = static_cast<CatchContext *>(ctx); if (c->exceptionVarName->isEqualTo(name)) return c->exceptionValue.asReturnedValue(); } - else if (ctx->type >= Type_CallContext) { + else if (ctx->d()->type >= Type_CallContext) { QV4::CallContext *c = static_cast<CallContext *>(ctx); ScopedFunctionObject f(scope, c->function); if (f->function() && (f->needsActivation() || hasWith || hasCatchScope)) { uint index = f->function()->internalClass->find(name); if (index < UINT_MAX) { if (index < c->function->formalParameterCount()) - return c->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue(); + return c->d()->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue(); return c->locals[index - c->function->formalParameterCount()].asReturnedValue(); } } @@ -392,7 +392,7 @@ ReturnedValue ExecutionContext::getProperty(const StringRef name) return f.asReturnedValue(); } - else if (ctx->type == Type_GlobalContext) { + else if (ctx->d()->type == Type_GlobalContext) { GlobalContext *g = static_cast<GlobalContext *>(ctx); bool hasProperty = false; v = g->global->get(name, &hasProperty); @@ -411,13 +411,13 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR base = (Object *)0; name->makeIdentifier(); - if (name->equals(engine->id_this)) - return callData->thisObject.asReturnedValue(); + if (name->equals(d()->engine->id_this)) + return d()->callData->thisObject.asReturnedValue(); bool hasWith = false; bool hasCatchScope = false; - for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) { - if (ctx->type == Type_WithContext) { + for (ExecutionContext *ctx = this; ctx; ctx = ctx->d()->outer) { + if (ctx->d()->type == Type_WithContext) { Object *w = static_cast<WithContext *>(ctx)->withObject; hasWith = true; bool hasProperty = false; @@ -429,21 +429,21 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR continue; } - else if (ctx->type == Type_CatchContext) { + else if (ctx->d()->type == Type_CatchContext) { hasCatchScope = true; CatchContext *c = static_cast<CatchContext *>(ctx); if (c->exceptionVarName->isEqualTo(name)) return c->exceptionValue.asReturnedValue(); } - else if (ctx->type >= Type_CallContext) { + else if (ctx->d()->type >= Type_CallContext) { QV4::CallContext *c = static_cast<CallContext *>(ctx); FunctionObject *f = c->function; if (f->function() && (f->needsActivation() || hasWith || hasCatchScope)) { uint index = f->function()->internalClass->find(name); if (index < UINT_MAX) { if (index < c->function->formalParameterCount()) - return c->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue(); + return c->d()->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue(); return c->locals[index - c->function->formalParameterCount()].asReturnedValue(); } } @@ -451,7 +451,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR bool hasProperty = false; v = c->activation->get(name, &hasProperty); if (hasProperty) { - if (ctx->type == Type_QmlContext) + if (ctx->d()->type == Type_QmlContext) base = c->activation; return v.asReturnedValue(); } @@ -461,7 +461,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR return c->function->asReturnedValue(); } - else if (ctx->type == Type_GlobalContext) { + else if (ctx->d()->type == Type_GlobalContext) { GlobalContext *g = static_cast<GlobalContext *>(ctx); bool hasProperty = false; v = g->global->get(name, &hasProperty); @@ -476,56 +476,56 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR ReturnedValue ExecutionContext::throwError(const ValueRef value) { - return engine->throwException(value); + return d()->engine->throwException(value); } ReturnedValue ExecutionContext::throwError(const QString &message) { Scope scope(this); - ScopedValue v(scope, engine->newString(message)); - v = engine->newErrorObject(v); + ScopedValue v(scope, d()->engine->newString(message)); + v = d()->engine->newErrorObject(v); return throwError(v); } ReturnedValue ExecutionContext::throwSyntaxError(const QString &message, const QString &fileName, int line, int column) { Scope scope(this); - Scoped<Object> error(scope, engine->newSyntaxErrorObject(message, fileName, line, column)); + Scoped<Object> error(scope, d()->engine->newSyntaxErrorObject(message, fileName, line, column)); return throwError(error); } ReturnedValue ExecutionContext::throwSyntaxError(const QString &message) { Scope scope(this); - Scoped<Object> error(scope, engine->newSyntaxErrorObject(message)); + Scoped<Object> error(scope, d()->engine->newSyntaxErrorObject(message)); return throwError(error); } ReturnedValue ExecutionContext::throwTypeError() { Scope scope(this); - Scoped<Object> error(scope, engine->newTypeErrorObject(QStringLiteral("Type error"))); + Scoped<Object> error(scope, d()->engine->newTypeErrorObject(QStringLiteral("Type error"))); return throwError(error); } ReturnedValue ExecutionContext::throwTypeError(const QString &message) { Scope scope(this); - Scoped<Object> error(scope, engine->newTypeErrorObject(message)); + Scoped<Object> error(scope, d()->engine->newTypeErrorObject(message)); return throwError(error); } ReturnedValue ExecutionContext::throwUnimplemented(const QString &message) { Scope scope(this); - ScopedValue v(scope, engine->newString(QStringLiteral("Unimplemented ") + message)); - v = engine->newErrorObject(v); + ScopedValue v(scope, d()->engine->newString(QStringLiteral("Unimplemented ") + message)); + v = d()->engine->newErrorObject(v); return throwError(v); } ReturnedValue ExecutionContext::catchException(StackTrace *trace) { - return engine->catchException(this, trace); + return d()->engine->catchException(this, trace); } ReturnedValue ExecutionContext::throwReferenceError(const ValueRef value) @@ -533,7 +533,7 @@ ReturnedValue ExecutionContext::throwReferenceError(const ValueRef value) Scope scope(this); Scoped<String> s(scope, value->toString(this)); QString msg = s->toQString() + QStringLiteral(" is not defined"); - Scoped<Object> error(scope, engine->newReferenceErrorObject(msg)); + Scoped<Object> error(scope, d()->engine->newReferenceErrorObject(msg)); return throwError(error); } @@ -541,7 +541,7 @@ ReturnedValue ExecutionContext::throwReferenceError(const QString &message, cons { Scope scope(this); QString msg = message; - Scoped<Object> error(scope, engine->newReferenceErrorObject(msg, fileName, line, column)); + Scoped<Object> error(scope, d()->engine->newReferenceErrorObject(msg, fileName, line, column)); return throwError(error); } @@ -550,20 +550,20 @@ ReturnedValue ExecutionContext::throwRangeError(const ValueRef value) Scope scope(this); ScopedString s(scope, value->toString(this)); QString msg = s->toQString() + QStringLiteral(" out of range"); - ScopedObject error(scope, engine->newRangeErrorObject(msg)); + ScopedObject error(scope, d()->engine->newRangeErrorObject(msg)); return throwError(error); } ReturnedValue ExecutionContext::throwRangeError(const QString &message) { Scope scope(this); - ScopedObject error(scope, engine->newRangeErrorObject(message)); + ScopedObject error(scope, d()->engine->newRangeErrorObject(message)); return throwError(error); } ReturnedValue ExecutionContext::throwURIError(const ValueRef msg) { Scope scope(this); - ScopedObject error(scope, engine->newURIErrorObject(msg)); + ScopedObject error(scope, d()->engine->newURIErrorObject(msg)); return throwError(error); } |