*/
QJSValue QJSValue::property(const QString& name) const
{
+ ExecutionEngine *engine = d->engine;
+ if (!engine)
+ return QJSValue();
+ QV4::Scope scope(engine);
+
Object *o = d->value.asObject();
if (!o)
return QJSValue();
- ExecutionEngine *engine = d->engine;
String *s = engine->newString(name);
uint idx = s->asArrayIndex();
if (idx < UINT_MAX)
s->makeIdentifier();
QV4::ExecutionContext *ctx = engine->current;
try {
- QV4::Value v = o->get(s);
+ QV4::ScopedValue v(scope, o->get(s));
return new QJSValuePrivate(engine, v);
} catch (QV4::Exception &e) {
e.accept(ctx);
*/
QJSValue QJSValue::property(quint32 arrayIndex) const
{
+ ExecutionEngine *engine = d->engine;
+ if (!engine)
+ return QJSValue();
+
+ QV4::Scope scope(engine);
Object *o = d->value.asObject();
if (!o)
return QJSValue();
- ExecutionEngine *engine = d->engine;
QV4::ExecutionContext *ctx = engine->current;
try {
- QV4::Value v = arrayIndex == UINT_MAX ? o->get(engine->id_uintMax) : o->getIndexed(arrayIndex);
+ QV4::ScopedValue v(scope, arrayIndex == UINT_MAX ? o->get(engine->id_uintMax) : o->getIndexed(arrayIndex).asReturnedValue());
return new QJSValuePrivate(engine, v);
} catch (QV4::Exception &e) {
e.accept(ctx);
QV4::Object *o = d_ptr->iterator.object;
QV4::ExecutionEngine *engine = o->internalClass->engine;
+ QV4::Scope scope(engine);
+
QV4::ExecutionContext *ctx = engine->current;
try {
- QV4::Value v;
+ QV4::ScopedValue v(scope);
if (d_ptr->currentName)
v = o->get(d_ptr->currentName);
else if (d_ptr->currentIndex != UINT_MAX)
{
if (o->isArrayObject())
return o->arrayLength();
- return o->get(ctx->engine->id_length).toUInt32();
+ Scope scope(ctx);
+ ScopedValue v(scope, o->get(ctx->engine->id_length));
+ return v->toUInt32();
}
Value ArrayPrototype::method_isArray(SimpleCallContext *ctx)
Value ArrayPrototype::method_toString(SimpleCallContext *ctx)
{
+ QV4::Scope scope(ctx);
QV4::Object *o = ctx->thisObject.toObject(ctx);
- FunctionObject *f = o->get(ctx->engine->newString("join")).asFunctionObject();
+ ScopedValue v(scope, o->get(ctx->engine->newString("join")));
+ FunctionObject *f = v->asFunctionObject();
if (f) {
- Scope scope(ctx);
ScopedCallData d(scope, 0);
d->thisObject = ctx->thisObject;
return Value::fromReturnedValue(f->call(d));
Value ArrayPrototype::method_join(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
Value arg = ctx->argument(0);
QString r4;
else
r4 = arg.toString(ctx)->toQString();
- Value self = ctx->thisObject;
- const Value length = self.property(ctx, ctx->engine->id_length);
- const quint32 r2 = Value::toUInt32(length.isUndefined() ? 0 : length.toNumber());
+ Scoped<Object> self(scope, ctx->thisObject);
+ ScopedValue length(scope, self->get(ctx->engine->id_length));
+ const quint32 r2 = Value::toUInt32(length->isUndefined() ? 0 : length->toNumber());
static QSet<Object *> visitedArrayElements;
- if (! r2 || visitedArrayElements.contains(self.objectValue()))
+ if (! r2 || visitedArrayElements.contains(self.getPointer()))
return Value::fromString(ctx, QString());
// avoid infinite recursion
- visitedArrayElements.insert(self.objectValue());
+ visitedArrayElements.insert(self.getPointer());
QString R;
// ### FIXME
- if (ArrayObject *a = self.asArrayObject()) {
+ if (ArrayObject *a = self->asArrayObject()) {
for (uint i = 0; i < a->arrayLength(); ++i) {
if (i)
R += r4;
//
// crazy!
//
- Value r6 = self.property(ctx, ctx->engine->newString(QStringLiteral("0")));
- if (!(r6.isUndefined() || r6.isNull()))
- R = r6.toString(ctx)->toQString();
+ ScopedValue r6(scope, self->get(ctx->engine->newString(QStringLiteral("0"))));
+ if (!r6->isNullOrUndefined())
+ R = r6->toString(ctx)->toQString();
+ ScopedValue r12(scope);
for (quint32 k = 1; k < r2; ++k) {
R += r4;
String *name = Value::fromDouble(k).toString(ctx);
- Value r12 = self.property(ctx, name);
+ r12 = self->get(name);
- if (! (r12.isUndefined() || r12.isNull()))
- R += r12.toString(ctx)->toQString();
+ if (!r12->isNullOrUndefined())
+ R += r12->toString(ctx)->toQString();
}
}
- visitedArrayElements.remove(self.objectValue());
+ visitedArrayElements.remove(self.getPointer());
return Value::fromString(ctx, R);
}
if (pidx < UINT_MAX && (!instance->arrayAttributes || !instance->arrayAttributes[0].isGeneric()))
front = instance->arrayData + pidx;
- Value result = front ? instance->getValue(front, instance->arrayAttributes ? instance->arrayAttributes[pidx] : Attr_Data) : Value::undefinedValue();
+ Value result = front ? Value::fromReturnedValue(instance->getValue(front, instance->arrayAttributes ? instance->arrayAttributes[pidx] : Attr_Data)) : Value::undefinedValue();
if (!instance->protoHasArray() && instance->arrayDataLen <= len) {
if (!instance->sparseArray) {
Object *o = ctx->thisObject.toObject(ctx);
ArrayObject *result = ctx->engine->newArrayObject();
- uint len = o->get(ctx->engine->id_length).toUInt32();
+ uint len = ArrayPrototype::getLength(ctx, o);
double s = ctx->argument(0).toInteger();
uint start;
if (s < 0)
ReturnedValue ExecutionContext::getProperty(String *name)
{
+ Scope scope(this);
+ ScopedValue v(scope);
name->makeIdentifier();
if (name->isEqualTo(engine->id_this))
Object *w = static_cast<WithContext *>(ctx)->withObject;
hasWith = true;
bool hasProperty = false;
- Value v = w->get(name, &hasProperty);
+ v = w->get(name, &hasProperty);
if (hasProperty) {
return v.asReturnedValue();
}
}
if (c->activation) {
bool hasProperty = false;
- Value v = c->activation->get(name, &hasProperty);
+ v = c->activation->get(name, &hasProperty);
if (hasProperty)
return v.asReturnedValue();
}
else if (ctx->type == Type_GlobalContext) {
GlobalContext *g = static_cast<GlobalContext *>(ctx);
bool hasProperty = false;
- Value v = g->global->get(name, &hasProperty);
+ v = g->global->get(name, &hasProperty);
if (hasProperty)
return v.asReturnedValue();
}
ReturnedValue ExecutionContext::getPropertyNoThrow(String *name)
{
+ Scope scope(this);
+ ScopedValue v(scope);
name->makeIdentifier();
if (name->isEqualTo(engine->id_this))
Object *w = static_cast<WithContext *>(ctx)->withObject;
hasWith = true;
bool hasProperty = false;
- Value v = w->get(name, &hasProperty);
+ v = w->get(name, &hasProperty);
if (hasProperty) {
return v.asReturnedValue();
}
}
if (c->activation) {
bool hasProperty = false;
- Value v = c->activation->get(name, &hasProperty);
+ v = c->activation->get(name, &hasProperty);
if (hasProperty)
return v.asReturnedValue();
}
else if (ctx->type == Type_GlobalContext) {
GlobalContext *g = static_cast<GlobalContext *>(ctx);
bool hasProperty = false;
- Value v = g->global->get(name, &hasProperty);
+ v = g->global->get(name, &hasProperty);
if (hasProperty)
return v.asReturnedValue();
}
ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Object **base)
{
+ Scope scope(this);
+ ScopedValue v(scope);
*base = 0;
name->makeIdentifier();
Object *w = static_cast<WithContext *>(ctx)->withObject;
hasWith = true;
bool hasProperty = false;
- Value v = w->get(name, &hasProperty);
+ v = w->get(name, &hasProperty);
if (hasProperty) {
*base = w;
return v.asReturnedValue();
}
if (c->activation) {
bool hasProperty = false;
- Value v = c->activation->get(name, &hasProperty);
+ v = c->activation->get(name, &hasProperty);
if (hasProperty) {
if (ctx->type == Type_QmlContext)
*base = c->activation;
else if (ctx->type == Type_GlobalContext) {
GlobalContext *g = static_cast<GlobalContext *>(ctx);
bool hasProperty = false;
- Value v = g->global->get(name, &hasProperty);
+ v = g->global->get(name, &hasProperty);
if (hasProperty)
return v.asReturnedValue();
}
if (tv->isNumber() && !std::isfinite(tv->toNumber()))
return Value::nullValue();
- FunctionObject *toIso = O->objectValue()->get(ctx->engine->newString(QStringLiteral("toISOString"))).asFunctionObject();
+ ScopedValue v(scope, O->objectValue()->get(ctx->engine->newString(QStringLiteral("toISOString"))));
+ FunctionObject *toIso = v->asFunctionObject();
if (!toIso)
ctx->throwTypeError();
cout << prefix << "\t\"" << qPrintable(name.stringValue()->toQString()) << "\"" << endl;
PropertyAttributes attrs;
Property *d = o->__getOwnProperty__(name.stringValue(), &attrs);
- Value pval = o->getValue(d, attrs);
+ Value pval = Value::fromReturnedValue(o->getValue(d, attrs));
cout << prefix << "\tvalue:" << endl;
realDumpValue(pval, ctx, prefix + "\t");
}
return false;
ExecutionContext *ctx = f->engine()->current;
- Object *o = f->get(ctx->engine->id_prototype).asObject();
+ QV4::Scope scope(ctx);
+
+ Scoped<Object> o(scope, f->get(ctx->engine->id_prototype));
if (!o)
ctx->throwTypeError();
if (! v)
break;
- else if (o == v)
+ else if (o.getPointer() == v)
return true;
}
{
FunctionObject *f = static_cast<FunctionObject *>(that);
ExecutionEngine *v4 = f->engine();
+ Scope scope(v4);
InternalClass *ic = v4->objectClass;
- Value proto = f->get(v4->id_prototype);
- if (proto.isObject())
- ic = v4->emptyClass->changePrototype(proto.objectValue());
+ Scoped<Object> proto(scope, f->get(v4->id_prototype));
+ if (!!proto)
+ ic = v4->emptyClass->changePrototype(proto.getPointer());
Object *obj = v4->newObject(ic);
return Value::fromObject(obj).asReturnedValue();
}
, boundArgs(boundArgs)
{
vtbl = &static_vtbl;
- int len = target->get(scope->engine->id_length).toUInt32();
+ int len = Value::fromReturnedValue(target->get(scope->engine->id_length)).toUInt32();
len -= boundArgs.size();
if (len < 0)
len = 0;
return vtbl->call(this, callData);
}
+ static FunctionObject *cast(const Value &v) {
+ return v.asFunctionObject();
+ }
+
static FunctionObject *creatScriptFunction(ExecutionContext *scope, Function *function);
protected:
QString result;
if (Object *o = value.asObject()) {
- FunctionObject *toJSON = o->get(ctx->engine->newString(QStringLiteral("toJSON"))).asFunctionObject();
- if (toJSON) {
+ Scoped<FunctionObject> toJSON(scope, o->get(ctx->engine->newString(QStringLiteral("toJSON"))));
+ if (!!toJSON) {
ScopedCallData callData(scope, 1);
callData->thisObject = value;
callData->args[0] = Value::fromString(ctx, key);
if (stack.contains(o))
ctx->throwTypeError();
+ Scope scope(o->engine());
+
QString result;
stack.push(o);
QString stepback = indent;
} else {
for (int i = 0; i < propertyList.size(); ++i) {
bool exists;
- Value v = o->get(propertyList.at(i), &exists);
+ ScopedValue v(scope, o->get(propertyList.at(i), &exists));
if (!exists)
continue;
QString member = makeMember(propertyList.at(i)->toQString(), v);
l->getter = Lookup::primitiveGetterAccessor1;
if (result)
*result = p->value;
- Value res = proto->getValue(object, p, attrs);
+ Value res = Value::fromReturnedValue(proto->getValue(object, p, attrs));
if (result)
*result = res;
return;
l->globalGetter = globalGetterAccessor1;
else if (l->level == 2)
l->globalGetter = globalGetterAccessor2;
- Value res = o->getValue(p, attrs);
+ Value res = Value::fromReturnedValue(o->getValue(p, attrs));
if (result)
*result = res;
return;
return false;
}
-Value Managed::get(String *name, bool *hasProperty)
+ReturnedValue Managed::get(String *name, bool *hasProperty)
{
return vtbl->get(this, name, hasProperty);
}
void (*destroy)(Managed *);
void (*collectDeletables)(Managed *, GCDeletable **deletable);
bool (*hasInstance)(Managed *, const Value &value);
- Value (*get)(Managed *, String *name, bool *hasProperty);
+ ReturnedValue (*get)(Managed *, String *name, bool *hasProperty);
Value (*getIndexed)(Managed *, uint index, bool *hasProperty);
void (*put)(Managed *, String *name, const Value &value);
void (*putIndexed)(Managed *, uint index, const Value &value);
return vtbl == &T::static_vtbl ? static_cast<const T *>(this) : 0;
}
+ template<typename T>
+ static T *cast(const Value &v) {
+ return v.as<T>();
+ }
+ static Managed *cast(const Value &v) {
+ return v.asManaged();
+ }
+
ArrayObject *asArrayObject() { return type == Type_ArrayObject ? reinterpret_cast<ArrayObject *>(this) : 0; }
FunctionObject *asFunctionObject() { return type == Type_FunctionObject ? reinterpret_cast<FunctionObject *>(this) : 0; }
BooleanObject *asBooleanObject() { return type == Type_BooleanObject ? reinterpret_cast<BooleanObject *>(this) : 0; }
}
ReturnedValue construct(CallData *d);
ReturnedValue call(CallData *d);
- Value get(String *name, bool *hasProperty = 0);
+ ReturnedValue get(String *name, bool *hasProperty = 0);
Value getIndexed(uint index, bool *hasProperty = 0);
void put(String *name, const Value &value)
{ vtbl->put(this, name, value); }
put(ctx->engine->newString(name), value);
}
-Value Object::getValue(const Value &thisObject, const Property *p, PropertyAttributes attrs)
+ReturnedValue Object::getValue(const Value &thisObject, const Property *p, PropertyAttributes attrs)
{
if (!attrs.isAccessor())
- return p->value;
+ return p->value.asReturnedValue();
FunctionObject *getter = p->getter();
if (!getter)
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
Scope scope(getter->engine());
ScopedCallData callData(scope, 0);
callData->thisObject = thisObject;
- return Value::fromReturnedValue(getter->call(callData));
+ return getter->call(callData);
}
void Object::putValue(Property *pd, PropertyAttributes attrs, const Value &value)
return false;
}
-Value Object::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue Object::get(Managed *m, String *name, bool *hasProperty)
{
return static_cast<Object *>(m)->internalGet(name, hasProperty);
}
l->getter = Lookup::getterAccessor2;
if (result)
*result = p->value;
- Value res = o->getValue(p, attrs);
+ Value res = Value::fromReturnedValue(o->getValue(p, attrs));
if (result)
*result = res;
return;
}
// Section 8.12.3
-Value Object::internalGet(String *name, bool *hasProperty)
+ReturnedValue Object::internalGet(String *name, bool *hasProperty)
{
uint idx = name->asArrayIndex();
if (idx != UINT_MAX)
- return getIndexed(idx, hasProperty);
+ return getIndexed(idx, hasProperty).asReturnedValue();
name->makeIdentifier();
if (hasProperty)
*hasProperty = false;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
Value Object::internalGetIndexed(uint index, bool *hasProperty)
if (pd) {
if (hasProperty)
*hasProperty = true;
- return getValue(pd, attrs);
+ return Value::fromReturnedValue(getValue(pd, attrs));
}
if (hasProperty)
while (--len > i)
if (!arrayAttributes[len].isGeneric())
break;
- arrayData[i].value = getValue(arrayData + len, arrayAttributes[len]);
+ arrayData[i].value = Value::fromReturnedValue(getValue(arrayData + len, arrayAttributes[len]));
arrayAttributes[i] = Attr_Data;
arrayAttributes[len].clear();
} else if (arrayAttributes[i].isAccessor()) {
- arrayData[i].value = getValue(arrayData + i, arrayAttributes[i]);
+ arrayData[i].value = Value::fromReturnedValue(getValue(arrayData + i, arrayAttributes[i]));
arrayAttributes[i] = Attr_Data;
}
}
//
void put(ExecutionContext *ctx, const QString &name, const Value &value);
- static Value getValue(const Value &thisObject, const Property *p, PropertyAttributes attrs);
- Value getValue(const Property *p, PropertyAttributes attrs) const {
+ static ReturnedValue getValue(const Value &thisObject, const Property *p, PropertyAttributes attrs);
+ ReturnedValue getValue(const Property *p, PropertyAttributes attrs) const {
return getValue(Value::fromObject(const_cast<Object *>(this)), p, attrs);
}
ReturnedValue asReturnedValue() { return Value::fromObject(this).asReturnedValue(); }
+ static Object *cast(const Value &v) {
+ return v.asObject();
+ }
+
// Array handling
uint allocArrayValue() {
}
void ensureMemberIndex(uint idx);
- inline Value get(String *name, bool *hasProperty = 0)
+ inline ReturnedValue get(String *name, bool *hasProperty = 0)
{ return vtbl->get(this, name, hasProperty); }
inline Value getIndexed(uint idx, bool *hasProperty = 0)
{ return vtbl->getIndexed(this, idx, hasProperty); }
static const ManagedVTable static_vtbl;
static void destroy(Managed *that);
static void markObjects(Managed *that);
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static Value getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void putIndexed(Managed *m, uint index, const Value &value);
private:
- Value internalGet(String *name, bool *hasProperty);
+ ReturnedValue internalGet(String *name, bool *hasProperty);
Value internalGetIndexed(uint index, bool *hasProperty);
void internalPut(String *name, const Value &value);
void internalPutIndexed(uint index, const Value &value);
return Value::nullValue();
if (value)
- *value = object->getValue(p, attrs);
+ *value = Value::fromReturnedValue(object->getValue(p, attrs));
if (name)
return Value::fromString(name);
return Value::nullValue();
if (value)
- *value = object->getValue(p, attrs);
+ *value = Value::fromReturnedValue(object->getValue(p, attrs));
if (name)
return Value::fromString(name);
ReturnedValue ObjectCtor::construct(Managed *that, CallData *callData)
{
- ObjectCtor *ctor = static_cast<ObjectCtor *>(that);
ExecutionEngine *v4 = that->engine();
+ Scope scope(v4);
+ ObjectCtor *ctor = static_cast<ObjectCtor *>(that);
if (!callData->argc || callData->args[0].isUndefined() || callData->args[0].isNull()) {
Object *obj = v4->newObject();
- Value proto = ctor->get(v4->id_prototype);
- if (proto.isObject())
- obj->setPrototype(proto.objectValue());
+ Scoped<Object> proto(scope, ctor->get(v4->id_prototype));
+ if (!!proto)
+ obj->setPrototype(proto.getPointer());
return Value::fromObject(obj).asReturnedValue();
}
return Value::fromReturnedValue(__qmljs_to_object(v4->current, ValueRef(&callData->args[0]))).asReturnedValue();
break;
Property n;
PropertyAttributes nattrs;
- toPropertyDescriptor(ctx, o->getValue(pd, attrs), &n, &nattrs);
+ toPropertyDescriptor(ctx, Value::fromReturnedValue(o->getValue(pd, attrs)), &n, &nattrs);
bool ok;
if (name)
ok = O.objectValue()->__defineOwnProperty__(ctx, name, n, nattrs);
{
Scope scope(ctx);
Object *o = ctx->thisObject.toObject(ctx);
- Value ts = o->get(ctx->engine->newString(QStringLiteral("toString")));
- FunctionObject *f = ts.asFunctionObject();
+ Scoped<FunctionObject> f(scope, o->get(ctx->engine->newString(QStringLiteral("toString"))));
if (!f)
ctx->throwTypeError();
ScopedCallData callData(scope, 0);
if (!v.isObject())
ctx->throwTypeError();
+ Scope scope(ctx);
Object *o = v.objectValue();
attrs->clear();
desc->setSetter(0);
if (o->__hasProperty__(ctx->engine->id_enumerable))
- attrs->setEnumerable(o->get(ctx->engine->id_enumerable).toBoolean());
+ attrs->setEnumerable(Value::fromReturnedValue(o->get(ctx->engine->id_enumerable)).toBoolean());
if (o->__hasProperty__(ctx->engine->id_configurable))
- attrs->setConfigurable(o->get(ctx->engine->id_configurable).toBoolean());
+ attrs->setConfigurable(Value::fromReturnedValue(o->get(ctx->engine->id_configurable)).toBoolean());
if (o->__hasProperty__(ctx->engine->id_get)) {
- Value get = o->get(ctx->engine->id_get);
- FunctionObject *f = get.asFunctionObject();
+ ScopedValue get(scope, o->get(ctx->engine->id_get));
+ FunctionObject *f = get->asFunctionObject();
if (f) {
desc->setGetter(f);
- } else if (get.isUndefined()) {
+ } else if (get->isUndefined()) {
desc->setGetter((FunctionObject *)0x1);
} else {
ctx->throwTypeError();
}
if (o->__hasProperty__(ctx->engine->id_set)) {
- Value set = o->get(ctx->engine->id_set);
- FunctionObject *f = set.asFunctionObject();
+ ScopedValue set(scope, o->get(ctx->engine->id_set));
+ FunctionObject *f = set->asFunctionObject();
if (f) {
desc->setSetter(f);
- } else if (set.isUndefined()) {
+ } else if (set->isUndefined()) {
desc->setSetter((FunctionObject *)0x1);
} else {
ctx->throwTypeError();
if (o->__hasProperty__(ctx->engine->id_writable)) {
if (attrs->isAccessor())
ctx->throwTypeError();
- attrs->setWritable(o->get(ctx->engine->id_writable).toBoolean());
+ attrs->setWritable(Value::fromReturnedValue(o->get(ctx->engine->id_writable)).toBoolean());
// writable forces it to be a data descriptor
desc->value = Value::undefinedValue();
}
if (o->__hasProperty__(ctx->engine->id_value)) {
if (attrs->isAccessor())
ctx->throwTypeError();
- desc->value = o->get(ctx->engine->id_value);
+ desc->value = Value::fromReturnedValue(o->get(ctx->engine->id_value));
attrs->setType(PropertyAttributes::Data);
}
}
}
}
- return QV4::Object::get(this, name, hasProperty);
+ return QV4::Value::fromReturnedValue(QV4::Object::get(this, name, hasProperty));
}
QQmlData::flushPendingBinding(m_object, result->coreIndex);
QV4::String *connect = ctx->engine->newIdentifier(QStringLiteral("connect"));
QV4::String *disconnect = ctx->engine->newIdentifier(QStringLiteral("disconnect"));
- handler->put(connect, ctx->engine->functionClass->prototype->get(connect));
- handler->put(disconnect, ctx->engine->functionClass->prototype->get(disconnect));
+ handler->put(connect, QV4::Value::fromReturnedValue(ctx->engine->functionClass->prototype->get(connect)));
+ handler->put(disconnect, QV4::Value::fromReturnedValue(ctx->engine->functionClass->prototype->get(disconnect)));
return QV4::Value::fromObject(handler);
} else {
return Value::fromObject(new (engine->memoryManager) QV4::QObjectWrapper(engine, object));
}
-QV4::Value QObjectWrapper::get(Managed *m, String *name, bool *hasProperty)
+QV4::ReturnedValue QObjectWrapper::get(Managed *m, String *name, bool *hasProperty)
{
QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
ExecutionEngine *v4 = m->engine();
QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(v4);
- return that->getQmlProperty(v4->current, qmlContext, name, IgnoreRevision, hasProperty, /*includeImports*/ true);
+ return that->getQmlProperty(v4->current, qmlContext, name, IgnoreRevision, hasProperty, /*includeImports*/ true).asReturnedValue();
}
void QObjectWrapper::put(Managed *m, String *name, const Value &value)
++it->arrayIndex;
if (attributes)
*attributes = QV4::Attr_Data;
- it->tmpDynamicProperty.value = that->get(*name);
+ it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(that->get(*name));
return &it->tmpDynamicProperty;
}
const int methodCount = mo->methodCount();
++it->arrayIndex;
if (attributes)
*attributes = QV4::Attr_Data;
- it->tmpDynamicProperty.value = that->get(*name);
+ it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(that->get(*name));
return &it->tmpDynamicProperty;
}
return QV4::Object::advanceIterator(m, it, name, index, attributes);
String *m_destroy;
String *m_toString;
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static PropertyAttributes query(const Managed *, String *name);
static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes);
{
}
-Value RegExp::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue RegExp::get(Managed *, String *, bool *)
{
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
Value RegExp::getIndexed(Managed *m, uint index, bool *hasProperty)
protected:
static void destroy(Managed *that);
static void markObjects(Managed *that);
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *, String *, bool *);
static Value getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void putIndexed(Managed *m, uint index, const Value &value);
QString RegExpObject::source() const
{
- return const_cast<RegExpObject *>(this)->get(internalClass->engine->newIdentifier(QStringLiteral("source"))).stringValue()->toQString();
+ Value s = Value::fromReturnedValue(const_cast<RegExpObject *>(this)->get(internalClass->engine->newIdentifier(QStringLiteral("source"))));
+ return s.stringValue()->toQString();
}
uint RegExpObject::flags() const
}
String *name = index->toString(ctx);
- return o->get(name).asReturnedValue();
+ return o->get(name);
}
void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const ValueRef index, const ValueRef value)
Value res;
Managed *m = object->asManaged();
if (m)
- return m->get(name).asReturnedValue();
+ return m->get(name);
if (object->isNullOrUndefined()) {
QString message = QStringLiteral("Cannot read property '%1' of %2").arg(name->toQString()).arg(object->toQStringNoThrow());
}
m = __qmljs_convert_to_object(ctx, object);
- return m->get(name).asReturnedValue();
+ return m->get(name);
}
ReturnedValue __qmljs_get_activation_property(ExecutionContext *ctx, String *name)
ReturnedValue __qmljs_call_property(ExecutionContext *context, String *name, CallDataRef callData)
{
+ Scope scope(context);
Managed *baseObject = callData->thisObject.asManaged();
if (!baseObject) {
if (callData->thisObject.isNullOrUndefined()) {
callData->thisObject = Value::fromObject(static_cast<Object *>(baseObject));
}
- FunctionObject *o = baseObject->get(name).asFunctionObject();
+ Scoped<FunctionObject> o(scope, baseObject->get(name));
if (!o) {
QString error = QString("Property '%1' of object %2 is not a function").arg(name->toQString(), callData->thisObject.toQStringNoThrow());
context->throwTypeError(error);
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);
- Object *o = baseObject->get(index->toString(context)).asObject();
+ Scoped<Object> o(scope, baseObject->get(index->toString(context)));
if (!o)
context->throwTypeError();
ReturnedValue __qmljs_construct_property(ExecutionContext *context, const ValueRef base, String *name, CallDataRef callData)
{
+ Scope scope(context);
Object *thisObject = base->toObject(context);
- Value func = thisObject->get(name);
- Object *f = func.asObject();
+ Scoped<Object> f(scope, thisObject->get(name));
if (!f)
context->throwTypeError();
Value *ptr;
};
+template<typename T>
+struct Scoped
+{
+ Scoped(const Scope &scope)
+ {
+ ptr = scope.engine->jsStackTop++;
+#ifndef QT_NO_DEBUG
+ ++scope.size;
+#endif
+ }
+
+ Scoped(const Scope &scope, const Value &v)
+ {
+ ptr = scope.engine->jsStackTop++;
+ if (T::cast(v))
+ *ptr = v;
+ else
+ *ptr = QV4::Value::undefinedValue();
+#ifndef QT_NO_DEBUG
+ ++scope.size;
+#endif
+ }
+
+ Scoped(const Scope &scope, const ReturnedValue &v)
+ {
+ ptr = scope.engine->jsStackTop++;
+ if (T::cast(QV4::Value::fromReturnedValue(v)))
+ ptr->val = v;
+ else
+ *ptr = QV4::Value::undefinedValue();
+#ifndef QT_NO_DEBUG
+ ++scope.size;
+#endif
+ }
+
+ Scoped<T> &operator=(const Value &v) {
+ if (T::cast(v))
+ *ptr = v;
+ else
+ *ptr = QV4::Value::undefinedValue();
+ return *this;
+ }
+
+ Scoped<T> &operator=(const ReturnedValue &v) {
+ if (T::cast(QV4::Value::fromReturnedValue(v)))
+ ptr->val = v;
+ else
+ *ptr = QV4::Value::undefinedValue();
+ return *this;
+ }
+
+ Scoped<T> &operator=(const Scoped<T> &other) {
+ *ptr = *other.ptr;
+ return *this;
+ }
+
+ T *operator->() {
+ return static_cast<T *>(ptr->asManaged());
+ }
+
+// const Value *operator->() const {
+// return T::cast(*ptr);
+// }
+
+ bool operator!() const {
+ return !ptr->asManaged();
+ }
+
+ T *getPointer() {
+ return static_cast<T *>(ptr->asManaged());
+ }
+
+ Value asValue() const {
+ return *ptr;
+ }
+
+ ReturnedValue asReturnedValue() const { return ptr->val; }
+
+ Value *ptr;
+};
+
struct ScopedCallData {
ScopedCallData(Scope &scope, int argc)
{
void Serialize::serialize(QByteArray &data, const QV4::Value &v, QV8Engine *engine)
{
QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
+ QV4::Scope scope(v4);
+
if (v.isEmpty()) {
} else if (v.isUndefined()) {
push(data, valueheader(WorkerUndefined));
if (o->isListType()) {
// valid sequence. we generate a length (sequence length + 1 for the sequence type)
- uint32_t seqLength = o->get(v4->id_length).toUInt32();
+ uint32_t seqLength = ScopedValue(scope, o->get(v4->id_length))->toUInt32();
uint32_t length = seqLength + 1;
if (length > 0xFFFFFF) {
push(data, valueheader(WorkerUndefined));
}
push(data, valueheader(WorkerObject, length));
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
+ QV4::ScopedValue val(scope);
for (quint32 ii = 0; ii < length; ++ii) {
QV4::String *s = properties->getIndexed(ii).asString();
serialize(data, QV4::Value::fromString(s), engine);
bool hasCaught = false;
QV4::ExecutionContext *ctx = v4->current;
- QV4::Value val = QV4::Value::undefinedValue();
try {
val = o->get(s);
} catch (QV4::Exception &e) {
static_cast<String*>(that)->~String();
}
-Value String::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue String::get(Managed *m, String *name, bool *hasProperty)
{
String *that = static_cast<String *>(m);
ExecutionEngine *v4 = m->engine();
if (name == v4->id_length) {
if (hasProperty)
*hasProperty = true;
- return Value::fromInt32(that->_text.length());
+ return Value::fromInt32(that->_text.length()).asReturnedValue();
}
PropertyAttributes attrs;
Property *pd = v4->stringClass->prototype->__getPropertyDescriptor__(name, &attrs);
if (!pd || attrs.isGeneric()) {
if (hasProperty)
*hasProperty = false;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
if (hasProperty)
*hasProperty = true;
}
if (hasProperty)
*hasProperty = true;
- return engine->stringClass->prototype->getValue(Value::fromString(that), pd, attrs);
+ return Value::fromReturnedValue(engine->stringClass->prototype->getValue(Value::fromString(that), pd, attrs));
}
void String::put(Managed *m, String *name, const Value &value)
return _text.length();
}
+ static String *cast(const Value &v) {
+ return v.asString();
+ }
+
ReturnedValue asReturnedValue() { return Value::fromString(this).asReturnedValue(); }
QString _text;
protected:
static void destroy(Managed *);
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static Value getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void putIndexed(Managed *m, uint index, const Value &value);
bool global = rx->global;
// ### use the standard builtin function, not the one that might be redefined in the proto
- FunctionObject *exec = context->engine->regExpClass->prototype->get(context->engine->newString(QStringLiteral("exec")), 0).asFunctionObject();
+ Scoped<FunctionObject> exec(scope, context->engine->regExpClass->prototype->get(context->engine->newString(QStringLiteral("exec")), 0));
ScopedCallData callData(scope, 1);
callData->thisObject = Value::fromObject(rx);
uint n = 0;
ScopedValue result(scope);
ScopedValue matchStr(scope);
+ ScopedValue index(scope);
while (1) {
result = exec->call(callData);
if (result->isNull())
break;
assert(result->isObject());
- double thisIndex = rx->get(lastIndex, 0).toInteger();
+ index = rx->get(lastIndex, 0);
+ double thisIndex = index->toInteger();
if (previousLastIndex == thisIndex) {
previousLastIndex = thisIndex + 1;
rx->put(lastIndex, Value::fromDouble(previousLastIndex));
}
-Value Value::property(ExecutionContext *ctx, String *name) const
-{
- return isObject() ? objectValue()->get(name) : undefinedValue();
-}
-
-
PersistentValue::PersistentValue(const Value &val)
: d(new PersistentValuePrivate(val))
{
uint asArrayIndex() const;
uint asArrayLength(bool *ok) const;
- Value property(ExecutionContext *ctx, String *name) const;
-
inline ExecutionEngine *engine() const;
ReturnedValue asReturnedValue() const { return val; }
}
-Value QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
{
- QmlContextWrapper *resource = m->as<QmlContextWrapper>();
QV4::ExecutionEngine *v4 = m->engine();
+ QV4::Scope scope(v4);
+ QmlContextWrapper *resource = m->as<QmlContextWrapper>();
if (!resource)
v4->current->throwTypeError();
// In V8 the JS global object would come _before_ the QML global object,
// so simulate that here.
bool hasProp;
- QV4::Value result = v4->globalObject->get(name, &hasProp);
+ QV4::ScopedValue result(scope, v4->globalObject->get(name, &hasProp));
if (hasProp) {
if (hasProperty)
*hasProperty = hasProp;
- return result;
+ return result.asReturnedValue();
}
if (resource->isNullWrapper)
if (hasProp) {
if (hasProperty)
*hasProperty = hasProp;
- return result;
+ return result.asReturnedValue();
}
// Its possible we could delay the calculation of the "actual" context (in the case
if (!context) {
if (hasProperty)
*hasProperty = true;
- return result;
+ return result.asReturnedValue();
}
// Search type (attached property/enum/imported scripts) names
if (r.scriptIndex != -1) {
int index = r.scriptIndex;
if (index < context->importedScripts.count())
- return context->importedScripts.at(index).value();
+ return context->importedScripts.at(index).value().asReturnedValue();
else
- return QV4::Value::undefinedValue();
+ return QV4::Value::undefinedValue().asReturnedValue();
} else if (r.type) {
- return QmlTypeWrapper::create(engine, scopeObject, r.type);
+ return QmlTypeWrapper::create(engine, scopeObject, r.type).asReturnedValue();
} else if (r.importNamespace) {
- return QmlTypeWrapper::create(engine, scopeObject, context->imports, r.importNamespace);
+ return QmlTypeWrapper::create(engine, scopeObject, context->imports, r.importNamespace).asReturnedValue();
}
Q_ASSERT(!"Unreachable");
}
ep->captureProperty(&context->idValues[propertyIdx].bindings);
if (hasProperty)
*hasProperty = true;
- return QV4::QObjectWrapper::wrap(v4, context->idValues[propertyIdx]);
+ return QV4::QObjectWrapper::wrap(v4, context->idValues[propertyIdx]).asReturnedValue();
} else {
QQmlContextPrivate *cp = context->asQQmlContextPrivate();
QQmlListProperty<QObject> prop(context->asQQmlContext(), (void*) qintptr(propertyIdx),
QQmlContextPrivate::context_count,
QQmlContextPrivate::context_at);
- return QmlListWrapper::create(engine, prop, qMetaTypeId<QQmlListProperty<QObject> >());
+ return QmlListWrapper::create(engine, prop, qMetaTypeId<QQmlListProperty<QObject> >()).asReturnedValue();
} else {
- return engine->fromVariant(cp->propertyValues.at(propertyIdx));
+ return engine->fromVariant(cp->propertyValues.at(propertyIdx)).asReturnedValue();
}
}
}
if (hasProp) {
if (hasProperty)
*hasProperty = true;
- return result;
+ return result.asReturnedValue();
}
}
scopeObject = 0;
// Search context object
if (context->contextObject) {
bool hasProp = false;
- QV4::Value result = QV4::QObjectWrapper::getQmlProperty(v4->current, context, context->contextObject, name, QV4::QObjectWrapper::CheckRevision, &hasProp);
+ result = QV4::QObjectWrapper::getQmlProperty(v4->current, context, context->contextObject, name, QV4::QObjectWrapper::CheckRevision, &hasProp);
if (hasProp) {
if (hasProperty)
*hasProperty = true;
- return result;
+ return result.asReturnedValue();
}
}
expressionContext->unresolvedNames = true;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
void setReadOnly(bool b) { readOnly = b; }
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void destroy(Managed *that);
}
QV4::ErrorObject *errorObj = e.value().asErrorObject();
if (errorObj && errorObj->asSyntaxError())
- error.setDescription(errorObj->get(errorObj->engine()->newString("message")).toQStringNoThrow());
+ error.setDescription(QV4::Value::fromReturnedValue(errorObj->get(errorObj->engine()->newString("message"))).toQStringNoThrow());
else
error.setDescription(e.value().toQStringNoThrow());
}
}
-Value QmlListWrapper::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue QmlListWrapper::get(Managed *m, String *name, bool *hasProperty)
{
QV4::ExecutionEngine *v4 = m->engine();
QmlListWrapper *w = m->as<QmlListWrapper>();
if (name == v4->id_length && !w->object.isNull()) {
quint32 count = w->property.count ? w->property.count(&w->property) : 0;
- return Value::fromUInt32(count);
+ return Value::fromUInt32(count).asReturnedValue();
}
uint idx = name->asArrayIndex();
if (idx != UINT_MAX)
- return getIndexed(m, idx, hasProperty);
+ return getIndexed(m, idx, hasProperty).asReturnedValue();
return Object::get(m, name, hasProperty);
}
QVariant toVariant() const;
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static Value getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes);
}
-Value QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
{
QmlTypeWrapper *w = m->as<QmlTypeWrapper>();
QV4::ExecutionEngine *v4 = m->engine();
bool ok;
int value = e.keyToValue(enumName.constData(), &ok);
if (ok)
- return QV4::Value::fromInt32(value);
+ return QV4::Value::fromInt32(value).asReturnedValue();
}
}
}
// check for property.
- return QV4::QObjectWrapper::getQmlProperty(v4->current, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty);
+ return QV4::QObjectWrapper::getQmlProperty(v4->current, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty).asReturnedValue();
} else if (!siinfo->scriptApi(e).isUndefined()) {
QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine);
// NOTE: if used in a binding, changes will not trigger re-evaluation since non-NOTIFYable.
bool ok = false;
int value = type->enumValue(name, &ok);
if (ok)
- return QV4::Value::fromInt32(value);
+ return QV4::Value::fromInt32(value).asReturnedValue();
// Fall through to base implementation
} else if (w->object) {
QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
if (ao)
- return QV4::QObjectWrapper::getQmlProperty(v4->current, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty);
+ return QV4::QObjectWrapper::getQmlProperty(v4->current, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty).asReturnedValue();
// Fall through to base implementation
}
if (r.isValid()) {
QQmlContextData *context = v8engine->callingContext();
if (r.type) {
- return create(w->v8, object, r.type, w->mode);
+ return create(w->v8, object, r.type, w->mode).asReturnedValue();
} else if (r.scriptIndex != -1) {
int index = r.scriptIndex;
if (index < context->importedScripts.count())
- return context->importedScripts.at(index).value();
+ return context->importedScripts.at(index).value().asReturnedValue();
} else if (r.importNamespace) {
- return create(w->v8, object, context->imports, r.importNamespace);
+ return create(w->v8, object, context->imports, r.importNamespace).asReturnedValue();
}
- return QV4::Value::undefinedValue();
+ return QV4::Value::undefinedValue().asReturnedValue();
}
static QV4::Value create(QV8Engine *, QObject *, QQmlTypeNameCache *, const void *, TypeNameMode = IncludeEnums);
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static PropertyAttributes query(const Managed *, String *name);
static void destroy(Managed *that);
}
}
-Value QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
{
QmlValueTypeWrapper *r = m->as<QmlValueTypeWrapper>();
QV4::ExecutionEngine *v4 = m->engine();
QmlValueTypeReference *reference = static_cast<QmlValueTypeReference *>(r);
if (!reference->object || !readReferenceValue(reference))
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
} else {
Q_ASSERT(r->objectType == QmlValueTypeWrapper::Copy);
if (result->isFunction()) {
// calling a Q_INVOKABLE function of a value type
QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(v4);
- return QV4::QObjectWrapper::getQmlProperty(v4->current, qmlContext, r->type, name, QV4::QObjectWrapper::IgnoreRevision);
+ return QV4::QObjectWrapper::getQmlProperty(v4->current, qmlContext, r->type, name, QV4::QObjectWrapper::IgnoreRevision).asReturnedValue();
}
#define VALUE_TYPE_LOAD(metatype, cpptype, constructor) \
cpptype v; \
void *args[] = { &v, 0 }; \
r->type->qt_metacall(QMetaObject::ReadProperty, result->coreIndex, args); \
- return constructor(v); \
+ return constructor(v).asReturnedValue(); \
}
// These four types are the most common used by the value type wrappers
QVariant v(result->propType, (void *)0);
void *args[] = { v.data(), 0 };
r->type->qt_metacall(QMetaObject::ReadProperty, result->coreIndex, args);
- return r->v8->fromVariant(v);
+ return r->v8->fromVariant(v).asReturnedValue();
#undef VALUE_TYPE_ACCESSOR
}
bool isEqual(const QVariant& value);
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void destroy(Managed *that);
static bool isEqualTo(Managed *m, Managed *other);
static void destroy(Managed *that) {
that->as<NamedNodeMap>()->~NamedNodeMap();
}
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static Value getIndexed(Managed *m, uint index, bool *hasProperty);
QList<NodeImpl *> list; // Only used in NamedNodeMap
static void destroy(Managed *that) {
that->as<NodeList>()->~NodeList();
}
- static Value get(Managed *m, String *name, bool *hasProperty);
+ static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
static Value getIndexed(Managed *m, uint index, bool *hasProperty);
// C++ API
return Value::undefinedValue();
}
-Value NamedNodeMap::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue NamedNodeMap::get(Managed *m, String *name, bool *hasProperty)
{
NamedNodeMap *r = m->as<NamedNodeMap>();
QV4::ExecutionEngine *v4 = m->engine();
name->makeIdentifier();
if (name->isEqualTo(v4->id_length))
- return Value::fromInt32(r->list.count());
+ return Value::fromInt32(r->list.count()).asReturnedValue();
QV8Engine *engine = v4->v8Engine;
if (r->list.at(ii)->name == str) {
if (hasProperty)
*hasProperty = true;
- return Node::create(engine, r->list.at(ii));
+ return Node::create(engine, r->list.at(ii)).asReturnedValue();
}
}
if (hasProperty)
*hasProperty = false;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
Value NamedNodeMap::create(QV8Engine *engine, NodeImpl *data, const QList<NodeImpl *> &list)
return Value::undefinedValue();
}
-Value NodeList::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue NodeList::get(Managed *m, String *name, bool *hasProperty)
{
QV4::ExecutionEngine *v4 = m->engine();
NodeList *r = m->as<NodeList>();
name->makeIdentifier();
if (name->isEqualTo(v4->id_length))
- return Value::fromInt32(r->d->children.count());
+ return Value::fromInt32(r->d->children.count()).asReturnedValue();
return Object::get(m, name, hasProperty);
}
if (!o)
ctx->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
- Object *thisObj = o->get(v4->newString(QStringLiteral("ThisObject"))).asObject();
+ Scoped<Object> thisObj(scope, o->get(v4->newString(QStringLiteral("ThisObject"))));
if (!thisObj)
ctx->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
- FunctionObject *callback = thisObj->get(v4->newString(QStringLiteral("onreadystatechange"))).asFunctionObject();
+ Scoped<FunctionObject> callback(scope, thisObj->get(v4->newString(QStringLiteral("onreadystatechange"))));
if (!callback) {
// not an error, but no onreadystatechange function to call.
return;
}
- Value activationObject = o->get(v4->newString(QStringLiteral("ActivationObject")));
- if (!activationObject.asObject())
+ Scoped<Object> activationObject(scope, o->get(v4->newString(QStringLiteral("ActivationObject"))));
+ if (!activationObject)
v4->current->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ActivationObject"));
- QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject);
+ QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject.asValue());
if (callingContext) {
QV4::ScopedCallData callData(scope, 0);
- callData->thisObject = activationObject;
+ callData->thisObject = activationObject.asValue();
callback->call(callData);
}
return QV4::Value::fromObject(object);
}
- static QV4::Value get(QV4::Managed *m, QV4::String *name, bool *hasProperty)
+ static QV4::ReturnedValue get(QV4::Managed *m, QV4::String *name, bool *hasProperty)
{
QQmlDelegateModelGroupChangeArray *array = m->as<QQmlDelegateModelGroupChangeArray>();
if (!array)
if (name == m->engine()->id_length) {
if (hasProperty)
*hasProperty = true;
- return QV4::Value::fromInt32(array->count());
+ return QV4::Value::fromInt32(array->count()).asReturnedValue();
}
return Object::get(m, name, hasProperty);
#include <private/qv4value_p.h>
#include <private/qv4functionobject_p.h>
#include <private/qv4objectproto_p.h>
+#include <private/qv4scopedvalue_p.h>
#if defined(Q_OS_QNX) || defined(Q_OS_ANDROID)
#include <ctype.h>
QV8Engine *engine = ctx->engine->v8Engine;
QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
+ QV4::Scope scope(v4);
if (ctx->argumentCount == 2) {
QQuickContext2DStyle *pattern = new (v4->memoryManager) QQuickContext2DStyle(v4);
QImage patternTexture;
if (QV4::Object *o = ctx->arguments[0].asObject()) {
- QQuickJSContext2DPixelData *pixelData = o->get(ctx->engine->newString(QStringLiteral("data"))).as<QQuickJSContext2DPixelData>();
- if (pixelData) {
+ QV4::Scoped<QQuickJSContext2DPixelData> pixelData(scope, o->get(ctx->engine->newString(QStringLiteral("data"))));
+ if (!!pixelData) {
patternTexture = pixelData->image;
}
} else {
QV4::ExecutionEngine *v4 = obj->engine();
- QV4::Value vbold = obj->get(v4->newString(QStringLiteral("bold")));
- QV4::Value vcap = obj->get(v4->newString(QStringLiteral("capitalization")));
- QV4::Value vfam = obj->get(v4->newString(QStringLiteral("family")));
- QV4::Value vital = obj->get(v4->newString(QStringLiteral("italic")));
- QV4::Value vlspac = obj->get(v4->newString(QStringLiteral("letterSpacing")));
- QV4::Value vpixsz = obj->get(v4->newString(QStringLiteral("pixelSize")));
- QV4::Value vpntsz = obj->get(v4->newString(QStringLiteral("pointSize")));
- QV4::Value vstrk = obj->get(v4->newString(QStringLiteral("strikeout")));
- QV4::Value vundl = obj->get(v4->newString(QStringLiteral("underline")));
- QV4::Value vweight = obj->get(v4->newString(QStringLiteral("weight")));
- QV4::Value vwspac = obj->get(v4->newString(QStringLiteral("wordSpacing")));
+ QV4::Value vbold = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("bold"))));
+ QV4::Value vcap = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("capitalization"))));
+ QV4::Value vfam = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("family"))));
+ QV4::Value vital = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("italic"))));
+ QV4::Value vlspac = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("letterSpacing"))));
+ QV4::Value vpixsz = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("pixelSize"))));
+ QV4::Value vpntsz = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("pointSize"))));
+ QV4::Value vstrk = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("strikeout"))));
+ QV4::Value vundl = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("underline"))));
+ QV4::Value vweight = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("weight"))));
+ QV4::Value vwspac = QV4::Value::fromReturnedValue(obj->get(v4->newString(QStringLiteral("wordSpacing"))));
// pull out the values, set ok to true if at least one valid field is given.
if (vbold.isBoolean()) {
if (!e) {
std::cerr << "Uncaught exception: " << qPrintable(exception.value().toString(ctx)->toQString()) << std::endl;
} else {
- std::cerr << "Uncaught exception: " << qPrintable(e->get(ctx->engine->newString(QStringLiteral("message")), 0).toString(ctx)->toQString()) << std::endl;
+ std::cerr << "Uncaught exception: " << qPrintable(QV4::Value::fromReturnedValue(e->get(ctx->engine->newString(QStringLiteral("message")), 0)).toString(ctx)->toQString()) << std::endl;
}
foreach (const QV4::ExecutionEngine::StackFrame &frame, exception.stackTrace()) {