assert(s->index < o->context->callData->argc);
o->context->callData->args[s->index] = callData->argc ? callData->args[0].asReturnedValue() : Encode::undefined();
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
void ArgumentsObject::markObjects(Managed *that)
ScopedString str(scope, ctx->engine->newString(QStringLiteral("Array.prototype.push: Overflow")));
ctx->throwRangeError(str);
}
- return Primitive::fromDouble(newLen).asReturnedValue();
+ return Encode(newLen);
}
if (!instance->protoHasArray() && instance->arrayDataLen <= len) {
if (!len) {
if (!instance->isArrayObject())
instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromInt32(0)));
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
Property *front = 0;
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
uint len = getLength(ctx, instance.getPointer());
if (!len)
- return Primitive::fromInt32(-1).asReturnedValue();
+ return Encode(-1);
ScopedValue searchValue(scope);
uint fromIndex = 0;
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
uint len = getLength(ctx, instance.getPointer());
if (!len)
- return Primitive::fromInt32(-1).asReturnedValue();
+ return Encode(-1);
ScopedValue searchValue(scope);
uint fromIndex = len;
if (exists && __qmljs_strict_equal(v, searchValue))
return Encode(k);
}
- return Primitive::fromInt32(-1).asReturnedValue();
+ return Encode(-1);
}
ReturnedValue ArrayPrototype::method_every(SimpleCallContext *ctx)
return v.asReturnedValue();
}
}
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, Object **base)
static ReturnedValue throwTypeError(SimpleCallContext *ctx)
{
ctx->throwTypeError();
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
static ReturnedValue construct(Managed *m, CallData *)
{
m->engine()->current->throwTypeError();
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
static ReturnedValue call(Managed *that, CallData *callData);
}
}
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
ReturnedValue Lookup::getter0(Lookup *l, const ValueRef object)
Scope scope(o->engine());
FunctionObject *getter = o->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = *object;
Scope scope(o->engine());
FunctionObject *getter = o->prototype()->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = *object;
Scope scope(o->engine());
FunctionObject *getter = o->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = *object;
Object *o = l->proto;
if (l->classList[0] == o->internalClass) {
Scope scope(o->engine());
- Value res;
FunctionObject *getter = o->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = *object;
if (l->classList[0] == o->internalClass &&
l->classList[1] == o->prototype()->internalClass) {
Scope scope(o->engine());
- Value res;
FunctionObject *getter = o->prototype()->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = *object;
ReturnedValue Lookup::stringLengthGetter(Lookup *l, const ValueRef object)
{
if (String *s = object->asString())
- return Primitive::fromUInt32(s->length()).asReturnedValue();
+ return Encode(s->length());
l->getter = getterGeneric;
return getterGeneric(l, object);
Scope scope(o->engine());
FunctionObject *getter = o->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = Primitive::undefinedValue();
Scope scope(o->engine());
FunctionObject *getter = o->prototype()->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = Primitive::undefinedValue();
Scope scope(o->engine());
FunctionObject *getter = o->memberData[l->index].getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
ScopedCallData callData(scope, 0);
callData->thisObject = Primitive::undefinedValue();
ReturnedValue NumberCtor::call(Managed *, CallData *callData)
{
double dbl = callData->argc ? callData->args[0].toNumber() : 0.;
- return Primitive::fromDouble(dbl).asReturnedValue();
+ return Encode(dbl);
}
void NumberPrototype::init(ExecutionEngine *engine, ObjectRef ctor)
return p->value.asReturnedValue();
FunctionObject *getter = p->getter();
if (!getter)
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
Scope scope(getter->engine());
ScopedCallData callData(scope, 0);
Scope scope(pd->set->engine());
ScopedCallData callData(scope, 1);
callData->args[0] = *value;
- callData->thisObject = Value::fromObject(this);
+ callData->thisObject = this;
pd->set->call(callData);
return;
}
return o->getValue(p, attrs);
}
}
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
void Object::setLookup(Managed *m, Lookup *l, const ValueRef value)
if (hasProperty)
*hasProperty = false;
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
Scope scope(engine());
ScopedCallData callData(scope, 1);
callData->args[0] = *value;
- callData->thisObject = Value::fromObject(this);
+ callData->thisObject = this;
pd->setter()->call(callData);
return;
}
Scope scope(engine());
ScopedCallData callData(scope, 1);
callData->args[0] = *value;
- callData->thisObject = Value::fromObject(this);
+ callData->thisObject = this;
pd->setter()->call(callData);
return;
}
}
-ReturnedValue Object::arrayIndexOf(Value v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
+ReturnedValue Object::arrayIndexOf(const ValueRef v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
{
Scope scope(engine());
ScopedValue value(scope);
for (uint i = fromIndex; i < endIndex; ++i) {
bool exists;
value = o->getIndexed(i, &exists);
- if (exists && __qmljs_strict_equal(value, ValueRef(&v)))
+ if (exists && __qmljs_strict_equal(value, v))
return Encode(i);
}
} else if (sparseArray) {
for (SparseArrayNode *n = sparseArray->lowerBound(fromIndex); n != sparseArray->end() && n->key() < endIndex; n = n->nextNode()) {
value = o->getValue(arrayData + n->value, arrayAttributes ? arrayAttributes[n->value] : Attr_Data);
- if (__qmljs_strict_equal(value, ValueRef(&v)))
+ if (__qmljs_strict_equal(value, v))
return Encode(n->key());
}
} else {
while (pd < end) {
if (!arrayAttributes || !arrayAttributes[pd - arrayData].isGeneric()) {
value = o->getValue(pd, arrayAttributes ? arrayAttributes[pd - arrayData] : Attr_Data);
- if (__qmljs_strict_equal(value, ValueRef(&v)))
+ if (__qmljs_strict_equal(value, v))
return Encode((uint)(pd - arrayData));
}
++pd;
if (other->arrayAttributes) {
for (int i = 0; i < other->arrayDataLen; ++i) {
bool exists;
- arrayData[oldSize + i].value = Value::fromReturnedValue(const_cast<ArrayObject *>(other)->getIndexed(i, &exists));
+ arrayData[oldSize + i].value = const_cast<ArrayObject *>(other)->getIndexed(i, &exists);
arrayDataLen = oldSize + i + 1;
if (arrayAttributes)
arrayAttributes[oldSize + i] = Attr_Data;
while (--len > i)
if (!arrayAttributes[len].isGeneric())
break;
- arrayData[i].value = Value::fromReturnedValue(getValue(arrayData + len, arrayAttributes[len]));
+ arrayData[i].value = getValue(arrayData + len, arrayAttributes[len]);
arrayAttributes[i] = Attr_Data;
arrayAttributes[len].clear();
} else if (arrayAttributes[i].isAccessor()) {
- arrayData[i].value = Value::fromReturnedValue(getValue(arrayData + i, arrayAttributes[i]));
+ arrayData[i].value = getValue(arrayData + i, arrayAttributes[i]);
arrayAttributes[i] = Attr_Data;
}
}
static ReturnedValue getValue(const ValueRef thisObject, const Property *p, PropertyAttributes attrs);
ReturnedValue getValue(const Property *p, PropertyAttributes attrs) const {
Scope scope(this->engine());
- ScopedValue t(scope, Value::fromObject(const_cast<Object *>(this)));
+ ScopedValue t(scope, const_cast<Object *>(this));
return getValue(t, p, attrs);
}
void arrayConcat(const ArrayObject *other);
void arraySort(ExecutionContext *context, ObjectRef thisObject, const ValueRef comparefn, uint arrayDataLen);
- ReturnedValue arrayIndexOf(Value v, uint fromIndex, uint arrayDataLen, ExecutionContext *ctx, Object *o);
+ ReturnedValue arrayIndexOf(const ValueRef v, uint fromIndex, uint arrayDataLen, ExecutionContext *ctx, Object *o);
void arrayReserve(uint n);
void ensureArrayAttributes();
};
struct BooleanObject: Object {
- Value value;
- BooleanObject(ExecutionEngine *engine, const ValueRef value): Object(engine->booleanClass), value(*value) { type = Type_BooleanObject; }
+ SafeValue value;
+ BooleanObject(ExecutionEngine *engine, const ValueRef val)
+ : Object(engine->booleanClass) {
+ type = Type_BooleanObject;
+ value = val;
+ }
protected:
- BooleanObject(InternalClass *ic): Object(ic), value(Primitive::fromBoolean(false)) { type = Type_BooleanObject; }
+ BooleanObject(InternalClass *ic)
+ : Object(ic) {
+ type = Type_BooleanObject;
+ value = Encode(false);
+ }
};
struct NumberObject: Object {
- Value value;
- NumberObject(ExecutionEngine *engine, const ValueRef value): Object(engine->numberClass), value(*value) { type = Type_NumberObject; }
+ SafeValue value;
+ NumberObject(ExecutionEngine *engine, const ValueRef val)
+ : Object(engine->numberClass) {
+ type = Type_NumberObject;
+ value = val;
+ }
protected:
- NumberObject(InternalClass *ic): Object(ic), value(Primitive::fromInt32(0)) { type = Type_NumberObject; }
+ NumberObject(InternalClass *ic)
+ : Object(ic) {
+ type = Type_NumberObject;
+ value = Encode((int)0);
+ }
};
struct ArrayObject: Object {
inline uint Object::arrayLength() const
{
if (isArrayObject()) {
- // length is always the first property of an array
- Value v = memberData[ArrayObject::LengthPropertyIndex].value;
- if (v.isInteger())
- return v.integerValue();
- return Primitive::toUInt32(v.doubleValue());
+ if (memberData[ArrayObject::LengthPropertyIndex].value.isInteger())
+ return memberData[ArrayObject::LengthPropertyIndex].value.integerValue();
+ return Primitive::toUInt32(memberData[ArrayObject::LengthPropertyIndex].value.doubleValue());
}
return 0;
}
obj->setPrototype(proto.getPointer());
return obj.asReturnedValue();
}
- return Value::fromReturnedValue(__qmljs_to_object(v4->current, ValueRef(&callData->args[0]))).asReturnedValue();
+ return __qmljs_to_object(v4->current, ValueRef(&callData->args[0]));
}
ReturnedValue ObjectCtor::call(Managed *m, CallData *callData)
ctx->throwTypeError();
Scoped<Object> o(scope, ctx->argument(1), Scoped<Object>::Convert);
+ ScopedValue val(scope);
ObjectIterator it(o.getPointer(), ObjectIterator::EnumerableOnly);
while (1) {
break;
Property n;
PropertyAttributes nattrs;
- toPropertyDescriptor(ctx, Value::fromReturnedValue(o->getValue(pd, attrs)), &n, &nattrs);
+ val = o->getValue(pd, attrs);
+ toPropertyDescriptor(ctx, val, &n, &nattrs);
bool ok;
if (name)
ok = O->__defineOwnProperty__(ctx, name, n, nattrs);
return Encode::undefined();
}
-void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Property *desc, PropertyAttributes *attrs)
+void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, const ValueRef v, Property *desc, PropertyAttributes *attrs)
{
Scope scope(ctx);
ScopedObject o(scope, v);
attrs->clear();
desc->setGetter(0);
desc->setSetter(0);
+ ScopedValue tmp(scope);
if (o->__hasProperty__(ctx->engine->id_enumerable))
- attrs->setEnumerable(Value::fromReturnedValue(o->get(ctx->engine->id_enumerable)).toBoolean());
+ attrs->setEnumerable((tmp = o->get(ctx->engine->id_enumerable))->toBoolean());
if (o->__hasProperty__(ctx->engine->id_configurable))
- attrs->setConfigurable(Value::fromReturnedValue(o->get(ctx->engine->id_configurable)).toBoolean());
+ attrs->setConfigurable((tmp = o->get(ctx->engine->id_configurable))->toBoolean());
if (o->__hasProperty__(ctx->engine->id_get)) {
ScopedValue get(scope, o->get(ctx->engine->id_get));
if (o->__hasProperty__(ctx->engine->id_writable)) {
if (attrs->isAccessor())
ctx->throwTypeError();
- attrs->setWritable(Value::fromReturnedValue(o->get(ctx->engine->id_writable)).toBoolean());
+ attrs->setWritable((tmp = o->get(ctx->engine->id_writable))->toBoolean());
// writable forces it to be a data descriptor
desc->value = Primitive::undefinedValue();
}
if (o->__hasProperty__(ctx->engine->id_value)) {
if (attrs->isAccessor())
ctx->throwTypeError();
- desc->value = Value::fromReturnedValue(o->get(ctx->engine->id_value));
+ desc->value = o->get(ctx->engine->id_value);
attrs->setType(PropertyAttributes::Data);
}
Scope scope(engine);
// Let obj be the result of creating a new object as if by the expression new Object() where Object
// is the standard built-in constructor with that name.
- Scoped<Object> o(scope, engine->newObject());
+ ScopedObject o(scope, engine->newObject());
ScopedString s(scope);
Property pd;
s = engine->newString(QStringLiteral("writable"));
o->__defineOwnProperty__(ctx, s, pd, Attr_Data);
} else {
- pd.value = desc->getter() ? Value::fromObject(desc->getter()) : Primitive::undefinedValue();
+ pd.value = desc->getter() ? desc->getter()->asReturnedValue() : Encode::undefined();
s = engine->newString(QStringLiteral("get"));
o->__defineOwnProperty__(ctx, s, pd, Attr_Data);
- pd.value = desc->setter() ? Value::fromObject(desc->setter()) : Primitive::undefinedValue();
+ pd.value = desc->setter() ? desc->setter()->asReturnedValue() : Encode::undefined();
s = engine->newString(QStringLiteral("set"));
o->__defineOwnProperty__(ctx, s, pd, Attr_Data);
}
static ReturnedValue method_get_proto(SimpleCallContext *ctx);
static ReturnedValue method_set_proto(SimpleCallContext *ctx);
- static void toPropertyDescriptor(ExecutionContext *ctx, Value v, Property *desc, PropertyAttributes *attrs);
+ static void toPropertyDescriptor(ExecutionContext *ctx, const ValueRef v, Property *desc, PropertyAttributes *attrs);
static ReturnedValue fromPropertyDescriptor(ExecutionContext *ctx, const Property *desc, PropertyAttributes attrs);
static Returned<ArrayObject> *getOwnPropertyNames(ExecutionEngine *v4, const ValueRef o);
using namespace QV4;
-static QPair<QObject *, int> extractQtMethod(QV4::FunctionObject *function)
+static QPair<QObject *, int> extractQtMethod(QV4::FunctionObjectRef function)
{
- if (function && function->subtype == QV4::FunctionObject::WrappedQtMethod) {
- QObjectMethod *method = static_cast<QObjectMethod*>(function);
- return qMakePair(method->object(), method->methodIndex());
+ QV4::ExecutionEngine *v4 = function->engine();
+ if (v4) {
+ QV4::Scope scope(v4);
+ QV4::Scoped<QObjectMethod> method(scope, function->as<QObjectMethod>());
+ if (method)
+ return qMakePair(method->object(), method->methodIndex());
}
return qMakePair((QObject *)0, -1);
}
-static QPair<QObject *, int> extractQtSignal(const Value &value)
+static QPair<QObject *, int> extractQtSignal(const ValueRef value)
{
- if (QV4::FunctionObject *function = value.asFunctionObject())
- return extractQtMethod(function);
-
- if (QV4::QmlSignalHandler *handler = value.as<QV4::QmlSignalHandler>())
- return qMakePair(handler->object(), handler->signalIndex());
+ QV4::ExecutionEngine *v4 = value->engine();
+ if (v4) {
+ QV4::Scope scope(v4);
+ QV4::ScopedFunctionObject function(scope, value);
+ if (function)
+ return extractQtMethod(function);
+
+ QV4::Scoped<QV4::QmlSignalHandler> handler(scope, value);
+ if (handler)
+ return qMakePair(handler->object(), handler->signalIndex());
+ }
return qMakePair((QObject *)0, -1);
}
return vmemo->vmeMethod(result->coreIndex);
} else if (result->isV4Function()) {
QV4::Scoped<QV4::Object> qmlcontextobject(scope, ctx->engine->qmlContextObject());
- return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex,
- qmlcontextobject.asValue()).asReturnedValue();
+ return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex, qmlcontextobject);
} else if (result->isSignalHandler()) {
QV4::Scoped<QV4::QmlSignalHandler> handler(scope, new (ctx->engine->memoryManager) QV4::QmlSignalHandler(ctx->engine, m_object, result->coreIndex));
return handler.asReturnedValue();
} else {
- return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex).asReturnedValue();
+ return QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, result->coreIndex);
}
}
// tainted object list
Scoped<Object> alternateWrapper(scope, (Object *)0);
if (engine->m_multiplyWrappedQObjects && ddata->hasTaintedV8Object)
- alternateWrapper = Value::fromObject(engine->m_multiplyWrappedQObjects->value(object));
+ alternateWrapper = engine->m_multiplyWrappedQObjects->value(object);
// If our tainted handle doesn't exist or has been collected, and there isn't
// a handle in the ddata, we can assume ownership of the ddata->v8object
++it->arrayIndex;
if (attributes)
*attributes = QV4::Attr_Data;
- it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(that->get(n));
+ it->tmpDynamicProperty.value = that->get(n);
return &it->tmpDynamicProperty;
}
const int methodCount = mo->methodCount();
++it->arrayIndex;
if (attributes)
*attributes = QV4::Attr_Data;
- it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(that->get(n));
+ it->tmpDynamicProperty.value = that->get(n);
return &it->tmpDynamicProperty;
}
return QV4::Object::advanceIterator(m, it, name, index, attributes);
QV4::ExecutionContext *ctx = v4->current;
QV4::ScopedCallData callData(scope, argCount);
- callData->thisObject = This->thisObject.isUndefined() ? Value::fromObject(v4->globalObject) : Value::fromReturnedValue(This->thisObject.value());
+ callData->thisObject = This->thisObject.isUndefined() ? v4->globalObject->asReturnedValue() : This->thisObject.value();
for (int ii = 0; ii < argCount; ++ii) {
int type = argsTypes[ii + 1];
if (type == qMetaTypeId<QVariant>()) {
- callData->args[ii] = QV4::Value::fromReturnedValue(v4->v8Engine->fromVariant(*((QVariant *)metaArgs[ii + 1])));
+ callData->args[ii] = v4->v8Engine->fromVariant(*((QVariant *)metaArgs[ii + 1]));
} else {
- callData->args[ii] = QV4::Value::fromReturnedValue(v4->v8Engine->fromVariant(QVariant(type, metaArgs[ii + 1])));
+ callData->args[ii] = v4->v8Engine->fromVariant(QVariant(type, metaArgs[ii + 1]));
}
}
(connection->thisObject.isUndefined() || __qmljs_strict_equal(connection->thisObject, thisObject))) {
QV4::ScopedFunctionObject f(scope, connection->function.value());
- QPair<QObject *, int> connectedFunctionData = extractQtMethod(f.getPointer());
+ QPair<QObject *, int> connectedFunctionData = extractQtMethod(f);
if (connectedFunctionData.first == receiverToDisconnect &&
connectedFunctionData.second == slotIndexToDisconnect) {
*ret = true;
if (ctx->callData->argc == 0)
V4THROW_ERROR("Function.prototype.disconnect: no arguments given");
+ QV4::Scope scope(ctx);
+
QPair<QObject *, int> signalInfo = extractQtSignal(ctx->callData->thisObject);
QObject *signalObject = signalInfo.first;
int signalIndex = signalInfo.second;
if (signalIndex < 0 || signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal)
V4THROW_ERROR("Function.prototype.disconnect: this object is not a signal");
- QV4::Value functionValue = QV4::Primitive::undefinedValue();
- QV4::Value functionThisValue = QV4::Primitive::undefinedValue();
+ QV4::ScopedFunctionObject functionValue(scope);
+ QV4::ScopedValue functionThisValue(scope, QV4::Encode::undefined());
if (ctx->callData->argc == 1) {
functionValue = ctx->callData->args[0];
functionValue = ctx->callData->args[1];
}
- if (!functionValue.asFunctionObject())
+ if (!functionValue)
V4THROW_ERROR("Function.prototype.disconnect: target is not a function");
- if (!functionThisValue.isUndefined() && !functionThisValue.isObject())
+ if (!functionThisValue->isUndefined() && !functionThisValue->isObject())
V4THROW_ERROR("Function.prototype.disconnect: target this is not an object");
- QPair<QObject *, int> functionData = extractQtMethod(functionValue.asFunctionObject());
+ QPair<QObject *, int> functionData = extractQtMethod(functionValue);
void *a[] = {
ctx->engine,
- &functionValue,
- &functionThisValue,
+ functionValue.ptr,
+ functionThisValue.ptr,
functionData.first,
&functionData.second
};
QV4::Scoped<ArrayObject> array(scope, v4->newArrayObject());
array->arrayReserve(list.count());
for (int ii = 0; ii < list.count(); ++ii) {
- array->arrayData[ii].value = Value::fromReturnedValue(QV4::QObjectWrapper::wrap(v4, list.at(ii)));
+ array->arrayData[ii].value = QV4::QObjectWrapper::wrap(v4, list.at(ii));
array->arrayDataLen = ii + 1;
}
array->setArrayLengthUnchecked(list.count());
}
}
-Value QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
+ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal)
{
- return Value::fromObject(new (scope->engine->memoryManager) QObjectMethod(scope, object, index, qmlGlobal));
+ return (new (scope->engine->memoryManager) QObjectMethod(scope, object, index, qmlGlobal))->asReturnedValue();
}
-QObjectMethod::QObjectMethod(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
+QObjectMethod::QObjectMethod(ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal)
: FunctionObject(scope)
, m_object(object)
, m_index(index)
{
vtbl = &static_vtbl;
subtype = WrappedQtMethod;
- m_qmlGlobal = qmlGlobal.asReturnedValue();
+ m_qmlGlobal = qmlGlobal;
}
QV4::ReturnedValue QObjectMethod::method_toString(QV4::ExecutionContext *ctx)
return ctx->engine->newString(result)->asReturnedValue();
}
-QV4::ReturnedValue QObjectMethod::method_destroy(QV4::ExecutionContext *ctx, const Value *args, int argc)
+QV4::ReturnedValue QObjectMethod::method_destroy(QV4::ExecutionContext *ctx, const ValueRef args, int argc)
{
if (!m_object)
return Encode::undefined();
enum { DestroyMethod = -1, ToStringMethod = -2 };
- static Value create(QV4::ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal = Primitive::undefinedValue());
+ static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal = Primitive::undefinedValue());
int methodIndex() const { return m_index; }
QObject *object() const { return m_object.data(); }
private:
- QObjectMethod(QV4::ExecutionContext *scope, QObject *object, int index, const QV4::Value &qmlGlobal);
+ QObjectMethod(QV4::ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal);
QV4::ReturnedValue method_toString(QV4::ExecutionContext *ctx);
- QV4::ReturnedValue method_destroy(QV4::ExecutionContext *ctx, const Value *args, int argc);
+ QV4::ReturnedValue method_destroy(QV4::ExecutionContext *ctx, const ValueRef args, int argc);
QPointer<QObject> m_object;
int m_index;
ReturnedValue RegExp::get(Managed *, const StringRef, bool *)
{
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
ReturnedValue RegExp::getIndexed(Managed *m, uint index, bool *hasProperty)
{
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
void RegExp::put(Managed *m, const StringRef name, const ValueRef value)
ctx->throwTypeError();
ScopedCallData callData(scope, ctx->callData->argc);
- memcpy(callData->args, ctx->callData->args, ctx->callData->argc*sizeof(Value));
- RegExpObject *re = Value::fromReturnedValue(ctx->engine->regExpCtor.asFunctionObject()->construct(callData)).as<RegExpObject>();
+ memcpy(callData->args, ctx->callData->args, ctx->callData->argc*sizeof(SafeValue));
+
+ Scoped<RegExpObject> re(scope, ctx->engine->regExpCtor.asFunctionObject()->construct(callData));
r->value = re->value;
r->global = re->global;
if (o) {
uint n = index->asArrayIndex();
if (n < UINT_MAX) {
- return Primitive::fromBoolean(o->deleteIndexedProperty(n)).asReturnedValue();
+ return Encode((bool)o->deleteIndexedProperty(n));
}
}
}
double x = __qmljs_to_number(pleft);
double y = __qmljs_to_number(pright);
- return Primitive::fromDouble(x + y).asReturnedValue();
+ return Encode(x + y);
}
QV4::ReturnedValue __qmljs_instanceof(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
ctx->throwTypeError();
bool r = o->hasInstance(left);
- return Primitive::fromBoolean(r).asReturnedValue();
+ return Encode(r);
}
QV4::ReturnedValue __qmljs_in(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
Scope scope(ctx);
ScopedString s(scope, left->toString(ctx));
bool r = right->objectValue()->__hasProperty__(s);
- return Primitive::fromBoolean(r).asReturnedValue();
+ return Encode(r);
}
static void inplaceBitOp(ExecutionContext *ctx, const StringRef name, const ValueRef value, BinOp op)
ExecutionContext *ctx = engine->current;
Scope scope(ctx);
ScopedCallData callData(scope, 0);
- callData->thisObject = Value::fromObject(object);
+ callData->thisObject = object;
ScopedValue conv(scope, object->get(*meth1));
if (FunctionObject *o = conv->asFunctionObject()) {
- Value r = Value::fromReturnedValue(o->call(callData));
- if (r.isPrimitive())
- return r.asReturnedValue();
+ ScopedValue r(scope, o->call(callData));
+ if (r->isPrimitive())
+ return r->asReturnedValue();
}
conv = object->get(*meth2);
if (FunctionObject *o = conv->asFunctionObject()) {
- Value r = Value::fromReturnedValue(o->call(callData));
- if (r.isPrimitive())
- return r.asReturnedValue();
+ ScopedValue r(scope, o->call(callData));
+ if (r->isPrimitive())
+ return r->asReturnedValue();
}
ctx->throwTypeError();
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
Bool __qmljs_to_boolean(const ValueRef value)
if (idx < UINT_MAX) {
if (String *str = object->asString()) {
if (idx >= (uint)str->toQString().length()) {
- return Primitive::undefinedValue().asReturnedValue();
+ return Encode::undefined();
}
const QString s = str->toQString().mid(idx, 1);
return scope.engine->newString(s)->asReturnedValue();
double dx = __qmljs_to_number(x);
return dx == y->asDouble();
} else if (x->isBoolean()) {
- Value nx = Primitive::fromDouble((double) x->booleanValue());
- return __qmljs_cmp_eq(ValueRef(&nx), y);
+ return __qmljs_cmp_eq(Primitive::fromDouble((double) x->booleanValue()), y);
} else if (y->isBoolean()) {
- Value ny = Primitive::fromDouble((double) y->booleanValue());
- return __qmljs_cmp_eq(x, ValueRef(&ny));
+ return __qmljs_cmp_eq(x, Primitive::fromDouble((double) y->booleanValue()));
} else if ((x->isNumber() || x->isString()) && y->isObject()) {
Scope scope(y->objectValue()->engine());
ScopedValue py(scope, __qmljs_to_primitive(y, PREFERREDTYPE_HINT));
Object *base;
ScopedValue func(scope, context->getPropertyAndBase(name, &base));
if (base)
- callData->thisObject = Value::fromObject(base);
+ callData->thisObject = base;
FunctionObject *o = func->asFunctionObject();
if (!o) {
QString objectAsString = QStringLiteral("[null]");
- if (base)
- objectAsString = Value::fromObject(base).toQStringNoThrow();
+ if (base) {
+ ScopedValue b(scope, base);
+ objectAsString = b->toQStringNoThrow();
+ }
QString msg = QStringLiteral("Property '%1' of object %2 is not a function").arg(name->toQString()).arg(objectAsString);
context->throwTypeError(msg);
}
ReturnedValue __qmljs_call_element(ExecutionContext *context, const ValueRef index, CallDataRef callData)
{
Scope scope(context);
- Object *baseObject = callData->thisObject.toObject(context);
- callData->thisObject = Value::fromObject(baseObject);
+ ScopedObject baseObject(scope, callData->thisObject.toObject(context));
+ callData->thisObject = baseObject;
ScopedString s(scope, index->toString(context));
- Scoped<Object> o(scope, baseObject->get(s));
+ ScopedObject o(scope, baseObject->get(s));
if (!o)
context->throwTypeError();
{
TRACE1(value);
- if (value->isInteger())
- return Primitive::fromInt32(value->integerValue() + 1).asReturnedValue();
+ if (value->isInteger() && value->integerValue() < INT_MAX)
+ return Encode(value->integerValue() + 1);
else {
double d = value->toNumber();
- return Primitive::fromDouble(d + 1).asReturnedValue();
+ return Encode(d + 1.);
}
}
{
TRACE1(value);
- if (value->isInteger())
- return Primitive::fromInt32(value->integerValue() - 1).asReturnedValue();
+ if (value->isInteger() && value->integerValue() > INT_MIN)
+ return Encode(value->integerValue() - 1);
else {
double d = value->toNumber();
- return Primitive::fromDouble(d - 1).asReturnedValue();
+ return Encode(d - 1.);
}
}
// +0 != -0, so we need to convert to double when negating 0
if (value->isInteger() && value->integerValue())
- return QV4::Primitive::fromInt32(-value->integerValue()).asReturnedValue();
+ return Encode(-value->integerValue());
else {
double n = __qmljs_to_number(value);
- return QV4::Primitive::fromDouble(-n).asReturnedValue();
+ return Encode(-n);
}
}
TRACE2(left, right);
if (QV4::Value::integerCompatible(*left, *right))
- return QV4::Primitive::fromInt32(left->integerValue() | right->integerValue()).asReturnedValue();
+ return Encode(left->integerValue() | right->integerValue());
int lval = left->toInt32();
int rval = right->toInt32();
- return QV4::Primitive::fromInt32(lval | rval).asReturnedValue();
+ return Encode(lval | rval);
}
inline ReturnedValue __qmljs_bit_xor(const QV4::ValueRef left, const QV4::ValueRef right)
TRACE2(left, right);
if (QV4::Value::integerCompatible(*left, *right))
- return QV4::Primitive::fromInt32(left->integerValue() ^ right->integerValue()).asReturnedValue();
+ return Encode(left->integerValue() ^ right->integerValue());
int lval = left->toInt32();
int rval = right->toInt32();
- return QV4::Primitive::fromInt32(lval ^ rval).asReturnedValue();
+ return Encode(lval ^ rval);
}
inline ReturnedValue __qmljs_bit_and(const QV4::ValueRef left, const QV4::ValueRef right)
TRACE2(left, right);
if (QV4::Value::integerCompatible(*left, *right))
- return QV4::Primitive::fromInt32(left->integerValue() & right->integerValue()).asReturnedValue();
+ return Encode(left->integerValue() & right->integerValue());
int lval = left->toInt32();
int rval = right->toInt32();
- return QV4::Primitive::fromInt32(lval & rval).asReturnedValue();
+ return Encode(lval & rval);
}
inline QV4::ReturnedValue __qmljs_add(QV4::ExecutionContext *ctx, const QV4::ValueRef left, const QV4::ValueRef right)
if (QV4::Value::integerCompatible(*left, *right) && right->integerValue() != 0) {
int intRes = left->integerValue() % right->integerValue();
if (intRes != 0 || left->integerValue() >= 0)
- return QV4::Primitive::fromInt32(intRes).asReturnedValue();
+ return Encode(intRes);
}
double lval = __qmljs_to_number(left);
TRACE2(left, right);
if (QV4::Value::integerCompatible(*left, *right))
- return QV4::Primitive::fromInt32(left->integerValue() << ((uint(right->integerValue()) & 0x1f))).asReturnedValue();
+ return Encode((int)(left->integerValue() << ((uint(right->integerValue()) & 0x1f))));
int lval = left->toInt32();
unsigned rval = right->toUInt32() & 0x1f;
- return QV4::Primitive::fromInt32(lval << rval).asReturnedValue();
+ return Encode((int)(lval << rval));
}
inline QV4::ReturnedValue __qmljs_shr(const QV4::ValueRef left, const QV4::ValueRef right)
TRACE2(left, right);
if (QV4::Value::integerCompatible(*left, *right))
- return QV4::Primitive::fromInt32(left->integerValue() >> ((uint(right->integerValue()) & 0x1f))).asReturnedValue();
+ return Encode((int)(left->integerValue() >> ((uint(right->integerValue()) & 0x1f))));
int lval = left->toInt32();
unsigned rval = right->toUInt32() & 0x1f;
- return QV4::Primitive::fromInt32(lval >> rval).asReturnedValue();
+ return Encode((int)(lval >> rval));
}
inline QV4::ReturnedValue __qmljs_ushr(const QV4::ValueRef left, const QV4::ValueRef right)
res = lval >> rval;
}
- if (res > INT_MAX)
- return QV4::Primitive::fromDouble(res).asReturnedValue();
- else
- return QV4::Primitive::fromInt32(res).asReturnedValue();
+ return Encode(res);
}
inline QV4::ReturnedValue __qmljs_gt(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- return QV4::Primitive::fromBoolean(__qmljs_cmp_gt(left, right)).asReturnedValue();
+ bool r = __qmljs_cmp_gt(left, right);
+ return Encode(r);
}
inline QV4::ReturnedValue __qmljs_lt(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- return QV4::Primitive::fromBoolean(__qmljs_cmp_lt(left, right)).asReturnedValue();
+ bool r = __qmljs_cmp_lt(left, right);
+ return Encode(r);
}
inline QV4::ReturnedValue __qmljs_ge(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- return QV4::Primitive::fromBoolean(__qmljs_cmp_ge(left, right)).asReturnedValue();
+ bool r = __qmljs_cmp_ge(left, right);
+ return Encode(r);
}
inline QV4::ReturnedValue __qmljs_le(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- return QV4::Primitive::fromBoolean(__qmljs_cmp_le(left, right)).asReturnedValue();
+ bool r = __qmljs_cmp_le(left, right);
+ return Encode(r);
}
inline QV4::ReturnedValue __qmljs_eq(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- return QV4::Primitive::fromBoolean(__qmljs_cmp_eq(left, right)).asReturnedValue();
+ bool r = __qmljs_cmp_eq(left, right);
+ return Encode(r);
}
inline QV4::ReturnedValue __qmljs_ne(const QV4::ValueRef left, const QV4::ValueRef right)
{
TRACE2(left, right);
- return QV4::Primitive::fromBoolean(!__qmljs_cmp_eq(left, right)).asReturnedValue();
+ bool r = !__qmljs_cmp_eq(left, right);
+ return Encode(r);
}
inline QV4::ReturnedValue __qmljs_se(const QV4::ValueRef left, const QV4::ValueRef right)
TRACE2(left, right);
bool r = __qmljs_strict_equal(left, right);
- return QV4::Primitive::fromBoolean(r).asReturnedValue();
+ return Encode(r);
}
inline QV4::ReturnedValue __qmljs_sne(const QV4::ValueRef left, const QV4::ValueRef right)
TRACE2(left, right);
bool r = ! __qmljs_strict_equal(left, right);
- return QV4::Primitive::fromBoolean(r).asReturnedValue();
+ return Encode(r);
}
inline QV4::Bool __qmljs_cmp_eq(const QV4::ValueRef left, const QV4::ValueRef right)
~Scope() {
#ifndef QT_NO_DEBUG
Q_ASSERT(engine->jsStackTop >= mark);
- memset(mark, 0, (engine->jsStackTop - mark)*sizeof(Value));
+ memset(mark, 0, (engine->jsStackTop - mark)*sizeof(SafeValue));
#endif
engine->jsStackTop = mark;
}
- Value *alloc(int nValues) {
+ SafeValue *alloc(int nValues) {
SafeValue *ptr = engine->jsStackTop;
engine->jsStackTop += nValues;
#ifndef QT_NO_DEBUG
struct ScopedCallData {
ScopedCallData(Scope &scope, int argc)
{
- int size = qMax(argc, (int)QV4::Global::ReservedArgumentCount) + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value);
+ int size = qMax(argc, (int)QV4::Global::ReservedArgumentCount) + qOffsetOf(QV4::CallData, args)/sizeof(QV4::SafeValue);
ptr = reinterpret_cast<CallData *>(scope.engine->stackPush(size));
ptr->tag = QV4::Value::Integer_Type;
ptr->argc = argc;
isel->setUseFastLookups(false);
QV4::CompiledData::CompilationUnit *compilationUnit = isel->compile();
vmFunction = compilationUnit->linkToEngine(v4);
- ScopedValue holder(valueScope, Value::fromObject(new (v4->memoryManager) CompilationUnitHolder(v4, compilationUnit)));
+ ScopedValue holder(valueScope, new (v4->memoryManager) CompilationUnitHolder(v4, compilationUnit));
compilationUnitHolder = holder;
}
F(QString, QString, QStringList, QString()) \
F(QUrl, Url, QList<QUrl>, QUrl())
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *engine, const QString &element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, const QString &element)
{
- QV4::Value v;
- v = engine->newString(element)->asReturnedValue();
- return v;
+ return engine->newString(element)->asReturnedValue();
}
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *, int element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *, int element)
{
- return QV4::Primitive::fromInt32(element);
+ return QV4::Encode(element);
}
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *engine, const QUrl &element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, const QUrl &element)
{
- QV4::Value v;
- v = engine->newString(element.toString())->asReturnedValue();
- return v;
+ return engine->newString(element.toString())->asReturnedValue();
}
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *, qreal element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *, qreal element)
{
- return QV4::Primitive::fromDouble(element);
+ return QV4::Encode(element);
}
-static QV4::Value convertElementToValue(QV4::ExecutionEngine *, bool element)
+static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *, bool element)
{
- return QV4::Primitive::fromBoolean(element);
+ return QV4::Encode(element);
}
static QString convertElementToString(const QString &element)
defineAccessorProperty(QStringLiteral("length"), method_get_length, method_set_length);
}
- QV4::Value containerGetIndexed(uint index, bool *hasProperty)
+ QV4::ReturnedValue containerGetIndexed(uint index, bool *hasProperty)
{
/* Qt containers have int (rather than uint) allowable indexes. */
if (index > INT_MAX) {
generateWarning(engine()->current, QLatin1String("Index out of range during indexed get"));
if (hasProperty)
*hasProperty = false;
- return QV4::Primitive::undefinedValue();
+ return Encode::undefined();
}
if (m_isReference) {
if (!m_object) {
if (hasProperty)
*hasProperty = false;
- return QV4::Primitive::undefinedValue();
+ return Encode::undefined();
}
loadReference();
}
}
if (hasProperty)
*hasProperty = false;
- return QV4::Primitive::undefinedValue();
+ return Encode::undefined();
}
void containerPutIndexed(uint index, const QV4::ValueRef value)
bool m_isReference;
static QV4::ReturnedValue getIndexed(QV4::Managed *that, uint index, bool *hasProperty)
- { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(index, hasProperty).asReturnedValue(); }
+ { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(index, hasProperty); }
static void putIndexed(Managed *that, uint index, const QV4::ValueRef value)
{ static_cast<QQmlSequence<Container> *>(that)->containerPutIndexed(index, value); }
static QV4::PropertyAttributes queryIndexed(const QV4::Managed *that, uint index)