Remove more uses of Value
authorLars Knoll <lars.knoll@digia.com>
Mon, 30 Sep 2013 13:41:24 +0000 (15:41 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 2 Oct 2013 14:07:33 +0000 (16:07 +0200)
Change-Id: I889e760f75b485a28e1f2a2c26b2337ae9bfafac
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
27 files changed:
src/qml/compiler/qv4compileddata.cpp
src/qml/compiler/qv4compileddata_p.h
src/qml/compiler/qv4instr_moth_p.h
src/qml/compiler/qv4isel_masm.cpp
src/qml/compiler/qv4isel_masm_p.h
src/qml/compiler/qv4isel_moth_p.h
src/qml/compiler/qv4isel_util_p.h
src/qml/compiler/qv4ssa.cpp
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4context_p.h
src/qml/jsruntime/qv4dateobject_p.h
src/qml/jsruntime/qv4debugging.cpp
src/qml/jsruntime/qv4debugging_p.h
src/qml/jsruntime/qv4engine.cpp
src/qml/jsruntime/qv4engine_p.h
src/qml/jsruntime/qv4exception.cpp
src/qml/jsruntime/qv4exception_gcc.cpp
src/qml/jsruntime/qv4exception_p.h
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4functionobject_p.h
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4objectproto.cpp
src/qml/jsruntime/qv4property_p.h
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4value_def_p.h
src/qml/jsruntime/qv4value_p.h
src/qml/jsruntime/qv4vme_moth.cpp

index 4139a7e..5c1c418 100644 (file)
@@ -81,9 +81,9 @@ QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine)
     for (int i = 0; i < data->stringTableSize; ++i)
         runtimeStrings[i] = engine->newIdentifier(data->stringAt(i));
 
-    runtimeRegularExpressions = new QV4::Value[data->regexpTableSize];
+    runtimeRegularExpressions = new QV4::SafeValue[data->regexpTableSize];
     // memset the regexps to 0 in case a GC run happens while we're within the loop below
-    memset(runtimeRegularExpressions, 0, data->regexpTableSize * sizeof(QV4::Value));
+    memset(runtimeRegularExpressions, 0, data->regexpTableSize * sizeof(QV4::SafeValue));
     for (int i = 0; i < data->regexpTableSize; ++i) {
         const CompiledData::RegExp *re = data->regexpAt(i);
         int flags = 0;
@@ -93,8 +93,7 @@ QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine)
             flags |= QQmlJS::V4IR::RegExp::RegExp_IgnoreCase;
         if (re->flags & CompiledData::RegExp::RegExp_Multiline)
             flags |= QQmlJS::V4IR::RegExp::RegExp_Multiline;
