Convert Execution contexts to new constructor syntax
authorLars Knoll <lars.knoll@digia.com>
Fri, 9 May 2014 14:50:17 +0000 (16:50 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 22 Jul 2014 11:49:19 +0000 (13:49 +0200)
Change-Id: I4bc6a61b7a96139353e20871ff7ff007822c64c3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jit/qv4assembler.cpp
src/qml/jsruntime/qv4argumentsobject.cpp
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4context_p.h
src/qml/jsruntime/qv4debugging.cpp
src/qml/jsruntime/qv4engine.cpp
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4managed_p.h
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4script.cpp
src/qml/jsruntime/qv4vme_moth.cpp

index 707b53f..cb2279b 100644 (file)
@@ -210,7 +210,7 @@ Assembler::Pointer Assembler::loadArgLocalAddress(RegisterID baseReg, IR::ArgLoc
     } break;
     case IR::ArgLocal::Local:
     case IR::ArgLocal::ScopedLocal: {
-        loadPtr(Address(context, qOffsetOf(CallContext, locals)), baseReg);
+        loadPtr(Address(context, qOffsetOf(CallContext::Data, locals)), baseReg);
         offset = al->index * sizeof(Value);
     } break;
     default:
index edd7f3a..71563b7 100644 (file)
@@ -73,10 +73,10 @@ ArgumentsObject::Data::Data(CallContext *context)
     } else {
         args->setHasAccessorProperty();
         Q_ASSERT(CalleePropertyIndex == args->internalClass()->find(context->d()->engine->id_callee));
-        args->memberData()[CalleePropertyIndex] = context->function->asReturnedValue();
+        args->memberData()[CalleePropertyIndex] = context->d()->function->asReturnedValue();
     }
     Q_ASSERT(LengthPropertyIndex == args->internalClass()->find(context->d()->engine->id_length));
-    args->memberData()[LengthPropertyIndex] = Primitive::fromInt32(context->realArgumentCount);
+    args->memberData()[LengthPropertyIndex] = Primitive::fromInt32(context->d()->realArgumentCount);
 }
 
 void ArgumentsObject::fullyCreate()
@@ -84,8 +84,8 @@ void ArgumentsObject::fullyCreate()
     if (fullyCreated())
         return;
 
-    uint numAccessors = qMin((int)context()->function->formalParameterCount(), context()->realArgumentCount);
-    uint argCount = qMin(context()->realArgumentCount, context()->d()->callData->argc);
+    uint numAccessors = qMin((int)context()->d()->function->formalParameterCount(), context()->d()->realArgumentCount);
+    uint argCount = qMin(context()->d()->realArgumentCount, context()->d()->callData->argc);
     ArrayData::realloc(this, ArrayData::Sparse, 0, argCount, true);
     context()->d()->engine->requireArgumentsAccessors(numAccessors);
     mappedArguments().ensureIndex(engine(), numAccessors);
@@ -109,7 +109,7 @@ bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const
     Property map;
     PropertyAttributes mapAttrs;
     bool isMapped = false;
-    uint numAccessors = qMin((int)context()->function->formalParameterCount(), context()->realArgumentCount);
+    uint numAccessors = qMin((int)context()->d()->function->formalParameterCount(), context()->d()->realArgumentCount);
     if (pd && index < (uint)numAccessors)
         isMapped = arrayData()->attributes(index).isAccessor() && pd->getter() == context()->d()->engine->argumentsAccessors[index].getter();
 
@@ -188,8 +188,8 @@ PropertyAttributes ArgumentsObject::queryIndexed(const Managed *m, uint index)
     if (args->fullyCreated())
         return Object::queryIndexed(m, index);
 
-    uint numAccessors = qMin((int)args->context()->function->formalParameterCount(), args->context()->realArgumentCount);
-    uint argCount = qMin(args->context()->realArgumentCount, args->context()->d()->callData->argc);
+    uint numAccessors = qMin((int)args->context()->d()->function->formalParameterCount(), args->context()->d()->realArgumentCount);
+    uint argCount = qMin(args->context()->d()->realArgumentCount, args->context()->d()->callData->argc);
     if (index >= argCount)
         return PropertyAttributes();
     if (index >= numAccessors)
index 3f4bd72..48bf0b8 100644 (file)
 using namespace QV4;
 
 DEFINE_MANAGED_VTABLE(ExecutionContext);
+DEFINE_MANAGED_VTABLE(CallContext);
+DEFINE_MANAGED_VTABLE(WithContext);
+DEFINE_MANAGED_VTABLE(GlobalContext);
 
-CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData *callData)
+HeapObject *ExecutionContext::newCallContext(FunctionObject *function, CallData *callData)
 {
     Q_ASSERT(function->function());
 
-    CallContext *c = static_cast<CallContext *>(d()->engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(function, callData->argc)));
-    new (c) CallContext(d()->engine, Type_CallContext);
+    CallContext::Data *c = reinterpret_cast<CallContext::Data *>(d()->engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(function, callData->argc)));
+    new (c) CallContext::Data(d()->engine, Type_CallContext);
 
     c->function = function;
     c->realArgumentCount = callData->argc;
 
-    c->d()->strictMode = function->strictMode();
-    c->d()->outer = function->scope();
+    c->strictMode = function->strictMode();
+    c->outer = function->scope();
 
     c->activation = 0;
 
-    c->d()->compilationUnit = function->function()->compilationUnit;
-    c->d()->lookups = c->d()->compilationUnit->runtimeLookups;
+    c->compilationUnit = function->function()->compilationUnit;
+    c->lookups = c->compilationUnit->runtimeLookups;
     c->locals = (Value *)((quintptr(c + 1) + 7) & ~7);
 
     const CompiledData::Function *compiledFunction = function->function()->compiledFunction;
@@ -77,31 +80,29 @@ CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData
     if (nLocals)
         std::fill(c->locals, c->locals + nLocals, Primitive::undefinedValue());
 
-    c->d()->callData = reinterpret_cast<CallData *>(c->locals + nLocals);
-    ::memcpy(c->d()->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(Value));
+    c->callData = reinterpret_cast<CallData *>(c->locals + nLocals);
+    ::memcpy(c->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(Value));
     if (callData->argc < static_cast<int>(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);
+        std::fill(c->callData->args + c->callData->argc, c->callData->args + compiledFunction->nFormals, Primitive::undefinedValue());
+    c->callData->argc = qMax((uint)callData->argc, compiledFunction->nFormals);
 
     return c;
 }
 
-WithContext *ExecutionContext::newWithContext(Object *with)
+HeapObject *ExecutionContext::newWithContext(Object *with)
 {
-    WithContext *w = new (d()->engine->memoryManager) WithContext(d()->engine, with);
-    return w;
+    return new (d()->engine) WithContext::Data(d()->engine, with);
 }
 
-CatchContext *ExecutionContext::newCatchContext(String *exceptionVarName, const ValueRef exceptionValue)
+HeapObject *ExecutionContext::newCatchContext(String *exceptionVarName, const ValueRef exceptionValue)
 {
-    CatchContext *c = new (d()->engine->memoryManager) CatchContext(d()->engine, exceptionVarName, exceptionValue);
-    return c;
+    return new (d()->engine) CatchContext::Data(d()->engine, exceptionVarName, exceptionValue);
 }
 
-CallContext *ExecutionContext::newQmlContext(FunctionObject *f, Object *qml)
+HeapObject *ExecutionContext::newQmlContext(FunctionObject *f, Object *qml)
 {
-    CallContext *c = static_cast<CallContext *>(d()->engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(f, 0)));
-    new (c) CallContext(d()->engine, qml, f);
+    CallContext::Data *c = reinterpret_cast<CallContext::Data *>(d()->engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(f, 0)));
+    new (c) CallContext::Data(d()->engine, qml, f);
     return c;
 }
 
@@ -117,9 +118,9 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable)
     while (ctx) {
         if (ctx->d()->type >= Type_CallContext) {
             CallContext *c = static_cast<CallContext *>(ctx);
-            if (!c->activation)
-                c->activation = d()->engine->newObject()->getPointer();
-            activation = c->activation;
+            if (!c->d()->activation)
+                c->d()->activation = d()->engine->newObject()->getPointer();
+            activation = c->d()->activation;
             break;
         }
         ctx = ctx->d()->outer;
@@ -134,53 +135,53 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable)
 }
 
 
-GlobalContext::GlobalContext(ExecutionEngine *eng)
-    : ExecutionContext(eng, Type_GlobalContext)
+GlobalContext::Data::Data(ExecutionEngine *eng)
+    : ExecutionContext::Data(eng, Type_GlobalContext)
 {
-    d()->global = eng->globalObject;
+    global = eng->globalObject;
 }
 
-WithContext::WithContext(ExecutionEngine *engine, Object *with)
-    : ExecutionContext(engine, Type_WithContext)
+WithContext::Data::Data(ExecutionEngine *engine, Object *with)
+    : ExecutionContext::Data(engine, Type_WithContext)
 {
-    d()->callData = d()->parent->d()->callData;
-    d()->outer = d()->parent;
-    d()->lookups = d()->parent->d()->lookups;
-    d()->compilationUnit = d()->parent->d()->compilationUnit;
+    callData = parent->d()->callData;
+    outer = parent;
+    lookups = parent->d()->lookups;
+    compilationUnit = parent->d()->compilationUnit;
 
-    d()->withObject = with;
+    withObject = with;
 }
 
