diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-03-05 16:24:56 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-07 16:55:12 +0100 |
commit | b287d58b3937160b30388f29410df0f14bb0d778 (patch) | |
tree | a9ade90f36a77b8839ec69f4d7ad3881a5da6c97 /src/qml/jsruntime | |
parent | b8ca4132433c2d1eef0a6cda8be8a1754786702b (diff) |
Move some methods from ExecutionContext to CallContext
This is where they really belong. Slightly simplifies
and cleans up the code.
Change-Id: Ib5782c1f57c761c46f4bc52c3d496220299f8ac9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 55 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context_p.h | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 10 |
3 files changed, 35 insertions, 42 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 4878592426..fa5dc7285c 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -133,38 +133,6 @@ void ExecutionContext::createMutableBinding(const StringRef name, bool deletable activation->__defineOwnProperty__(this, name, desc, attrs); } -String * const *ExecutionContext::formals() const -{ - if (type < Type_SimpleCallContext) - return 0; - QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function; - return (f && f->function) ? f->function->internalClass->nameMap.constData() : 0; -} - -unsigned int ExecutionContext::formalCount() const -{ - if (type < Type_SimpleCallContext) - return 0; - QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function; - return f ? f->formalParameterCount() : 0; -} - -String * const *ExecutionContext::variables() const -{ - if (type < Type_SimpleCallContext) - return 0; - QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function; - return (f && f->function) ? f->function->internalClass->nameMap.constData() + f->function->compiledFunction->nFormals : 0; -} - -unsigned int ExecutionContext::variableCount() const -{ - if (type < Type_SimpleCallContext) - return 0; - QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function; - return f ? f->varCount() : 0; -} - GlobalContext::GlobalContext(ExecutionEngine *eng) : ExecutionContext(eng, Type_GlobalContext) @@ -220,6 +188,27 @@ CallContext::CallContext(ExecutionEngine *engine, ObjectRef qml, FunctionObject std::fill(locals, locals + function->varCount(), Primitive::undefinedValue()); } +String * const *CallContext::formals() const +{ + return (function && function->function) ? function->function->internalClass->nameMap.constData() : 0; +} + +unsigned int CallContext::formalCount() const +{ + return function ? function->formalParameterCount() : 0; +} + +String * const *CallContext::variables() const +{ + return (function && function->function) ? function->function->internalClass->nameMap.constData() + function->function->compiledFunction->nFormals : 0; +} + +unsigned int CallContext::variableCount() const +{ + return function ? function->varCount() : 0; +} + + bool ExecutionContext::deleteProperty(const StringRef name) { @@ -277,7 +266,7 @@ void ExecutionContext::markObjects(Managed *m, ExecutionEngine *engine) if (ctx->type >= Type_CallContext) { QV4::CallContext *c = static_cast<CallContext *>(ctx); - for (unsigned local = 0, lastLocal = c->variableCount(); local < lastLocal; ++local) + for (unsigned local = 0, lastLocal = c->function->varCount(); local < lastLocal; ++local) c->locals[local].mark(engine); if (c->activation) c->activation->mark(engine); diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index 952582ac00..ddced40714 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -124,12 +124,6 @@ struct Q_QML_EXPORT ExecutionContext : public Managed CatchContext *newCatchContext(const StringRef exceptionVarName, const ValueRef exceptionValue); CallContext *newQmlContext(FunctionObject *f, ObjectRef qml); - // formals are in reverse order - String * const *formals() const; - unsigned int formalCount() const; - String * const *variables() const; - unsigned int variableCount() const; - void createMutableBinding(const StringRef name, bool deletable); ReturnedValue throwError(const QV4::ValueRef value); @@ -175,6 +169,12 @@ struct CallContext : public ExecutionContext Value *locals; Object *activation; + // formals are in reverse order + String * const *formals() const; + unsigned int formalCount() const; + String * const *variables() const; + unsigned int variableCount() const; + inline ReturnedValue argument(int i); bool needsOwnArguments() const; }; diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 195eac669d..ebcc8bbefa 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -220,9 +220,13 @@ void Script::parse() } QStringList inheritedLocals; - if (inheritContext) - for (String * const *i = scope->variables(), * const *ei = i + scope->variableCount(); i < ei; ++i) - inheritedLocals.append(*i ? (*i)->toQString() : QString()); + if (inheritContext) { + CallContext *ctx = scope->asCallContext(); + if (ctx) { + for (String * const *i = ctx->variables(), * const *ei = i + ctx->variableCount(); i < ei; ++i) + inheritedLocals.append(*i ? (*i)->toQString() : QString()); + } + } RuntimeCodegen cg(scope, strictMode); cg.generateFromProgram(sourceFile, sourceCode, program, &module, QQmlJS::Codegen::EvalCode, inheritedLocals); |