-        QV4::RegExpObject *obj = engine->newRegExpObject(data->stringAt(re->stringIndex), flags)->getPointer();
-        runtimeRegularExpressions[i] = QV4::Value::fromObject(obj);
+        runtimeRegularExpressions[i] = engine->newRegExpObject(data->stringAt(re->stringIndex), flags);
     }
 
     if (data->lookupTableSize) {
index 5159ac5..6784707 100644 (file)
@@ -467,7 +467,7 @@ struct Q_QML_EXPORT CompilationUnit
 
     QV4::SafeString *runtimeStrings; // Array
     QV4::Lookup *runtimeLookups;
-    QV4::Value *runtimeRegularExpressions;
+    QV4::SafeValue *runtimeRegularExpressions;
     QV4::InternalClass **runtimeClasses;
     QVector<QV4::Function *> runtimeFunctions;
 //    QVector<QV4::Function *> runtimeFunctionsSortedByAddress;
index 100b6f6..f8ccfff 100644 (file)
@@ -130,7 +130,7 @@ struct Param {
         TempType     = 3,
         ScopedLocalType  = 4
     };
-    QV4::Value value;
+    QV4::Primitive value;
     unsigned type  : 3;
     unsigned scope : 29;
     unsigned index;
@@ -141,7 +141,7 @@ struct Param {
     bool isTemp() const { return type == TempType; }
     bool isScopedLocal() const { return type == ScopedLocalType; }
 
-    static Param createValue(const QV4::Value &v)
+    static Param createValue(const QV4::Primitive &v)
     {
         Param p;
         p.type = ValueType;
index b7ce1cc..6dabbce 100644 (file)
@@ -280,12 +280,12 @@ Assembler::Pointer Assembler::loadTempAddress(RegisterID reg, V4IR::Temp *t)
     case V4IR::Temp::Formal:
     case V4IR::Temp::ScopedFormal: {
         loadPtr(Address(context, qOffsetOf(CallContext, callData)), reg);
-        offset = sizeof(CallData) + (t->index - 1) * sizeof(Value);
+        offset = sizeof(CallData) + (t->index - 1) * sizeof(SafeValue);
     } break;
     case V4IR::Temp::Local:
     case V4IR::Temp::ScopedLocal: {
         loadPtr(Address(context, qOffsetOf(CallContext, locals)), reg);
-        offset = t->index * sizeof(Value);
+        offset = t->index * sizeof(SafeValue);
     } break;
     case V4IR::Temp::StackSlot: {
         return stackSlotPointer(t);
@@ -351,14 +351,14 @@ void Assembler::copyValue(Result result, V4IR::Expr* source)
         storeDouble(FPGpr0, result);
 #endif
     } else if (V4IR::Const *c = source->asConst()) {
-        QV4::Value v = convertToValue(c);
+        QV4::Primitive v = convertToValue(c);
         storeValue(v, result);
     } else {
         Q_UNREACHABLE();
     }
 }
 
-void Assembler::storeValue(QV4::Value value, V4IR::Temp* destination)
+void Assembler::storeValue(QV4::Primitive value, V4IR::Temp* destination)
 {
     Address addr = loadTempAddress(ScratchRegister, destination);
     storeValue(value, addr);
@@ -664,7 +664,7 @@ void InstructionSelection::run(int functionIndex)
     const int locals = _as->stackLayout().calculateJSStackFrameSize();
     _as->loadPtr(Address(Assembler::ContextRegister, qOffsetOf(ExecutionContext, engine)), Assembler::ScratchRegister);
     _as->loadPtr(Address(Assembler::ScratchRegister, qOffsetOf(ExecutionEngine, jsStackTop)), Assembler::LocalsRegister);
-    _as->addPtr(Assembler::TrustedImm32(sizeof(QV4::Value)*locals), Assembler::LocalsRegister);
+    _as->addPtr(Assembler::TrustedImm32(sizeof(QV4::SafeValue)*locals), Assembler::LocalsRegister);
     _as->storePtr(Assembler::LocalsRegister, Address(Assembler::ScratchRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
 
     for (int i = 0, ei = _function->basicBlocks.size(); i != ei; ++i) {
@@ -1189,19 +1189,19 @@ void InstructionSelection::swapValues(V4IR::Temp *sourceTemp, V4IR::Temp *target
         _as->load32(addr, Assembler::ScratchRegister);
         _as->store32((Assembler::RegisterID) registerTemp->index, addr);
         addr.offset += 4;
-        QV4::Value tag;
+        quint32 tag;
         switch (registerTemp->type) {
         case V4IR::BoolType:
-            tag = QV4::Primitive::fromBoolean(false);
+            tag = QV4::Value::_Boolean_Type;
             break;
         case V4IR::SInt32Type:
-            tag = QV4::Primitive::fromInt32(0);
+            tag = QV4::Value::_Integer_Type;
             break;
         default:
-            tag = QV4::Primitive::undefinedValue();
+            tag = QV4::Value::Undefined_Type;
             Q_UNREACHABLE();
         }
-        _as->store32(Assembler::TrustedImm32(tag.tag), addr);
+        _as->store32(Assembler::TrustedImm32(tag), addr);
         _as->move(Assembler::ScratchRegister, (Assembler::RegisterID) registerTemp->index);
     }
 }
@@ -1774,19 +1774,19 @@ void InstructionSelection::visitRet(V4IR::Ret *s)
             } else {
                 _as->zeroExtend32ToPtr((Assembler::RegisterID) t->index,
                                        Assembler::ReturnValueRegister);
-                QV4::Value upper;
+                quint64 tag;
                 switch (t->type) {
                 case V4IR::SInt32Type:
-                    upper = QV4::Primitive::fromInt32(0);
+                    tag = QV4::Value::_Integer_Type;
                     break;
                 case V4IR::BoolType:
-                    upper = QV4::Primitive::fromBoolean(false);
+                    tag = QV4::Value::_Boolean_Type;
                     break;
                 default:
-                    upper = QV4::Primitive::undefinedValue();
+                    tag = QV4::Value::Undefined_Type;
                     Q_UNREACHABLE();
                 }
-                _as->or64(Assembler::TrustedImm64(((int64_t) upper.tag) << 32),
+                _as->or64(Assembler::TrustedImm64(tag << 32),
                           Assembler::ReturnValueRegister);
             }
         } else {
@@ -1794,7 +1794,7 @@ void InstructionSelection::visitRet(V4IR::Ret *s)
         }
 #endif
     } else if (V4IR::Const *c = s->expr->asConst()) {
-        QV4::Value retVal = convertToValue(c);
+        QV4::Primitive retVal = convertToValue(c);
 #if CPU(X86)
         _as->move(Assembler::TrustedImm32(retVal.int_32), JSC::X86Registers::eax);
         _as->move(Assembler::TrustedImm32(retVal.tag), JSC::X86Registers::edx);
@@ -1810,7 +1810,7 @@ void InstructionSelection::visitRet(V4IR::Ret *s)
     }
 
     const int locals = _as->stackLayout().calculateJSStackFrameSize();
-    _as->subPtr(Assembler::TrustedImm32(sizeof(QV4::Value)*locals), Assembler::LocalsRegister);
+    _as->subPtr(Assembler::TrustedImm32(sizeof(QV4::SafeValue)*locals), Assembler::LocalsRegister);
     _as->loadPtr(Address(Assembler::ContextRegister, qOffsetOf(ExecutionContext, engine)), Assembler::ScratchRegister);
     _as->storePtr(Assembler::LocalsRegister, Address(Assembler::ScratchRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
 
@@ -1847,7 +1847,7 @@ int InstructionSelection::prepareCallData(V4IR::ExprList* args, V4IR::Expr *this
     }
 
     Pointer p = _as->stackLayout().callDataAddress(qOffsetOf(CallData, tag));
-    _as->store32(Assembler::TrustedImm32(QV4::Value::Integer_Type), p);
+    _as->store32(Assembler::TrustedImm32(QV4::Value::_Integer_Type), p);
     p = _as->stackLayout().callDataAddress(qOffsetOf(CallData, argc));
     _as->store32(Assembler::TrustedImm32(argc), p);
     p = _as->stackLayout().callDataAddress(qOffsetOf(CallData, thisObject));
index fd84b03..20b0c1b 100644 (file)
@@ -323,8 +323,8 @@ public:
 
         int calculateJSStackFrameSize() const
         {
-            const int locals = (localCount + sizeof(QV4::CallData)/sizeof(QV4::Value) - 1 + maxOutgoingArgumentCount) + 1;
-            int frameSize = locals * sizeof(QV4::Value);
+            const int locals = (localCount + sizeof(QV4::CallData)/sizeof(QV4::SafeValue) - 1 + maxOutgoingArgumentCount) + 1;
+            int frameSize = locals * sizeof(QV4::SafeValue);
             return frameSize;
         }
 
@@ -334,7 +334,7 @@ public:
             Q_ASSERT(idx < localCount);
 
             Pointer addr = callDataAddress(0);
-            addr.offset -= sizeof(QV4::Value) * (idx + 1);
+            addr.offset -= sizeof(QV4::SafeValue) * (idx + 1);
             return addr;
         }
 
@@ -346,11 +346,11 @@ public:
             Q_ASSERT(argument < maxOutgoingArgumentCount);
 
             const int index = maxOutgoingArgumentCount - argument;
-            return Pointer(Assembler::LocalsRegister, sizeof(QV4::Value) * (-index));
+            return Pointer(Assembler::LocalsRegister, sizeof(QV4::SafeValue) * (-index));
         }
 
         Pointer callDataAddress(int offset = 0) const {
-            return Pointer(Assembler::LocalsRegister, -(sizeof(QV4::CallData) + sizeof(QV4::Value) * (maxOutgoingArgumentCount - 1)) + offset);
+            return Pointer(Assembler::LocalsRegister, -(sizeof(QV4::CallData) + sizeof(QV4::SafeValue) * (maxOutgoingArgumentCount - 1)) + offset);
         }
 
         Address savedRegPointer(int offset) const
@@ -358,7 +358,7 @@ public:
             Q_ASSERT(offset >= 0);
             Q_ASSERT(offset < savedRegCount);
 
-            const int off = offset * sizeof(QV4::Value);
+            const int off = offset * sizeof(QV4::SafeValue);
             return Address(Assembler::StackFrameRegister, - calleeSavedRegisterSpace() - off);
         }
 
@@ -610,7 +610,7 @@ public:
 
     void storeUInt32ReturnValue(RegisterID dest)
     {
-        Pointer tmp(StackPointerRegister, -int(sizeof(QV4::Value)));
+        Pointer tmp(StackPointerRegister, -int(sizeof(QV4::SafeValue)));
         storeReturnValue(tmp);
         toUInt32Register(tmp, dest);
     }
@@ -622,7 +622,7 @@ public:
         xor64(ScratchRegister, ReturnValueRegister);
         move64ToDouble(ReturnValueRegister, dest);
 #else
-        Pointer tmp(StackPointerRegister, -int(sizeof(QV4::Value)));
+        Pointer tmp(StackPointerRegister, -int(sizeof(QV4::SafeValue)));
         storeReturnValue(tmp);
         loadDouble(tmp, dest);
 #endif
@@ -817,14 +817,14 @@ public:
         JSC::MacroAssembler::storeDouble(FPGpr0, target);
     }
 
-    void storeValue(QV4::Value value, RegisterID destination)
+    void storeValue(QV4::Primitive value, RegisterID destination)
     {
         Q_UNUSED(value);
         Q_UNUSED(destination);
         Q_UNREACHABLE();
     }
 
-    void storeValue(QV4::Value value, Address destination)
+    void storeValue(QV4::Primitive value, Address destination)
     {
 #ifdef VALUE_FITS_IN_REGISTER
         store64(TrustedImm64(value.val), destination);
@@ -835,7 +835,7 @@ public:
 #endif
     }
 
-    void storeValue(QV4::Value value, V4IR::Temp* temp);
+    void storeValue(QV4::Primitive value, V4IR::Temp* temp);
 
     void enterStandardStackFrame();
     void leaveStandardStackFrame();
@@ -1120,7 +1120,7 @@ public:
             Address tagAddr = addr;
             tagAddr.offset += 4;
 
-            QV4::Value v = convertToValue(c);
+            QV4::Primitive v = convertToValue(c);
             store32(TrustedImm32(v.int_32), addr);
             store32(TrustedImm32(v.tag), tagAddr);
             return Pointer(addr);
index 8482e35..ca03c5f 100644 (file)
@@ -154,7 +154,7 @@ private:
 
     int scratchTempIndex() const { return _function->tempCount; }
     int callDataStart() const { return scratchTempIndex() + 1; }
-    int outgoingArgumentTempStart() const { return callDataStart() + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value); }
+    int outgoingArgumentTempStart() const { return callDataStart() + qOffsetOf(QV4::CallData, args)/sizeof(QV4::SafeValue); }
     int frameSize() const { return outgoingArgumentTempStart() + _function->maxNumberOfArguments; }
 
     template <int Instr>
