aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-09 13:38:10 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-11 13:02:23 +0200
commit262d7261033df7650938c38401112a4767d926ff (patch)
tree8a9ecd61f546d40afa796e5ec3e786301fba1258 /src/qml
parent6324e987e23b4fefc622f1fc6493baa1a3e47ee9 (diff)
Continue conversion to using scoped values
This converts all methods in qv4runtime_p.h to not use raw values in arguments anymore. The conversion of return values will be done in a separate commit. Change-Id: Ie6e8f3bed459d09cb831f7f87920b7eada161502 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/compiler/qv4isel_masm.cpp4
-rw-r--r--src/qml/compiler/qv4ssa.cpp18
-rw-r--r--src/qml/jsapi/qjsvalue.cpp4
-rw-r--r--src/qml/jsruntime/qv4arrayobject.cpp14
-rw-r--r--src/qml/jsruntime/qv4context.cpp4
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp20
-rw-r--r--src/qml/jsruntime/qv4errorobject.cpp10
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp11
-rw-r--r--src/qml/jsruntime/qv4lookup.cpp2
-rw-r--r--src/qml/jsruntime/qv4numberobject.cpp6
-rw-r--r--src/qml/jsruntime/qv4object.cpp59
-rw-r--r--src/qml/jsruntime/qv4object_p.h8
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp6
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp9
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp24
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp354
-rw-r--r--src/qml/jsruntime/qv4runtime_p.h403
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h4
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp17
-rw-r--r--src/qml/jsruntime/qv4value.cpp85
-rw-r--r--src/qml/jsruntime/qv4value_p.h46
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp46
22 files changed, 601 insertions, 553 deletions
diff --git a/src/qml/compiler/qv4isel_masm.cpp b/src/qml/compiler/qv4isel_masm.cpp
index d357e00c3d..f18ba19db5 100644
--- a/src/qml/compiler/qv4isel_masm.cpp
+++ b/src/qml/compiler/qv4isel_masm.cpp
@@ -841,7 +841,9 @@ static void *tryWrapper(ExecutionContext *context, void *localsPtr, MiddleOfFunc
ex.accept(context);
*exceptionVar = ex.value();
try {
- ExecutionContext *catchContext = __qmljs_builtin_push_catch_scope(exceptionVarName, ex.value(), context);
+ QV4::ValueScope scope(context);
+ QV4::ScopedValue exception(scope, ex.value());
+ ExecutionContext *catchContext = __qmljs_builtin_push_catch_scope(exceptionVarName, exception, context);
addressToContinueAt = catchBody(catchContext, localsPtr);
context = __qmljs_builtin_pop_scope(catchContext);
} catch (Exception& ex) {
diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp
index 107ea3058d..528450b73e 100644
--- a/src/qml/compiler/qv4ssa.cpp
+++ b/src/qml/compiler/qv4ssa.cpp
@@ -2118,22 +2118,22 @@ bool tryOptimizingComparison(Expr *&expr)
switch (b->op) {
case OpGt:
- leftConst->value = __qmljs_cmp_gt(l, r);
+ leftConst->value = __qmljs_cmp_gt(&l, &r);
leftConst->type = BoolType;
expr = leftConst;
return true;
case OpLt:
- leftConst->value = __qmljs_cmp_lt(l, r);
+ leftConst->value = __qmljs_cmp_lt(&l, &r);
leftConst->type = BoolType;
expr = leftConst;
return true;
case OpGe:
- leftConst->value = __qmljs_cmp_ge(l, r);
+ leftConst->value = __qmljs_cmp_ge(&l, &r);
leftConst->type = BoolType;
expr = leftConst;
return true;
case OpLe:
- leftConst->value = __qmljs_cmp_le(l, r);
+ leftConst->value = __qmljs_cmp_le(&l, &r);
leftConst->type = BoolType;
expr = leftConst;
return true;
@@ -2142,7 +2142,7 @@ bool tryOptimizingComparison(Expr *&expr)
return false;
// intentional fall-through
case OpEqual:
- leftConst->value = __qmljs_cmp_eq(l, r);
+ leftConst->value = __qmljs_cmp_eq(&l, &r);
leftConst->type = BoolType;
expr = leftConst;
return true;
@@ -2151,7 +2151,7 @@ bool tryOptimizingComparison(Expr *&expr)
return false;
// intentional fall-through
case OpNotEqual:
- leftConst->value = __qmljs_cmp_ne(l, r);
+ leftConst->value = __qmljs_cmp_ne(&l, &r);
leftConst->type = BoolType;
expr = leftConst;
return true;
@@ -2318,8 +2318,10 @@ void optimizeSSA(Function *function, DefUsesCalculator &defUses)
if (!rightConst || rightConst->type == StringType || rightConst->type == ObjectType)
continue;
- double l = __qmljs_to_number(convertToValue(leftConst));
- double r = __qmljs_to_number(convertToValue(rightConst));
+ QV4::Value lc = convertToValue(leftConst);
+ QV4::Value rc = convertToValue(rightConst);
+ double l = __qmljs_to_number(&lc);
+ double r = __qmljs_to_number(&rc);
switch (b->op) {
case OpMul:
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp
index 2640ea5d1c..f18814cedf 100644
--- a/src/qml/jsapi/qjsvalue.cpp
+++ b/src/qml/jsapi/qjsvalue.cpp
@@ -743,7 +743,7 @@ QJSValue& QJSValue::operator=(const QJSValue& other)
*/
bool QJSValue::equals(const QJSValue& other) const
{
- return __qmljs_cmp_eq(d->value, other.d->value);
+ return __qmljs_cmp_eq(QV4::ValueRef(d), QV4::ValueRef(other.d));
}
/*!
@@ -770,7 +770,7 @@ bool QJSValue::equals(const QJSValue& other) const
*/
bool QJSValue::strictlyEquals(const QJSValue& other) const
{
- return __qmljs_strict_equal(d->value, other.d->value);
+ return __qmljs_strict_equal(QV4::ValueRef(d), QV4::ValueRef(other.d));
}
/*!
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp
index 3ab74d8080..e3b08f5941 100644
--- a/src/qml/jsruntime/qv4arrayobject.cpp
+++ b/src/qml/jsruntime/qv4arrayobject.cpp
@@ -546,12 +546,14 @@ Value ArrayPrototype::method_unshift(SimpleCallContext *ctx)
Value ArrayPrototype::method_indexOf(SimpleCallContext *ctx)
{
+ ValueScope scope(ctx);
+
Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
if (!len)
return Value::fromInt32(-1);
- Value searchValue;
+ ScopedValue searchValue(scope);
uint fromIndex = 0;
if (ctx->argumentCount >= 1)
@@ -569,9 +571,10 @@ Value ArrayPrototype::method_indexOf(SimpleCallContext *ctx)
}
if (instance->isStringObject()) {
+ ScopedValue v(scope);
for (uint k = fromIndex; k < len; ++k) {
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (exists && __qmljs_strict_equal(v, searchValue))
return Value::fromDouble(k);
}
@@ -583,12 +586,14 @@ Value ArrayPrototype::method_indexOf(SimpleCallContext *ctx)
Value ArrayPrototype::method_lastIndexOf(SimpleCallContext *ctx)
{
+ ValueScope scope(ctx);
+
Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
if (!len)
return Value::fromInt32(-1);
- Value searchValue;
+ ScopedValue searchValue(scope);
uint fromIndex = len;
if (ctx->argumentCount >= 1)
@@ -608,10 +613,11 @@ Value ArrayPrototype::method_lastIndexOf(SimpleCallContext *ctx)
fromIndex = (uint) f + 1;
}
+ ScopedValue v(scope);
for (uint k = fromIndex; k > 0;) {
--k;
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (exists && __qmljs_strict_equal(v, searchValue))
return Value::fromDouble(k);
}
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index 563b6b2709..1e42a186a0 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -596,7 +596,9 @@ Value ExecutionContext::getPropertyAndBase(String *name, Object **base)
void ExecutionContext::throwError(const Value &value)
{
- __qmljs_throw(this, value);
+ ValueScope scope(this);
+ ScopedValue v(scope, value);
+ __qmljs_throw(this, v);
}
void ExecutionContext::throwError(const QString &message)
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 5d9abfe74e..1ef4aec246 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -662,16 +662,17 @@ Value DateCtor::construct(Managed *m, CallData *callData)
t = currentTime();
else if (callData->argc == 1) {
- Value arg = callData->args[0];
- if (DateObject *d = arg.asDateObject())
+ ValueScope scope(m->engine());
+ ScopedValue arg(scope, callData->args[0]);
+ if (DateObject *d = arg->asDateObject())
arg = d->value;
else
arg = __qmljs_to_primitive(arg, PREFERREDTYPE_HINT);
- if (arg.isString())
- t = ParseString(arg.stringValue()->toQString());
+ if (arg->isString())
+ t = ParseString(arg->stringValue()->toQString());
else
- t = TimeClip(arg.toNumber());
+ t = TimeClip(arg->toNumber());
}
else { // d.argc > 1
@@ -1290,13 +1291,14 @@ Value DatePrototype::method_toISOString(SimpleCallContext *ctx)
Value DatePrototype::method_toJSON(SimpleCallContext *ctx)
{
- Value O = __qmljs_to_object(ctx, ctx->thisObject);
- Value tv = __qmljs_to_primitive(O, NUMBER_HINT);
+ ValueScope scope(ctx);
+ ScopedValue O(scope, __qmljs_to_object(ctx, ValueRef(&ctx->thisObject)));
+ ScopedValue tv(scope, __qmljs_to_primitive(O, NUMBER_HINT));
- if (tv.isNumber() && !std::isfinite(tv.toNumber()))
+ if (tv->isNumber() && !std::isfinite(tv->toNumber()))
return Value::nullValue();
- FunctionObject *toIso = O.objectValue()->get(ctx->engine->newString(QStringLiteral("toISOString"))).asFunctionObject();
+ FunctionObject *toIso = O->objectValue()->get(ctx->engine->newString(QStringLiteral("toISOString"))).asFunctionObject();
if (!toIso)
ctx->throwTypeError();
diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp
index 6e6aeca299..6174c9a7f5 100644
--- a/src/qml/jsruntime/qv4errorobject.cpp
+++ b/src/qml/jsruntime/qv4errorobject.cpp
@@ -327,20 +327,22 @@ void ErrorPrototype::init(ExecutionEngine *engine, const Value &ctor, Object *ob
Value ErrorPrototype::method_toString(SimpleCallContext *ctx)
{
+ ValueScope scope(ctx);
+
Object *o = ctx->thisObject.asObject();
if (!o)
ctx->throwTypeError();
- Value name = o->get(ctx->engine->newString(QString::fromLatin1("name")));
+ ScopedValue name(scope, o->get(ctx->engine->newString(QString::fromLatin1("name"))));
QString qname;
- if (name.isUndefined())
+ if (name->isUndefined())
qname = QString::fromLatin1("Error");
else
qname = __qmljs_to_string(name, ctx).stringValue()->toQString();
- Value message = o->get(ctx->engine->newString(QString::fromLatin1("message")));
+ ScopedValue message(scope, o->get(ctx->engine->newString(QString::fromLatin1("message"))));
QString qmessage;
- if (!message.isUndefined())
+ if (!message->isUndefined())
qmessage = __qmljs_to_string(message, ctx).stringValue()->toQString();
QString str;
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index 82c7e8caed..ef1f500580 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -886,6 +886,8 @@ Value JsonObject::method_parse(SimpleCallContext *ctx)
Value JsonObject::method_stringify(SimpleCallContext *ctx)
{
+ ValueScope scope(ctx);
+
Stringify stringify(ctx);
Object *o = ctx->argument(1).asObject();
@@ -893,12 +895,13 @@ Value JsonObject::method_stringify(SimpleCallContext *ctx)
stringify.replacerFunction = o->asFunctionObject();
if (o->isArrayObject()) {
uint arrayLen = o->arrayLength();
+ ScopedValue v(scope);
for (uint i = 0; i < arrayLen; ++i) {
- Value v = o->getIndexed(i);
- if (v.asNumberObject() || v.asStringObject() || v.isNumber())
+ v = o->getIndexed(i);
+ if (v->asNumberObject() || v->asStringObject() || v->isNumber())
v = __qmljs_to_string(v, ctx);
- if (v.isString()) {
- String *s = v.stringValue();
+ if (v->isString()) {
+ String *s = v->stringValue();
if (!stringify.propertyList.contains(s))
stringify.propertyList.append(s);
}
diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp
index 5484f9772d..2cffa55642 100644
--- a/src/qml/jsruntime/qv4lookup.cpp
+++ b/src/qml/jsruntime/qv4lookup.cpp
@@ -492,7 +492,7 @@ void Lookup::setterGeneric(Lookup *l, const Value &object, const Value &value)
{
Object *o = object.asObject();
if (!o) {
- o = __qmljs_convert_to_object(l->name->engine()->current, object);
+ o = __qmljs_convert_to_object(l->name->engine()->current, ValueRef::fromRawValue(&object));
o->put(l->name, value);
return;
}
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp
index dbdf109a4a..ffcbca2ce5 100644
--- a/src/qml/jsruntime/qv4numberobject.cpp
+++ b/src/qml/jsruntime/qv4numberobject.cpp
@@ -225,7 +225,9 @@ Value NumberPrototype::method_toExponential(SimpleCallContext *ctx)
Value NumberPrototype::method_toPrecision(SimpleCallContext *ctx)
{
- Value v = thisNumberValue(ctx);
+ ValueScope scope(ctx);
+
+ ScopedValue v(scope, thisNumberValue(ctx));
Value prec = ctx->argument(0);
if (prec.isUndefined())
@@ -239,7 +241,7 @@ Value NumberPrototype::method_toPrecision(SimpleCallContext *ctx)
char str[100];
double_conversion::StringBuilder builder(str, sizeof(str));
- double_conversion::DoubleToStringConverter::EcmaScriptConverter().ToPrecision(v.asDouble(), precision, &builder);
+ double_conversion::DoubleToStringConverter::EcmaScriptConverter().ToPrecision(v->asDouble(), precision, &builder);
QString result = QString::fromLatin1(builder.Finalize());
return Value::fromString(ctx, result);
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index fbee25e68b..14584da46d 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -165,50 +165,54 @@ void Object::putValue(Property *pd, PropertyAttributes attrs, const Value &value
}
-void Object::inplaceBinOp(ExecutionContext *, BinOp op, String *name, const Value &rhs)
+void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, String *name, const ValueRef rhs)
{
- Value v = get(name);
- Value result;
- op(&result, v, rhs);
+ ValueScope scope(ctx);
+ ScopedValue v(scope, get(name));
+ ScopedValue result(scope);
+ op(result, v, rhs);
put(name, result);
}
-void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, const Value &index, const Value &rhs)
+void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, const ValueRef index, const ValueRef rhs)
{
- uint idx = index.asArrayIndex();
+ ValueScope scope(ctx);
+ uint idx = index->asArrayIndex();
if (idx < UINT_MAX) {
bool hasProperty = false;
- Value v = getIndexed(idx, &hasProperty);
- Value result;
- op(&result, v, rhs);
+ ScopedValue v(scope, getIndexed(idx, &hasProperty));
+ ScopedValue result(scope);
+ op(result, v, rhs);
putIndexed(idx, result);
return;
}
- String *name = index.toString(ctx);
+ String *name = index->toString(ctx);
assert(name);
inplaceBinOp(ctx, op, name, rhs);
}
-void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, String *name, const Value &rhs)
+void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, String *name, const ValueRef rhs)
{
- Value v = get(name);
- Value result;
- op(ctx, &result, v, rhs);
+ ValueScope scope(ctx);
+ ScopedValue v(scope, get(name));
+ ScopedValue result(scope);
+ op(ctx, result, v, rhs);
put(name, result);
}
-void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const Value &index, const Value &rhs)
+void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs)
{
- uint idx = index.asArrayIndex();
+ ValueScope scope(ctx);
+ uint idx = index->asArrayIndex();
if (idx < UINT_MAX) {
bool hasProperty = false;
- Value v = getIndexed(idx, &hasProperty);
- Value result;
- op(ctx, &result, v, rhs);
+ ScopedValue v(scope, getIndexed(idx, &hasProperty));
+ ScopedValue result(scope);
+ op(ctx, result, v, rhs);
putIndexed(idx, result);
return;
}
- String *name = index.toString(ctx);
+ String *name = index->toString(ctx);
assert(name);
inplaceBinOp(ctx, op, name, rhs);
}
@@ -1133,18 +1137,21 @@ void Object::copyArrayData(Object *other)
Value Object::arrayIndexOf(Value v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
{
+ ValueScope scope(engine());
+ ScopedValue value(scope);
+
if (o->protoHasArray() || o->arrayAttributes) {
// lets be safe and slow
for (uint i = fromIndex; i < endIndex; ++i) {
bool exists;
- Value value = o->getIndexed(i, &exists);
- if (exists && __qmljs_strict_equal(value, v))
+ value = o->getIndexed(i, &exists);
+ if (exists && __qmljs_strict_equal(value, ValueRef(&v)))
return Value::fromDouble(i);
}
} else if (sparseArray) {
for (SparseArrayNode *n = sparseArray->lowerBound(fromIndex); n != sparseArray->end() && n->key() < endIndex; n = n->nextNode()) {
- Value value = o->getValue(arrayData + n->value, arrayAttributes ? arrayAttributes[n->value] : Attr_Data);
- if (__qmljs_strict_equal(value, v))
+ value = o->getValue(arrayData + n->value, arrayAttributes ? arrayAttributes[n->value] : Attr_Data);
+ if (__qmljs_strict_equal(value, ValueRef(&v)))
return Value::fromDouble(n->key());
}
} else {
@@ -1155,8 +1162,8 @@ Value Object::arrayIndexOf(Value v, uint fromIndex, uint endIndex, ExecutionCont
pd += fromIndex;
while (pd < end) {
if (!arrayAttributes || !arrayAttributes[pd - arrayData].isGeneric()) {
- Value value = o->getValue(pd, arrayAttributes ? arrayAttributes[pd - arrayData] : Attr_Data);
- if (__qmljs_strict_equal(value, v))
+ value = o->getValue(pd, arrayAttributes ? arrayAttributes[pd - arrayData] : Attr_Data);
+ if (__qmljs_strict_equal(value, ValueRef(&v)))
return Value::fromDouble(pd - arrayData);
}
++pd;
diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h
index 995749ff74..c6329b9665 100644
--- a/src/qml/jsruntime/qv4object_p.h
+++ b/src/qml/jsruntime/qv4object_p.h
@@ -156,10 +156,10 @@ struct Q_QML_EXPORT Object: Managed {
void putValue(Property *pd, PropertyAttributes attrs, const Value &value);
- void inplaceBinOp(ExecutionContext *, BinOp op, String *name, const Value &rhs);
- void inplaceBinOp(ExecutionContext *ctx, BinOp op, const Value &index, const Value &rhs);
- void inplaceBinOp(ExecutionContext *ctx, BinOpContext op, String *name, const Value &rhs);
- void inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const Value &index, const Value &rhs);
+ void inplaceBinOp(ExecutionContext *, BinOp op, String *name, const ValueRef rhs);
+ void inplaceBinOp(ExecutionContext *ctx, BinOp op, const ValueRef index, const ValueRef rhs);
+ void inplaceBinOp(ExecutionContext *ctx, BinOpContext op, String *name, const ValueRef rhs);
+ void inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs);
/* The spec default: Writable: true, Enumerable: false, Configurable: true */
void defineDefaultProperty(String *name, Value value);
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 99ac4dd0df..2f8f6375f0 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -90,14 +90,14 @@ Value ObjectCtor::construct(Managed *that, CallData *callData)
obj->setPrototype(proto.objectValue());
return Value::fromObject(obj);
}
- return __qmljs_to_object(v4->current, callData->args[0]);
+ return __qmljs_to_object(v4->current, ValueRef(&callData->args[0]));
}
Value ObjectCtor::call(Managed *m, CallData *callData)
{
if (!callData->argc || callData->args[0].isUndefined() || callData->args[0].isNull())
return Value::fromObject(m->engine()->newObject());
- return __qmljs_to_object(m->engine()->current, callData->args[0]);
+ return __qmljs_to_object(m->engine()->current, ValueRef(&callData->args[0]));
}
void ObjectPrototype::init(ExecutionContext *ctx, const Value &ctor)
@@ -373,7 +373,7 @@ Value ObjectPrototype::method_toString(SimpleCallContext *ctx)
} else if (ctx->thisObject.isNull()) {
return Value::fromString(ctx, QStringLiteral("[object Null]"));
} else {
- Value obj = __qmljs_to_object(ctx, ctx->thisObject);
+ Value obj = __qmljs_to_object(ctx, ValueRef(&ctx->thisObject));
QString className = obj.objectValue()->className();
return Value::fromString(ctx, QString::fromUtf8("[object %1]").arg(className));
}
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index fbe5b4484d..1e868ef3fe 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -740,14 +740,15 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase
return;
}
- QV4::Value function = *reinterpret_cast<QV4::Value*>(metaArgs[1]);
- QV4::Value thisObject = *reinterpret_cast<QV4::Value*>(metaArgs[2]);
+ QV4::ValueScope scope(v4);
+ QV4::ScopedValue function(scope, *reinterpret_cast<QV4::Value*>(metaArgs[1]));
+ QV4::ScopedValue thisObject(scope, *reinterpret_cast<QV4::Value*>(metaArgs[2]));
QObject *receiverToDisconnect = reinterpret_cast<QObject*>(metaArgs[3]);
int slotIndexToDisconnect = *reinterpret_cast<int*>(metaArgs[4]);
if (slotIndexToDisconnect != -1) {
// This is a QObject function wrapper
- if (connection->thisObject.isEmpty() == thisObject.isEmpty() &&
+ if (connection->thisObject.isEmpty() == thisObject->isEmpty() &&
(connection->thisObject.isEmpty() || __qmljs_strict_equal(connection->thisObject, thisObject))) {
QPair<QObject *, int> connectedFunctionData = extractQtMethod(connection->function.value().asFunctionObject());
@@ -760,7 +761,7 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase
} else {
// This is a normal JS function
if (__qmljs_strict_equal(connection->function, function) &&
- connection->thisObject.isEmpty() == thisObject.isEmpty() &&
+ connection->thisObject.isEmpty() == thisObject->isEmpty() &&
(connection->thisObject.isEmpty() || __qmljs_strict_equal(connection->thisObject, thisObject))) {
*ret = true;
return;
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index 420e29096b..448d10180c 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -231,11 +231,13 @@ RegExpCtor::RegExpCtor(ExecutionContext *scope)
Value RegExpCtor::construct(Managed *m, CallData *callData)
{
- Value r = callData->argc > 0 ? callData->args[0] : Value::undefinedValue();
- Value f = callData->argc > 1 ? callData->args[1] : Value::undefinedValue();
ExecutionContext *ctx = m->engine()->current;
- if (RegExpObject *re = r.as<RegExpObject>()) {
- if (!f.isUndefined())
+ ValueScope scope(ctx);
+
+ ScopedValue r(scope, callData->argc > 0 ? callData->args[0] : Value::undefinedValue());
+ ScopedValue f(scope, callData->argc > 1 ? callData->args[1] : Value::undefinedValue());
+ if (RegExpObject *re = r->as<RegExpObject>()) {
+ if (!f->isUndefined())
ctx->throwTypeError();
RegExpObject *o = ctx->engine->newRegExpObject(re->value, re->global);
@@ -243,15 +245,15 @@ Value RegExpCtor::construct(Managed *m, CallData *callData)
}
QString pattern;
- if (!r.isUndefined())
- pattern = r.toString(ctx)->toQString();
+ if (!r->isUndefined())
+ pattern = r->toString(ctx)->toQString();
bool global = false;
bool ignoreCase = false;
bool multiLine = false;
- if (!f.isUndefined()) {
+ if (!f->isUndefined()) {
f = __qmljs_to_string(f, ctx);
- QString str = f.stringValue()->toQString();
+ QString str = f->stringValue()->toQString();
for (int i = 0; i < str.length(); ++i) {
if (str.at(i) == QChar('g') && !global) {
global = true;
@@ -296,13 +298,15 @@ void RegExpPrototype::init(ExecutionContext *ctx, const Value &ctor)
Value RegExpPrototype::method_exec(SimpleCallContext *ctx)
{
+ ValueScope scope(ctx);
+
RegExpObject *r = ctx->thisObject.as<RegExpObject>();
if (!r)
ctx->throwTypeError();
- Value arg = ctx->argument(0);
+ ScopedValue arg(scope, ctx->argument(0));
arg = __qmljs_to_string(arg, ctx);
- QString s = arg.stringValue()->toQString();
+ QString s = arg->stringValue()->toQString();
int offset = r->global ? r->lastIndexProperty(ctx)->value.toInt32() : 0;
if (offset < 0 || offset > s.length()) {
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 2a3f96429c..733f353330 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -127,10 +127,10 @@ void __qmljs_init_closure(ExecutionContext *ctx, ValueRef result, int functionId
*result = Value::fromObject(FunctionObject::creatScriptFunction(ctx, clos));
}
-void __qmljs_delete_subscript(ExecutionContext *ctx, ValueRef result, const Value &base, const Value &index)
+void __qmljs_delete_subscript(ExecutionContext *ctx, ValueRef result, const ValueRef base, const ValueRef index)
{
- if (Object *o = base.asObject()) {
- uint n = index.asArrayIndex();
+ if (Object *o = base->asObject()) {
+ uint n = index->asArrayIndex();
if (n < UINT_MAX) {
Value res = Value::fromBoolean(o->deleteIndexedProperty(n));
if (result)
@@ -139,13 +139,13 @@ void __qmljs_delete_subscript(ExecutionContext *ctx, ValueRef result, const Valu
}
}
- String *name = index.toString(ctx);
+ String *name = index->toString(ctx);
__qmljs_delete_member(ctx, result, base, name);
}
-void __qmljs_delete_member(ExecutionContext *ctx, ValueRef result, const Value &base, String *name)
+void __qmljs_delete_member(ExecutionContext *ctx, ValueRef result, const ValueRef base, String *name)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
Value res = Value::fromBoolean(obj->deleteProperty(name));
if (result)
*result = res;
@@ -162,8 +162,8 @@ void __qmljs_add_helper(ExecutionContext *ctx, ValueRef result, const ValueRef l
{
ValueScope scope(ctx);
- ScopedValue pleft(scope, __qmljs_to_primitive(*left, PREFERREDTYPE_HINT));
- ScopedValue pright(scope, __qmljs_to_primitive(*right, PREFERREDTYPE_HINT));
+ ScopedValue pleft(scope, __qmljs_to_primitive(left, PREFERREDTYPE_HINT));
+ ScopedValue pright(scope, __qmljs_to_primitive(right, PREFERREDTYPE_HINT));
if (pleft->isString() || pright->isString()) {
if (!pleft->isString())
pleft = __qmljs_to_string(pleft, ctx);
@@ -178,221 +178,223 @@ void __qmljs_add_helper(ExecutionContext *ctx, ValueRef result, const ValueRef l
*result = Value::fromDouble(x + y);
}
-void __qmljs_instanceof(ExecutionContext *ctx, ValueRef result, const Value &left, const Value &right)
+void __qmljs_instanceof(ExecutionContext *ctx, ValueRef result, const ValueRef left, const ValueRef right)
{
- Object *o = right.asObject();
+ Object *o = right->asObject();
if (!o)
ctx->throwTypeError();
- bool r = o->hasInstance(left);
+ bool r = o->hasInstance(*left);
*result = Value::fromBoolean(r);
}
-void __qmljs_in(ExecutionContext *ctx, ValueRef result, const Value &left, const Value &right)
+void __qmljs_in(ExecutionContext *ctx, ValueRef result, const ValueRef left, const ValueRef right)
{
- if (!right.isObject())
+ if (!right->isObject())
ctx->throwTypeError();
- String *s = left.toString(ctx);
- bool r = right.objectValue()->__hasProperty__(s);
+ String *s = left->toString(ctx);
+ bool r = right->objectValue()->__hasProperty__(s);
*result = Value::fromBoolean(r);
}
-void inplaceBitOp(ExecutionContext *ctx, String *name, const Value &value, BinOp op)
+static void inplaceBitOp(ExecutionContext *ctx, String *name, const ValueRef value, BinOp op)
{
- Value lhs = ctx->getProperty(name);
- Value result;
- op(&result, lhs, value);
+ ValueScope scope(ctx);
+ ScopedValue lhs(scope, ctx->getProperty(name));
+ ScopedValue result(scope);
+ op(result, lhs, value);
ctx->setProperty(name, result);
}
-void __qmljs_inplace_bit_and_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_bit_and_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_bit_and);
}
-void __qmljs_inplace_bit_or_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_bit_or_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_bit_or);
}
-void __qmljs_inplace_bit_xor_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_bit_xor_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_bit_xor);
}
-void __qmljs_inplace_add_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_add_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
- Value lhs = ctx->getProperty(name);
- Value result;
- __qmljs_add(ctx, &result, lhs, value);
+ ValueScope scope(ctx);
+ ScopedValue lhs(scope, ctx->getProperty(name));
+ ScopedValue result(scope);
+ __qmljs_add(ctx, result, lhs, value);
ctx->setProperty(name, result);
}
-void __qmljs_inplace_sub_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_sub_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_sub);
}
-void __qmljs_inplace_mul_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_mul_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_mul);
}
-void __qmljs_inplace_div_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_div_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_div);
}
-void __qmljs_inplace_mod_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_mod_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_mod);
}
-void __qmljs_inplace_shl_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_shl_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_shl);
}
-void __qmljs_inplace_shr_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_shr_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_shr);
}
-void __qmljs_inplace_ushr_name(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_inplace_ushr_name(ExecutionContext *ctx, String *name, const ValueRef value)
{
inplaceBitOp(ctx, name, value, __qmljs_ushr);
}
-void __qmljs_inplace_bit_and_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_bit_and_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_bit_and, index, rhs);
}
-void __qmljs_inplace_bit_or_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_bit_or_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_bit_or, index, rhs);
}
-void __qmljs_inplace_bit_xor_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_bit_xor_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_bit_xor, index, rhs);
}
-void __qmljs_inplace_add_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_add_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_add, index, rhs);
}
-void __qmljs_inplace_sub_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_sub_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_sub, index, rhs);
}
-void __qmljs_inplace_mul_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_mul_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_mul, index, rhs);
}
-void __qmljs_inplace_div_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_div_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_div, index, rhs);
}
-void __qmljs_inplace_mod_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_mod_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_mod, index, rhs);
}
-void __qmljs_inplace_shl_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_shl_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_shl, index, rhs);
}
-void __qmljs_inplace_shr_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_shr_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_shr, index, rhs);
}
-void __qmljs_inplace_ushr_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
+void __qmljs_inplace_ushr_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs)
{
- Object *obj = base.toObject(ctx);
+ Object *obj = base->toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_ushr, index, rhs);
}
-void __qmljs_inplace_bit_and_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_bit_and_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_bit_and, name, rhs);
}
-void __qmljs_inplace_bit_or_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_bit_or_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_bit_or, name, rhs);
}
-void __qmljs_inplace_bit_xor_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_bit_xor_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_bit_xor, name, rhs);
}
-void __qmljs_inplace_add_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_add_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_add, name, rhs);
}
-void __qmljs_inplace_sub_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_sub_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_sub, name, rhs);
}
-void __qmljs_inplace_mul_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_mul_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_mul, name, rhs);
}
-void __qmljs_inplace_div_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_div_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_div, name, rhs);
}
-void __qmljs_inplace_mod_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_mod_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_mod, name, rhs);
}
-void __qmljs_inplace_shl_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_shl_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_shl, name, rhs);
}
-void __qmljs_inplace_shr_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_shr_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_shr, name, rhs);
}
-void __qmljs_inplace_ushr_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
+void __qmljs_inplace_ushr_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs)
{
- Object *o = base.toObject(ctx);
+ Object *o = base->toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_ushr, name, rhs);
}
@@ -478,74 +480,74 @@ Value __qmljs_object_default_value(Object *object, int typeHint)
return Value::undefinedValue();
}
-Bool __qmljs_to_boolean(const Value &value)
+Bool __qmljs_to_boolean(const ValueRef value)
{
- return value.toBoolean();
+ return value->toBoolean();
}
-Object *__qmljs_convert_to_object(ExecutionContext *ctx, const Value &value)
+Object *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRef value)
{
- assert(!value.isObject());
- switch (value.type()) {
+ assert(!value->isObject());
+ switch (value->type()) {
case Value::Undefined_Type:
case Value::Null_Type:
ctx->throwTypeError();
case Value::Boolean_Type:
- return ctx->engine->newBooleanObject(value);
+ return ctx->engine->newBooleanObject(*value);
case Value::String_Type:
- return ctx->engine->newStringObject(value);
+ return ctx->engine->newStringObject(*value);
break;
case Value::Object_Type:
Q_UNREACHABLE();
case Value::Integer_Type:
default: // double
- return ctx->engine->newNumberObject(value);
+ return ctx->engine->newNumberObject(*value);
}
}
-String *__qmljs_convert_to_string(ExecutionContext *ctx, const Value &value)
+String *__qmljs_convert_to_string(ExecutionContext *ctx, const ValueRef value)
{
- switch (value.type()) {
+ switch (value->type()) {
case Value::Undefined_Type:
return ctx->engine->id_undefined;
case Value::Null_Type:
return ctx->engine->id_null;
case Value::Boolean_Type:
- if (value.booleanValue())
+ if (value->booleanValue())
return ctx->engine->id_true;
else
return ctx->engine->id_false;
case Value::String_Type:
- return value.stringValue();
+ return value->stringValue();
case Value::Object_Type: {
Value prim = __qmljs_to_primitive(value, STRING_HINT);
if (prim.isPrimitive())
- return __qmljs_convert_to_string(ctx, prim);
+ return __qmljs_convert_to_string(ctx, ValueRef(&prim));
else
ctx->throwTypeError();
}
case Value::Integer_Type:
- return __qmljs_string_from_number(ctx, value.int_32).stringValue();
+ return __qmljs_string_from_number(ctx, value->int_32).stringValue();
default: // double
- return __qmljs_string_from_number(ctx, value.doubleValue()).stringValue();
+ return __qmljs_string_from_number(ctx, value->doubleValue()).stringValue();
} // switch
}
-void __qmljs_set_property(ExecutionContext *ctx, const Value &object, String *name, const Value &value)
+void __qmljs_set_property(ExecutionContext *ctx, const ValueRef object, String *name, const ValueRef value)
{
- Object *o = object.toObject(ctx);
- o->put(name, value);
+ Object *o = object->toObject(ctx);
+ o->put(name, *value);
}
-void __qmljs_get_element(ExecutionContext *ctx, ValueRef result, const Value &object, const Value &index)
+void __qmljs_get_element(ExecutionContext *ctx, ValueRef result, const ValueRef object, const ValueRef index)
{
- uint idx = index.asArrayIndex();
+ uint idx = index->asArrayIndex();
- Object *o = object.asObject();
+ Object *o = object->asObject();
if (!o) {
if (idx < UINT_MAX) {
- if (String *str = object.asString()) {
+ if (String *str = object->asString()) {
if (idx >= (uint)str->toQString().length()) {
if (result)
*result = Value::undefinedValue();
@@ -558,8 +560,8 @@ void __qmljs_get_element(ExecutionContext *ctx, ValueRef result, const Value &ob
}
}
- if (object.isNull() || object.isUndefined()) {
- QString message = QStringLiteral("Cannot read property '%1' of %2").arg(index.toQString()).arg(object.toQString());
+ if (object->isNullOrUndefined()) {
+ QString message = QStringLiteral("Cannot read property '%1' of %2").arg(index->toQString()).arg(object->toQString());
ctx->throwTypeError(message);
}
@@ -582,17 +584,17 @@ void __qmljs_get_element(ExecutionContext *ctx, ValueRef result, const Value &ob
return;
}
- String *name = index.toString(ctx);
+ String *name = index->toString(ctx);
Value res = o->get(name);
if (result)
*result = res;
}
-void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value &index, const Value &value)
+void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const ValueRef index, const ValueRef value)
{
- Object *o = object.toObject(ctx);
+ Object *o = object->toObject(ctx);
- uint idx = index.asArrayIndex();
+ uint idx = index->asArrayIndex();
if (idx < UINT_MAX) {
uint pidx = o->propertyIndexFromArrayIndex(idx);
if (pidx < UINT_MAX) {
@@ -604,7 +606,7 @@ void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value
Property *p = o->arrayData + pidx;
if (!o->arrayAttributes || o->arrayAttributes[pidx].isData()) {
- p->value = value;
+ p->value = *value;
return;
}
@@ -618,53 +620,53 @@ void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value
ScopedCallData callData(ctx->engine, 1);
callData->thisObject = Value::fromObject(o);
- callData->args[0] = value;
+ callData->args[0] = *value;
setter->call(callData);
return;
}
}
- o->putIndexed(idx, value);
+ o->putIndexed(idx, *value);
return;
}
- String *name = index.toString(ctx);
- o->put(name, value);
+ String *name = index->toString(ctx);
+ o->put(name, *value);
}
-void __qmljs_foreach_iterator_object(ExecutionContext *ctx, ValueRef result, const Value &in)
+void __qmljs_foreach_iterator_object(ExecutionContext *ctx, ValueRef result, const ValueRef in)
{
Object *o = 0;
- if (!in.isNull() && !in.isUndefined())
- o = in.toObject(ctx);
+ if (!in->isNullOrUndefined())
+ o = in->toObject(ctx);
Object *it = ctx->engine->newForEachIteratorObject(ctx, o);
*result = Value::fromObject(it);
}
-void __qmljs_foreach_next_property_name(ValueRef result, const Value &foreach_iterator)
+void __qmljs_foreach_next_property_name(ValueRef result, const ValueRef foreach_iterator)
{
- assert(foreach_iterator.isObject());
+ assert(foreach_iterator->isObject());
- ForEachIteratorObject *it = static_cast<ForEachIteratorObject *>(foreach_iterator.objectValue());
+ ForEachIteratorObject *it = static_cast<ForEachIteratorObject *>(foreach_iterator->objectValue());
assert(it->as<ForEachIteratorObject>());
*result = it->nextPropertyName();
}
-void __qmljs_set_activation_property(ExecutionContext *ctx, String *name, const Value &value)
+void __qmljs_set_activation_property(ExecutionContext *ctx, String *name, const ValueRef value)
{
- ctx->setProperty(name, value);
+ ctx->setProperty(name, *value);
}
-void __qmljs_get_property(ExecutionContext *ctx, ValueRef result, const Value &object, String *name)
+void __qmljs_get_property(ExecutionContext *ctx, ValueRef result, const ValueRef object, String *name)
{
Value res;
- Managed *m = object.asManaged();
+ Managed *m = object->asManaged();
if (m) {
res = m->get(name);
} else {
- if (object.isNull() || object.isUndefined()) {
- QString message = QStringLiteral("Cannot read property '%1' of %2").arg(name->toQString()).arg(object.toQString());
+ if (object->isNullOrUndefined()) {
+ QString message = QStringLiteral("Cannot read property '%1' of %2").arg(name->toQString()).arg(object->toQString());
ctx->throwTypeError(message);
}
@@ -680,51 +682,51 @@ void __qmljs_get_activation_property(ExecutionContext *ctx, ValueRef result, Str
*result = ctx->getProperty(name);
}
-uint __qmljs_equal_helper(const Value &x, const Value &y)
+uint __qmljs_equal_helper(const ValueRef x, const ValueRef y)
{
- Q_ASSERT(x.type() != y.type());
+ Q_ASSERT(x->type() != y->type());
- if (x.isNumber() && y.isNumber())
- return x.asDouble() == y.asDouble();
- if (x.isNull() && y.isUndefined()) {
+ if (x->isNumber() && y->isNumber())
+ return x->asDouble() == y->asDouble();
+ if (x->isNull() && y->isUndefined()) {
return true;
- } else if (x.isUndefined() && y.isNull()) {
+ } else if (x->isUndefined() && y->isNull()) {
return true;
- } else if (x.isNumber() && y.isString()) {
+ } else if (x->isNumber() && y->isString()) {
double dy = __qmljs_to_number(y);
- return x.asDouble() == dy;
- } else if (x.isString() && y.isNumber()) {
+ return x->asDouble() == dy;
+ } else if (x->isString() && y->isNumber()) {
double dx = __qmljs_to_number(x);
- return dx == y.asDouble();
- } else if (x.isBoolean()) {
- Value nx = Value::fromDouble((double) x.booleanValue());
- return __qmljs_cmp_eq(nx, y);
- } else if (y.isBoolean()) {
- Value ny = Value::fromDouble((double) y.booleanValue());
- return __qmljs_cmp_eq(x, ny);
- } else if ((x.isNumber() || x.isString()) && y.isObject()) {
+ return dx == y->asDouble();
+ } else if (x->isBoolean()) {
+ Value nx = Value::fromDouble((double) x->booleanValue());
+ return __qmljs_cmp_eq(ValueRef(&nx), y);
+ } else if (y->isBoolean()) {
+ Value ny = Value::fromDouble((double) y->booleanValue());
+ return __qmljs_cmp_eq(x, ValueRef(&ny));
+ } else if ((x->isNumber() || x->isString()) && y->isObject()) {
Value py = __qmljs_to_primitive(y, PREFERREDTYPE_HINT);
- return __qmljs_cmp_eq(x, py);
- } else if (x.isObject() && (y.isNumber() || y.isString())) {
+ return __qmljs_cmp_eq(x, ValueRef(&py));
+ } else if (x->isObject() && (y->isNumber() || y->isString())) {
Value px = __qmljs_to_primitive(x, PREFERREDTYPE_HINT);
- return __qmljs_cmp_eq(px, y);
+ return __qmljs_cmp_eq(ValueRef(&px), y);
}
return false;
}
-Bool __qmljs_strict_equal(const Value &x, const Value &y)
+Bool __qmljs_strict_equal(const ValueRef x, const ValueRef y)
{
TRACE2(x, y);
- if (x.rawValue() == y.rawValue())
+ if (x->rawValue() == y->rawValue())
// NaN != NaN
- return (x.tag & QV4::Value::NotDouble_Mask) != QV4::Value::NaN_Mask;
+ return (x->tag & QV4::Value::NotDouble_Mask) != QV4::Value::NaN_Mask;
- if (x.isNumber())
- return y.isNumber() && x.asDouble() == y.asDouble();
- if (x.isString())
- return y.isString() && x.stringValue()->isEqualTo(y.stringValue());
+ if (x->isNumber())
+ return y->isNumber() && x->asDouble() == y->asDouble();
+ if (x->isString())
+ return y->isString() && x->stringValue()->isEqualTo(y->stringValue());
return false;
}
@@ -792,7 +794,7 @@ void __qmljs_call_property(ExecutionContext *context, ValueRef result, String *n
context->throwTypeError(message);
}
- baseObject = __qmljs_convert_to_object(context, callData->thisObject);
+ baseObject = __qmljs_convert_to_object(context, ValueRef(&callData->thisObject));
callData->thisObject = Value::fromObject(static_cast<Object *>(baseObject));
}
@@ -905,9 +907,9 @@ void __qmljs_construct_property(ExecutionContext *context, ValueRef result, cons
*result = res;
}
-void __qmljs_throw(ExecutionContext *context, const Value &value)
+void __qmljs_throw(ExecutionContext *context, const ValueRef value)
{
- Exception::throwException(context, value);
+ Exception::throwException(context, *value);
}
void __qmljs_builtin_typeof(ExecutionContext *ctx, ValueRef result, const ValueRef value)
@@ -984,7 +986,7 @@ void __qmljs_builtin_post_increment(ValueRef result, ValueRef val)
return;
}
- double d = __qmljs_to_number(*val);
+ double d = val->toNumber();
*val = Value::fromDouble(d + 1);
if (result)
*result = Value::fromDouble(d);
@@ -999,7 +1001,7 @@ void __qmljs_builtin_post_increment_name(ExecutionContext *context, ValueRef res
*result = v;
v.int_32 += 1;
} else {
- double d = __qmljs_to_number(v);
+ double d = v.toNumber();
if (result)
*result = Value::fromDouble(d);
v = Value::fromDouble(d + 1);
@@ -1019,7 +1021,7 @@ void __qmljs_builtin_post_increment_member(ExecutionContext *context, ValueRef r
*result = v;
v.int_32 += 1;
} else {
- double d = __qmljs_to_number(v);
+ double d = v.toNumber();
if (result)
*result = Value::fromDouble(d);
v = Value::fromDouble(d + 1);
@@ -1046,7 +1048,7 @@ void __qmljs_builtin_post_increment_element(ExecutionContext *context, ValueRef
*result = v;
v.int_32 += 1;
} else {
- double d = __qmljs_to_number(v);
+ double d = v.toNumber();
if (result)
*result = Value::fromDouble(d);
v = Value::fromDouble(d + 1);
@@ -1064,7 +1066,7 @@ void __qmljs_builtin_post_decrement(ValueRef result, ValueRef val)
return;
}
- double d = __qmljs_to_number(*val);
+ double d = val->toNumber();
*val = Value::fromDouble(d - 1);
if (result)
*result = Value::fromDouble(d);
@@ -1079,7 +1081,7 @@ void __qmljs_builtin_post_decrement_name(ExecutionContext *context, ValueRef res
*result = v;
v.int_32 -= 1;
} else {
- double d = __qmljs_to_number(v);
+ double d = v.toNumber();
if (result)
*result = Value::fromDouble(d);
v = Value::fromDouble(d - 1);
@@ -1099,7 +1101,7 @@ void __qmljs_builtin_post_decrement_member(ExecutionContext *context, ValueRef r
*result = v;
v.int_32 -= 1;
} else {
- double d = __qmljs_to_number(v);
+ double d = v.toNumber();
if (result)
*result = Value::fromDouble(d);
v = Value::fromDouble(d - 1);
@@ -1126,7 +1128,7 @@ void __qmljs_builtin_post_decrement_element(ExecutionContext *context, ValueRef
*result = v;
v.int_32 -= 1;
} else {
- double d = __qmljs_to_number(v);
+ double d = v.toNumber();
if (result)
*result = Value::fromDouble(d);
v = Value::fromDouble(d - 1);
@@ -1135,15 +1137,15 @@ void __qmljs_builtin_post_decrement_element(ExecutionContext *context, ValueRef
o->putIndexed(idx, v);
}
-ExecutionContext *__qmljs_builtin_push_with_scope(const Value &o, ExecutionContext *ctx)
+ExecutionContext *__qmljs_builtin_push_with_scope(const ValueRef o, ExecutionContext *ctx)
{
- Object *obj = o.toObject(ctx);
+ Object *obj = o->toObject(ctx);
return ctx->newWithContext(obj);
}
-ExecutionContext *__qmljs_builtin_push_catch_scope(String *exceptionVarName, const Value &exceptionValue, ExecutionContext *ctx)
+ExecutionContext *__qmljs_builtin_push_catch_scope(String *exceptionVarName, const ValueRef exceptionValue, ExecutionContext *ctx)
{
- return ctx->newCatchContext(exceptionVarName, exceptionValue);
+ return ctx->newCatchContext(exceptionVarName, *exceptionValue);
}
ExecutionContext *__qmljs_builtin_pop_scope(ExecutionContext *ctx)
@@ -1156,9 +1158,9 @@ void __qmljs_builtin_declare_var(ExecutionContext *ctx, bool deletable, String *
ctx->createMutableBinding(name, deletable);
}
-void __qmljs_builtin_define_property(ExecutionContext *ctx, const Value &object, String *name, Value *val)
+void __qmljs_builtin_define_property(ExecutionContext *ctx, const ValueRef object, String *name, ValueRef val)
{
- Object *o = object.asObject();
+ Object *o = object->asObject();
assert(o);
uint idx = name->asArrayIndex();
@@ -1191,9 +1193,9 @@ void __qmljs_builtin_define_array(ExecutionContext *ctx, ValueRef array, Value *
*array = Value::fromObject(a);
}
-void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const Value &object, String *name, const Value *getter, const Value *setter)
+void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const ValueRef object, String *name, const ValueRef getter, const ValueRef setter)
{
- Object *o = object.asObject();
+ Object *o = object->asObject();
assert(o);
uint idx = name->asArrayIndex();
@@ -1236,7 +1238,7 @@ void __qmljs_increment(QV4::ValueRef result, const QV4::ValueRef value)
if (value->isInteger())
*result = Value::fromInt32(value->integerValue() + 1);
else {
- double d = __qmljs_to_number(*value);
+ double d = value->toNumber();
*result = Value::fromDouble(d + 1);
}
}
@@ -1248,19 +1250,19 @@ void __qmljs_decrement(QV4::ValueRef result, const QV4::ValueRef value)
if (value->isInteger())
*result = Value::fromInt32(value->integerValue() - 1);
else {
- double d = __qmljs_to_number(*value);
+ double d = value->toNumber();
*result = Value::fromDouble(d - 1);
}
}
-void __qmljs_value_to_double(double *result, const Value &value)
+void __qmljs_value_to_double(double *result, const ValueRef value)
{
- *result = __qmljs_to_number(value);
+ *result = value->toNumber();
}
-int __qmljs_value_to_int32(const Value &value)
+int __qmljs_value_to_int32(const ValueRef value)
{
- return value.toInt32();
+ return value->toInt32();
}
int __qmljs_double_to_int32(const double &d)
@@ -1268,9 +1270,9 @@ int __qmljs_double_to_int32(const double &d)
return Value::toInt32(d);
}
-unsigned __qmljs_value_to_uint32(const Value &value)
+unsigned __qmljs_value_to_uint32(const ValueRef value)
{
- return value.toUInt32();
+ return value->toUInt32();
}
unsigned __qmljs_double_to_uint32(const double &d)
diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h
index ea4643f2a9..d1ca86fddd 100644
--- a/src/qml/jsruntime/qv4runtime_p.h
+++ b/src/qml/jsruntime/qv4runtime_p.h
@@ -117,13 +117,13 @@ void __qmljs_builtin_post_decrement_member(QV4::ExecutionContext *context, QV4::
void __qmljs_builtin_post_decrement_element(QV4::ExecutionContext *context, QV4::ValueRef result, const QV4::ValueRef base, const QV4::ValueRef index);
void Q_NORETURN __qmljs_builtin_rethrow(QV4::ExecutionContext *context);
-QV4::ExecutionContext *__qmljs_builtin_push_with_scope(const QV4::Value &o, QV4::ExecutionContext *ctx);
-QV4::ExecutionContext *__qmljs_builtin_push_catch_scope(QV4::String *exceptionVarName, const QV4::Value &exceptionValue, QV4::ExecutionContext *ctx);
+QV4::ExecutionContext *__qmljs_builtin_push_with_scope(const QV4::ValueRef o, QV4::ExecutionContext *ctx);
+QV4::ExecutionContext *__qmljs_builtin_push_catch_scope(QV4::String *exceptionVarName, const QV4::ValueRef exceptionValue, QV4::ExecutionContext *ctx);
QV4::ExecutionContext *__qmljs_builtin_pop_scope(QV4::ExecutionContext *ctx);
void __qmljs_builtin_declare_var(QV4::ExecutionContext *ctx, bool deletable, QV4::String *name);
-void __qmljs_builtin_define_property(QV4::ExecutionContext *ctx, const QV4::Value &object, QV4::String *name, QV4::Value *val);
+void __qmljs_builtin_define_property(QV4::ExecutionContext *ctx, const QV4::ValueRef object, QV4::String *name, QV4::ValueRef val);
void __qmljs_builtin_define_array(QV4::ExecutionContext *ctx, QV4::ValueRef array, QV4::Value *values, uint length);
-void __qmljs_builtin_define_getter_setter(QV4::ExecutionContext *ctx, const QV4::Value &object, QV4::String *name, const QV4::Value *getter, const QV4::Value *setter);
+void __qmljs_builtin_define_getter_setter(QV4::ExecutionContext *ctx, const QV4::ValueRef object, QV4::String *name, const QV4::ValueRef getter, const QV4::ValueRef setter);
void __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value *args, int classId);
void __qmljs_builtin_setup_arguments_object(ExecutionContext *ctx, QV4::ValueRef result);
@@ -140,34 +140,34 @@ QV4::String *__qmljs_string_concat(QV4::ExecutionContext *ctx, QV4::String *firs
// objects
Q_QML_EXPORT QV4::Value __qmljs_object_default_value(QV4::Object *object, int typeHint);
-void __qmljs_set_activation_property(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value& value);
-void __qmljs_set_property(QV4::ExecutionContext *ctx, const QV4::Value &object, QV4::String *name, const QV4::Value &value);
-void __qmljs_get_property(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &object, QV4::String *name);
+void __qmljs_set_activation_property(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::ValueRef value);
+void __qmljs_set_property(QV4::ExecutionContext *ctx, const QV4::ValueRef object, QV4::String *name, const QV4::ValueRef value);
+void __qmljs_get_property(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef object, QV4::String *name);
void __qmljs_get_activation_property(QV4::ExecutionContext *ctx, QV4::ValueRef result, QV4::String *name);
void __qmljs_call_global_lookup(QV4::ExecutionContext *context, QV4::ValueRef result, uint index, CallDataRef callData);
void __qmljs_construct_global_lookup(QV4::ExecutionContext *context, QV4::ValueRef result, uint index, CallDataRef callData);
-void __qmljs_get_element(QV4::ExecutionContext *ctx, QV4::ValueRef retval, const QV4::Value &object, const QV4::Value &index);
-void __qmljs_set_element(QV4::ExecutionContext *ctx, const QV4::Value &object, const QV4::Value &index, const QV4::Value &value);
+void __qmljs_get_element(QV4::ExecutionContext *ctx, QV4::ValueRef retval, const QV4::ValueRef object, const QV4::ValueRef index);
+void __qmljs_set_element(QV4::ExecutionContext *ctx, const QV4::ValueRef object, const QV4::ValueRef index, const QV4::ValueRef value);
// For each
-void __qmljs_foreach_iterator_object(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &in);
-void __qmljs_foreach_next_property_name(QV4::ValueRef result, const QV4::Value &foreach_iterator);
+void __qmljs_foreach_iterator_object(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef in);
+void __qmljs_foreach_next_property_name(QV4::ValueRef result, const ValueRef foreach_iterator);
// type conversion and testing
-QV4::Value __qmljs_to_primitive(const QV4::Value &value, int typeHint);
-Q_QML_EXPORT QV4::Bool __qmljs_to_boolean(const QV4::Value &value);
-double __qmljs_to_number(const QV4::Value &value);
-QV4::Value __qmljs_to_string(const QV4::Value &value, QV4::ExecutionContext *ctx);
-Q_QML_EXPORT QV4::String *__qmljs_convert_to_string(QV4::ExecutionContext *ctx, const QV4::Value &value);
+QV4::Value __qmljs_to_primitive(const ValueRef value, int typeHint);
+Q_QML_EXPORT QV4::Bool __qmljs_to_boolean(const QV4::ValueRef value);
+double __qmljs_to_number(const QV4::ValueRef value);
+QV4::Value __qmljs_to_string(const ValueRef value, QV4::ExecutionContext *ctx);
+Q_QML_EXPORT QV4::String *__qmljs_convert_to_string(QV4::ExecutionContext *ctx, const ValueRef value);
void __qmljs_numberToString(QString *result, double num, int radix = 10);
-QV4::Value __qmljs_to_object(QV4::ExecutionContext *ctx, const QV4::Value &value);
-QV4::Object *__qmljs_convert_to_object(QV4::ExecutionContext *ctx, const QV4::Value &value);
+QV4::Value __qmljs_to_object(QV4::ExecutionContext *ctx, const ValueRef value);
+QV4::Object *__qmljs_convert_to_object(QV4::ExecutionContext *ctx, const ValueRef value);
-QV4::Bool __qmljs_equal_helper(const Value &x, const Value &y);
-Q_QML_EXPORT QV4::Bool __qmljs_strict_equal(const QV4::Value &x, const QV4::Value &y);
+QV4::Bool __qmljs_equal_helper(const ValueRef x, const ValueRef y);
+Q_QML_EXPORT QV4::Bool __qmljs_strict_equal(const ValueRef x, const ValueRef y);
// unary operators
typedef void (*UnaryOpName)(QV4::ValueRef, const QV4::ValueRef);
@@ -178,145 +178,125 @@ void __qmljs_not(QV4::ValueRef result, const QV4::ValueRef value);
void __qmljs_increment(QV4::ValueRef result, const QV4::ValueRef value);
void __qmljs_decrement(QV4::ValueRef result, const QV4::ValueRef value);
-Q_QML_EXPORT void __qmljs_value_to_double(double *result, const Value &value);
-Q_QML_EXPORT int __qmljs_value_to_int32(const Value &value);
+Q_QML_EXPORT void __qmljs_value_to_double(double *result, const ValueRef value);
+Q_QML_EXPORT int __qmljs_value_to_int32(const ValueRef value);
Q_QML_EXPORT int __qmljs_double_to_int32(const double &d);
-Q_QML_EXPORT unsigned __qmljs_value_to_uint32(const Value &value);
+Q_QML_EXPORT unsigned __qmljs_value_to_uint32(const ValueRef value);
Q_QML_EXPORT unsigned __qmljs_double_to_uint32(const double &d);
-void __qmljs_delete_subscript(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &base, const QV4::Value &index);
-void __qmljs_delete_member(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &base, QV4::String *name);
+void __qmljs_delete_subscript(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef base, const QV4::ValueRef index);
+void __qmljs_delete_member(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef base, QV4::String *name);
void __qmljs_delete_name(QV4::ExecutionContext *ctx, QV4::ValueRef result, QV4::String *name);
-void Q_NORETURN __qmljs_throw(QV4::ExecutionContext*, const QV4::Value &value);
+void Q_NORETURN __qmljs_throw(QV4::ExecutionContext*, const QV4::ValueRef value);
// binary operators
-typedef void (*BinOp)(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-typedef void (*BinOpContext)(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-
-void __qmljs_instanceof(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_in(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_add(ExecutionContext *ctx, QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_bit_or(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_bit_xor(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_bit_and(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_sub(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_mul(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_div(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_mod(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_shl(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_shr(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_ushr(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_gt(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_lt(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_ge(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_le(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_eq(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_ne(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_se(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
-void __qmljs_sne(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right);
+typedef void (*BinOp)(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+typedef void (*BinOpContext)(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+
+void __qmljs_instanceof(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_in(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_add(ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_bit_or(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_bit_xor(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_bit_and(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_sub(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_mul(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_div(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_mod(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_shl(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_shr(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_ushr(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_gt(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_lt(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_ge(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_le(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_eq(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_ne(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_se(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
+void __qmljs_sne(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
void __qmljs_add_helper(QV4::ExecutionContext *ctx, QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right);
-typedef void (*InplaceBinOpName)(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_bit_and_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_bit_or_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_bit_xor_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_add_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_sub_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_mul_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_div_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_mod_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_shl_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_shr_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-void __qmljs_inplace_ushr_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::Value &value);
-
-typedef void (*InplaceBinOpElement)(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_bit_and_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_bit_or_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_bit_xor_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_add_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_sub_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_mul_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_div_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_mod_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_shl_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_shr_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-void __qmljs_inplace_ushr_element(QV4::ExecutionContext *ctx, const QV4::Value &base, const QV4::Value &index, const QV4::Value &rhs);
-
-typedef void (*InplaceBinOpMember)(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_bit_and_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_bit_or_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_bit_xor_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_add_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_sub_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_mul_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_div_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_mod_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_shl_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_shr_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-void __qmljs_inplace_ushr_member(QV4::ExecutionContext *ctx, const QV4::Value &base, QV4::String *name, const QV4::Value &rhs);
-
-typedef QV4::Bool (*CmpOp)(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_gt(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_lt(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_ge(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_le(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_eq(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_ne(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_se(const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_sne(const QV4::Value &left, const QV4::Value &right);
-
-typedef QV4::Bool (*CmpOpContext)(QV4::ExecutionContext *ctx, const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_instanceof(QV4::ExecutionContext *ctx, const QV4::Value &left, const QV4::Value &right);
-QV4::Bool __qmljs_cmp_in(QV4::ExecutionContext *ctx, const QV4::Value &left, const QV4::Value &right);
+typedef void (*InplaceBinOpName)(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::ValueRef value);
+void __qmljs_inplace_bit_and_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::ValueRef value);
+void __qmljs_inplace_bit_or_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::ValueRef value);
+void __qmljs_inplace_bit_xor_name(QV4::ExecutionContext *ctx, QV4::String *name, const QV4::ValueRef value);
+void __qmljs_inplace_add_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+void __qmljs_inplace_sub_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+void __qmljs_inplace_mul_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+void __qmljs_inplace_div_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+void __qmljs_inplace_mod_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+void __qmljs_inplace_shl_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+void __qmljs_inplace_shr_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+void __qmljs_inplace_ushr_name(QV4::ExecutionContext *ctx, QV4::String *name, const ValueRef value);
+
+typedef void (*InplaceBinOpElement)(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_bit_and_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_bit_or_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_bit_xor_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_add_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_sub_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_mul_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_div_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_mod_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_shl_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_shr_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+void __qmljs_inplace_ushr_element(QV4::ExecutionContext *ctx, const QV4::ValueRef base, const QV4::ValueRef index, const QV4::ValueRef rhs);
+
+typedef void (*InplaceBinOpMember)(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_bit_and_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_bit_or_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_bit_xor_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_add_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_sub_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_mul_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_div_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_mod_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_shl_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_shr_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+void __qmljs_inplace_ushr_member(QV4::ExecutionContext *ctx, const QV4::ValueRef base, QV4::String *name, const QV4::ValueRef rhs);
+
+typedef QV4::Bool (*CmpOp)(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_gt(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_lt(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_ge(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_le(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_eq(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_ne(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_se(const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_sne(const QV4::ValueRef left, const QV4::ValueRef right);
+
+typedef QV4::Bool (*CmpOpContext)(QV4::ExecutionContext *ctx, const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_instanceof(QV4::ExecutionContext *ctx, const QV4::ValueRef left, const QV4::ValueRef right);
+QV4::Bool __qmljs_cmp_in(QV4::ExecutionContext *ctx, const QV4::ValueRef left, const QV4::ValueRef right);
// type conversion and testing
-inline QV4::Value __qmljs_to_primitive(const QV4::Value &value, int typeHint)
+inline QV4::Value __qmljs_to_primitive(const QV4::ValueRef value, int typeHint)
{
- QV4::Object *o = value.asObject();
+ QV4::Object *o = value->asObject();
if (!o)
- return value;
+ return *value;
return __qmljs_object_default_value(o, typeHint);
}
-inline double __qmljs_to_number(const QV4::Value &value)
-{
- switch (value.type()) {
- case QV4::Value::Undefined_Type:
- return std::numeric_limits<double>::quiet_NaN();
- case QV4::Value::Null_Type:
- return 0;
- case QV4::Value::Boolean_Type:
- return (value.booleanValue() ? 1. : 0.);
- case QV4::Value::Integer_Type:
- return value.int_32;
- case QV4::Value::String_Type:
- return __qmljs_string_to_number(value.stringValue()->toQString());
- case QV4::Value::Object_Type: {
- QV4::Value prim = __qmljs_to_primitive(value, QV4::NUMBER_HINT);
- return __qmljs_to_number(prim);
- }
- default: // double
- return value.doubleValue();
- }
+inline double __qmljs_to_number(const ValueRef value)
+{
+ return value->toNumber();
}
-Q_QML_EXPORT int __qmljs_value_to_int32(const QV4::Value &value);
-Q_QML_EXPORT unsigned __qmljs_value_to_uint32(const QV4::Value &value);
-
-inline QV4::Value __qmljs_to_string(const QV4::Value &value, QV4::ExecutionContext *ctx)
+inline QV4::Value __qmljs_to_string(const QV4::ValueRef value, QV4::ExecutionContext *ctx)
{
- if (value.isString())
- return value;
+ if (value->isString())
+ return *value;
return QV4::Value::fromString(__qmljs_convert_to_string(ctx, value));
}
-inline QV4::Value __qmljs_to_object(QV4::ExecutionContext *ctx, const QV4::Value &value)
+inline QV4::Value __qmljs_to_object(QV4::ExecutionContext *ctx, const QV4::ValueRef value)
{
- if (value.isObject())
- return value;
+ if (value->isObject())
+ return *value;
return QV4::Value::fromObject(__qmljs_convert_to_object(ctx, value));
}
@@ -329,7 +309,7 @@ inline void __qmljs_uplus(QV4::ValueRef result, const QV4::ValueRef value)
if (result->tryIntegerConversion())
return;
- double n = __qmljs_to_number(*value);
+ double n = __qmljs_to_number(value);
*result = QV4::Value::fromDouble(n);
}
@@ -341,7 +321,7 @@ inline void __qmljs_uminus(QV4::ValueRef result, const QV4::ValueRef value)
if (value->isInteger() && value->integerValue())
*result = QV4::Value::fromInt32(-value->integerValue());
else {
- double n = __qmljs_to_number(*value);
+ double n = __qmljs_to_number(value);
*result = QV4::Value::fromDouble(-n);
}
}
@@ -354,7 +334,7 @@ inline void __qmljs_compl(QV4::ValueRef result, const QV4::ValueRef value)
if (value->isConvertibleToInt())
n = value->int_32;
else
- n = QV4::Value::toInt32(__qmljs_to_number(*value));
+ n = QV4::Value::toInt32(__qmljs_to_number(value));
*result = QV4::Value::fromInt32(~n);
}
@@ -368,12 +348,12 @@ inline void __qmljs_not(QV4::ValueRef result, const QV4::ValueRef value)
}
// binary operators
-inline void __qmljs_bit_or(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_bit_or(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = QV4::Value::fromInt32(left.integerValue() | right.integerValue());
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = QV4::Value::fromInt32(left->integerValue() | right->integerValue());
return;
}
@@ -382,12 +362,12 @@ inline void __qmljs_bit_or(ValueRef result, const QV4::Value &left, const QV4::V
*result = QV4::Value::fromInt32(lval | rval);
}
-inline void __qmljs_bit_xor(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_bit_xor(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = QV4::Value::fromInt32(left.integerValue() ^ right.integerValue());
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = QV4::Value::fromInt32(left->integerValue() ^ right->integerValue());
return;
}
@@ -396,12 +376,12 @@ inline void __qmljs_bit_xor(QV4::ValueRef result, const QV4::Value &left, const
*result = QV4::Value::fromInt32(lval ^ rval);
}
-inline void __qmljs_bit_and(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_bit_and(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = QV4::Value::fromInt32(left.integerValue() & right.integerValue());
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = QV4::Value::fromInt32(left->integerValue() & right->integerValue());
return;
}
@@ -410,29 +390,29 @@ inline void __qmljs_bit_and(ValueRef result, const QV4::Value &left, const QV4::
*result = QV4::Value::fromInt32(lval & rval);
}
-inline void __qmljs_add(QV4::ExecutionContext *ctx, ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_add(QV4::ExecutionContext *ctx, ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = add_int32(left.integerValue(), right.integerValue());
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = add_int32(left->integerValue(), right->integerValue());
return;
}
- if (QV4::Value::bothDouble(left, right)) {
- *result = QV4::Value::fromDouble(left.doubleValue() + right.doubleValue());
+ if (QV4::Value::bothDouble(*left, *right)) {
+ *result = QV4::Value::fromDouble(left->doubleValue() + right->doubleValue());
return;
}
- __qmljs_add_helper(ctx, result, ValueRef::fromRawValue(&left), ValueRef::fromRawValue(&right));
+ __qmljs_add_helper(ctx, result, left, right);
}
-inline void __qmljs_sub(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_sub(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = sub_int32(left.integerValue(), right.integerValue());
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = sub_int32(left->integerValue(), right->integerValue());
return;
}
@@ -441,12 +421,12 @@ inline void __qmljs_sub(QV4::ValueRef result, const QV4::Value &left, const QV4:
*result = QV4::Value::fromDouble(lval - rval);
}
-inline void __qmljs_mul(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_mul(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = mul_int32(left.integerValue(), right.integerValue());
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = mul_int32(left->integerValue(), right->integerValue());
return;
}
@@ -455,7 +435,7 @@ inline void __qmljs_mul(ValueRef result, const QV4::Value &left, const QV4::Valu
*result = QV4::Value::fromDouble(lval * rval);
}
-inline void __qmljs_div(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_div(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
@@ -464,13 +444,13 @@ inline void __qmljs_div(QV4::ValueRef result, const QV4::Value &left, const QV4:
*result = QV4::Value::fromDouble(lval / rval);
}
-inline void __qmljs_mod(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_mod(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right) && right.integerValue() != 0) {
- int intRes = left.integerValue() % right.integerValue();
- if (intRes != 0 || left.integerValue() >= 0) {
+ if (QV4::Value::integerCompatible(*left, *right) && right->integerValue() != 0) {
+ int intRes = left->integerValue() % right->integerValue();
+ if (intRes != 0 || left->integerValue() >= 0) {
*result = QV4::Value::fromInt32(intRes);
return;
}
@@ -481,12 +461,12 @@ inline void __qmljs_mod(ValueRef result, const QV4::Value &left, const QV4::Valu
*result = QV4::Value::fromDouble(std::fmod(lval, rval));
}
-inline void __qmljs_shl(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_shl(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = QV4::Value::fromInt32(left.integerValue() << ((uint(right.integerValue()) & 0x1f)));
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = QV4::Value::fromInt32(left->integerValue() << ((uint(right->integerValue()) & 0x1f)));
return;
}
@@ -495,12 +475,12 @@ inline void __qmljs_shl(QV4::ValueRef result, const QV4::Value &left, const QV4:
*result = QV4::Value::fromInt32(lval << rval);
}
-inline void __qmljs_shr(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_shr(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right)) {
- *result = QV4::Value::fromInt32(left.integerValue() >> ((uint(right.integerValue()) & 0x1f)));
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ *result = QV4::Value::fromInt32(left->integerValue() >> ((uint(right->integerValue()) & 0x1f)));
return;
}
@@ -509,13 +489,13 @@ inline void __qmljs_shr(ValueRef result, const QV4::Value &left, const QV4::Valu
*result = QV4::Value::fromInt32(lval >> rval);
}
-inline void __qmljs_ushr(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_ushr(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
uint res;
- if (QV4::Value::integerCompatible(left, right)) {
- res = uint(left.integerValue()) >> (uint(right.integerValue()) & 0x1f);
+ if (QV4::Value::integerCompatible(*left, *right)) {
+ res = uint(left->integerValue()) >> (uint(right->integerValue()) & 0x1f);
} else {
unsigned lval = QV4::Value::toUInt32(__qmljs_to_number(left));
unsigned rval = QV4::Value::toUInt32(__qmljs_to_number(right)) & 0x1f;
@@ -528,49 +508,49 @@ inline void __qmljs_ushr(QV4::ValueRef result, const QV4::Value &left, const QV4
*result = QV4::Value::fromInt32(res);
}
-inline void __qmljs_gt(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_gt(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
*result = QV4::Value::fromBoolean(__qmljs_cmp_gt(left, right));
}
-inline void __qmljs_lt(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_lt(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
*result = QV4::Value::fromBoolean(__qmljs_cmp_lt(left, right));
}
-inline void __qmljs_ge(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_ge(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
*result = QV4::Value::fromBoolean(__qmljs_cmp_ge(left, right));
}
-inline void __qmljs_le(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_le(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
*result = QV4::Value::fromBoolean(__qmljs_cmp_le(left, right));
}
-inline void __qmljs_eq(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_eq(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
*result = QV4::Value::fromBoolean(__qmljs_cmp_eq(left, right));
}
-inline void __qmljs_ne(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_ne(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
*result = QV4::Value::fromBoolean(!__qmljs_cmp_eq(left, right));
}
-inline void __qmljs_se(QV4::ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_se(QV4::ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
@@ -578,7 +558,7 @@ inline void __qmljs_se(QV4::ValueRef result, const QV4::Value &left, const QV4::
*result = QV4::Value::fromBoolean(r);
}
-inline void __qmljs_sne(ValueRef result, const QV4::Value &left, const QV4::Value &right)
+inline void __qmljs_sne(ValueRef result, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
@@ -586,12 +566,13 @@ inline void __qmljs_sne(ValueRef result, const QV4::Value &left, const QV4::Valu
*result = QV4::Value::fromBoolean(r);
}
-inline QV4::Bool __qmljs_cmp_gt(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_gt(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right))
- return left.integerValue() > right.integerValue();
+ if (QV4::Value::integerCompatible(*left, *right))
+ return left->integerValue() > right->integerValue();
+ // Safe, as l & r are primitive values
QV4::Value l = __qmljs_to_primitive(left, QV4::NUMBER_HINT);
QV4::Value r = __qmljs_to_primitive(right, QV4::NUMBER_HINT);
@@ -600,17 +581,17 @@ inline QV4::Bool __qmljs_cmp_gt(const QV4::Value &left, const QV4::Value &right)
} else if (l.isString() && r.isString()) {
return r.stringValue()->compare(l.stringValue());
} else {
- double dl = __qmljs_to_number(l);
- double dr = __qmljs_to_number(r);
+ double dl = __qmljs_to_number(ValueRef(&l));
+ double dr = __qmljs_to_number(ValueRef(&r));
return dl > dr;
}
}
-inline QV4::Bool __qmljs_cmp_lt(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_lt(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right))
- return left.integerValue() < right.integerValue();
+ if (QV4::Value::integerCompatible(*left, *right))
+ return left->integerValue() < right->integerValue();
QV4::Value l = __qmljs_to_primitive(left, QV4::NUMBER_HINT);
QV4::Value r = __qmljs_to_primitive(right, QV4::NUMBER_HINT);
@@ -620,17 +601,17 @@ inline QV4::Bool __qmljs_cmp_lt(const QV4::Value &left, const QV4::Value &right)
} else if (l.isString() && r.isString()) {
return l.stringValue()->compare(r.stringValue());
} else {
- double dl = __qmljs_to_number(l);
- double dr = __qmljs_to_number(r);
+ double dl = __qmljs_to_number(ValueRef(&l));
+ double dr = __qmljs_to_number(ValueRef(&r));
return dl < dr;
}
}
-inline QV4::Bool __qmljs_cmp_ge(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_ge(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right))
- return left.integerValue() >= right.integerValue();
+ if (QV4::Value::integerCompatible(*left, *right))
+ return left->integerValue() >= right->integerValue();
QV4::Value l = __qmljs_to_primitive(left, QV4::NUMBER_HINT);
QV4::Value r = __qmljs_to_primitive(right, QV4::NUMBER_HINT);
@@ -640,17 +621,17 @@ inline QV4::Bool __qmljs_cmp_ge(const QV4::Value &left, const QV4::Value &right)
} else if (l.isString() && r.isString()) {
return !l.stringValue()->compare(r.stringValue());
} else {
- double dl = __qmljs_to_number(l);
- double dr = __qmljs_to_number(r);
+ double dl = __qmljs_to_number(ValueRef(&l));
+ double dr = __qmljs_to_number(ValueRef(&r));
return dl >= dr;
}
}
-inline QV4::Bool __qmljs_cmp_le(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_le(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(left, right))
- return left.integerValue() <= right.integerValue();
+ if (QV4::Value::integerCompatible(*left, *right))
+ return left->integerValue() <= right->integerValue();
QV4::Value l = __qmljs_to_primitive(left, QV4::NUMBER_HINT);
QV4::Value r = __qmljs_to_primitive(right, QV4::NUMBER_HINT);
@@ -660,51 +641,51 @@ inline QV4::Bool __qmljs_cmp_le(const QV4::Value &left, const QV4::Value &right)
} else if (l.isString() && r.isString()) {
return !r.stringValue()->compare(l.stringValue());
} else {
- double dl = __qmljs_to_number(l);
- double dr = __qmljs_to_number(r);
+ double dl = __qmljs_to_number(ValueRef(&l));
+ double dr = __qmljs_to_number(ValueRef(&r));
return dl <= dr;
}
}
-inline QV4::Bool __qmljs_cmp_eq(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_eq(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- if (left.val == right.val)
+ if (left->val == right->val)
// NaN != NaN
- return (left.tag & QV4::Value::NotDouble_Mask) != QV4::Value::NaN_Mask;
+ return (left->tag & QV4::Value::NotDouble_Mask) != QV4::Value::NaN_Mask;
- if (left.type() == right.type()) {
- if (left.isManaged())
- return left.managed()->isEqualTo(right.managed());
+ if (left->type() == right->type()) {
+ if (left->isManaged())
+ return left->managed()->isEqualTo(right->managed());
return false;
}
return __qmljs_equal_helper(left, right);
}
-inline QV4::Bool __qmljs_cmp_ne(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_ne(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
return !__qmljs_cmp_eq(left, right);
}
-inline QV4::Bool __qmljs_cmp_se(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_se(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
return __qmljs_strict_equal(left, right);
}
-inline QV4::Bool __qmljs_cmp_sne(const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_sne(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
return ! __qmljs_strict_equal(left, right);
}
-inline QV4::Bool __qmljs_cmp_instanceof(QV4::ExecutionContext *ctx, const QV4::Value &left, const QV4::Value &right)
+inline QV4::Bool __qmljs_cmp_instanceof(QV4::ExecutionContext *ctx, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
@@ -713,7 +694,7 @@ inline QV4::Bool __qmljs_cmp_instanceof(QV4::ExecutionContext *ctx, const QV4::V
return v.booleanValue();
}
-inline uint __qmljs_cmp_in(QV4::ExecutionContext *ctx, const QV4::Value &left, const QV4::Value &right)
+inline uint __qmljs_cmp_in(QV4::ExecutionContext *ctx, const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index 55c0b99230..a0e0d784a7 100644
--- a/src/qml/jsruntime/qv4scopedvalue_p.h
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -203,6 +203,10 @@ struct ScopedCallData {
struct ValueRef {
ValueRef(const ScopedValue &v)
: ptr(v.ptr) {}
+ ValueRef(const PersistentValue &v)
+ : ptr(&v.d->value) {}
+ ValueRef(PersistentValuePrivate *p)
+ : ptr(&p->value) {}
// Important: Do NOT add a copy constructor to this class
// adding a copy constructor actually changes the calling convention, ie.
// is not even binary compatible. Adding it would break assumptions made
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index 6fdb3e6dda..0a9cb32e6f 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -280,12 +280,15 @@ Value StringPrototype::method_charCodeAt(SimpleCallContext *context)
Value StringPrototype::method_concat(SimpleCallContext *context)
{
+ ValueScope scope(context);
+
QString value = getThisString(context, context->thisObject);
+ ScopedValue v(scope);
for (int i = 0; i < context->argumentCount; ++i) {
- Value v = __qmljs_to_string(context->arguments[i], context);
- assert(v.isString());
- value += v.stringValue()->toQString();
+ v = __qmljs_to_string(ValueRef(&context->arguments[i]), context);
+ assert(v->isString());
+ value += v->stringValue()->toQString();
}
return Value::fromString(context, value);
@@ -312,15 +315,17 @@ Value StringPrototype::method_indexOf(SimpleCallContext *context)
Value StringPrototype::method_lastIndexOf(SimpleCallContext *context)
{
+ ValueScope scope(context);
+
const QString value = getThisString(context, context->thisObject);
QString searchString;
if (context->argumentCount) {
- Value v = __qmljs_to_string(context->arguments[0], context);
+ Value v = __qmljs_to_string(ValueRef(&context->arguments[0]), context);
searchString = v.stringValue()->toQString();
}
- Value posArg = context->argumentCount > 1 ? context->arguments[1] : Value::undefinedValue();
+ ScopedValue posArg(scope, context->argumentCount > 1 ? context->arguments[1] : Value::undefinedValue());
double position = __qmljs_to_number(posArg);
if (std::isnan(position))
position = +qInf();
@@ -784,7 +789,7 @@ Value StringPrototype::method_trim(SimpleCallContext *ctx)
if (ctx->thisObject.isNull() || ctx->thisObject.isUndefined())
ctx->throwTypeError();
- QString s = __qmljs_to_string(ctx->thisObject, ctx).stringValue()->toQString();
+ QString s = __qmljs_to_string(ValueRef(&ctx->thisObject), ctx).stringValue()->toQString();
const QChar *chars = s.constData();
int start, end;
for (start = 0; start < s.length(); ++start) {
diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp
index a41262f12f..718b87d2c9 100644
--- a/src/qml/jsruntime/qv4value.cpp
+++ b/src/qml/jsruntime/qv4value.cpp
@@ -48,12 +48,47 @@
using namespace QV4;
+int Value::toInt32() const
+{
+ if (isConvertibleToInt())
+ return int_32;
+ double d;
+ if (isDouble())
+ d = dbl;
+ else
+ d = toNumber();
+
+ const double D32 = 4294967296.0;
+ const double D31 = D32 / 2.0;
+
+ if ((d >= -D31 && d < D31))
+ return static_cast<int>(d);
+
+ return Value::toInt32(d);
+}
+
+unsigned int Value::toUInt32() const
+{
+ if (isConvertibleToInt())
+ return (unsigned) int_32;
+ double d;
+ if (isDouble())
+ d = dbl;
+ else
+ d = toNumber();
+
+ const double D32 = 4294967296.0;
+ if (d >= 0 && d < D32)
+ return static_cast<uint>(d);
+ return toUInt32(d);
+}
+
int Value::toUInt16() const
{
if (isConvertibleToInt())
return (ushort)(uint)integerValue();
- double number = __qmljs_to_number(*this);
+ double number = toNumber();
double D16 = 65536.0;
if ((number >= 0 && number < D16))
@@ -79,12 +114,32 @@ double Value::toInteger() const
if (isConvertibleToInt())
return int_32;
- return Value::toInteger(__qmljs_to_number(*this));
+ return Value::toInteger(toNumber());
}
double Value::toNumber() const
{
- return __qmljs_to_number(*this);
+ QV4::Value v = *this;
+
+ redo:
+ switch (v.type()) {
+ case QV4::Value::Undefined_Type:
+ return std::numeric_limits<double>::quiet_NaN();
+ case QV4::Value::Null_Type:
+ return 0;
+ case QV4::Value::Boolean_Type:
+ return (v.booleanValue() ? 1. : 0.);
+ case QV4::Value::Integer_Type:
+ return v.int_32;
+ case QV4::Value::String_Type:
+ return __qmljs_string_to_number(v.toQString());
+ case QV4::Value::Object_Type: {
+ v = __qmljs_to_primitive(ValueRef::fromRawValue(this), QV4::NUMBER_HINT);
+ goto redo;
+ }
+ default: // double
+ return v.doubleValue();
+ }
}
QString Value::toQString() const
@@ -103,16 +158,18 @@ QString Value::toQString() const
return stringValue()->toQString();
case Value::Object_Type: {
ExecutionContext *ctx = objectValue()->internalClass->engine->current;
+ ValueScope scope(ctx);
try {
- Value prim = __qmljs_to_primitive(*this, STRING_HINT);
- if (prim.isPrimitive())
- return prim.toQString();
+ ScopedValue prim(scope, __qmljs_to_primitive(ValueRef::fromRawValue(this), STRING_HINT));
+ if (prim->isPrimitive())
+ return prim->toQString();
} catch (Exception &e) {
e.accept(ctx);
try {
- Value prim = __qmljs_to_primitive(e.value(), STRING_HINT);
- if (prim.isPrimitive())
- return prim.toQString();
+ ScopedValue ex(scope, e.value());
+ ScopedValue prim(scope, __qmljs_to_primitive(ex, STRING_HINT));
+ if (prim->isPrimitive())
+ return prim->toQString();
} catch(Exception &e) {
e.accept(ctx);
}
@@ -216,9 +273,17 @@ String *Value::toString(ExecutionContext *ctx) const
{
if (isString())
return stringValue();
- return __qmljs_convert_to_string(ctx, *this);
+ return __qmljs_convert_to_string(ctx, ValueRef::fromRawValue(this));
+}
+
+Object *Value::toObject(ExecutionContext *ctx) const
+{
+ if (isObject())
+ return objectValue();
+ return __qmljs_convert_to_object(ctx, ValueRef::fromRawValue(this));
}
+
Value Value::property(ExecutionContext *ctx, String *name) const
{
return isObject() ? objectValue()->get(name) : undefinedValue();
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h
index 5fbd4ac2d7..8d6f26ea57 100644
--- a/src/qml/jsruntime/qv4value_p.h
+++ b/src/qml/jsruntime/qv4value_p.h
@@ -59,8 +59,6 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
-double __qmljs_to_number(const QV4::Value &value);
-Q_QML_EXPORT QV4::String *__qmljs_convert_to_string(QV4::ExecutionContext *ctx, const QV4::Value &value);
QV4::Object *__qmljs_convert_to_object(QV4::ExecutionContext *ctx, const QV4::Value &value);
inline Managed *Value::asManaged() const
@@ -193,48 +191,6 @@ inline bool Value::toBoolean() const
}
}
-inline Object *Value::toObject(ExecutionContext *ctx) const
-{
- if (isObject())
- return objectValue();
- return __qmljs_convert_to_object(ctx, *this);
-}
-
-inline int Value::toInt32() const
-{
- if (isConvertibleToInt())
- return int_32;
- double d;
- if (isDouble())
- d = dbl;
- else
- d = __qmljs_to_number(*this);
-
- const double D32 = 4294967296.0;
- const double D31 = D32 / 2.0;
-
- if ((d >= -D31 && d < D31))
- return static_cast<int>(d);
-
- return Value::toInt32(d);
-}
-
-inline unsigned int Value::toUInt32() const
-{
- if (isConvertibleToInt())
- return (unsigned) int_32;
- double d;
- if (isDouble())
- d = dbl;
- else
- d = __qmljs_to_number(*this);
-
- const double D32 = 4294967296.0;
- if (d >= 0 && d < D32)
- return static_cast<uint>(d);
- return toUInt32(d);
-}
-
inline uint Value::asArrayIndex() const
{
if (isInteger() && int_32 >= 0)
@@ -380,6 +336,7 @@ public:
}
private:
+ friend struct ValueRef;
PersistentValuePrivate *d;
};
@@ -414,6 +371,7 @@ public:
void markOnce();
private:
+ friend struct ValueRef;
PersistentValuePrivate *d;
};
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 67b1e6135a..92b0c75e8c 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -283,23 +283,23 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_BEGIN_INSTR(StoreName)
TRACE(inline, "property name = %s", instr.name->toQString().toUtf8().constData());
- __qmljs_set_activation_property(context, runtimeStrings[instr.name], VALUE(instr.source));
+ __qmljs_set_activation_property(context, runtimeStrings[instr.name], VALUEPTR(instr.source));
MOTH_END_INSTR(StoreName)
MOTH_BEGIN_INSTR(LoadElement)
- __qmljs_get_element(context, VALUEPTR(instr.result), VALUE(instr.base), VALUE(instr.index));
+ __qmljs_get_element(context, VALUEPTR(instr.result), VALUEPTR(instr.base), VALUEPTR(instr.index));
MOTH_END_INSTR(LoadElement)
MOTH_BEGIN_INSTR(StoreElement)
- __qmljs_set_element(context, VALUE(instr.base), VALUE(instr.index), VALUE(instr.source));
+ __qmljs_set_element(context, VALUEPTR(instr.base), VALUEPTR(instr.index), VALUEPTR(instr.source));
MOTH_END_INSTR(StoreElement)
MOTH_BEGIN_INSTR(LoadProperty)
- __qmljs_get_property(context, VALUEPTR(instr.result), VALUE(instr.base), runtimeStrings[instr.name]);
+ __qmljs_get_property(context, VALUEPTR(instr.result), VALUEPTR(instr.base), runtimeStrings[instr.name]);
MOTH_END_INSTR(LoadProperty)
MOTH_BEGIN_INSTR(StoreProperty)
- __qmljs_set_property(context, VALUE(instr.base), runtimeStrings[instr.name], VALUE(instr.source));
+ __qmljs_set_property(context, VALUEPTR(instr.base), runtimeStrings[instr.name], VALUEPTR(instr.source));
MOTH_END_INSTR(StoreProperty)
MOTH_BEGIN_INSTR(Push)
@@ -358,7 +358,7 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_END_INSTR(CallActivationProperty)
MOTH_BEGIN_INSTR(CallBuiltinThrow)
- __qmljs_throw(context, VALUE(instr.arg));
+ __qmljs_throw(context, VALUEPTR(instr.arg));
MOTH_END_INSTR(CallBuiltinThrow)
MOTH_BEGIN_INSTR(EnterTry)
@@ -372,7 +372,7 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
ex.accept(context);
VALUE(instr.exceptionVar) = ex.value();
try {
- QV4::ExecutionContext *catchContext = __qmljs_builtin_push_catch_scope(runtimeStrings[instr.exceptionVarName], ex.value(), context);
+ QV4::ExecutionContext *catchContext = __qmljs_builtin_push_catch_scope(runtimeStrings[instr.exceptionVarName], VALUEPTR(instr.exceptionVar), context);
const uchar *catchCode = ((uchar *)&instr.catchOffset) + instr.catchOffset;
run(catchContext, catchCode, stack, stackSize);
code = catchCode;
@@ -394,7 +394,7 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_END_INSTR(CallBuiltinFinishTry)
MOTH_BEGIN_INSTR(CallBuiltinPushScope)
- context = __qmljs_builtin_push_with_scope(VALUE(instr.arg), context);
+ context = __qmljs_builtin_push_with_scope(VALUEPTR(instr.arg), context);
MOTH_END_INSTR(CallBuiltinPushScope)
MOTH_BEGIN_INSTR(CallBuiltinPopScope)
@@ -402,19 +402,19 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_END_INSTR(CallBuiltinPopScope)
MOTH_BEGIN_INSTR(CallBuiltinForeachIteratorObject)
- __qmljs_foreach_iterator_object(context, VALUEPTR(instr.result), VALUE(instr.arg));
+ __qmljs_foreach_iterator_object(context, VALUEPTR(instr.result), VALUEPTR(instr.arg));
MOTH_END_INSTR(CallBuiltinForeachIteratorObject)
MOTH_BEGIN_INSTR(CallBuiltinForeachNextPropertyName)
- __qmljs_foreach_next_property_name(VALUEPTR(instr.result), VALUE(instr.arg));
+ __qmljs_foreach_next_property_name(VALUEPTR(instr.result), VALUEPTR(instr.arg));
MOTH_END_INSTR(CallBuiltinForeachNextPropertyName)
MOTH_BEGIN_INSTR(CallBuiltinDeleteMember)
- __qmljs_delete_member(context, VALUEPTR(instr.result), VALUE(instr.base), runtimeStrings[instr.member]);
+ __qmljs_delete_member(context, VALUEPTR(instr.result), VALUEPTR(instr.base), runtimeStrings[instr.member]);
MOTH_END_INSTR(CallBuiltinDeleteMember)
MOTH_BEGIN_INSTR(CallBuiltinDeleteSubscript)
- __qmljs_delete_subscript(context, VALUEPTR(instr.result), VALUE(instr.base), VALUE(instr.index));
+ __qmljs_delete_subscript(context, VALUEPTR(instr.result), VALUEPTR(instr.base), VALUEPTR(instr.index));
MOTH_END_INSTR(CallBuiltinDeleteSubscript)
MOTH_BEGIN_INSTR(CallBuiltinDeleteName)
@@ -474,11 +474,11 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_END_INSTR(CallBuiltinDeclareVar)
MOTH_BEGIN_INSTR(CallBuiltinDefineGetterSetter)
- __qmljs_builtin_define_getter_setter(context, VALUE(instr.object), runtimeStrings[instr.name], VALUEPTR(instr.getter), VALUEPTR(instr.setter));
+ __qmljs_builtin_define_getter_setter(context, VALUEPTR(instr.object), runtimeStrings[instr.name], VALUEPTR(instr.getter), VALUEPTR(instr.setter));
MOTH_END_INSTR(CallBuiltinDefineGetterSetter)
MOTH_BEGIN_INSTR(CallBuiltinDefineProperty)
- __qmljs_builtin_define_property(context, VALUE(instr.object), runtimeStrings[instr.name], VALUEPTR(instr.value));
+ __qmljs_builtin_define_property(context, VALUEPTR(instr.object), runtimeStrings[instr.name], VALUEPTR(instr.value));
MOTH_END_INSTR(CallBuiltinDefineProperty)
MOTH_BEGIN_INSTR(CallBuiltinDefineArray)
@@ -529,7 +529,7 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_END_INSTR(Jump)
MOTH_BEGIN_INSTR(CJump)
- uint cond = __qmljs_to_boolean(VALUE(instr.condition));
+ uint cond = __qmljs_to_boolean(VALUEPTR(instr.condition));
TRACE(condition, "%s", cond ? "TRUE" : "FALSE");
if (cond)
code = ((uchar *)&instr.offset) + instr.offset;
@@ -540,11 +540,11 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_END_INSTR(Unop)
MOTH_BEGIN_INSTR(Binop)
- instr.alu(VALUEPTR(instr.result), VALUE(instr.lhs), VALUE(instr.rhs));
+ instr.alu(VALUEPTR(instr.result), VALUEPTR(instr.lhs), VALUEPTR(instr.rhs));
MOTH_END_INSTR(Binop)
MOTH_BEGIN_INSTR(BinopContext)
- instr.alu(context, VALUEPTR(instr.result), VALUE(instr.lhs), VALUE(instr.rhs));
+ instr.alu(context, VALUEPTR(instr.result), VALUEPTR(instr.lhs), VALUEPTR(instr.rhs));
MOTH_END_INSTR(BinopContext)
MOTH_BEGIN_INSTR(AddNumberParams)
@@ -587,21 +587,21 @@ QV4::Value VME::run(QV4::ExecutionContext *context, const uchar *&code,
MOTH_BEGIN_INSTR(InplaceElementOp)
instr.alu(context,
- VALUE(instr.base),
- VALUE(instr.index),
- VALUE(instr.source));
+ VALUEPTR(instr.base),
+ VALUEPTR(instr.index),
+ VALUEPTR(instr.source));
MOTH_END_INSTR(InplaceElementOp)
MOTH_BEGIN_INSTR(InplaceMemberOp)
instr.alu(context,
- VALUE(instr.base),
+ VALUEPTR(instr.base),
runtimeStrings[instr.member],
- VALUE(instr.source));
+ VALUEPTR(instr.source));
MOTH_END_INSTR(InplaceMemberOp)
MOTH_BEGIN_INSTR(InplaceNameOp)
TRACE(name, "%s", instr.name->toQString().toUtf8().constData());
- instr.alu(context, runtimeStrings[instr.name], VALUE(instr.source));
+ instr.alu(context, runtimeStrings[instr.name], VALUEPTR(instr.source));
MOTH_END_INSTR(InplaceNameOp)
#ifdef MOTH_THREADED_INTERPRETER