Remove more occurrences of QV4::Value
authorLars Knoll <lars.knoll@digia.com>
Thu, 26 Sep 2013 20:07:27 +0000 (22:07 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 30 Sep 2013 06:05:38 +0000 (08:05 +0200)
Change-Id: I66c370680d7e6bee2e73a7a940aa96ab4009ec57
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
20 files changed:
src/qml/jsruntime/qv4argumentsobject.cpp
src/qml/jsruntime/qv4arrayobject.cpp
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4engine.cpp
src/qml/jsruntime/qv4functionobject_p.h
src/qml/jsruntime/qv4lookup.cpp
src/qml/jsruntime/qv4numberobject.cpp
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4object_p.h
src/qml/jsruntime/qv4objectproto.cpp
src/qml/jsruntime/qv4objectproto_p.h
src/qml/jsruntime/qv4qobjectwrapper.cpp
src/qml/jsruntime/qv4qobjectwrapper_p.h
src/qml/jsruntime/qv4regexp.cpp
src/qml/jsruntime/qv4regexpobject.cpp
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4runtime_p.h
src/qml/jsruntime/qv4scopedvalue_p.h
src/qml/jsruntime/qv4script.cpp
src/qml/jsruntime/qv4sequenceobject.cpp

index 7e4b828..cf72cde 100644 (file)
@@ -173,7 +173,7 @@ ReturnedValue ArgumentsSetterFunction::call(Managed *setter, CallData *callData)
 
     assert(s->index < o->context->callData->argc);
     o->context->callData->args[s->index] = callData->argc ? callData->args[0].asReturnedValue() : Encode::undefined();
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 void ArgumentsObject::markObjects(Managed *that)
index 7051276..3ad3ec6 100644 (file)
@@ -279,7 +279,7 @@ ReturnedValue ArrayPrototype::method_push(SimpleCallContext *ctx)
             ScopedString str(scope, ctx->engine->newString(QStringLiteral("Array.prototype.push: Overflow")));
             ctx->throwRangeError(str);
         }
-        return Primitive::fromDouble(newLen).asReturnedValue();
+        return Encode(newLen);
     }
 
     if (!instance->protoHasArray() && instance->arrayDataLen <= len) {
@@ -345,7 +345,7 @@ ReturnedValue ArrayPrototype::method_shift(SimpleCallContext *ctx)
     if (!len) {
         if (!instance->isArrayObject())
             instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromInt32(0)));
-        return Primitive::undefinedValue().asReturnedValue();
+        return Encode::undefined();
     }
 
     Property *front = 0;
@@ -558,7 +558,7 @@ ReturnedValue ArrayPrototype::method_indexOf(SimpleCallContext *ctx)
     ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
     uint len = getLength(ctx, instance.getPointer());
     if (!len)
-        return Primitive::fromInt32(-1).asReturnedValue();
+        return Encode(-1);
 
     ScopedValue searchValue(scope);
     uint fromIndex = 0;
@@ -598,7 +598,7 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(SimpleCallContext *ctx)
     ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
     uint len = getLength(ctx, instance.getPointer());
     if (!len)
-        return Primitive::fromInt32(-1).asReturnedValue();
+        return Encode(-1);
 
     ScopedValue searchValue(scope);
     uint fromIndex = len;
@@ -628,7 +628,7 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(SimpleCallContext *ctx)
         if (exists && __qmljs_strict_equal(v, searchValue))
             return Encode(k);
     }
-    return Primitive::fromInt32(-1).asReturnedValue();
+    return Encode(-1);
 }
 
 ReturnedValue ArrayPrototype::method_every(SimpleCallContext *ctx)
index aa0688e..ff17754 100644 (file)
@@ -522,7 +522,7 @@ ReturnedValue ExecutionContext::getPropertyNoThrow(const StringRef name)
                 return v.asReturnedValue();
         }
     }
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, Object **base)
index 62d8a2c..8808678 100644 (file)
@@ -82,7 +82,7 @@ static QBasicAtomicInt engineSerial = Q_BASIC_ATOMIC_INITIALIZER(1);
 static ReturnedValue throwTypeError(SimpleCallContext *ctx)
 {
     ctx->throwTypeError();
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
index 7fece1d..29bfa31 100644 (file)
@@ -199,7 +199,7 @@ struct IndexedBuiltinFunction: FunctionObject
     static ReturnedValue construct(Managed *m, CallData *)
     {
         m->engine()->current->throwTypeError();
-        return Primitive::undefinedValue().asReturnedValue();
+        return Encode::undefined();
     }
 
     static ReturnedValue call(Managed *that, CallData *callData);
index d71d79e..4527dcb 100644 (file)
@@ -135,7 +135,7 @@ ReturnedValue Lookup::getterGeneric(QV4::Lookup *l, const ValueRef object)
         }
     }
 
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 ReturnedValue Lookup::getter0(Lookup *l, const ValueRef object)
@@ -182,7 +182,7 @@ ReturnedValue Lookup::getterAccessor0(Lookup *l, const ValueRef object)
             Scope scope(o->engine());
             FunctionObject *getter = o->memberData[l->index].getter();
             if (!getter)
-                return Primitive::undefinedValue().asReturnedValue();
+                return Encode::undefined();
 
             ScopedCallData callData(scope, 0);
             callData->thisObject = *object;
@@ -201,7 +201,7 @@ ReturnedValue Lookup::getterAccessor1(Lookup *l, const ValueRef object)
             Scope scope(o->engine());
             FunctionObject *getter = o->prototype()->memberData[l->index].getter();
             if (!getter)
-                return Primitive::undefinedValue().asReturnedValue();
+                return Encode::undefined();
 
             ScopedCallData callData(scope, 0);
             callData->thisObject = *object;
@@ -223,7 +223,7 @@ ReturnedValue Lookup::getterAccessor2(Lookup *l, const ValueRef object)
                     Scope scope(o->engine());
                     FunctionObject *getter = o->memberData[l->index].getter();
                     if (!getter)
-                        return Primitive::undefinedValue().asReturnedValue();
+                        return Encode::undefined();
 
                     ScopedCallData callData(scope, 0);
                     callData->thisObject = *object;