index 12a606e..5084de8 100644 (file)
@@ -63,11 +63,11 @@ inline bool canConvertToUnsignedInteger(double value)
     return uval == value && !(value == 0 && isNegative(value));
 }
 
-inline QV4::Value convertToValue(V4IR::Const *c)
+inline QV4::Primitive convertToValue(V4IR::Const *c)
 {
     switch (c->type) {
     case V4IR::MissingType:
-        return QV4::Value::emptyValue();
+        return QV4::Primitive::emptyValue();
     case V4IR::NullType:
         return QV4::Primitive::nullValue();
     case V4IR::UndefinedType:
index 3d6cd44..deadf47 100644 (file)
@@ -2223,8 +2223,8 @@ bool tryOptimizingComparison(Expr *&expr)
     if (!rightConst || rightConst->type == StringType || rightConst->type == VarType)
         return false;
 
-    QV4::Value l = convertToValue(leftConst);
-    QV4::Value r = convertToValue(rightConst);
+    QV4::Primitive l = convertToValue(leftConst);
+    QV4::Primitive r = convertToValue(rightConst);
 
     switch (b->op) {
     case OpGt:
@@ -2439,8 +2439,8 @@ void optimizeSSA(Function *function, DefUsesCalculator &defUses)
                     if (!rightConst || rightConst->type == StringType || rightConst->type == VarType)
                         continue;
 
-                    QV4::Value lc = convertToValue(leftConst);
-                    QV4::Value rc = convertToValue(rightConst);
+                    QV4::Primitive lc = convertToValue(leftConst);
+                    QV4::Primitive rc = convertToValue(rightConst);
                     double l = __qmljs_to_number(&lc);
                     double r = __qmljs_to_number(&rc);
 
index f229ad6..9dc5e2f 100644 (file)
@@ -51,7 +51,7 @@
 
 using namespace QV4;
 
-CallContext *ExecutionContext::newCallContext(void *stackSpace, Value *locals, FunctionObject *function, CallData *callData)
+CallContext *ExecutionContext::newCallContext(void *stackSpace, SafeValue *locals, FunctionObject *function, CallData *callData)
 {
     CallContext *c = (CallContext *)stackSpace;
 #ifndef QT_NO_DEBUG
@@ -121,13 +121,13 @@ CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData
         c->lookups = c->compilationUnit->runtimeLookups;
     }
 
-    c->locals = (Value *)(c + 1);
+    c->locals = (SafeValue *)(c + 1);
 
     if (function->varCount)
         std::fill(c->locals, c->locals + function->varCount, Primitive::undefinedValue());
 
     c->callData = reinterpret_cast<CallData *>(c->locals + function->varCount);
-    ::memcpy(c->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(Value));
+    ::memcpy(c->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(SafeValue));
     if (callData->argc < function->formalParameterCount)
         std::fill(c->callData->args + c->callData->argc, c->callData->args + function->formalParameterCount, Primitive::undefinedValue());
     c->callData->argc = qMax((uint)callData->argc, function->formalParameterCount);
@@ -143,7 +143,7 @@ WithContext *ExecutionContext::newWithContext(ObjectRef with)
     return w;
 }
 
-CatchContext *ExecutionContext::newCatchContext(String *exceptionVarName, const Value &exceptionValue)
+CatchContext *ExecutionContext::newCatchContext(const StringRef exceptionVarName, const ValueRef exceptionValue)
 {
     CatchContext *c = static_cast<CatchContext *>(engine->memoryManager->allocContext(sizeof(CatchContext)));
     engine->current = c;
@@ -214,9 +214,9 @@ void GlobalContext::initGlobalContext(ExecutionEngine *eng)
 {
     initBaseContext(Type_GlobalContext, eng, /*parentContext*/0);
     callData = reinterpret_cast<CallData *>(this + 1);
-    callData->tag = QV4::Value::Integer_Type;
+    callData->tag = QV4::Value::_Integer_Type;
     callData->argc = 0;
-    callData->thisObject = Value::fromObject(eng->globalObject);
+    callData->thisObject = eng->globalObject;
     global = 0;
 }
 
@@ -231,7 +231,7 @@ void WithContext::initWithContext(ExecutionContext *p, ObjectRef with)
     withObject = with.getPointer();
 }
 
-void CatchContext::initCatchContext(ExecutionContext *p, String *exceptionVarName, const Value &exceptionValue)
+void CatchContext::initCatchContext(ExecutionContext *p, const StringRef exceptionVarName, const ValueRef exceptionValue)
 {
     initBaseContext(Type_CatchContext, p->engine, p);
     strictMode = p->strictMode;
@@ -268,7 +268,7 @@ void CallContext::initQmlContext(ExecutionContext *parentContext, ObjectRef qml,
         lookups = compilationUnit->runtimeLookups;
     }
 
-    locals = (Value *)(this + 1);
+    locals = (SafeValue *)(this + 1);
     if (function->varCount)
         std::fill(locals, locals + function->varCount, Primitive::undefinedValue());
 }
@@ -286,7 +286,7 @@ bool ExecutionContext::deleteProperty(const StringRef name)
                 return w->withObject->deleteProperty(name);
         } else if (ctx->type == Type_CatchContext) {
             CatchContext *c = static_cast<CatchContext *>(ctx);
-            if (c->exceptionVarName->isEqualTo(name))
+            if (c->exceptionVarName->stringValue()->isEqualTo(name))
                 return false;
         } else if (ctx->type >= Type_CallContext) {
             CallContext *c = static_cast<CallContext *>(ctx);
@@ -343,8 +343,7 @@ void ExecutionContext::mark()
         w->withObject->mark();
     } else if (type == Type_CatchContext) {
         CatchContext *c = static_cast<CatchContext *>(this);
-        if (c->exceptionVarName)
-            c->exceptionVarName->mark();
+        c->exceptionVarName->mark();
         c->exceptionValue.mark();
     } else if (type == Type_GlobalContext) {
         GlobalContext *g = static_cast<GlobalContext *>(this);
@@ -362,7 +361,7 @@ void ExecutionContext::setProperty(const StringRef name, const ValueRef value)
                 w->put(name, value);
                 return;
             }
-        } else if (ctx->type == Type_CatchContext && static_cast<CatchContext *>(ctx)->exceptionVarName->isEqualTo(name)) {
+        } else if (ctx->type == Type_CatchContext && static_cast<CatchContext *>(ctx)->exceptionVarName->stringValue()->isEqualTo(name)) {
             static_cast<CatchContext *>(ctx)->exceptionValue = *value;
             return;
         } else {
@@ -423,7 +422,7 @@ ReturnedValue ExecutionContext::getProperty(const StringRef name)
         else if (ctx->type == Type_CatchContext) {
             hasCatchScope = true;
             CatchContext *c = static_cast<CatchContext *>(ctx);
-            if (c->exceptionVarName->isEqualTo(name))
+            if (c->exceptionVarName->stringValue()->isEqualTo(name))
                 return c->exceptionValue.asReturnedValue();
         }
 
@@ -488,7 +487,7 @@ ReturnedValue ExecutionContext::getPropertyNoThrow(const StringRef name)
         else if (ctx->type == Type_CatchContext) {
             hasCatchScope = true;
             CatchContext *c = static_cast<CatchContext *>(ctx);
-            if (c->exceptionVarName->isEqualTo(name))
+            if (c->exceptionVarName->stringValue()->isEqualTo(name))
                 return c->exceptionValue.asReturnedValue();
         }
 
@@ -553,7 +552,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR
         else if (ctx->type == Type_CatchContext) {
             hasCatchScope = true;
             CatchContext *c = static_cast<CatchContext *>(ctx);
-            if (c->exceptionVarName->isEqualTo(name))
+            if (c->exceptionVarName->stringValue()->isEqualTo(name))
                 return c->exceptionValue.asReturnedValue();
         }
 
@@ -579,7 +578,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR
             }
             if (f->function && f->function->isNamedExpression()
                 && name->isEqualTo(f->function->name))
