aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4context.cpp
diff options
context:
space:
mode:
authorLars Knoll <[email protected]>2017-02-06 15:51:01 +0100
committerLars Knoll <[email protected]>2017-03-09 08:59:01 +0000
commit38221427bc21a11b96de7fa7666264c34298c0c0 (patch)
tree3a5bd84b10a7ca4d96acba04db6dbb4fd1a90807 /src/qml/jsruntime/qv4context.cpp
parentb214d6cc2f96837d6502c9a3068bbd0d08b5b929 (diff)
Get rid of QV4::Function::needsActivation()
We can just as well simply check whether we have a simple or regular CallContext instead. Change-Id: Iddd4ca249ab6b3b13d7ef0a732c22a26bcb23dbb Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4context.cpp')
-rw-r--r--src/qml/jsruntime/qv4context.cpp87
1 files changed, 37 insertions, 50 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index be53b14786..a9b0d67630 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -202,7 +202,6 @@ unsigned int SimpleCallContext::variableCount() const
bool ExecutionContext::deleteProperty(String *name)
{
Scope scope(this);
- bool hasWith = false;
ScopedContext ctx(scope, this);
for (; ctx; ctx = ctx->d()->outer) {
switch (ctx->d()->type) {
@@ -213,7 +212,6 @@ bool ExecutionContext::deleteProperty(String *name)
break;
}
case Heap::ExecutionContext::Type_WithContext: {
- hasWith = true;
ScopedObject withObject(scope, static_cast<Heap::WithContext *>(ctx->d())->withObject);
if (withObject->hasProperty(name))
return withObject->deleteProperty(name);
@@ -225,15 +223,16 @@ bool ExecutionContext::deleteProperty(String *name)
return global->deleteProperty(name);
break;
}
- case Heap::ExecutionContext::Type_CallContext:
+ case Heap::ExecutionContext::Type_CallContext: {
+ Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
+ uint index = c->v4Function->internalClass->find(name);
+ if (index < UINT_MAX)
+ // ### throw in strict mode?
+ return false;
+ Q_FALLTHROUGH();
+ }
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d());
- if (c->v4Function && (c->v4Function->needsActivation() || hasWith)) {
- uint index = c->v4Function->internalClass->find(name);
- if (index < UINT_MAX)
- // ### throw in strict mode?
- return false;
- }
ScopedObject qml(scope, c->activation);
if (qml && qml->hasProperty(name))
return qml->deleteProperty(name);
@@ -376,13 +375,10 @@ ReturnedValue ExecutionContext::getProperty(String *name)
if (name->equals(d()->engine->id_this()))
return thisObject().asReturnedValue();
- bool hasWith = false;
- bool hasCatchScope = false;
ScopedContext ctx(scope, this);
for (; ctx; ctx = ctx->d()->outer) {
switch (ctx->d()->type) {
case Heap::ExecutionContext::Type_CatchContext: {
- hasCatchScope = true;
Heap::CatchContext *c = static_cast<Heap::CatchContext *>(ctx->d());
if (c->exceptionVarName->isEqualTo(name->d()))
return c->exceptionValue.asReturnedValue();
@@ -390,7 +386,6 @@ ReturnedValue ExecutionContext::getProperty(String *name)
}
case Heap::ExecutionContext::Type_WithContext: {
ScopedObject w(scope, static_cast<Heap::WithContext *>(ctx->d())->withObject);
- hasWith = true;
bool hasProperty = false;
v = w->get(name, &hasProperty);
if (hasProperty) {
@@ -406,18 +401,23 @@ ReturnedValue ExecutionContext::getProperty(String *name)
return v->asReturnedValue();
break;
}
- case Heap::ExecutionContext::Type_CallContext:
+ case Heap::ExecutionContext::Type_CallContext: {
+ Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
+ uint index = c->v4Function->internalClass->find(name);
+ if (index < UINT_MAX) {
+ if (index < c->v4Function->nFormals)
+ return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
+ Q_ASSERT(c->type = Heap::ExecutionContext::Type_CallContext);
+ return c->locals[index - c->v4Function->nFormals].asReturnedValue();
+ }
+ if (c->v4Function->isNamedExpression()) {
+ if (c->function && name->equals(ScopedString(scope, c->v4Function->name())))
+ return c->function->asReturnedValue();
+ }
+ Q_FALLTHROUGH();
+ }
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d());
- if (c->v4Function && (c->v4Function->needsActivation() || hasWith || hasCatchScope)) {
- uint index = c->v4Function->internalClass->find(name);
- if (index < UINT_MAX) {
- if (index < c->v4Function->nFormals)
- return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
- Q_ASSERT(c->type = Heap::ExecutionContext::Type_CallContext);
- return static_cast<Heap::CallContext *>(c)->locals[index - c->v4Function->nFormals].asReturnedValue();
- }
- }
ScopedObject activation(scope, c->activation);
if (activation) {
bool hasProperty = false;
@@ -425,12 +425,6 @@ ReturnedValue ExecutionContext::getProperty(String *name)
if (hasProperty)
return v->asReturnedValue();
}
- if (c->v4Function->isNamedExpression()) {
- Q_ASSERT(c->type == Heap::CallContext::Type_CallContext);
- Heap::CallContext *ctx = static_cast<Heap::CallContext *>(c);
- if (ctx->function && name->equals(ScopedString(scope, c->v4Function->name())))
- return ctx->function->asReturnedValue();
- }
break;
}
case Heap::ExecutionContext::Type_QmlContext: {
@@ -457,13 +451,10 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
if (name->equals(d()->engine->id_this()))
return thisObject().asReturnedValue();
- bool hasWith = false;
- bool hasCatchScope = false;
ScopedContext ctx(scope, this);
for (; ctx; ctx = ctx->d()->outer) {
switch (ctx->d()->type) {
case Heap::ExecutionContext::Type_CatchContext: {
- hasCatchScope = true;
Heap::CatchContext *c = static_cast<Heap::CatchContext *>(ctx->d());
if (c->exceptionVarName->isEqualTo(name->d()))
return c->exceptionValue.asReturnedValue();
@@ -471,7 +462,6 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
}
case Heap::ExecutionContext::Type_WithContext: {
ScopedObject w(scope, static_cast<Heap::WithContext *>(ctx->d())->withObject);
- hasWith = true;
bool hasProperty = false;
v = w->get(name, &hasProperty);
if (hasProperty) {
@@ -488,19 +478,22 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
return v->asReturnedValue();
break;
}
- case Heap::ExecutionContext::Type_CallContext:
+ case Heap::ExecutionContext::Type_CallContext: {
+ Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
+ uint index = c->v4Function->internalClass->find(name);
+ if (index < UINT_MAX) {
+ if (index < c->v4Function->nFormals)
+ return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
+ return c->locals[index - c->v4Function->nFormals].asReturnedValue();
+ }
+ if (c->v4Function->isNamedExpression()) {
+ if (c->function && name->equals(ScopedString(scope, c->v4Function->name())))
+ return c->function->asReturnedValue();
+ }
+ Q_FALLTHROUGH();
+ }
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d());
- if (c->v4Function && (c->v4Function->needsActivation() || hasWith || hasCatchScope)) {
- Q_ASSERT(c->type == Heap::CallContext::Type_CallContext);
- Heap::CallContext *ctx = static_cast<Heap::CallContext *>(c);
- uint index = c->v4Function->internalClass->find(name);
- if (index < UINT_MAX) {
- if (index < c->v4Function->nFormals)
- return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
- return ctx->locals[index - c->v4Function->nFormals].asReturnedValue();
- }
- }
ScopedObject activation(scope, c->activation);
if (activation) {
bool hasProperty = false;
@@ -508,12 +501,6 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
if (hasProperty)
return v->asReturnedValue();
}
- if (c->v4Function->isNamedExpression()) {
- Q_ASSERT(c->type == Heap::CallContext::Type_CallContext);
- Heap::CallContext *ctx = static_cast<Heap::CallContext *>(c);
- if (ctx->function && name->equals(ScopedString(scope, c->v4Function->name())))
- return ctx->function->asReturnedValue();
- }
break;
}
case Heap::ExecutionContext::Type_QmlContext: {