-CatchContext::CatchContext(ExecutionEngine *engine, String *exceptionVarName, const ValueRef exceptionValue)
-    : ExecutionContext(engine, Type_CatchContext)
+CatchContext::Data::Data(ExecutionEngine *engine, String *exceptionVarName, const ValueRef exceptionValue)
+    : ExecutionContext::Data(engine, Type_CatchContext)
 {
-    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;
+    strictMode = parent->d()->strictMode;
+    callData = parent->d()->callData;
+    outer = parent;
+    lookups = parent->d()->lookups;
+    compilationUnit = parent->d()->compilationUnit;
 
-    this->d()->exceptionVarName = exceptionVarName;
-    this->d()->exceptionValue = exceptionValue;
+    this->exceptionVarName = exceptionVarName;
+    this->exceptionValue = exceptionValue;
 }
 
-CallContext::CallContext(ExecutionEngine *engine, Object *qml, FunctionObject *function)
-    : ExecutionContext(engine, Type_QmlContext)
+CallContext::Data::Data(ExecutionEngine *engine, Object *qml, FunctionObject *function)
+    : ExecutionContext::Data(engine, Type_QmlContext)
 {
     this->function = function;
-    d()->callData = reinterpret_cast<CallData *>(this + 1);
-    d()->callData->tag = QV4::Value::_Integer_Type;
-    d()->callData->argc = 0;
-    d()->callData->thisObject = Primitive::undefinedValue();
+    callData = reinterpret_cast<CallData *>(this + 1);
+    callData->tag = QV4::Value::_Integer_Type;
+    callData->argc = 0;
+    callData->thisObject = Primitive::undefinedValue();
 
-    d()->strictMode = true;
-    d()->outer = function->scope();
+    strictMode = true;
+    outer = function->scope();
 
     activation = qml;
 
     if (function->function()) {
-        d()->compilationUnit = function->function()->compilationUnit;
-        d()->lookups = d()->compilationUnit->runtimeLookups;
+        compilationUnit = function->function()->compilationUnit;
+        lookups = compilationUnit->runtimeLookups;
     }
 
     locals = (Value *)(this + 1);
@@ -190,22 +191,22 @@ CallContext::CallContext(ExecutionEngine *engine, Object *qml, FunctionObject *f
 
 String * const *CallContext::formals() const
 {
-    return (function && function->function()) ? function->function()->internalClass->nameMap.constData() : 0;
+    return (d()->function && d()->function->function()) ? d()->function->function()->internalClass->nameMap.constData() : 0;
 }
 
 unsigned int CallContext::formalCount() const
 {
-    return function ? function->formalParameterCount() : 0;
+    return d()->function ? d()->function->formalParameterCount() : 0;
 }
 
 String * const *CallContext::variables() const
 {
-    return (function && function->function()) ? function->function()->internalClass->nameMap.constData() + function->function()->compiledFunction->nFormals : 0;
+    return (d()->function && d()->function->function()) ? d()->function->function()->internalClass->nameMap.constData() + d()->function->function()->compiledFunction->nFormals : 0;
 }
 
 unsigned int CallContext::variableCount() const
 {
-    return function ? function->varCount() : 0;
+    return d()->function ? d()->function->varCount() : 0;
 }
 
 
@@ -226,15 +227,15 @@ bool ExecutionContext::deleteProperty(String *name)
                 return false;
         } else if (ctx->d()->type >= Type_CallContext) {
             CallContext *c = static_cast<CallContext *>(ctx);
-            FunctionObject *f = c->function;
+            FunctionObject *f = c->d()->function;
             if (f->needsActivation() || hasWith) {
                 uint index = f->function()->internalClass->find(name);
                 if (index < UINT_MAX)
                     // ### throw in strict mode?
                     return false;
             }
-            if (c->activation && c->activation->hasProperty(name))
-                return c->activation->deleteProperty(name);
+            if (c->d()->activation && c->d()->activation->hasProperty(name))
+                return c->d()->activation->deleteProperty(name);
         } else if (ctx->d()->type == Type_GlobalContext) {
             GlobalContext *g = static_cast<GlobalContext *>(ctx);
             if (g->d()->global->hasProperty(name))
@@ -249,7 +250,7 @@ bool ExecutionContext::deleteProperty(String *name)
 
 bool CallContext::needsOwnArguments() const
 {
-    return function->needsActivation() || d()->callData->argc < static_cast<int>(function->formalParameterCount());
+    return d()->function->needsActivation() || d()->callData->argc < static_cast<int>(d()->function->formalParameterCount());
 }
 
 void ExecutionContext::markObjects(Managed *m, ExecutionEngine *engine)
@@ -266,11 +267,11 @@ void ExecutionContext::markObjects(Managed *m, ExecutionEngine *engine)
 
     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);
+        for (unsigned local = 0, lastLocal = c->d()->function->varCount(); local < lastLocal; ++local)
+            c->d()->locals[local].mark(engine);
+        if (c->d()->activation)
+            c->d()->activation->mark(engine);
+        c->d()->function->mark(engine);
     } else if (ctx->d()->type == Type_WithContext) {
         WithContext *w = static_cast<WithContext *>(ctx);
         w->d()->withObject->mark(engine);
@@ -301,19 +302,19 @@ void ExecutionContext::setProperty(String *name, const ValueRef value)
             ScopedObject activation(scope, (Object *)0);
             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 (c->d()->function->function()) {
+                    uint index = c->d()->function->function()->internalClass->find(name);
                     if (index < UINT_MAX) {
-                        if (index < c->function->formalParameterCount()) {
-                            c->d()->callData->args[c->function->formalParameterCount() - index - 1] = *value;
+                        if (index < c->d()->function->formalParameterCount()) {
+                            c->d()->callData->args[c->d()->function->formalParameterCount() - index - 1] = *value;
                         } else {
-                            index -= c->function->formalParameterCount();
-                            c->locals[index] = *value;
+                            index -= c->d()->function->formalParameterCount();
+                            c->d()->locals[index] = *value;
                         }
                         return;
                     }
                 }
-                activation = c->activation;
+                activation = c->d()->activation;
             } else if (ctx->d()->type == Type_GlobalContext) {
                 activation = static_cast<GlobalContext *>(ctx)->d()->global;
             }
@@ -372,18 +373,18 @@ ReturnedValue ExecutionContext::getProperty(String *name)
 
         else if (ctx->d()->type >= Type_CallContext) {
             QV4::CallContext *c = static_cast<CallContext *>(ctx);
-            ScopedFunctionObject f(scope, c->function);
+            ScopedFunctionObject f(scope, c->d()->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->d()->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue();
-                    return c->locals[index - c->function->formalParameterCount()].asReturnedValue();
+                    if (index < c->d()->function->formalParameterCount())
+                        return c->d()->callData->args[c->d()->function->formalParameterCount() - index - 1].asReturnedValue();
+                    return c->d()->locals[index - c->d()->function->formalParameterCount()].asReturnedValue();
                 }
             }
-            if (c->activation) {
+            if (c->d()->activation) {
                 bool hasProperty = false;
-                v = c->activation->get(name, &hasProperty);
+                v = c->d()->activation->get(name, &hasProperty);
                 if (hasProperty)
                     return v.asReturnedValue();
             }
@@ -438,27 +439,27 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Object *&base)
 
         else if (ctx->d()->type >= Type_CallContext) {
             QV4::CallContext *c = static_cast<CallContext *>(ctx);
-            FunctionObject *f = c->function;
+            FunctionObject *f = c->d()->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->d()->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue();
-                    return c->locals[index - c->function->formalParameterCount()].asReturnedValue();
+                    if (index < c->d()->function->formalParameterCount())
+                        return c->d()->callData->args[c->d()->function->formalParameterCount() - index - 1].asReturnedValue();
+                    return c->d()->locals[index - c->d()->function->formalParameterCount()].asReturnedValue();
                 }
             }