-                return Value::fromObject(c->function).asReturnedValue();
+                return c->function->asReturnedValue();
         }
 
         else if (ctx->type == Type_GlobalContext) {
index 7f9ef77..d368dc6 100644 (file)
@@ -112,10 +112,10 @@ struct Q_QML_EXPORT ExecutionContext
         interpreterInstructionPointer = 0;
     }
 
-    CallContext *newCallContext(void *stackSpace, Value *locals, FunctionObject *f, CallData *callData);
+    CallContext *newCallContext(void *stackSpace, SafeValue *locals, FunctionObject *f, CallData *callData);
     CallContext *newCallContext(FunctionObject *f, CallData *callData);
     WithContext *newWithContext(ObjectRef with);
-    CatchContext *newCatchContext(String* exceptionVarName, const QV4::Value &exceptionValue);
+    CatchContext *newCatchContext(const StringRef exceptionVarName, const ValueRef exceptionValue);
     CallContext *newQmlContext(FunctionObject *f, ObjectRef qml);
 
     String * const *formals() const;
@@ -163,7 +163,7 @@ struct CallContext : public SimpleCallContext
     void initQmlContext(ExecutionContext *parentContext, ObjectRef qml, QV4::FunctionObject *function);
     bool needsOwnArguments() const;
 
