Remove some more uses of QV4::Value
authorLars Knoll <lars.knoll@digia.com>
Mon, 30 Sep 2013 18:57:57 +0000 (20:57 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 2 Oct 2013 14:07:33 +0000 (16:07 +0200)
All remaining uses should be GC safe now.

Change-Id: I05c962de6ab896f108f70caa1bf937a24e67bfe1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/compiler/qv4isel_masm.cpp
src/qml/compiler/qv4isel_masm_p.h
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4mm.cpp
src/qml/jsruntime/qv4numberobject.cpp
src/qml/jsruntime/qv4objectiterator.cpp
src/qml/jsruntime/qv4stringobject_p.h
src/qml/jsruntime/qv4vme_moth.cpp
src/qml/jsruntime/qv4vme_moth_p.h
src/quick/items/context2d/qquickcontext2d.cpp

index 6dabbce..6afbee2 100644 (file)
@@ -699,12 +699,12 @@ void InstructionSelection::run(int functionIndex)
     _as = oldAssembler;
 }
 
-void *InstructionSelection::addConstantTable(QVector<Value> *values)
+void *InstructionSelection::addConstantTable(QVector<Primitive> *values)
 {
     compilationUnit->constantValues.append(*values);
     values->clear();
 
-    QVector<QV4::Value> &finalValues = compilationUnit->constantValues.last();
+    QVector<QV4::Primitive> &finalValues = compilationUnit->constantValues.last();
     finalValues.squeeze();
     return finalValues.data();
 }