-            if (c->activation) {
+            if (c->d()->activation) {
                 bool hasProperty = false;
-                v = c->activation->get(name, &hasProperty);
+                v = c->d()->activation->get(name, &hasProperty);
                 if (hasProperty) {
                     if (ctx->d()->type == Type_QmlContext)
-                        base = c->activation;
+                        base = c->d()->activation;
                     return v.asReturnedValue();
                 }
             }
             if (f->function() && f->function()->isNamedExpression()
                 && name->equals(f->function()->name()))
-                return c->function->asReturnedValue();
+                return c->d()->function->asReturnedValue();
         }
 
         else if (ctx->d()->type == Type_GlobalContext) {
index beb3368..fe05774 100644 (file)
@@ -88,6 +88,20 @@ struct Q_QML_EXPORT ExecutionContext : public Managed
     };
 
     struct Data : Managed::Data {
+        Data(ExecutionEngine *engine, ContextType t)
+            : Managed::Data(engine->executionContextClass)
+            , type(t)
+            , strictMode(false)
+            , engine(engine)
+            , parent(engine->currentContext())
+            , outer(0)
+            , lookups(0)
+            , compilationUnit(0)
+            , currentEvalCode(0)
+            , lineNumber(-1)
+        {
+            engine->current = reinterpret_cast<ExecutionContext *>(this);
+        }
         ContextType type;
         bool strictMode;
 
@@ -137,10 +151,10 @@ struct Q_QML_EXPORT ExecutionContext : public Managed
         engine->current = this;
     }
 