@@ -266,10 +266,9 @@ ReturnedValue Lookup::primitiveGetterAccessor0(Lookup *l, const ValueRef object)
         Object *o = l->proto;
         if (l->classList[0] == o->internalClass) {
             Scope scope(o->engine());
-            Value res;
             FunctionObject *getter = o->memberData[l->index].getter();
             if (!getter)
-                return Primitive::undefinedValue().asReturnedValue();
+                return Encode::undefined();
 
             ScopedCallData callData(scope, 0);
             callData->thisObject = *object;
@@ -287,10 +286,9 @@ ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, const ValueRef object)
         if (l->classList[0] == o->internalClass &&
             l->classList[1] == o->prototype()->internalClass) {
             Scope scope(o->engine());
-            Value res;
             FunctionObject *getter = o->prototype()->memberData[l->index].getter();
             if (!getter)
-                return Primitive::undefinedValue().asReturnedValue();
+                return Encode::undefined();
 
             ScopedCallData callData(scope, 0);
             callData->thisObject = *object;
@@ -304,7 +302,7 @@ ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, const ValueRef object)
 ReturnedValue Lookup::stringLengthGetter(Lookup *l, const ValueRef object)
 {
     if (String *s = object->asString())
-        return Primitive::fromUInt32(s->length()).asReturnedValue();
+        return Encode(s->length());
 
     l->getter = getterGeneric;
     return getterGeneric(l, object);
@@ -384,7 +382,7 @@ ReturnedValue Lookup::globalGetterAccessor0(Lookup *l, ExecutionContext *ctx)
         Scope scope(o->engine());
         FunctionObject *getter = o->memberData[l->index].getter();
         if (!getter)
-            return Primitive::undefinedValue().asReturnedValue();
+            return Encode::undefined();
 
         ScopedCallData callData(scope, 0);
         callData->thisObject = Primitive::undefinedValue();
@@ -402,7 +400,7 @@ ReturnedValue Lookup::globalGetterAccessor1(Lookup *l, ExecutionContext *ctx)
         Scope scope(o->engine());
         FunctionObject *getter = o->prototype()->memberData[l->index].getter();
         if (!getter)
-            return Primitive::undefinedValue().asReturnedValue();
+            return Encode::undefined();
 
         ScopedCallData callData(scope, 0);
         callData->thisObject = Primitive::undefinedValue();
@@ -423,7 +421,7 @@ ReturnedValue Lookup::globalGetterAccessor2(Lookup *l, ExecutionContext *ctx)
                 Scope scope(o->engine());
                 FunctionObject *getter = o->memberData[l->index].getter();
                 if (!getter)
-                    return Primitive::undefinedValue().asReturnedValue();
+                    return Encode::undefined();
 
                 ScopedCallData callData(scope, 0);
                 callData->thisObject = Primitive::undefinedValue();
index 5f25406..06a04b4 100644 (file)
@@ -67,7 +67,7 @@ ReturnedValue NumberCtor::construct(Managed *m, CallData *callData)
 ReturnedValue NumberCtor::call(Managed *, CallData *callData)
 {
     double dbl = callData->argc ? callData->args[0].toNumber() : 0.;
-    return Primitive::fromDouble(dbl).asReturnedValue();
+    return Encode(dbl);
 }
 
 void NumberPrototype::init(ExecutionEngine *engine, ObjectRef ctor)
index 3fdbf66..f7401ea 100644 (file)
@@ -135,7 +135,7 @@ ReturnedValue Object::getValue(const ValueRef thisObject, const Property *p, Pro
         return p->value.asReturnedValue();
     FunctionObject *getter = p->getter();
     if (!getter)
-        return Primitive::undefinedValue().asReturnedValue();
+        return Encode::undefined();
 
     Scope scope(getter->engine());
     ScopedCallData callData(scope, 0);
@@ -150,7 +150,7 @@ void Object::putValue(Property *pd, PropertyAttributes attrs, const ValueRef val
             Scope scope(pd->set->engine());
             ScopedCallData callData(scope, 1);
             callData->args[0] = *value;
-            callData->thisObject = Value::fromObject(this);
+            callData->thisObject = this;
             pd->set->call(callData);
             return;
         }
@@ -538,7 +538,7 @@ ReturnedValue Object::getLookup(Managed *m, Lookup *l)
             return o->getValue(p, attrs);
         }
     }
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 void Object::setLookup(Managed *m, Lookup *l, const ValueRef value)
@@ -710,7 +710,7 @@ ReturnedValue Object::internalGetIndexed(uint index, bool *hasProperty)
 
     if (hasProperty)
         *hasProperty = false;
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 
@@ -777,7 +777,7 @@ void Object::internalPut(const StringRef name, const ValueRef value)
         Scope scope(engine());
         ScopedCallData callData(scope, 1);
         callData->args[0] = *value;
-        callData->thisObject = Value::fromObject(this);
+        callData->thisObject = this;
         pd->setter()->call(callData);
         return;
     }
@@ -856,7 +856,7 @@ void Object::internalPutIndexed(uint index, const ValueRef value)
         Scope scope(engine());
         ScopedCallData callData(scope, 1);
         callData->args[0] = *value;
-        callData->thisObject = Value::fromObject(this);
+        callData->thisObject = this;
         pd->setter()->call(callData);
         return;
     }
@@ -1140,7 +1140,7 @@ void Object::copyArrayData(Object *other)
 }
 
 
