aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4context.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-07-04 16:07:50 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2017-07-05 09:05:55 +0000
commitcfb17c44cf3ae1268d066ba414759068059a7bbd (patch)
tree58efa2997a5ac52b7d1f11ec0c8de2754f02f03b /src/qml/jsruntime/qv4context.cpp
parent79ceef9f467d065c6e921892e9cc4ed46a0183cc (diff)
Simplify and unite handling of activation objects in Contexts
All ExecutionContexts (except for CatchContext) have or can have some sort of activation object. Unify them in one pointer in the ExecutionContext class, and unify it's handling where it's actually the same. Change-Id: I6750999ddbd5d1d74235ef4b34dcd7546c432541 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4context.cpp')
-rw-r--r--src/qml/jsruntime/qv4context.cpp103
1 files changed, 25 insertions, 78 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index ba72a9e43b..7c0a872a3b 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -132,8 +132,7 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable)
case Heap::ExecutionContext::Type_QmlContext: {
// this is ugly, as it overrides the inner callcontext, but has to stay as long
// as bindings still get their own callcontext
- Heap::QmlContext *qml = static_cast<Heap::QmlContext *>(ctx->d());
- activation = qml->qml;
+ activation = ctx->d()->activation;
break;
}
case Heap::ExecutionContext::Type_GlobalContext: {
@@ -158,7 +157,7 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable)
void Heap::GlobalContext::init(ExecutionEngine *eng)
{
Heap::ExecutionContext::init(Heap::ExecutionContext::Type_GlobalContext);
- global.set(eng, eng->globalObject->d());
+ activation.set(eng, eng->globalObject->d());
}
void Heap::CatchContext::init(ExecutionContext *outerContext, String *exceptionVarName,
@@ -185,7 +184,7 @@ void Heap::WithContext::init(ExecutionContext *outerContext, Object *with)
constantTable = outer->constantTable;
compilationUnit = outer->compilationUnit;
- withObject.set(internalClass->engine, with);
+ activation.set(internalClass->engine, with);
}
Identifier * const *SimpleCallContext::formals() const
@@ -225,18 +224,6 @@ bool ExecutionContext::deleteProperty(String *name)
return false;
break;
}
- case Heap::ExecutionContext::Type_WithContext: {
- ScopedObject withObject(scope, static_cast<Heap::WithContext *>(ctx->d())->withObject);
- if (withObject->hasProperty(name))
- return withObject->deleteProperty(name);
- break;
- }
- case Heap::ExecutionContext::Type_GlobalContext: {
- ScopedObject global(scope, static_cast<Heap::GlobalContext *>(ctx->d())->global);
- if (global->hasProperty(name))
- return global->deleteProperty(name);
- break;
- }
case Heap::ExecutionContext::Type_CallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
uint index = c->v4Function->internalClass->find(id);
@@ -245,11 +232,12 @@ bool ExecutionContext::deleteProperty(String *name)
return false;
Q_FALLTHROUGH();
}
+ case Heap::ExecutionContext::Type_WithContext:
+ case Heap::ExecutionContext::Type_GlobalContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
- Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d());
- ScopedObject qml(scope, c->activation);
- if (qml && qml->hasProperty(name))
- return qml->deleteProperty(name);
+ ScopedObject object(scope, ctx->d()->activation);
+ if (object && object->hasProperty(name))
+ return object->deleteProperty(name);
break;
}
case Heap::ExecutionContext::Type_QmlContext:
@@ -329,17 +317,14 @@ void ExecutionContext::setProperty(String *name, const Value &value)
break;
}
case Heap::ExecutionContext::Type_WithContext: {
- ScopedObject w(scope, static_cast<Heap::WithContext *>(ctx->d())->withObject);
+ // the semantics are different from the setProperty calls of other activations
+ ScopedObject w(scope, static_cast<Heap::WithContext *>(ctx->d())->activation);
if (w->hasProperty(name)) {
w->put(name, value);
return;
}
break;
}
- case Heap::ExecutionContext::Type_GlobalContext: {
- activation = static_cast<Heap::GlobalContext *>(ctx->d())->global;
- break;
- }
case Heap::ExecutionContext::Type_CallContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d());
@@ -356,11 +341,13 @@ void ExecutionContext::setProperty(String *name, const Value &value)
return;
}
}
- activation = c->activation;
- break;
}
+ Q_FALLTHROUGH();
+ case Heap::ExecutionContext::Type_GlobalContext:
+ activation = ctx->d()->activation;
+ break;
case Heap::ExecutionContext::Type_QmlContext: {
- activation = static_cast<Heap::QmlContext *>(ctx->d())->qml;
+ activation = ctx->d()->activation;
activation->put(name, value);
return;
}
@@ -401,23 +388,6 @@ ReturnedValue ExecutionContext::getProperty(String *name)
return c->exceptionValue.asReturnedValue();
break;
}
- case Heap::ExecutionContext::Type_WithContext: {
- ScopedObject w(scope, static_cast<Heap::WithContext *>(ctx->d())->withObject);
- bool hasProperty = false;
- v = w->get(name, &hasProperty);
- if (hasProperty) {
- return v->asReturnedValue();
- }
- break;
- }
- case Heap::ExecutionContext::Type_GlobalContext: {
- ScopedObject global(scope, static_cast<Heap::GlobalContext *>(ctx->d())->global);
- bool hasProperty = false;
- v = global->get(name, &hasProperty);
- if (hasProperty)
- return v->asReturnedValue();
- break;
- }
case Heap::ExecutionContext::Type_CallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
name->makeIdentifier();
@@ -436,9 +406,11 @@ ReturnedValue ExecutionContext::getProperty(String *name)
}
Q_FALLTHROUGH();
}
+ case Heap::ExecutionContext::Type_WithContext:
+ case Heap::ExecutionContext::Type_GlobalContext:
+ case Heap::ExecutionContext::Type_QmlContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
- Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d());
- ScopedObject activation(scope, c->activation);
+ ScopedObject activation(scope, ctx->d()->activation);
if (activation) {
bool hasProperty = false;
v = activation->get(name, &hasProperty);
@@ -447,14 +419,6 @@ ReturnedValue ExecutionContext::getProperty(String *name)
}
break;
}
- case Heap::ExecutionContext::Type_QmlContext: {
- ScopedObject qml(scope, static_cast<Heap::QmlContext *>(ctx->d())->qml);
- bool hasProperty = false;
- v = qml->get(name, &hasProperty);
- if (hasProperty)
- return v->asReturnedValue();
- break;
- }
}
}
ScopedValue n(scope, name);
@@ -480,24 +444,6 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
return c->exceptionValue.asReturnedValue();
break;
}
- case Heap::ExecutionContext::Type_WithContext: {
- ScopedObject w(scope, static_cast<Heap::WithContext *>(ctx->d())->withObject);
- bool hasProperty = false;
- v = w->get(name, &hasProperty);
- if (hasProperty) {
- base->setM(w->d());
- return v->asReturnedValue();
- }
- break;
- }
- case Heap::ExecutionContext::Type_GlobalContext: {
- ScopedObject global(scope, static_cast<Heap::GlobalContext *>(ctx->d())->global);
- bool hasProperty = false;
- v = global->get(name, &hasProperty);
- if (hasProperty)
- return v->asReturnedValue();
- break;
- }
case Heap::ExecutionContext::Type_CallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
name->makeIdentifier();
@@ -515,9 +461,9 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
}
Q_FALLTHROUGH();
}
+ case Heap::ExecutionContext::Type_GlobalContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
- Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d());
- ScopedObject activation(scope, c->activation);
+ ScopedObject activation(scope, ctx->d()->activation);
if (activation) {
bool hasProperty = false;
v = activation->get(name, &hasProperty);
@@ -526,12 +472,13 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
}
break;
}
+ case Heap::ExecutionContext::Type_WithContext:
case Heap::ExecutionContext::Type_QmlContext: {
- ScopedObject qml(scope, static_cast<Heap::QmlContext *>(ctx->d())->qml);
+ ScopedObject o(scope, ctx->d()->activation);
bool hasProperty = false;
- v = qml->get(name, &hasProperty);
+ v = o->get(name, &hasProperty);
if (hasProperty) {
- base->setM(qml->d());
+ base->setM(o->d());
return v->asReturnedValue();
}
break;