diff options
Diffstat (limited to 'src/qml/jsruntime/qv4context_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4context_p.h | 98 |
1 files changed, 61 insertions, 37 deletions
diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index c06c10453b..2cdcf2b906 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -44,6 +44,7 @@ #include "qv4global_p.h" #include "qv4value_def_p.h" #include "qv4managed_p.h" +#include "qv4engine_p.h" QT_BEGIN_NAMESPACE @@ -69,19 +70,8 @@ struct WithContext; struct Q_QML_EXPORT ExecutionContext : public Managed { Q_MANAGED - ExecutionContext() - : Managed(0) { - vtbl = &static_vtbl; - } - void init() { - _data = 0; - internalClass = 0; - inUse = 1; - extensible = 1; - vtbl = &static_vtbl; - } - enum Type { + enum ContextType { Type_GlobalContext = 0x1, Type_CatchContext = 0x2, Type_WithContext = 0x3, @@ -90,7 +80,23 @@ struct Q_QML_EXPORT ExecutionContext : public Managed Type_QmlContext = 0x6 }; - Type type; + ExecutionContext(ExecutionEngine *engine, ContextType t, ExecutionContext *parent) + : Managed(engine->emptyClass) + { + setVTable(&static_vtbl); + this->type = t; + strictMode = false; + this->engine = engine; + this->parent = parent; + outer = 0; + lookups = 0; + compilationUnit = 0; + currentEvalCode = 0; + interpreterInstructionPointer = 0; + lineNumber = -1; + } + + ContextType type; bool strictMode; CallData *callData; @@ -112,20 +118,6 @@ struct Q_QML_EXPORT ExecutionContext : public Managed const uchar **interpreterInstructionPointer; int lineNumber; - void initBaseContext(Type type, ExecutionEngine *engine, ExecutionContext *parentContext) - { - this->type = type; - strictMode = false; - this->engine = engine; - parent = parentContext; - outer = 0; - lookups = 0; - compilationUnit = 0; - currentEvalCode = 0; - interpreterInstructionPointer = 0; - lineNumber = -1; - } - CallContext *newCallContext(FunctionObject *f, CallData *callData); WithContext *newWithContext(ObjectRef with); CatchContext *newCatchContext(const StringRef exceptionVarName, const ValueRef exceptionValue); @@ -168,17 +160,20 @@ struct Q_QML_EXPORT ExecutionContext : public Managed struct CallContext : public ExecutionContext { + CallContext(ExecutionEngine *engine, ExecutionContext *parent, ContextType t = Type_SimpleCallContext) + : ExecutionContext(engine, t, parent) + { + function = 0; + locals = 0; + activation = 0; + } + CallContext(ExecutionContext *parentContext, ObjectRef qml, QV4::FunctionObject *function); + FunctionObject *function; int realArgumentCount; SafeValue *locals; Object *activation; - void initSimpleCallContext(ExecutionEngine *engine, ExecutionContext *parent) { - initBaseContext(Type_SimpleCallContext, engine, parent); - function = 0; - locals = 0; - activation = 0; - } void initQmlContext(ExecutionContext *parentContext, ObjectRef qml, QV4::FunctionObject *function); inline ReturnedValue argument(int i); @@ -187,14 +182,14 @@ struct CallContext : public ExecutionContext struct GlobalContext : public ExecutionContext { - void initGlobalContext(ExecutionEngine *e); + GlobalContext(ExecutionEngine *engine, ExecutionContext *parent = 0); Object *global; }; struct CatchContext : public ExecutionContext { - void initCatchContext(ExecutionContext *p, const StringRef exceptionVarName, const ValueRef exceptionValue); + CatchContext(ExecutionContext *p, const StringRef exceptionVarName, const ValueRef exceptionValue); SafeString exceptionVarName; SafeValue exceptionValue; @@ -202,9 +197,8 @@ struct CatchContext : public ExecutionContext struct WithContext : public ExecutionContext { + WithContext(ExecutionContext *p, ObjectRef with); Object *withObject; - - void initWithContext(ExecutionContext *p, ObjectRef with); }; inline CallContext *ExecutionContext::asCallContext() @@ -217,6 +211,36 @@ inline const CallContext *ExecutionContext::asCallContext() const return type >= Type_SimpleCallContext ? static_cast<const CallContext *>(this) : 0; } + +inline void ExecutionEngine::pushContext(CallContext *context) +{ + context->parent = current; + current = context; + current->currentEvalCode = 0; +} + +inline ExecutionContext *ExecutionEngine::popContext() +{ + current = current->parent; + return current; +} + +struct ExecutionContextSaver +{ + ExecutionEngine *engine; + ExecutionContext *savedContext; + + ExecutionContextSaver(ExecutionContext *context) + : engine(context->engine) + , savedContext(context) + { + } + ~ExecutionContextSaver() + { + engine->current = savedContext; + } +}; + /* Function *f, int argc */ #define requiredMemoryForExecutionContect(f, argc) \ sizeof(CallContext) + sizeof(Value) * (f->varCount + qMax((uint)argc, f->formalParameterCount)) + sizeof(CallData) |