-ReturnedValue Object::arrayIndexOf(Value v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
+ReturnedValue Object::arrayIndexOf(const ValueRef v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
 {
     Scope scope(engine());
     ScopedValue value(scope);
@@ -1150,13 +1150,13 @@ ReturnedValue Object::arrayIndexOf(Value v, uint fromIndex, uint endIndex, Execu
         for (uint i = fromIndex; i < endIndex; ++i) {
             bool exists;
             value = o->getIndexed(i, &exists);
-            if (exists && __qmljs_strict_equal(value, ValueRef(&v)))
+            if (exists && __qmljs_strict_equal(value, v))
                 return Encode(i);
         }
     } else if (sparseArray) {
         for (SparseArrayNode *n = sparseArray->lowerBound(fromIndex); n != sparseArray->end() && n->key() < endIndex; n = n->nextNode()) {
             value = o->getValue(arrayData + n->value, arrayAttributes ? arrayAttributes[n->value] : Attr_Data);
-            if (__qmljs_strict_equal(value, ValueRef(&v)))
+            if (__qmljs_strict_equal(value, v))
                 return Encode(n->key());
         }
     } else {
@@ -1168,7 +1168,7 @@ ReturnedValue Object::arrayIndexOf(Value v, uint fromIndex, uint endIndex, Execu
         while (pd < end) {
             if (!arrayAttributes || !arrayAttributes[pd - arrayData].isGeneric()) {
                 value = o->getValue(pd, arrayAttributes ? arrayAttributes[pd - arrayData] : Attr_Data);
-                if (__qmljs_strict_equal(value, ValueRef(&v)))
+                if (__qmljs_strict_equal(value, v))
                     return Encode((uint)(pd - arrayData));
             }
             ++pd;
@@ -1208,7 +1208,7 @@ void Object::arrayConcat(const ArrayObject *other)
         if (other->arrayAttributes) {
             for (int i = 0; i < other->arrayDataLen; ++i) {
                 bool exists;
-                arrayData[oldSize + i].value = Value::fromReturnedValue(const_cast<ArrayObject *>(other)->getIndexed(i, &exists));
+                arrayData[oldSize + i].value = const_cast<ArrayObject *>(other)->getIndexed(i, &exists);
                 arrayDataLen = oldSize + i + 1;
                 if (arrayAttributes)
                     arrayAttributes[oldSize + i] = Attr_Data;
@@ -1250,11 +1250,11 @@ void Object::arraySort(ExecutionContext *context, ObjectRef thisObject, const Va
                 while (--len > i)
                     if (!arrayAttributes[len].isGeneric())
                         break;
-                arrayData[i].value = Value::fromReturnedValue(getValue(arrayData + len, arrayAttributes[len]));
+                arrayData[i].value = getValue(arrayData + len, arrayAttributes[len]);
                 arrayAttributes[i] = Attr_Data;
                 arrayAttributes[len].clear();
             } else if (arrayAttributes[i].isAccessor()) {
-                arrayData[i].value = Value::fromReturnedValue(getValue(arrayData + i, arrayAttributes[i]));
+                arrayData[i].value = getValue(arrayData + i, arrayAttributes[i]);
                 arrayAttributes[i] = Attr_Data;
             }
         }
index bbf0786..899fcde 100644 (file)
@@ -150,7 +150,7 @@ struct Q_QML_EXPORT Object: Managed {
     static ReturnedValue getValue(const ValueRef thisObject, const Property *p, PropertyAttributes attrs);
     ReturnedValue getValue(const Property *p, PropertyAttributes attrs) const {
         Scope scope(this->engine());
-        ScopedValue t(scope, Value::fromObject(const_cast<Object *>(this)));
+        ScopedValue t(scope, const_cast<Object *>(this));
         return getValue(t, p, attrs);
     }
 
@@ -270,7 +270,7 @@ public:
 
     void arrayConcat(const ArrayObject *other);
     void arraySort(ExecutionContext *context, ObjectRef thisObject, const ValueRef comparefn, uint arrayDataLen);
-    ReturnedValue arrayIndexOf(Value v, uint fromIndex, uint arrayDataLen, ExecutionContext *ctx, Object *o);
+    ReturnedValue arrayIndexOf(const ValueRef v, uint fromIndex, uint arrayDataLen, ExecutionContext *ctx, Object *o);
 
     void arrayReserve(uint n);
     void ensureArrayAttributes();
@@ -350,17 +350,33 @@ protected:
 };
 
 struct BooleanObject: Object {
-    Value value;
-    BooleanObject(ExecutionEngine *engine, const ValueRef value): Object(engine->booleanClass), value(*value) { type = Type_BooleanObject; }
+    SafeValue value;
+    BooleanObject(ExecutionEngine *engine, const ValueRef val)
+        : Object(engine->booleanClass) {
+        type = Type_BooleanObject;
+        value = val;
+    }
 protected:
-    BooleanObject(InternalClass *ic): Object(ic), value(Primitive::fromBoolean(false)) { type = Type_BooleanObject; }
+    BooleanObject(InternalClass *ic)
+        : Object(ic) {
+        type = Type_BooleanObject;
+        value = Encode(false);
+    }
 };
 
 struct NumberObject: Object {
-    Value value;
-    NumberObject(ExecutionEngine *engine, const ValueRef value): Object(engine->numberClass), value(*value) { type = Type_NumberObject; }
+    SafeValue value;
+    NumberObject(ExecutionEngine *engine, const ValueRef val)
+        : Object(engine->numberClass) {
+        type = Type_NumberObject;
+        value = val;
+    }
 protected:
-    NumberObject(InternalClass *ic): Object(ic), value(Primitive::fromInt32(0)) { type = Type_NumberObject; }
+    NumberObject(InternalClass *ic)
+        : Object(ic) {
+        type = Type_NumberObject;
+        value = Encode((int)0);
+    }
 };
 
 struct ArrayObject: Object {
@@ -381,11 +397,9 @@ struct ArrayObject: Object {
 inline uint Object::arrayLength() const
 {
     if (isArrayObject()) {
-        // length is always the first property of an array
-        Value v = memberData[ArrayObject::LengthPropertyIndex].value;
-        if (v.isInteger())
-            return v.integerValue();
-        return Primitive::toUInt32(v.doubleValue());
+        if (memberData[ArrayObject::LengthPropertyIndex].value.isInteger())
+            return memberData[ArrayObject::LengthPropertyIndex].value.integerValue();
+        return Primitive::toUInt32(memberData[ArrayObject::LengthPropertyIndex].value.doubleValue());
     }
     return 0;
 }
index 02f8cb6..65fd218 100644 (file)
@@ -91,7 +91,7 @@ ReturnedValue ObjectCtor::construct(Managed *that, CallData *callData)
             obj->setPrototype(proto.getPointer());
         return obj.asReturnedValue();
     }
-    return Value::fromReturnedValue(__qmljs_to_object(v4->current, ValueRef(&callData->args[0]))).asReturnedValue();
+    return __qmljs_to_object(v4->current, ValueRef(&callData->args[0]));
 }
 
 ReturnedValue ObjectCtor::call(Managed *m, CallData *callData)
@@ -220,6 +220,7 @@ ReturnedValue ObjectPrototype::method_defineProperties(SimpleCallContext *ctx)
         ctx->throwTypeError();
 
     Scoped<Object> o(scope, ctx->argument(1), Scoped<Object>::Convert);
+    ScopedValue val(scope);
 
     ObjectIterator it(o.getPointer(), ObjectIterator::EnumerableOnly);
     while (1) {
@@ -233,7 +234,8 @@ ReturnedValue ObjectPrototype::method_defineProperties(SimpleCallContext *ctx)
             break;
         Property n;
         PropertyAttributes nattrs;
-        toPropertyDescriptor(ctx, Value::fromReturnedValue(o->getValue(pd, attrs)), &n, &nattrs);
+        val = o->getValue(pd, attrs);
+        toPropertyDescriptor(ctx, val, &n, &nattrs);
         bool ok;
         if (name)
             ok = O->__defineOwnProperty__(ctx, name, n, nattrs);
@@ -541,7 +543,7 @@ ReturnedValue ObjectPrototype::method_set_proto(SimpleCallContext *ctx)
     return Encode::undefined();
 }
 
-void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Property *desc, PropertyAttributes *attrs)
+void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, const ValueRef v, Property *desc, PropertyAttributes *attrs)
 {
     Scope scope(ctx);
     ScopedObject o(scope, v);
@@ -551,12 +553,13 @@ void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Prope
     attrs->clear();
     desc->setGetter(0);
     desc->setSetter(0);
+    ScopedValue tmp(scope);
 
     if (o->__hasProperty__(ctx->engine->id_enumerable))
-        attrs->setEnumerable(Value::fromReturnedValue(o->get(ctx->engine->id_enumerable)).toBoolean());
+        attrs->setEnumerable((tmp = o->get(ctx->engine->id_enumerable))->toBoolean());
 
     if (o->__hasProperty__(ctx->engine->id_configurable))
-        attrs->setConfigurable(Value::fromReturnedValue(o->get(ctx->engine->id_configurable)).toBoolean());
+        attrs->setConfigurable((tmp = o->get(ctx->engine->id_configurable))->toBoolean());
 
     if (o->__hasProperty__(ctx->engine->id_get)) {
         ScopedValue get(scope, o->get(ctx->engine->id_get));
@@ -587,7 +590,7 @@ void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Prope
     if (o->__hasProperty__(ctx->engine->id_writable)) {
         if (attrs->isAccessor())
             ctx->throwTypeError();
-        attrs->setWritable(Value::fromReturnedValue(o->get(ctx->engine->id_writable)).toBoolean());
+        attrs->setWritable((tmp = o->get(ctx->engine->id_writable))->toBoolean());
         // writable forces it to be a data descriptor
         desc->value = Primitive::undefinedValue();
     }
@@ -595,7 +598,7 @@ void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Prope
     if (o->__hasProperty__(ctx->engine->id_value)) {
         if (attrs->isAccessor())
             ctx->throwTypeError();
-        desc->value = Value::fromReturnedValue(o->get(ctx->engine->id_value));
+        desc->value = o->get(ctx->engine->id_value);
         attrs->setType(PropertyAttributes::Data);
     }
 
@@ -613,7 +616,7 @@ ReturnedValue ObjectPrototype::fromPropertyDescriptor(ExecutionContext *ctx, con
     Scope scope(engine);
     // Let obj be the result of creating a new object as if by the expression new Object() where Object
     // is the standard built-in constructor with that name.
-    Scoped<Object> o(scope, engine->newObject());
+    ScopedObject o(scope, engine->newObject());
     ScopedString s(scope);
 
     Property pd;
@@ -625,10 +628,10 @@ ReturnedValue ObjectPrototype::fromPropertyDescriptor(ExecutionContext *ctx, con
         s = engine->newString(QStringLiteral("writable"));
         o->__defineOwnProperty__(ctx, s, pd, Attr_Data);
     } else {
-        pd.value = desc->getter() ? Value::fromObject(desc->getter()) : Primitive::undefinedValue();
+        pd.value = desc->getter() ? desc->getter()->asReturnedValue() : Encode::undefined();
         s = engine->newString(QStringLiteral("get"));
         o->__defineOwnProperty__(ctx, s, pd, Attr_Data);
-        pd.value = desc->setter() ? Value::fromObject(desc->setter()) : Primitive::undefinedValue();
+        pd.value = desc->setter() ? desc->setter()->asReturnedValue() : Encode::undefined();
         s = engine->newString(QStringLiteral("set"));
         o->__defineOwnProperty__(ctx, s, pd, Attr_Data);
     }
index 8994ba5..b5dcd06 100644 (file)
@@ -91,7 +91,7 @@ struct ObjectPrototype: Object
     static ReturnedValue method_get_proto(SimpleCallContext *ctx);
     static ReturnedValue method_set_proto(SimpleCallContext *ctx);
 
-    static void toPropertyDescriptor(ExecutionContext *ctx, Value v, Property *desc, PropertyAttributes *attrs);
+    static void toPropertyDescriptor(ExecutionContext *ctx, const ValueRef v, Property *desc, PropertyAttributes *attrs);
     static ReturnedValue fromPropertyDescriptor(ExecutionContext *ctx, const Property *desc, PropertyAttributes attrs);
 
     static Returned<ArrayObject> *getOwnPropertyNames(ExecutionEngine *v4, const ValueRef o);
index c206826..d28514f 100644 (file)
@@ -85,23 +85,32 @@ QT_BEGIN_NAMESPACE
 
 using namespace QV4;
 
-static QPair<QObject *, int> extractQtMethod(QV4::FunctionObject *function)
+static QPair<QObject *, int> extractQtMethod(QV4::FunctionObjectRef function)
 {
-    if (function && function->subtype == QV4::FunctionObject::WrappedQtMethod) {
-        QObjectMethod *method = static_cast<QObjectMethod*>(function);
-        return qMakePair(method->object(), method->methodIndex());
+    QV4::ExecutionEngine *v4 = function->engine();
+    if (v4) {
+        QV4::Scope scope(v4);
+        QV4::Scoped<QObjectMethod> method(scope, function->as<QObjectMethod>());
+        if (method)
+            return qMakePair(method->object(), method->methodIndex());
     }
 
     return qMakePair((QObject *)0, -1);
 }
 
-static QPair<QObject *, int> extractQtSignal(const Value &value)
+static QPair<QObject *, int> extractQtSignal(const ValueRef value)
 {
-    if (QV4::FunctionObject *function = value.asFunctionObject())
-        return extractQtMethod(function);
-
-    if (QV4::QmlSignalHandler *handler = value.as<QV4::QmlSignalHandler>())
-        return qMakePair(handler->object(), handler->signalIndex());
+    QV4::ExecutionEngine *v4 = value->engine();
+    if (v4) {
+        QV4::Scope scope(v4);
+        QV4::ScopedFunctionObject function(scope, value);
+        if (function)
+            return extractQtMethod(function);
+
+        QV4::Scoped<QV4::QmlSignalHandler> handler(scope, value);
+        if (handler)
+            return qMakePair(handler->object(), handler->signalIndex());
+    }
 
     return qMakePair((QObject *)0, -1);
 }
@@ -325,8 +334,7 @@ ReturnedValue QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextD
             return vmemo->vmeMethod(result->coreIndex);
         } else if (result->isV4Function()) {
             QV4::Scoped<QV4::Object> qmlcontextobject(scope, ctx->engine->qmlContextObject());
-            return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex,
-                                              qmlcontextobject.asValue()).asReturnedValue();
+            return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex, qmlcontextobject);
         } else if (result->isSignalHandler()) {
             QV4::Scoped<QV4::QmlSignalHandler> handler(scope, new (ctx->engine->memoryManager) QV4::QmlSignalHandler(ctx->engine, m_object, result->coreIndex));
 
@@ -337,7 +345,7 @@ ReturnedValue QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextD
 
             return handler.asReturnedValue();
         } else {
-            return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex).asReturnedValue();
+            return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex);
         }
     }
 
@@ -567,7 +575,7 @@ ReturnedValue QObjectWrapper::wrap(ExecutionEngine *engine, QObject *object)
         // tainted object list
         Scoped<Object> alternateWrapper(scope, (Object *)0);
         if (engine->m_multiplyWrappedQObjects && ddata->hasTaintedV8Object)
-            alternateWrapper = Value::fromObject(engine->m_multiplyWrappedQObjects->value(object));
+            alternateWrapper = engine->m_multiplyWrappedQObjects->value(object);
 
         // If our tainted handle doesn't exist or has been collected, and there isn't
         // a handle in the ddata, we can assume ownership of the ddata->v8object
@@ -658,7 +666,7 @@ Property *QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, String
         ++it->arrayIndex;
         if (attributes)
             *attributes = QV4::Attr_Data;
-        it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(that->get(n));
+        it->tmpDynamicProperty.value = that->get(n);
         return &it->tmpDynamicProperty;
     }
     const int methodCount = mo->methodCount();
@@ -668,7 +676,7 @@ Property *QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, String
         ++it->arrayIndex;
         if (attributes)
             *attributes = QV4::Attr_Data;
-        it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(that->get(n));
+        it->tmpDynamicProperty.value = that->get(n);
         return &it->tmpDynamicProperty;
     }
     return QV4::Object::advanceIterator(m, it, name, index, attributes);
@@ -708,13 +716,13 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase
             QV4::ExecutionContext *ctx = v4->current;
 
             QV4::ScopedCallData callData(scope, argCount);
-            callData->thisObject = This->thisObject.isUndefined() ? Value::fromObject(v4->globalObject) : Value::fromReturnedValue(This->thisObject.value());
+            callData->thisObject = This->thisObject.isUndefined() ? v4->globalObject->asReturnedValue() : This->thisObject.value();
             for (int ii = 0; ii < argCount; ++ii) {
                 int type = argsTypes[ii + 1];
                 if (type == qMetaTypeId<QVariant>()) {
-                    callData->args[ii] = QV4::Value::fromReturnedValue(v4->v8Engine->fromVariant(*((QVariant *)metaArgs[ii + 1])));
+                    callData->args[ii] = v4->v8Engine->fromVariant(*((QVariant *)metaArgs[ii + 1]));
                 } else {
-                    callData->args[ii] = QV4::Value::fromReturnedValue(v4->v8Engine->fromVariant(QVariant(type, metaArgs[ii + 1])));
+                    callData->args[ii] = v4->v8Engine->fromVariant(QVariant(type, metaArgs[ii + 1]));
                 }
             }
 
@@ -758,7 +766,7 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase
                         (connection->thisObject.isUndefined() || __qmljs_strict_equal(connection->thisObject, thisObject))) {
 
                     QV4::ScopedFunctionObject f(scope, connection->function.value());
-                    QPair<QObject *, int> connectedFunctionData = extractQtMethod(f.getPointer());
+                    QPair<QObject *, int> connectedFunctionData = extractQtMethod(f);
                     if (connectedFunctionData.first == receiverToDisconnect &&
                         connectedFunctionData.second == slotIndexToDisconnect) {
                         *ret = true;
@@ -837,6 +845,8 @@ ReturnedValue QObjectWrapper::method_disconnect(SimpleCallContext *ctx)
     if (ctx->callData->argc == 0)
         V4THROW_ERROR("Function.prototype.disconnect: no arguments given");
 
+    QV4::Scope scope(ctx);
+
     QPair<QObject *, int> signalInfo = extractQtSignal(ctx->callData->thisObject);
     QObject *signalObject = signalInfo.first;
     int signalIndex = signalInfo.second;
@@ -850,8 +860,8 @@ ReturnedValue QObjectWrapper::method_disconnect(SimpleCallContext *ctx)
     if (signalIndex < 0 || signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal)
         V4THROW_ERROR("Function.prototype.disconnect: this object is not a signal");
 
-    QV4::Value functionValue = QV4::Primitive::undefinedValue();
-    QV4::Value functionThisValue = QV4::Primitive::undefinedValue();
+    QV4::ScopedFunctionObject functionValue(scope);
+    QV4::ScopedValue functionThisValue(scope, QV4::Encode::undefined());
 
     if (ctx->callData->argc == 1) {
         functionValue = ctx->callData->args[0];
@@ -860,18 +870,18 @@ ReturnedValue QObjectWrapper::method_disconnect(SimpleCallContext *ctx)
         functionValue = ctx->callData->args[1];
     }
 
-    if (!functionValue.asFunctionObject())
+    if (!functionValue)
         V4THROW_ERROR("Function.prototype.disconnect: target is not a function");
 
-    if (!functionThisValue.isUndefined() && !functionThisValue.isObject())
+    if (!functionThisValue->isUndefined() && !functionThisValue->isObject())
         V4THROW_ERROR("Function.prototype.disconnect: target this is not an object");
 
-    QPair<QObject *, int> functionData = extractQtMethod(functionValue.asFunctionObject());
+    QPair<QObject *, int> functionData = extractQtMethod(functionValue);
 
     void *a[] = {
         ctx->engine,
-        &functionValue,
-        &functionThisValue,
+        functionValue.ptr,
+        functionThisValue.ptr,
         functionData.first,
         &functionData.second
     };
@@ -1618,7 +1628,7 @@ QV4::ReturnedValue CallArgument::toValue(QV8Engine *engine)
         QV4::Scoped<ArrayObject> array(scope, v4->newArrayObject());
         array->arrayReserve(list.count());
         for (int ii = 0; ii < list.count(); ++ii) {
-            array->arrayData[ii].value = Value::fromReturnedValue(QV4::QObjectWrapper::wrap(v4, list.at(ii)));
+            array->arrayData[ii].value = QV4::QObjectWrapper::wrap(v4, list.at(ii));
             array->arrayDataLen = ii + 1;
         }
         array->setArrayLengthUnchecked(list.count());
@@ -1644,19 +1654,19 @@ QV4::ReturnedValue CallArgument::toValue(QV8Engine *engine)
     }
 }
 