@@ -1872,14 +1872,14 @@ int InstructionSelection::prepareCallData(V4IR::ExprList* args, V4IR::Expr *this
 
 QT_BEGIN_NAMESPACE
 namespace QV4 {
-bool operator==(const Value &v1, const Value &v2)
+bool operator==(const Primitive &v1, const Primitive &v2)
 {
     return v1.rawValue() == v2.rawValue();
 }
 } // QV4 namespace
 QT_END_NAMESPACE
 
-int Assembler::ConstantTable::add(const Value &v)
+int Assembler::ConstantTable::add(const Primitive &v)
 {
     int idx = _values.indexOf(v);
     if (idx == -1) {
@@ -1895,12 +1895,12 @@ Assembler::ImplicitAddress Assembler::ConstantTable::loadValueAddress(V4IR::Cons
     return loadValueAddress(convertToValue(c), baseReg);
 }
 
-Assembler::ImplicitAddress Assembler::ConstantTable::loadValueAddress(const Value &v,
+Assembler::ImplicitAddress Assembler::ConstantTable::loadValueAddress(const Primitive &v,
                                                                       RegisterID baseReg)
 {
     _toPatch.append(_as->moveWithPatch(TrustedImmPtr(0), baseReg));
     ImplicitAddress addr(baseReg);
-    addr.offset = add(v) * sizeof(QV4::Value);
+    addr.offset = add(v) * sizeof(QV4::Primitive);
     Q_ASSERT(addr.offset >= 0);
     return addr;
 }
index 20b0c1b..a689cdf 100644 (file)
@@ -72,7 +72,7 @@ struct CompilationUnit : public QV4::CompiledData::CompilationUnit
     // Coderef + execution engine
 
     QVector<JSC::MacroAssemblerCodeRef> codeRefs;
-    QList<QVector<QV4::Value> > constantValues;
+    QList<QVector<QV4::Primitive> > constantValues;
     QVector<int> codeSizes; // corresponding to the endOfCode labels. MacroAssemblerCodeRef's size may
                             // be larger, as for example on ARM we append the exception handling table.
 };
@@ -387,14 +387,14 @@ public:
     public:
         ConstantTable(Assembler *as): _as(as) {}
 
-        int add(const QV4::Value &v);
+        int add(const QV4::Primitive &v);
         ImplicitAddress loadValueAddress(V4IR::Const *c, RegisterID baseReg);
-        ImplicitAddress loadValueAddress(const QV4::Value &v, RegisterID baseReg);
+        ImplicitAddress loadValueAddress(const QV4::Primitive &v, RegisterID baseReg);
         void finalize(JSC::LinkBuffer &linkBuffer, InstructionSelection *isel);
 
     private:
         Assembler *_as;
-        QVector<QV4::Value> _values;
+        QVector<QV4::Primitive> _values;
         QVector<DataLabelPtr> _toPatch;
     };
 
@@ -1361,7 +1361,7 @@ public:
 
     virtual void run(int functionIndex);
 
-    void *addConstantTable(QVector<QV4::Value> *values);
+    void *addConstantTable(QVector<QV4::Primitive> *values);
 protected:
     virtual QV4::CompiledData::CompilationUnit *backendCompileStep();
 
index 9dc5e2f..674dd46 100644 (file)
@@ -250,7 +250,7 @@ void CallContext::initQmlContext(ExecutionContext *parentContext, ObjectRef qml,
 
     this->function = function;
     this->callData = reinterpret_cast<CallData *>(this + 1);
-    this->callData->tag = QV4::Value::Integer_Type;
+    this->callData->tag = QV4::Value::_Integer_Type;
     this->callData->argc = 0;
     this->callData->thisObject = Primitive::undefinedValue();
 
index 54fee80..f6adadf 100644 (file)
@@ -579,12 +579,6 @@ void MemoryManager::unprotect(Managed *m)
         m_d->protectedObject.remove(m);
 }
 
-static inline void add(QVector<Managed *> &values, const Value &v)
-{
-    if (Object *o = v.asObject())
-        values.append(o);
-}
-
 void MemoryManager::setExecutionEngine(ExecutionEngine *engine)
 {
     m_d->engine = engine;
index 06a04b4..3ff4b79 100644 (file)
@@ -100,19 +100,29 @@ void NumberPrototype::init(ExecutionEngine *engine, ObjectRef ctor)
     defineDefaultProperty(QStringLiteral("toPrecision"), method_toPrecision);
 }
 
-inline Value thisNumberValue(ExecutionContext *ctx)
+inline ReturnedValue thisNumberValue(ExecutionContext *ctx)
 {
     if (ctx->callData->thisObject.isNumber())
-        return ctx->callData->thisObject;
+        return ctx->callData->thisObject.asReturnedValue();
     NumberObject *n = ctx->callData->thisObject.asNumberObject();
     if (!n)
         ctx->throwTypeError();
-    return n->value;
+    return n->value.asReturnedValue();
+}
+
+inline double thisNumber(ExecutionContext *ctx)
+{
+    if (ctx->callData->thisObject.isNumber())
+        return ctx->callData->thisObject.asDouble();
+    NumberObject *n = ctx->callData->thisObject.asNumberObject();
+    if (!n)
+        ctx->throwTypeError();
+    return n->value.asDouble();
 }
 
 ReturnedValue NumberPrototype::method_toString(SimpleCallContext *ctx)
 {
-    double num = thisNumberValue(ctx).asDouble();
+    double num = thisNumber(ctx);
 
     if (ctx->callData->argc && !ctx->callData->args[0].isUndefined()) {
         int radix = ctx->callData->args[0].toInt32();
@@ -165,20 +175,20 @@ ReturnedValue NumberPrototype::method_toString(SimpleCallContext *ctx)
 ReturnedValue NumberPrototype::method_toLocaleString(SimpleCallContext *ctx)
 {
     Scope scope(ctx);
-    Value v = thisNumberValue(ctx);
+    ScopedValue v(scope, thisNumberValue(ctx));
 
-    ScopedString str(scope, v.toString(ctx));
+    ScopedString str(scope, v->toString(ctx));
     return str.asReturnedValue();
 }
 
 ReturnedValue NumberPrototype::method_valueOf(SimpleCallContext *ctx)
 {
-    return thisNumberValue(ctx).asReturnedValue();
+    return thisNumberValue(ctx);
 }
 
 ReturnedValue NumberPrototype::method_toFixed(SimpleCallContext *ctx)
 {
-    double v = thisNumberValue(ctx).asDouble();
+    double v = thisNumber(ctx);
 
     double fdigits = 0;
 
@@ -206,7 +216,7 @@ ReturnedValue NumberPrototype::method_toFixed(SimpleCallContext *ctx)
 ReturnedValue NumberPrototype::method_toExponential(SimpleCallContext *ctx)
 {
     Scope scope(ctx);
-    double d = thisNumberValue(ctx).asDouble();
+    double d = thisNumber(ctx);
 
     int fdigits = -1;
 
@@ -229,7 +239,6 @@ ReturnedValue NumberPrototype::method_toExponential(SimpleCallContext *ctx)
 ReturnedValue NumberPrototype::method_toPrecision(SimpleCallContext *ctx)
 {
     Scope scope(ctx);
-
     ScopedValue v(scope, thisNumberValue(ctx));
 
     if (!ctx->callData->argc || ctx->callData->args[0].isUndefined())
index 2030489..46698b0 100644 (file)
@@ -123,7 +123,7 @@ ReturnedValue ObjectIterator::nextPropertyName(ValueRef value)
     if (!p)
         return Encode::null();
 
-    value = Value::fromReturnedValue(object->getValue(p, attrs));
+    value = object->getValue(p, attrs);
 
     if (!!name)
         return name->asReturnedValue();
@@ -144,7 +144,7 @@ ReturnedValue ObjectIterator::nextPropertyNameAsString(ValueRef value)
     if (!p)
         return Encode::null();
 
-    value = Value::fromReturnedValue(object->getValue(p, attrs));
+    value = object->getValue(p, attrs);
 
     if (!!name)
         return name->asReturnedValue();
index 08892d1..e677738 100644 (file)
@@ -52,7 +52,7 @@ namespace QV4 {
 struct StringObject: Object {
     Q_MANAGED
 
-    Value value;
+    SafeValue value;
     mutable Property tmpProperty;
     StringObject(ExecutionEngine *engine, const ValueRef value);
 
index 52832fe..a3fc43b 100644 (file)
@@ -135,7 +135,7 @@ static VMStats vmStats;
 #endif // WITH_STATS
 
 static inline QV4::Value *getValueRef(QV4::ExecutionContext *context,
-                                     QV4::Value* stack,
+                                     QV4::SafeValue* stack,
                                      const Param &param
 #if !defined(QT_NO_DEBUG)
                                      , unsigned stackSize
@@ -220,7 +220,7 @@ static inline QV4::Value *getValueRef(QV4::ExecutionContext *context,
 #define STOREVALUE(param, value) VALUE(param) = QV4::Value::fromReturnedValue((value))
 
 QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *&code,
-                            QV4::Value *stack, unsigned stackSize
+                            QV4::SafeValue *stack, unsigned stackSize
 #ifdef MOTH_THREADED_INTERPRETER
         , void ***storeJumpTable
 #endif
@@ -311,7 +311,7 @@ QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *&code,
         TRACE(inline, "stack size: %u", instr.value);
         stackSize = instr.value;
         stack = context->engine->stackPush(stackSize);
-        memset(stack, 0, stackSize * sizeof(QV4::Value));
+        memset(stack, 0, stackSize * sizeof(QV4::SafeValue));
     MOTH_END_INSTR(Push)
 
     MOTH_BEGIN_INSTR(CallValue)
@@ -456,12 +456,12 @@ QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *&code,
 
     MOTH_BEGIN_INSTR(CallBuiltinDefineArray)
         Q_ASSERT(instr.args + instr.argc <= stackSize);
-        QV4::Value *args = stack + instr.args;
+        QV4::SafeValue *args = stack + instr.args;
         STOREVALUE(instr.result, __qmljs_builtin_define_array(context, args, instr.argc));
     MOTH_END_INSTR(CallBuiltinDefineArray)
 
     MOTH_BEGIN_INSTR(CallBuiltinDefineObjectLiteral)
-        QV4::Value *args = stack + instr.args;
+        QV4::SafeValue *args = stack + instr.args;
     STOREVALUE(instr.result, __qmljs_builtin_define_object_literal(context, args, instr.internalClassId));
     MOTH_END_INSTR(CallBuiltinDefineObjectLiteral)
 
index 04c7f93..68d8086 100644 (file)
@@ -61,7 +61,7 @@ public:
 
 private:
     QV4::ReturnedValue run(QV4::ExecutionContext *, const uchar *&code,
-            QV4::Value *stack = 0, unsigned stackSize = 0
+            QV4::SafeValue *stack = 0, unsigned stackSize = 0
 #ifdef MOTH_THREADED_INTERPRETER
             , void ***storeJumpTable = 0
 #endif
index 02a813e..bab9a2c 100644 (file)
@@ -906,7 +906,7 @@ struct QQuickJSContext2DImageData : public QV4::Object
 
 
 
-    QV4::Value pixelData;
+    QV4::SafeValue pixelData;
 };
 
 DEFINE_MANAGED_VTABLE(QQuickJSContext2DImageData);
@@ -2975,7 +2975,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::SimpleCallC
                 V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
             }
         } else if (QQuickJSContext2DImageData *imageData = arg->as<QQuickJSContext2DImageData>()) {
-            QQuickJSContext2DPixelData *pix = imageData->pixelData.as<QQuickJSContext2DPixelData>();
+            QV4::Scoped<QQuickJSContext2DPixelData> pix(scope, imageData->pixelData.as<QQuickJSContext2DPixelData>());
             if (pix && !pix->image.isNull()) {
                 pixmap.take(new QQuickCanvasPixmap(pix->image, r->context->canvas()->window()));
             } else {
@@ -3240,7 +3240,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createImageData(QV4::Simpl
     if (ctx->callData->argc == 1) {
         QV4::ScopedValue arg0(scope, ctx->callData->args[0]);
         if (QQuickJSContext2DImageData *imgData = arg0->as<QQuickJSContext2DImageData>()) {
-            QQuickJSContext2DPixelData *pa = imgData->pixelData.as<QQuickJSContext2DPixelData>();
+            QV4::Scoped<QQuickJSContext2DPixelData> pa(scope, imgData->pixelData.as<QQuickJSContext2DPixelData>());
             if (pa) {
                 qreal w = pa->image.width();
                 qreal h = pa->image.height();
@@ -3320,7 +3320,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_putImageData(QV4::SimpleCa
     if (!imageData)
         return ctx->callData->thisObject.asReturnedValue();
 
-    QQuickJSContext2DPixelData *pixelArray = imageData->pixelData.as<QQuickJSContext2DPixelData>();
+    QV4::Scoped<QQuickJSContext2DPixelData> pixelArray(scope, imageData->pixelData.as<QQuickJSContext2DPixelData>());
     if (pixelArray) {
         w = pixelArray->image.width();
         h = pixelArray->image.height();