-    CallContext *newCallContext(FunctionObject *f, CallData *callData);
-    WithContext *newWithContext(Object *with);
-    CatchContext *newCatchContext(String *exceptionVarName, const ValueRef exceptionValue);
-    CallContext *newQmlContext(FunctionObject *f, Object *qml);
+    HeapObject *newCallContext(FunctionObject *f, CallData *callData);
+    HeapObject *newWithContext(Object *with);
+    HeapObject *newCatchContext(String *exceptionVarName, const ValueRef exceptionValue);
+    HeapObject *newQmlContext(FunctionObject *f, Object *qml);
 
     void createMutableBinding(String *name, bool deletable);
 
@@ -173,19 +187,28 @@ struct Q_QML_EXPORT ExecutionContext : public Managed
 
 struct CallContext : public ExecutionContext
 {
-    CallContext(ExecutionEngine *engine, ContextType t = Type_SimpleCallContext)
-        : ExecutionContext(engine, t)
-    {
-        function = 0;
-        locals = 0;
-        activation = 0;
-    }
-    CallContext(ExecutionEngine *engine, Object *qml, QV4::FunctionObject *function);
-
-    FunctionObject *function;
-    int realArgumentCount;
-    Value *locals;
-    Object *activation;
+    struct Data : ExecutionContext::Data {
+        Data(ExecutionEngine *engine, ContextType t = Type_SimpleCallContext)
+            : ExecutionContext::Data(engine, t)
+        {
+            function = 0;
+            locals = 0;
+            activation = 0;
+        }
+        Data(ExecutionEngine *engine, Object *qml, QV4::FunctionObject *function);
+
+        FunctionObject *function;
+        int realArgumentCount;
+        Value *locals;
+        Object *activation;
+    };
+    struct {
+        FunctionObject *function;
+        int realArgumentCount;
+        Value *locals;
+        Object *activation;
+    } __data;
+    V4_MANAGED
 
     // formals are in reverse order
     String * const *formals() const;
@@ -204,6 +227,7 @@ inline ReturnedValue CallContext::argument(int i) {
 struct GlobalContext : public ExecutionContext
 {
     struct Data : ExecutionContext::Data {
+        Data(ExecutionEngine *engine);
         Object *global;
     };
     struct {
@@ -211,12 +235,12 @@ struct GlobalContext : public ExecutionContext
     } __data;
     V4_MANAGED
 
-    GlobalContext(ExecutionEngine *engine);
 };
 
 struct CatchContext : public ExecutionContext
 {
     struct Data : ExecutionContext::Data {
+        Data(ExecutionEngine *engine, String *exceptionVarName, const ValueRef exceptionValue);
         StringValue exceptionVarName;
         Value exceptionValue;
     };
@@ -225,21 +249,18 @@ struct CatchContext : public ExecutionContext
         Value exceptionValue;
     } __data;
     V4_MANAGED
-
-    CatchContext(ExecutionEngine *engine, String *exceptionVarName, const ValueRef exceptionValue);
 };
 
 struct WithContext : public ExecutionContext
 {
     struct Data : ExecutionContext::Data {
+        Data(ExecutionEngine *engine, Object *with);
         Object *withObject;
     };
     struct {
         Object *withObject;
     } __data;
     V4_MANAGED
-
-    WithContext(ExecutionEngine *engine, Object *with);
 };
 
 inline CallContext *ExecutionContext::asCallContext()
index f2a95fc..04422b9 100644 (file)
@@ -224,7 +224,7 @@ static inline CallContext *findContext(ExecutionContext *ctxt, int frame)
 {
     while (ctxt) {
         CallContext *cCtxt = ctxt->asCallContext();
-        if (cCtxt && cCtxt->function) {
+        if (cCtxt && cCtxt->d()->function) {
             if (frame < 1)
                 return cCtxt;
             --frame;
@@ -327,7 +327,7 @@ void Debugger::collectLocalsInContext(Collector *collector, int frameNr, int sco
                 QString qName;
                 if (String *name = ctxt->variables()[i])
                     qName = name->toQString();
-                v = ctxt->locals[i];
+                v = ctxt->d()->locals[i];
                 collector->collect(qName, v);
             }
         }
@@ -367,7 +367,7 @@ bool Debugger::collectThisInContext(Debugger::Collector *collector, int frame)
             ExecutionContext *ctxt = findContext(engine->currentContext(), frameNr);
             while (ctxt) {
                 if (CallContext *cCtxt = ctxt->asCallContext())
-                    if (cCtxt->activation)
+                    if (cCtxt->d()->activation)
                         break;
                 ctxt = ctxt->d()->outer;
             }
@@ -376,7 +376,7 @@ bool Debugger::collectThisInContext(Debugger::Collector *collector, int frame)
                 return false;
 
             Scope scope(engine);
-            ScopedObject o(scope, ctxt->asCallContext()->activation);
+            ScopedObject o(scope, ctxt->asCallContext()->d()->activation);
             collector->collect(o);
             return true;
         }
@@ -517,7 +517,7 @@ Function *Debugger::getFunction() const
 {
     ExecutionContext *context = m_engine->currentContext();
     if (CallContext *callCtx = context->asCallContext())
-        return callCtx->function->function();
+        return callCtx->d()->function->function();
     else {
         Q_ASSERT(context->d()->type == QV4::ExecutionContext::Type_GlobalContext);
         return context->d()->engine->globalCode;
index 58520ad..f0e52f7 100644 (file)
@@ -459,13 +459,15 @@ void ExecutionEngine::enableProfiler()
 
 void ExecutionEngine::initRootContext()
 {
-    rootContext = static_cast<GlobalContext *>(memoryManager->allocManaged(sizeof(GlobalContext) + sizeof(CallData)));
-    new (rootContext) GlobalContext(this);
-    rootContext->d()->callData = reinterpret_cast<CallData *>(rootContext + 1);
-    rootContext->d()->callData->tag = QV4::Value::_Integer_Type;
-    rootContext->d()->callData->argc = 0;
-    rootContext->d()->callData->thisObject = globalObject;
-    rootContext->d()->callData->args[0] = Encode::undefined();
+    GlobalContext::Data *r = reinterpret_cast<GlobalContext::Data *>(memoryManager->allocManaged(sizeof(GlobalContext) + sizeof(CallData)));
+    new (r) GlobalContext::Data(this);
+    r->callData = reinterpret_cast<CallData *>(r + 1);
+    r->callData->tag = QV4::Value::_Integer_Type;
+    r->callData->argc = 0;
+    r->callData->thisObject = globalObject;
+    r->callData->args[0] = Encode::undefined();
+
+    rootContext = reinterpret_cast<GlobalContext *>(r);
 }
 
 InternalClass *ExecutionEngine::newClass(const InternalClass &other)
@@ -475,11 +477,11 @@ InternalClass *ExecutionEngine::newClass(const InternalClass &other)
 
 ExecutionContext *ExecutionEngine::pushGlobalContext()
 {
-    GlobalContext *g = new (memoryManager) GlobalContext(this);
-    g->d()->callData = rootContext->d()->callData;
+    GlobalContext::Data *g = new (this) GlobalContext::Data(this);
+    g->callData = rootContext->d()->callData;
 
-    Q_ASSERT(currentContext() == g);
-    return g;
+    Q_ASSERT(currentContext() == reinterpret_cast<GlobalContext *>(g));
+    return reinterpret_cast<GlobalContext *>(g);
 }
 
 
@@ -690,7 +692,7 @@ Returned<Object> *ExecutionEngine::qmlContextObject() const
     if (ctx->d()->type != ExecutionContext::Type_QmlContext)
         return 0;
 
-    return static_cast<CallContext *>(ctx)->activation->asReturned<Object>();
+    return static_cast<CallContext *>(ctx)->d()->activation->asReturned<Object>();
 }
 
 QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const
@@ -702,16 +704,16 @@ QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const
     QV4::ExecutionContext *c = currentContext();
     while (c && frameLimit) {
         CallContext *callCtx = c->asCallContext();
-        if (callCtx && callCtx->function) {
+        if (callCtx && callCtx->d()->function) {
             StackFrame frame;
-            if (callCtx->function->function())
-                frame.source = callCtx->function->function()->sourceFile();
-            name = callCtx->function->name();
+            if (callCtx->d()->function->function())
+                frame.source = callCtx->d()->function->function()->sourceFile();
+            name = callCtx->d()->function->name();
             frame.function = name->toQString();
             frame.line = -1;
             frame.column = -1;
 
-            if (callCtx->function->function())
+            if (callCtx->d()->function->function())
                 // line numbers can be negative for places where you can't set a real breakpoint
                 frame.line = qAbs(callCtx->d()->lineNumber);
 
@@ -790,9 +792,9 @@ QUrl ExecutionEngine::resolvedUrl(const QString &file)
     QV4::ExecutionContext *c = currentContext();
     while (c) {
         CallContext *callCtx = c->asCallContext();
-        if (callCtx && callCtx->function) {
-            if (callCtx->function->function())
-                base.setUrl(callCtx->function->function()->sourceFile());
+        if (callCtx && callCtx->d()->function) {
+            if (callCtx->d()->function->function())
+                base.setUrl(callCtx->d()->function->function()->sourceFile());
             break;
         }
         c = c->d()->parent;
index 1cbc803..efc2b17 100644 (file)
@@ -378,7 +378,7 @@ ReturnedValue ScriptFunction::construct(Managed *that, CallData *callData)
 
     ExecutionContext *context = v4->currentContext();
     callData->thisObject = obj.asReturnedValue();
-    ExecutionContext *ctx = context->newCallContext(f.getPointer(), callData);
+    ExecutionContext *ctx = reinterpret_cast<ExecutionContext *>(context->newCallContext(f.getPointer(), callData));
 
     ExecutionContextSaver ctxSaver(context);
     ScopedValue result(scope, Q_V4_PROFILE(v4, ctx, f->function()));
@@ -402,7 +402,7 @@ ReturnedValue ScriptFunction::call(Managed *that, CallData *callData)
     ExecutionContext *context = v4->currentContext();
     Scope scope(context);
 
-    CallContext *ctx = context->newCallContext(f, callData);
+    CallContext *ctx = reinterpret_cast<CallContext *>(context->newCallContext(f, callData));
 
     ExecutionContextSaver ctxSaver(context);
     ScopedValue result(scope, Q_V4_PROFILE(v4, ctx, f->function()));
@@ -460,21 +460,21 @@ ReturnedValue SimpleScriptFunction::construct(Managed *that, CallData *callData)
     ExecutionContext *context = v4->currentContext();
     ExecutionContextSaver ctxSaver(context);
 
-    CallContext ctx(v4);
-    ctx.d()->strictMode = f->strictMode();
-    ctx.d()->callData = callData;
+    CallContext::Data ctx(v4);
+    ctx.strictMode = f->strictMode();
+    ctx.callData = callData;
     ctx.function = f.getPointer();
-    ctx.d()->compilationUnit = f->function()->compilationUnit;
-    ctx.d()->lookups = ctx.d()->compilationUnit->runtimeLookups;
-    ctx.d()->outer = f->scope();
+    ctx.compilationUnit = f->function()->compilationUnit;
+    ctx.lookups = ctx.compilationUnit->runtimeLookups;
+    ctx.outer = f->scope();
     ctx.locals = v4->stackPush(f->varCount());
     while (callData->argc < (int)f->formalParameterCount()) {
         callData->args[callData->argc] = Encode::undefined();
         ++callData->argc;
     }
-    Q_ASSERT(v4->currentContext() == &ctx);
+    Q_ASSERT(v4->currentContext()->d() == &ctx);
 
-    Scoped<Object> result(scope, Q_V4_PROFILE(v4, &ctx, f->function()));
+    Scoped<Object> result(scope, Q_V4_PROFILE(v4, reinterpret_cast<CallContext *>(&ctx), f->function()));
 
     if (f->function()->compiledFunction->hasQmlDependencies())
         QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
@@ -497,21 +497,21 @@ ReturnedValue SimpleScriptFunction::call(Managed *that, CallData *callData)
     ExecutionContext *context = v4->currentContext();
     ExecutionContextSaver ctxSaver(context);
 
-    CallContext ctx(v4);
-    ctx.d()->strictMode = f->strictMode();
-    ctx.d()->callData = callData;
+    CallContext::Data ctx(v4);
+    ctx.strictMode = f->strictMode();
+    ctx.callData = callData;
     ctx.function = f;
-    ctx.d()->compilationUnit = f->function()->compilationUnit;
-    ctx.d()->lookups = ctx.d()->compilationUnit->runtimeLookups;
-    ctx.d()->outer = f->scope();
+    ctx.compilationUnit = f->function()->compilationUnit;
+    ctx.lookups = ctx.compilationUnit->runtimeLookups;
+    ctx.outer = f->scope();
     ctx.locals = v4->stackPush(f->varCount());
     while (callData->argc < (int)f->formalParameterCount()) {
         callData->args[callData->argc] = Encode::undefined();
         ++callData->argc;
     }
-    Q_ASSERT(v4->currentContext() == &ctx);
+    Q_ASSERT(v4->currentContext()->d() == &ctx);
 
-    ScopedValue result(scope, Q_V4_PROFILE(v4, &ctx, f->function()));
+    ScopedValue result(scope, Q_V4_PROFILE(v4, reinterpret_cast<CallContext *>(&ctx), f->function()));
 
     if (f->function()->compiledFunction->hasQmlDependencies())
         QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
@@ -560,12 +560,12 @@ ReturnedValue BuiltinFunction::call(Managed *that, CallData *callData)
     ExecutionContext *context = v4->currentContext();
     ExecutionContextSaver ctxSaver(context);
 
-    CallContext ctx(v4);
-    ctx.d()->strictMode = f->scope()->d()->strictMode; // ### needed? scope or parent context?
-    ctx.d()->callData = callData;
-    Q_ASSERT(v4->currentContext() == &ctx);
+    CallContext::Data ctx(v4);
+    ctx.strictMode = f->scope()->d()->strictMode; // ### needed? scope or parent context?
+    ctx.callData = callData;
+    Q_ASSERT(v4->currentContext()->d() == &ctx);
 
-    return f->d()->code(&ctx);
+    return f->d()->code(reinterpret_cast<CallContext *>(&ctx));
 }
 
 ReturnedValue IndexedBuiltinFunction::call(Managed *that, CallData *callData)
@@ -579,12 +579,12 @@ ReturnedValue IndexedBuiltinFunction::call(Managed *that, CallData *callData)
     ExecutionContext *context = v4->currentContext();
     ExecutionContextSaver ctxSaver(context);
 
-    CallContext ctx(v4);
-    ctx.d()->strictMode = f->scope()->d()->strictMode; // ### needed? scope or parent context?
-    ctx.d()->callData = callData;
-    Q_ASSERT(v4->currentContext() == &ctx);
+    CallContext::Data ctx(v4);
+    ctx.strictMode = f->scope()->d()->strictMode; // ### needed? scope or parent context?
+    ctx.callData = callData;
+    Q_ASSERT(v4->currentContext()->d() == &ctx);
 
-    return f->d()->code(&ctx, f->d()->index);
+    return f->d()->code(reinterpret_cast<CallContext *>(&ctx), f->d()->index);
 }
 
 DEFINE_OBJECT_VTABLE(IndexedBuiltinFunction);
index 1d5350c..04449f0 100644 (file)
@@ -210,6 +210,7 @@ struct Q_QML_PRIVATE_EXPORT Managed
 
         void *operator new(size_t size, ExecutionEngine *e);
         void *operator new(size_t, Managed *m) { return m; }
+        void *operator new(size_t, Managed::Data *m) { return m; }
     };
     Data data;
     V4_MANAGED
index 6dc3b1c..4ec1a7b 100644 (file)
@@ -1106,7 +1106,7 @@ ExecutionContext *Runtime::pushWithScope(const ValueRef o, ExecutionContext *ctx
 {
     Scope scope(ctx);
     ScopedObject obj(scope, o->toObject(ctx));
-    return ctx->newWithContext(obj);
+    return reinterpret_cast<ExecutionContext *>(ctx->newWithContext(obj));
 }
 
 ReturnedValue Runtime::unwindException(ExecutionContext *ctx)
@@ -1120,7 +1120,7 @@ ExecutionContext *Runtime::pushCatchScope(ExecutionContext *ctx, String *excepti
 {
     Scope scope(ctx);
     ScopedValue v(scope, ctx->engine()->catchException(ctx, 0));
-    return ctx->newCatchContext(exceptionVarName, v);
+    return reinterpret_cast<ExecutionContext *>(ctx->newCatchContext(exceptionVarName, v));
 }
 
 ExecutionContext *Runtime::popScope(ExecutionContext *ctx)
index c397922..cdc8622 100644 (file)
@@ -78,7 +78,7 @@ QmlBindingWrapper::Data::Data(ExecutionContext *scope, Function *f, Object *qml)
 
     o->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1));
 
-    o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml);
+    o->d()->qmlContext = reinterpret_cast<CallContext *>(s.engine->currentContext()->newQmlContext(o, qml));
     s.engine->popContext();
 }
 
@@ -96,7 +96,7 @@ QmlBindingWrapper::Data::Data(ExecutionContext *scope, Object *qml)
 
     o->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1));
 
-    o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml);
+    o->d()->qmlContext = reinterpret_cast<CallContext *>(s.engine->currentContext()->newQmlContext(o, qml));
     s.engine->popContext();
 }
 
@@ -111,7 +111,7 @@ ReturnedValue QmlBindingWrapper::call(Managed *that, CallData *)
         return QV4::Encode::undefined();
 
     CallContext *ctx = This->d()->qmlContext;
-    std::fill(ctx->locals, ctx->locals + ctx->function->varCount(), Primitive::undefinedValue());
+    std::fill(ctx->d()->locals, ctx->d()->locals + ctx->d()->function->varCount(), Primitive::undefinedValue());
     engine->pushContext(ctx);
     ScopedValue result(scope, This->function()->code(ctx, This->function()->codeData));
     engine->popContext();
index 99aba9c..7f058bf 100644 (file)
@@ -215,7 +215,7 @@ QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *code
             if (scope->d()->type >= QV4::ExecutionContext::Type_SimpleCallContext) {
                 QV4::CallContext *cc = static_cast<QV4::CallContext *>(scope);
                 scopes[2*i + 2] = cc->d()->callData->args;
-                scopes[2*i + 3] = cc->locals;
+                scopes[2*i + 3] = cc->d()->locals;
             } else {
                 scopes[2*i + 2] = 0;
                 scopes[2*i + 3] = 0;