-Value QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
+ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal)
 {
-    return Value::fromObject(new (scope->engine->memoryManager) QObjectMethod(scope, object, index, qmlGlobal));
+    return (new (scope->engine->memoryManager) QObjectMethod(scope, object, index, qmlGlobal))->asReturnedValue();
 }
 
-QObjectMethod::QObjectMethod(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
+QObjectMethod::QObjectMethod(ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal)
     : FunctionObject(scope)
     , m_object(object)
     , m_index(index)
 {
     vtbl = &static_vtbl;
     subtype = WrappedQtMethod;
-    m_qmlGlobal = qmlGlobal.asReturnedValue();
+    m_qmlGlobal = qmlGlobal;
 }
 
 QV4::ReturnedValue QObjectMethod::method_toString(QV4::ExecutionContext *ctx)
@@ -1683,7 +1693,7 @@ QV4::ReturnedValue QObjectMethod::method_toString(QV4::ExecutionContext *ctx)
     return ctx->engine->newString(result)->asReturnedValue();
 }
 
-QV4::ReturnedValue QObjectMethod::method_destroy(QV4::ExecutionContext *ctx, const Value *args, int argc)
+QV4::ReturnedValue QObjectMethod::method_destroy(QV4::ExecutionContext *ctx, const ValueRef args, int argc)
 {
     if (!m_object)
         return Encode::undefined();
index ce0c206..74c436c 100644 (file)
@@ -126,16 +126,16 @@ struct QObjectMethod : public QV4::FunctionObject
 
     enum { DestroyMethod = -1, ToStringMethod = -2 };
 
-    static Value create(QV4::ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal = Primitive::undefinedValue());
+    static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal = Primitive::undefinedValue());
 
     int methodIndex() const { return m_index; }
     QObject *object() const { return m_object.data(); }
 
 private:
-    QObjectMethod(QV4::ExecutionContext *scope, QObject *object, int index, const QV4::Value &qmlGlobal);
+    QObjectMethod(QV4::ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal);
 
     QV4::ReturnedValue method_toString(QV4::ExecutionContext *ctx);
-    QV4::ReturnedValue method_destroy(QV4::ExecutionContext *ctx, const Value *args, int argc);
+    QV4::ReturnedValue method_destroy(QV4::ExecutionContext *ctx, const ValueRef args, int argc);
 
     QPointer<QObject> m_object;
     int m_index;
index 3d9572e..bc0955f 100644 (file)
@@ -138,12 +138,12 @@ void RegExp::markObjects(Managed *that)
 
 ReturnedValue RegExp::get(Managed *, const StringRef, bool *)
 {
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 ReturnedValue RegExp::getIndexed(Managed *m, uint index, bool *hasProperty)
 {
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 void RegExp::put(Managed *m, const StringRef name, const ValueRef value)
index bab4a32..899938f 100644 (file)
@@ -374,8 +374,9 @@ ReturnedValue RegExpPrototype::method_compile(SimpleCallContext *ctx)
         ctx->throwTypeError();
 
     ScopedCallData callData(scope, ctx->callData->argc);
-    memcpy(callData->args, ctx->callData->args, ctx->callData->argc*sizeof(Value));
-    RegExpObject *re = Value::fromReturnedValue(ctx->engine->regExpCtor.asFunctionObject()->construct(callData)).as<RegExpObject>();
+    memcpy(callData->args, ctx->callData->args, ctx->callData->argc*sizeof(SafeValue));
+
+    Scoped<RegExpObject> re(scope, ctx->engine->regExpCtor.asFunctionObject()->construct(callData));
 
     r->value = re->value;
     r->global = re->global;
index cb059be..dabd9ad 100644 (file)
@@ -255,7 +255,7 @@ ReturnedValue __qmljs_delete_subscript(ExecutionContext *ctx, const ValueRef bas
     if (o) {
         uint n = index->asArrayIndex();
         if (n < UINT_MAX) {
-            return Primitive::fromBoolean(o->deleteIndexedProperty(n)).asReturnedValue();
+            return Encode((bool)o->deleteIndexedProperty(n));
         }
     }
 
@@ -291,7 +291,7 @@ QV4::ReturnedValue __qmljs_add_helper(ExecutionContext *ctx, const ValueRef left
     }
     double x = __qmljs_to_number(pleft);
     double y = __qmljs_to_number(pright);
-    return Primitive::fromDouble(x + y).asReturnedValue();
+    return Encode(x + y);
 }
 
 QV4::ReturnedValue __qmljs_instanceof(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
@@ -301,7 +301,7 @@ QV4::ReturnedValue __qmljs_instanceof(ExecutionContext *ctx, const ValueRef left
         ctx->throwTypeError();
 
     bool r = o->hasInstance(left);
-    return Primitive::fromBoolean(r).asReturnedValue();
+    return Encode(r);
 }
 
 QV4::ReturnedValue __qmljs_in(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
@@ -311,7 +311,7 @@ QV4::ReturnedValue __qmljs_in(ExecutionContext *ctx, const ValueRef left, const
     Scope scope(ctx);
     ScopedString s(scope, left->toString(ctx));
     bool r = right->objectValue()->__hasProperty__(s);
-    return Primitive::fromBoolean(r).asReturnedValue();
+    return Encode(r);
 }
 
 static void inplaceBitOp(ExecutionContext *ctx, const StringRef name, const ValueRef value, BinOp op)
@@ -584,24 +584,24 @@ ReturnedValue __qmljs_object_default_value(Object *object, int typeHint)
     ExecutionContext *ctx = engine->current;
     Scope scope(ctx);
     ScopedCallData callData(scope, 0);
-    callData->thisObject = Value::fromObject(object);
+    callData->thisObject = object;
 
     ScopedValue conv(scope, object->get(*meth1));
     if (FunctionObject *o = conv->asFunctionObject()) {
-        Value r = Value::fromReturnedValue(o->call(callData));
-        if (r.isPrimitive())
-            return r.asReturnedValue();
+        ScopedValue r(scope, o->call(callData));
+        if (r->isPrimitive())
+            return r->asReturnedValue();
     }
 
     conv = object->get(*meth2);
     if (FunctionObject *o = conv->asFunctionObject()) {
-        Value r = Value::fromReturnedValue(o->call(callData));
-        if (r.isPrimitive())
-            return r.asReturnedValue();
+        ScopedValue r(scope, o->call(callData));
+        if (r->isPrimitive())
+            return r->asReturnedValue();
     }
 
     ctx->throwTypeError();
-    return Primitive::undefinedValue().asReturnedValue();
+    return Encode::undefined();
 }
 
 Bool __qmljs_to_boolean(const ValueRef value)
@@ -674,7 +674,7 @@ ReturnedValue __qmljs_get_element(ExecutionContext *ctx, const ValueRef object,
         if (idx < UINT_MAX) {
             if (String *str = object->asString()) {
                 if (idx >= (uint)str->toQString().length()) {
-                    return Primitive::undefinedValue().asReturnedValue();
+                    return Encode::undefined();
                 }
                 const QString s = str->toQString().mid(idx, 1);
                 return scope.engine->newString(s)->asReturnedValue();
@@ -813,11 +813,9 @@ uint __qmljs_equal_helper(const ValueRef x, const ValueRef y)
         double dx = __qmljs_to_number(x);
         return dx == y->asDouble();
     } else if (x->isBoolean()) {
-        Value nx = Primitive::fromDouble((double) x->booleanValue());
-        return __qmljs_cmp_eq(ValueRef(&nx), y);
+        return __qmljs_cmp_eq(Primitive::fromDouble((double) x->booleanValue()), y);
     } else if (y->isBoolean()) {
-        Value ny = Primitive::fromDouble((double) y->booleanValue());
-        return __qmljs_cmp_eq(x, ValueRef(&ny));
+        return __qmljs_cmp_eq(x, Primitive::fromDouble((double) y->booleanValue()));
     } else if ((x->isNumber() || x->isString()) && y->isObject()) {
         Scope scope(y->objectValue()->engine());
         ScopedValue py(scope, __qmljs_to_primitive(y, PREFERREDTYPE_HINT));
@@ -964,13 +962,15 @@ ReturnedValue __qmljs_call_activation_property(ExecutionContext *context, const
     Object *base;
     ScopedValue func(scope, context->getPropertyAndBase(name, &base));
     if (base)
-        callData->thisObject = Value::fromObject(base);
+        callData->thisObject = base;
 
     FunctionObject *o = func->asFunctionObject();
     if (!o) {
         QString objectAsString = QStringLiteral("[null]");
-        if (base)
-            objectAsString = Value::fromObject(base).toQStringNoThrow();
+        if (base) {
+            ScopedValue b(scope, base);
+            objectAsString = b->toQStringNoThrow();
+        }
         QString msg = QStringLiteral("Property '%1' of object %2 is not a function").arg(name->toQString()).arg(objectAsString);
         context->throwTypeError(msg);
     }
@@ -1021,11 +1021,11 @@ ReturnedValue __qmljs_call_property_lookup(ExecutionContext *context, uint index
 ReturnedValue __qmljs_call_element(ExecutionContext *context, const ValueRef index, CallDataRef callData)
 {
     Scope scope(context);
-    Object *baseObject = callData->thisObject.toObject(context);
-    callData->thisObject = Value::fromObject(baseObject);
+    ScopedObject baseObject(scope, callData->thisObject.toObject(context));
+    callData->thisObject = baseObject;
 
     ScopedString s(scope, index->toString(context));
-    Scoped<Object> o(scope, baseObject->get(s));
+    ScopedObject o(scope, baseObject->get(s));
     if (!o)
         context->throwTypeError();
 
@@ -1247,11 +1247,11 @@ QV4::ReturnedValue __qmljs_increment(const QV4::ValueRef value)
 {
     TRACE1(value);
 
-    if (value->isInteger())
-        return Primitive::fromInt32(value->integerValue() + 1).asReturnedValue();
+    if (value->isInteger() && value->integerValue() < INT_MAX)
+        return Encode(value->integerValue() + 1);
     else {
         double d = value->toNumber();
-        return Primitive::fromDouble(d + 1).asReturnedValue();
+        return Encode(d + 1.);
     }
 }
 
@@ -1259,11 +1259,11 @@ QV4::ReturnedValue __qmljs_decrement(const QV4::ValueRef value)
 {
     TRACE1(value);
 
-    if (value->isInteger())
-        return Primitive::fromInt32(value->integerValue() - 1).asReturnedValue();
+    if (value->isInteger() && value->integerValue() > INT_MIN)
+        return Encode(value->integerValue() - 1);
     else {
         double d = value->toNumber();
-        return Primitive::fromDouble(d - 1).asReturnedValue();
+        return Encode(d - 1.);
     }
 }
 
index a9e8e01..da7f98e 100644 (file)
@@ -311,10 +311,10 @@ inline QV4::ReturnedValue __qmljs_uminus(const QV4::ValueRef value)
 
     // +0 != -0, so we need to convert to double when negating 0
     if (value->isInteger() && value->integerValue())
-        return QV4::Primitive::fromInt32(-value->integerValue()).asReturnedValue();
+        return Encode(-value->integerValue());
     else {
         double n = __qmljs_to_number(value);
-        return QV4::Primitive::fromDouble(-n).asReturnedValue();
+        return Encode(-n);
     }
 }
 
@@ -345,11 +345,11 @@ inline ReturnedValue __qmljs_bit_or(const QV4::ValueRef left, const QV4::ValueRe
     TRACE2(left, right);
 
     if (QV4::Value::integerCompatible(*left, *right))
-        return QV4::Primitive::fromInt32(left->integerValue() | right->integerValue()).asReturnedValue();
+        return Encode(left->integerValue() | right->integerValue());
 
     int lval = left->toInt32();
     int rval = right->toInt32();
-    return QV4::Primitive::fromInt32(lval | rval).asReturnedValue();
+    return Encode(lval | rval);
 }
 
 inline ReturnedValue __qmljs_bit_xor(const QV4::ValueRef left, const QV4::ValueRef right)
@@ -357,11 +357,11 @@ inline ReturnedValue __qmljs_bit_xor(const QV4::ValueRef left, const QV4::ValueR
     TRACE2(left, right);
 
     if (QV4::Value::integerCompatible(*left, *right))
-        return QV4::Primitive::fromInt32(left->integerValue() ^ right->integerValue()).asReturnedValue();
+        return Encode(left->integerValue() ^ right->integerValue());
 
     int lval = left->toInt32();
     int rval = right->toInt32();
-    return QV4::Primitive::fromInt32(lval ^ rval).asReturnedValue();
+    return Encode(lval ^ rval);
 }
 
 inline ReturnedValue __qmljs_bit_and(const QV4::ValueRef left, const QV4::ValueRef right)
@@ -369,11 +369,11 @@ inline ReturnedValue __qmljs_bit_and(const QV4::ValueRef left, const QV4::ValueR
     TRACE2(left, right);
 
     if (QV4::Value::integerCompatible(*left, *right))
-        return QV4::Primitive::fromInt32(left->integerValue() & right->integerValue()).asReturnedValue();
+        return Encode(left->integerValue() & right->integerValue());
 
     int lval = left->toInt32();
     int rval = right->toInt32();
-    return QV4::Primitive::fromInt32(lval & rval).asReturnedValue();
+    return Encode(lval & rval);
 }
 
 inline QV4::ReturnedValue __qmljs_add(QV4::ExecutionContext *ctx, const QV4::ValueRef left, const QV4::ValueRef right)
@@ -429,7 +429,7 @@ inline QV4::ReturnedValue __qmljs_mod(const QV4::ValueRef left, const QV4::Value
     if (QV4::Value::integerCompatible(*left, *right) && right->integerValue() != 0) {
         int intRes = left->integerValue() % right->integerValue();
         if (intRes != 0 || left->integerValue() >= 0)
-            return QV4::Primitive::fromInt32(intRes).asReturnedValue();
+            return Encode(intRes);
     }
 
     double lval = __qmljs_to_number(left);
@@ -442,11 +442,11 @@ inline QV4::ReturnedValue __qmljs_shl(const QV4::ValueRef left, const QV4::Value
     TRACE2(left, right);
 
     if (QV4::Value::integerCompatible(*left, *right))
-        return QV4::Primitive::fromInt32(left->integerValue() << ((uint(right->integerValue()) & 0x1f))).asReturnedValue();
+        return Encode((int)(left->integerValue() << ((uint(right->integerValue()) & 0x1f))));
 
     int lval = left->toInt32();
     unsigned rval = right->toUInt32() & 0x1f;
-    return QV4::Primitive::fromInt32(lval << rval).asReturnedValue();
+    return Encode((int)(lval << rval));
 }
 
 inline QV4::ReturnedValue __qmljs_shr(const QV4::ValueRef left, const QV4::ValueRef right)
@@ -454,11 +454,11 @@ inline QV4::ReturnedValue __qmljs_shr(const QV4::ValueRef left, const QV4::Value
     TRACE2(left, right);
 
     if (QV4::Value::integerCompatible(*left, *right))
-        return QV4::Primitive::fromInt32(left->integerValue() >> ((uint(right->integerValue()) & 0x1f))).asReturnedValue();
+        return Encode((int)(left->integerValue() >> ((uint(right->integerValue()) & 0x1f))));
 
     int lval = left->toInt32();
     unsigned rval = right->toUInt32() & 0x1f;
-    return QV4::Primitive::fromInt32(lval >> rval).asReturnedValue();
+    return Encode((int)(lval >> rval));
 }
 
 inline QV4::ReturnedValue __qmljs_ushr(const QV4::ValueRef left, const QV4::ValueRef right)
@@ -474,52 +474,55 @@ inline QV4::ReturnedValue __qmljs_ushr(const QV4::ValueRef left, const QV4::Valu
         res = lval >> rval;
     }
 
-    if (res > INT_MAX)
-        return QV4::Primitive::fromDouble(res).asReturnedValue();
-    else
-        return QV4::Primitive::fromInt32(res).asReturnedValue();
+    return Encode(res);
 }
 
 inline QV4::ReturnedValue __qmljs_gt(const QV4::ValueRef left, const QV4::ValueRef right)
 {
     TRACE2(left, right);
 
-    return QV4::Primitive::fromBoolean(__qmljs_cmp_gt(left, right)).asReturnedValue();
+    bool r = __qmljs_cmp_gt(left, right);
+    return Encode(r);
 }
 
 inline QV4::ReturnedValue __qmljs_lt(const QV4::ValueRef left, const QV4::ValueRef right)
 {
     TRACE2(left, right);
 
-    return QV4::Primitive::fromBoolean(__qmljs_cmp_lt(left, right)).asReturnedValue();
+    bool r = __qmljs_cmp_lt(left, right);
+    return Encode(r);
 }
 
 inline QV4::ReturnedValue __qmljs_ge(const QV4::ValueRef left, const QV4::ValueRef right)
 {
     TRACE2(left, right);
 
-    return QV4::Primitive::fromBoolean(__qmljs_cmp_ge(left, right)).asReturnedValue();
+    bool r = __qmljs_cmp_ge(left, right);
+    return Encode(r);
 }
 
 inline QV4::ReturnedValue __qmljs_le(const QV4::ValueRef left, const QV4::ValueRef right)
 {
     TRACE2(left, right);
 
-    return QV4::Primitive::fromBoolean(__qmljs_cmp_le(left, right)).asReturnedValue();
+    bool r = __qmljs_cmp_le(left, right);
+    return Encode(r);
 }
 
 inline QV4::ReturnedValue __qmljs_eq(const QV4::ValueRef left, const QV4::ValueRef right)
 {
     TRACE2(left, right);
 
-    return QV4::Primitive::fromBoolean(__qmljs_cmp_eq(left, right)).asReturnedValue();
+    bool r = __qmljs_cmp_eq(left, right);
+    return Encode(r);
 }
 
 inline QV4::ReturnedValue __qmljs_ne(const QV4::ValueRef left, const QV4::ValueRef right)
 {
     TRACE2(left, right);
 
-    return QV4::Primitive::fromBoolean(!__qmljs_cmp_eq(left, right)).asReturnedValue();
+    bool r = !__qmljs_cmp_eq(left, right);
+    return Encode(r);
 }
 
 inline QV4::ReturnedValue __qmljs_se(const QV4::ValueRef left, const QV4::ValueRef right)
@@ -527,7 +530,7 @@ inline QV4::ReturnedValue __qmljs_se(const QV4::ValueRef left, const QV4::ValueR
     TRACE2(left, right);
 
     bool r = __qmljs_strict_equal(left, right);
-    return QV4::Primitive::fromBoolean(r).asReturnedValue();
+    return Encode(r);
 }
 
 inline QV4::ReturnedValue __qmljs_sne(const QV4::ValueRef left, const QV4::ValueRef right)
@@ -535,7 +538,7 @@ inline QV4::ReturnedValue __qmljs_sne(const QV4::ValueRef left, const QV4::Value
     TRACE2(left, right);
 
     bool r = ! __qmljs_strict_equal(left, right);
-    return QV4::Primitive::fromBoolean(r).asReturnedValue();
+    return Encode(r);
 }
 
 inline QV4::Bool __qmljs_cmp_eq(const QV4::ValueRef left, const QV4::ValueRef right)
index 0f6c738..b32aed1 100644 (file)
@@ -72,12 +72,12 @@ struct Scope {
     ~Scope() {
 #ifndef QT_NO_DEBUG
         Q_ASSERT(engine->jsStackTop >= mark);
-        memset(mark, 0, (engine->jsStackTop - mark)*sizeof(Value));
+        memset(mark, 0, (engine->jsStackTop - mark)*sizeof(SafeValue));
 #endif
         engine->jsStackTop = mark;
     }
 
-    Value *alloc(int nValues) {
+    SafeValue *alloc(int nValues) {
         SafeValue *ptr = engine->jsStackTop;
         engine->jsStackTop += nValues;
 #ifndef QT_NO_DEBUG
@@ -364,7 +364,7 @@ struct CallData
 struct ScopedCallData {
     ScopedCallData(Scope &scope, int argc)
     {
-        int size = qMax(argc, (int)QV4::Global::ReservedArgumentCount) + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value);
+        int size = qMax(argc, (int)QV4::Global::ReservedArgumentCount) + qOffsetOf(QV4::CallData, args)/sizeof(QV4::SafeValue);
         ptr = reinterpret_cast<CallData *>(scope.engine->stackPush(size));
         ptr->tag = QV4::Value::Integer_Type;
         ptr->argc = argc;
index 432e3b4..d2963df 100644 (file)
@@ -201,7 +201,7 @@ void Script::parse()
             isel->setUseFastLookups(false);
         QV4::CompiledData::CompilationUnit *compilationUnit = isel->compile();
         vmFunction = compilationUnit->linkToEngine(v4);
-        ScopedValue holder(valueScope, Value::fromObject(new (v4->memoryManager) CompilationUnitHolder(v4, compilationUnit)));
+        ScopedValue holder(valueScope, new (v4->memoryManager) CompilationUnitHolder(v4, compilationUnit));
         compilationUnitHolder = holder;
     }
 
index f864d4d..5c3204d 100644 (file)
@@ -79,33 +79,29 @@ static void generateWarning(QV4::ExecutionContext *ctx, const QString& descripti
     F(QString, QString, QStringList, QString()) \
     F(QUrl, Url, QList<QUrl>, QUrl())
 
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *engine, const QString &element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, const QString &element)
 {
-    QV4::Value v;
-    v = engine->newString(element)->asReturnedValue();
-    return v;
+    return engine->newString(element)->asReturnedValue();
 }
 
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *, int element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *, int element)
 {
-    return QV4::Primitive::fromInt32(element);
+    return QV4::Encode(element);
 }
 
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *engine, const QUrl &element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, const QUrl &element)
 {
-    QV4::Value v;
-    v = engine->newString(element.toString())->asReturnedValue();
-    return v;
+    return engine->newString(element.toString())->asReturnedValue();
 }
 
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *, qreal element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *, qreal element)
 {
-    return QV4::Primitive::fromDouble(element);
+    return QV4::Encode(element);
 }
 
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *, bool element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *, bool element)
 {
-    return QV4::Primitive::fromBoolean(element);
+    return QV4::Encode(element);
 }
 
 static QString convertElementToString(const QString &element)
@@ -199,20 +195,20 @@ public:
         defineAccessorProperty(QStringLiteral("length"), method_get_length, method_set_length);
     }
 
-    QV4::Value containerGetIndexed(uint index, bool *hasProperty)
+    QV4::ReturnedValue containerGetIndexed(uint index, bool *hasProperty)
     {
         /* Qt containers have int (rather than uint) allowable indexes. */
         if (index > INT_MAX) {
             generateWarning(engine()->current, QLatin1String("Index out of range during indexed get"));
             if (hasProperty)
                 *hasProperty = false;
-            return QV4::Primitive::undefinedValue();
+            return Encode::undefined();
         }
         if (m_isReference) {
             if (!m_object) {
                 if (hasProperty)
                     *hasProperty = false;
-                return QV4::Primitive::undefinedValue();
+                return Encode::undefined();
             }
             loadReference();
         }
@@ -224,7 +220,7 @@ public:
         }
         if (hasProperty)
             *hasProperty = false;
-        return QV4::Primitive::undefinedValue();
+        return Encode::undefined();
     }
 
     void containerPutIndexed(uint index, const QV4::ValueRef value)
@@ -495,7 +491,7 @@ private:
     bool m_isReference;
 
     static QV4::ReturnedValue getIndexed(QV4::Managed *that, uint index, bool *hasProperty)
-    { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(index, hasProperty).asReturnedValue(); }
+    { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(index, hasProperty); }
     static void putIndexed(Managed *that, uint index, const QV4::ValueRef value)
     { static_cast<QQmlSequence<Container> *>(that)->containerPutIndexed(index, value); }
     static QV4::PropertyAttributes queryIndexed(const QV4::Managed *that, uint index)