-    Value *locals;
+    SafeValue *locals;
     Object *activation;
 };
 
@@ -176,10 +176,10 @@ struct GlobalContext : public ExecutionContext
 
 struct CatchContext : public ExecutionContext
 {
-    void initCatchContext(ExecutionContext *p, String *exceptionVarName, const QV4::Value &exceptionValue);
+    void initCatchContext(ExecutionContext *p, const StringRef exceptionVarName, const ValueRef exceptionValue);
 
-    String *exceptionVarName;
-    Value exceptionValue;
+    SafeString exceptionVarName;
+    SafeValue exceptionValue;
 };
 
 struct WithContext : public ExecutionContext
index 5658858..5cd0302 100644 (file)
@@ -53,19 +53,21 @@ namespace QV4 {
 
 struct DateObject: Object {
     Q_MANAGED
-    Value value;
-    DateObject(ExecutionEngine *engine, const Value &value): Object(engine->dateClass), value(value) {
+    SafeValue value;
+    DateObject(ExecutionEngine *engine, const ValueRef date): Object(engine->dateClass) {
         vtbl = &static_vtbl;
         type = Type_DateObject;
+        value = date;
     }
     DateObject(ExecutionEngine *engine, const QDateTime &value);
 
     QDateTime toQDateTime() const;
 
 protected:
-    DateObject(InternalClass *ic): Object(ic), value(Primitive::fromDouble(qSNaN())) {
+    DateObject(InternalClass *ic): Object(ic) {
         vtbl = &static_vtbl;
         type = Type_DateObject;
+        value = Primitive::fromDouble(qSNaN());
     }
 };
 
index f95178c..41ed34e 100644 (file)
@@ -172,7 +172,7 @@ void Debugger::maybeBreakAtInstruction(const uchar *code, bool breakPointHit)
         applyPendingBreakPoints();
 }
 
-void Debugger::aboutToThrow(const QV4::Value &value)
+void Debugger::aboutToThrow(const QV4::ValueRef value)
 {
     qDebug() << "*** We are about to throw...";
 }
@@ -205,43 +205,43 @@ void Debugger::applyPendingBreakPoints()
     m_havePendingBreakPoints = false;
 }
 
-static void realDumpValue(QV4::Value v, QV4::ExecutionContext *ctx, std::string prefix)
+static void realDumpValue(const QV4::ValueRef v, QV4::ExecutionContext *ctx, std::string prefix)
 {
     using namespace QV4;
     using namespace std;
 
     Scope scope(ctx);
 
-    cout << prefix << "tag: " << hex << v.tag << dec << endl << prefix << "\t-> ";
-    switch (v.type()) {
+    cout << prefix << "tag: " << hex << v->tag << dec << endl << prefix << "\t-> ";
+    switch (v->type()) {
     case Value::Undefined_Type: cout << "Undefined"; return;
     case Value::Null_Type: cout << "Null"; return;
     case Value::Boolean_Type: cout << "Boolean"; break;
     case Value::Integer_Type: cout << "Integer"; break;
-    case Value::Managed_Type: cout << v.managed()->className().toUtf8().data(); break;
+    case Value::Managed_Type: cout << v->managed()->className().toUtf8().data(); break;
     default: cout << "UNKNOWN" << endl; return;
     }
     cout << endl;
 
-    if (v.isBoolean()) {
-        cout << prefix << "\t-> " << (v.booleanValue() ? "TRUE" : "FALSE") << endl;
+    if (v->isBoolean()) {
+        cout << prefix << "\t-> " << (v->booleanValue() ? "TRUE" : "FALSE") << endl;
         return;
     }
 
-    if (v.isInteger()) {
-        cout << prefix << "\t-> " << v.integerValue() << endl;
+    if (v->isInteger()) {
+        cout << prefix << "\t-> " << v->integerValue() << endl;
         return;
     }
 
-    if (v.isDouble()) {
-        cout << prefix << "\t-> " << v.doubleValue() << endl;
+    if (v->isDouble()) {
+        cout << prefix << "\t-> " << v->doubleValue() << endl;
         return;
     }
 
-    if (v.isString()) {
+    if (v->isString()) {
         // maybe check something on the Managed object?
-        cout << prefix << "\t-> @" << hex << v.stringValue() << endl;
-        cout << prefix << "\t-> \"" << qPrintable(v.stringValue()->toQString()) << "\"" << endl;
+        cout << prefix << "\t-> @" << hex << v->stringValue() << endl;
+        cout << prefix << "\t-> \"" << qPrintable(v->stringValue()->toQString()) << "\"" << endl;
         return;
     }
 
@@ -274,17 +274,18 @@ static void realDumpValue(QV4::Value v, QV4::ExecutionContext *ctx, std::string
     cout << prefix << "properties:" << endl;
     ForEachIteratorObject it(ctx, o);
     ScopedValue name(scope);
+    ScopedValue pval(scope);
     for (name = it.nextPropertyName(); !name->isNull(); name = it.nextPropertyName()) {
         cout << prefix << "\t\"" << qPrintable(name->stringValue()->toQString()) << "\"" << endl;
         PropertyAttributes attrs;
         Property *d = o->__getOwnProperty__(ScopedString(scope, name), &attrs);
-        Value pval = Value::fromReturnedValue(o->getValue(d, attrs));
+        pval = o->getValue(d, attrs);
         cout << prefix << "\tvalue:" << endl;
         realDumpValue(pval, ctx, prefix + "\t");
     }
 }
 
-void dumpValue(QV4::Value v, QV4::ExecutionContext *ctx)
+void dumpValue(const QV4::ValueRef v, QV4::ExecutionContext *ctx)
 {
     realDumpValue(v, ctx, std::string(""));
 }
index 9088548..e44f415 100644 (file)
@@ -102,7 +102,7 @@ public: // compile-time interface
     void maybeBreakAtInstruction(const uchar *code, bool breakPointHit);
 
 public: // execution hooks
-    void aboutToThrow(const Value &value);
+    void aboutToThrow(const ValueRef value);
 
 private:
     // requires lock to be held
index 7b9071e..8032197 100644 (file)
@@ -367,9 +367,9 @@ Returned<FunctionObject> *ExecutionEngine::newBuiltinFunction(ExecutionContext *
     return f->asReturned<FunctionObject>();
 }
 
-Returned<BoundFunction> *ExecutionEngine::newBoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs)
+Returned<BoundFunction> *ExecutionEngine::newBoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<SafeValue> &boundArgs)
 {
-    assert(target);
+    Q_ASSERT(target);
 
     BoundFunction *f = new (memoryManager) BoundFunction(scope, target, boundThis, boundArgs);
     return f->asReturned<BoundFunction>();
@@ -441,7 +441,7 @@ Returned<ArrayObject> *ExecutionEngine::newArrayObject(InternalClass *ic)
 }
 
 
-Returned<DateObject> *ExecutionEngine::newDateObject(const Value &value)
+Returned<DateObject> *ExecutionEngine::newDateObject(const ValueRef value)
 {
     DateObject *object = new (memoryManager) DateObject(this, value);
     return object->asReturned<DateObject>();
index d93202d..79a4d3b 100644 (file)
@@ -267,7 +267,7 @@ struct Q_QML_EXPORT ExecutionEngine
     ExecutionContext *popContext();
 
     Returned<FunctionObject> *newBuiltinFunction(ExecutionContext *scope, const StringRef name, ReturnedValue (*code)(SimpleCallContext *));
-    Returned<BoundFunction> *newBoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs);
+    Returned<BoundFunction> *newBoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<SafeValue> &boundArgs);
 
     Returned<Object> *newObject();
     Returned<Object> *newObject(InternalClass *internalClass);
@@ -283,7 +283,7 @@ struct Q_QML_EXPORT ExecutionEngine
     Returned<ArrayObject> *newArrayObject(const QStringList &list);
     Returned<ArrayObject> *newArrayObject(InternalClass *ic);
 
-    Returned<DateObject> *newDateObject(const Value &value);
+    Returned<DateObject> *newDateObject(const ValueRef value);
     Returned<DateObject> *newDateObject(const QDateTime &dt);
 
     Returned<RegExpObject> *newRegExpObject(const QString &pattern, int flags);
index 2c42e6f..64e6bef 100644 (file)
@@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE
 using namespace QV4;
 
 
-void Exception::throwException(ExecutionContext *context, const Value &value)
+void Exception::throwException(ExecutionContext *context, const ValueRef value)
 {
     if (context->engine->debugger)
         context->engine->debugger->aboutToThrow(value);
@@ -86,13 +86,13 @@ void Exception::throwException(ExecutionContext *context, const Value &value)
     throwInternal(context, value);
 }
 
-Exception::Exception(ExecutionContext *throwingContext, const Value &exceptionValue)
+Exception::Exception(ExecutionContext *throwingContext, const ValueRef exceptionValue)
     : e(throwingContext->engine)
 {
     e->exceptionValue = exceptionValue;
     this->throwingContext = throwingContext->engine->current;
     accepted = false;
-    if (ErrorObject *error = exceptionValue.asErrorObject())
+    if (ErrorObject *error = exceptionValue->asErrorObject())
         m_stackTrace = error->stackTrace;
     else
         m_stackTrace = throwingContext->engine->stackTrace();
@@ -122,7 +122,7 @@ void Exception::partiallyUnwindContext(ExecutionContext *catchingContext)
 }
 
 #if !defined(V4_CXX_ABI_EXCEPTION)
-void Exception::throwInternal(ExecutionContext *throwingContext, const Value &exceptionValue)
+void Exception::throwInternal(ExecutionContext *throwingContext, const ValueRef exceptionValue)
 {
     throw Exception(throwingContext, exceptionValue);
 }
index 0324a06..5eb5fc2 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "qv4exception_p.h"
 
+#include <private/qv4scopedvalue_p.h>
 #include <unwind.h>
 #include <cxxabi.h>
 #include <bits/atomic_word.h>
@@ -108,7 +109,7 @@ QT_BEGIN_NAMESPACE
 
 using namespace QV4;
 
-void Exception::throwInternal(ExecutionContext *throwingContext, const Value &exceptionValue)
+void Exception::throwInternal(ExecutionContext *throwingContext, const ValueRef exceptionValue)
 {
     void *rawException = abi::__cxa_allocate_exception(sizeof(QV4::Exception));
     gcc_refcounted_compatible_exception *refCountedException = reinterpret_cast<gcc_refcounted_compatible_exception *>(rawException) - 1;
index 4777e56..a373ef2 100644 (file)
@@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE
 namespace QV4 {
 
 struct Q_QML_EXPORT Exception {
-    static void Q_NORETURN throwException(ExecutionContext *throwingContext, const Value &exceptionValue);
+    static void Q_NORETURN throwException(ExecutionContext *throwingContext, const ValueRef exceptionValue);
 
     ~Exception();
 
@@ -66,13 +66,13 @@ struct Q_QML_EXPORT Exception {
 private:
     void *operator new(size_t, void *p) { return p; }
 
-    explicit Exception(ExecutionContext *throwingContext, const Value &exceptionValue);
+    explicit Exception(ExecutionContext *throwingContext, const ValueRef exceptionValue);
 
     ExecutionEngine *e;
     ExecutionContext *throwingContext;
     bool accepted;
     ExecutionEngine::StackTrace m_stackTrace;
-    static void Q_NORETURN throwInternal(ExecutionContext *throwingContext, const Value &exceptionValue);
+    static void Q_NORETURN throwInternal(ExecutionContext *throwingContext, const ValueRef exceptionValue);
 };
 
 } // namespace QV4
index 59b23be..11580b0 100644 (file)
@@ -385,11 +385,11 @@ ReturnedValue FunctionPrototype::method_bind(SimpleCallContext *ctx)
         ctx->throwTypeError();
 
     ScopedValue boundThis(scope, ctx->argument(0));
-    QVector<Value> boundArgs;
+    QVector<SafeValue> boundArgs;
     for (uint i = 1; i < ctx->callData->argc; ++i)
         boundArgs += ctx->callData->args[i];
 
-    return ctx->engine->newBoundFunction(ctx->engine->rootContext, target.getPointer(), boundThis, boundArgs)->asReturnedValue();
+    return ctx->engine->newBoundFunction(ctx->engine->rootContext, target, boundThis, boundArgs)->asReturnedValue();
 }
 
 DEFINE_MANAGED_VTABLE(ScriptFunction);
@@ -663,13 +663,13 @@ DEFINE_MANAGED_VTABLE(IndexedBuiltinFunction);
 
 DEFINE_MANAGED_VTABLE(BoundFunction);
 
-BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs)
+BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<SafeValue> &boundArgs)
     : FunctionObject(scope, 0)
     , target(target)
-    , boundThis(boundThis)
     , boundArgs(boundArgs)
 {
     vtbl = &static_vtbl;
+    this->boundThis = boundThis;
 
     Scope s(scope);
     ScopedValue protectThis(s, this);
index 29bfa31..2423116 100644 (file)
@@ -225,10 +225,10 @@ struct SimpleScriptFunction: FunctionObject {
 struct BoundFunction: FunctionObject {
     Q_MANAGED
     FunctionObject *target;
-    Value boundThis;
-    QVector<Value> boundArgs;
+    SafeValue boundThis;
+    QVector<SafeValue> boundArgs;
 
-    BoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs);
+    BoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<SafeValue> &boundArgs);
     ~BoundFunction() {}
 
 
index 399cd2e..eaa3b59 100644 (file)
@@ -1283,7 +1283,7 @@ void Object::arrayReserve(uint n)
         arrayData = newArrayData;
         if (sparseArray) {
             for (uint i = arrayFreeList; i < arrayAlloc; ++i) {
-                arrayData[i].value = Value::emptyValue();
+                arrayData[i].value = Primitive::emptyValue();
                 arrayData[i].value = Primitive::fromInt32(i + 1);
             }
         } else {
@@ -1363,7 +1363,7 @@ bool Object::setArrayLength(uint newLen) {
                     } else {
                         arrayAttributes[it - arrayData].clear();
                     }
-                    it->value = Value::emptyValue();
+                    it->value = Primitive::emptyValue();
                 }
             }
             arrayDataLen = newLen;
index 20a5c51..4693834 100644 (file)
@@ -601,7 +601,7 @@ void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, const ValueRef
     }
 
     if (attrs->isGeneric())
-        desc->value = Value::emptyValue();
+        desc->value = Primitive::emptyValue();
 }
 
 
index 258a190..9763de5 100644 (file)
@@ -89,7 +89,7 @@ struct Property {
 
     static Property genericDescriptor() {
         Property pd;
-        pd.value = Value::emptyValue();
+        pd.value = Primitive::emptyValue();
         return pd;
     }
 
index 1dd35fc..b5c48af 100644 (file)
@@ -878,7 +878,7 @@ ReturnedValue __qmljs_construct_property(ExecutionContext *context, const ValueR
 
 void __qmljs_throw(ExecutionContext *context, const ValueRef value)
 {
-    Exception::throwException(context, *value);
+    Exception::throwException(context, value);
 }
 
 ReturnedValue __qmljs_builtin_typeof(ExecutionContext *ctx, const ValueRef value)
@@ -943,7 +943,7 @@ ExecutionContext *__qmljs_builtin_push_with_scope(const ValueRef o, ExecutionCon
 
 ExecutionContext *__qmljs_builtin_push_catch_scope(const StringRef exceptionVarName, const ValueRef exceptionValue, ExecutionContext *ctx)
 {
-    return ctx->newCatchContext(exceptionVarName.getPointer(), *exceptionValue);
+    return ctx->newCatchContext(exceptionVarNameexceptionValue);
 }
 
 ExecutionContext *__qmljs_builtin_pop_scope(ExecutionContext *ctx)
index 76f41dc..11b70ef 100644 (file)
@@ -273,7 +273,6 @@ struct Q_QML_EXPORT Value
         return val;
     }
 
-    static Value emptyValue();
     static Value fromObject(Object *o);
     static Value fromManaged(Managed *o);
 
@@ -357,6 +356,7 @@ struct SafeValue : public Value
 
 struct Q_QML_EXPORT Primitive : public Value
 {
+    static Primitive emptyValue();
     static Primitive fromBoolean(bool b);
     static Primitive fromInt32(int i);
     static Primitive undefinedValue();
index 604062b..e751a07 100644 (file)
@@ -121,9 +121,9 @@ inline Primitive Primitive::nullValue()
     return v;
 }
 
-inline Value Value::emptyValue()
+inline Primitive Primitive::emptyValue()
 {
-    Value v;
+    Primitive v;
     v.tag = Value::Empty_Type;
     v.uint_32 = 0;
     return v;
index d89300f..52832fe 100644 (file)
@@ -160,7 +160,7 @@ static inline QV4::Value *getValueRef(QV4::ExecutionContext *context,
 
     if (param.isValue()) {
         VMSTATS(paramIsValue);
-        return const_cast<QV4::Value *>(&param.value);
+        return const_cast<QV4::Value *>(&static_cast<const QV4::Value &>(param.value));
     } else if (param.isArgument()) {
         VMSTATS(paramIsArg);
         QV4::ExecutionContext *c = context;