From 1a2a83f80ba4ecc28eba72af57c81bd43a45946c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 11 Sep 2013 13:55:01 +0200 Subject: Use a ReturnedValue for Managed::call() Change-Id: Ief2d75e9789dd367c603d90dc0fe5316a0d055e3 Reviewed-by: Simon Hausmann --- src/qml/jsapi/qjsvalue.cpp | 6 ++-- src/qml/jsruntime/qv4argumentsobject.cpp | 8 ++--- src/qml/jsruntime/qv4argumentsobject_p.h | 4 +-- src/qml/jsruntime/qv4arrayobject.cpp | 55 +++++++++++++++++++------------- src/qml/jsruntime/qv4arrayobject_p.h | 2 +- src/qml/jsruntime/qv4booleanobject.cpp | 4 +-- src/qml/jsruntime/qv4booleanobject_p.h | 2 +- src/qml/jsruntime/qv4dateobject.cpp | 6 ++-- src/qml/jsruntime/qv4dateobject_p.h | 2 +- src/qml/jsruntime/qv4errorobject.cpp | 4 +-- src/qml/jsruntime/qv4errorobject_p.h | 2 +- src/qml/jsruntime/qv4functionobject.cpp | 30 ++++++++--------- src/qml/jsruntime/qv4functionobject_p.h | 16 +++++----- src/qml/jsruntime/qv4globalobject.cpp | 12 +++---- src/qml/jsruntime/qv4globalobject_p.h | 4 +-- src/qml/jsruntime/qv4jsonobject.cpp | 4 +-- src/qml/jsruntime/qv4lookup.cpp | 16 +++++----- src/qml/jsruntime/qv4managed.cpp | 2 +- src/qml/jsruntime/qv4managed_p.h | 6 ++-- src/qml/jsruntime/qv4numberobject.cpp | 4 +-- src/qml/jsruntime/qv4numberobject_p.h | 2 +- src/qml/jsruntime/qv4object.cpp | 2 +- src/qml/jsruntime/qv4objectproto.cpp | 8 ++--- src/qml/jsruntime/qv4objectproto_p.h | 2 +- src/qml/jsruntime/qv4qobjectwrapper.cpp | 4 +-- src/qml/jsruntime/qv4qobjectwrapper_p.h | 2 +- src/qml/jsruntime/qv4regexpobject.cpp | 6 ++-- src/qml/jsruntime/qv4regexpobject_p.h | 2 +- src/qml/jsruntime/qv4runtime.cpp | 20 ++++++------ src/qml/jsruntime/qv4script.cpp | 8 ++--- src/qml/jsruntime/qv4sequenceobject.cpp | 5 +-- src/qml/jsruntime/qv4stringobject.cpp | 23 +++++++------ src/qml/jsruntime/qv4stringobject_p.h | 2 +- src/qml/jsruntime/qv4value.cpp | 15 +++++++++ src/qml/jsruntime/qv4value_p.h | 5 ++- src/qml/qml/qqmljavascriptexpression.cpp | 5 +-- src/qml/qml/qqmlvmemetaobject.cpp | 3 +- src/qml/qml/qqmlxmlhttprequest.cpp | 4 +-- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 2 +- src/qml/types/qqmldelegatemodel.cpp | 4 +-- src/qml/types/qquickworkerscript.cpp | 11 ++++--- 41 files changed, 183 insertions(+), 141 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index beff645005..ea5c021231 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -506,6 +506,7 @@ QJSValue QJSValue::call(const QJSValueList &args) ExecutionEngine *engine = d->engine; assert(engine); + ValueScope scope(engine); ScopedCallData callData(engine, args.length()); callData->thisObject = Value::fromObject(engine->globalObject); for (int i = 0; i < args.size(); ++i) { @@ -516,7 +517,7 @@ QJSValue QJSValue::call(const QJSValueList &args) callData->args[i] = args.at(i).d->getValue(engine); } - Value result; + ScopedValue result(scope); QV4::ExecutionContext *ctx = engine->current; try { result = f->call(callData); @@ -556,6 +557,7 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList ExecutionEngine *engine = d->engine; assert(engine); + ValueScope scope(engine); if (!instance.d->checkEngine(engine)) { qWarning("QJSValue::call() failed: cannot call function with thisObject created in a different engine"); @@ -572,7 +574,7 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList callData->args[i] = args.at(i).d->getValue(engine); } - Value result; + ScopedValue result(scope); QV4::ExecutionContext *ctx = engine->current; try { result = f->call(callData); diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp index 5a53c0fc3e..89b6f49f1d 100644 --- a/src/qml/jsruntime/qv4argumentsobject.cpp +++ b/src/qml/jsruntime/qv4argumentsobject.cpp @@ -148,7 +148,7 @@ bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const DEFINE_MANAGED_VTABLE(ArgumentsGetterFunction); -Value ArgumentsGetterFunction::call(Managed *getter, CallData *callData) +ReturnedValue ArgumentsGetterFunction::call(Managed *getter, CallData *callData) { ArgumentsGetterFunction *g = static_cast(getter); Object *that = callData->thisObject.asObject(); @@ -159,12 +159,12 @@ Value ArgumentsGetterFunction::call(Managed *getter, CallData *callData) getter->engine()->current->throwTypeError(); assert(g->index < o->context->argumentCount); - return o->context->argument(g->index); + return o->context->argument(g->index).asReturnedValue(); } DEFINE_MANAGED_VTABLE(ArgumentsSetterFunction); -Value ArgumentsSetterFunction::call(Managed *setter, CallData *callData) +ReturnedValue ArgumentsSetterFunction::call(Managed *setter, CallData *callData) { ArgumentsSetterFunction *s = static_cast(setter); Object *that = callData->thisObject.asObject(); @@ -176,7 +176,7 @@ Value ArgumentsSetterFunction::call(Managed *setter, CallData *callData) assert(s->index < o->context->argumentCount); o->context->arguments[s->index] = callData->argc ? callData->args[0] : Value::undefinedValue(); - return Value::undefinedValue(); + return Value::undefinedValue().asReturnedValue(); } void ArgumentsObject::markObjects(Managed *that) diff --git a/src/qml/jsruntime/qv4argumentsobject_p.h b/src/qml/jsruntime/qv4argumentsobject_p.h index 66ee22c953..dec2f25c01 100644 --- a/src/qml/jsruntime/qv4argumentsobject_p.h +++ b/src/qml/jsruntime/qv4argumentsobject_p.h @@ -55,7 +55,7 @@ struct ArgumentsGetterFunction: FunctionObject ArgumentsGetterFunction(ExecutionContext *scope, uint index) : FunctionObject(scope), index(index) { vtbl = &static_vtbl; } - static Value call(Managed *that, CallData *d); + static ReturnedValue call(Managed *that, CallData *d); protected: static const ManagedVTable static_vtbl; @@ -68,7 +68,7 @@ struct ArgumentsSetterFunction: FunctionObject ArgumentsSetterFunction(ExecutionContext *scope, uint index) : FunctionObject(scope), index(index) { vtbl = &static_vtbl; } - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index e3b08f5941..58a2f256cc 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -80,9 +80,9 @@ Value ArrayCtor::construct(Managed *m, CallData *callData) return Value::fromObject(a); } -Value ArrayCtor::call(Managed *that, CallData *callData) +ReturnedValue ArrayCtor::call(Managed *that, CallData *callData) { - return construct(that, callData); + return construct(that, callData).asReturnedValue(); } ArrayPrototype::ArrayPrototype(InternalClass *ic) @@ -140,7 +140,7 @@ Value ArrayPrototype::method_toString(SimpleCallContext *ctx) if (f) { ScopedCallData d(ctx->engine, 0); d->thisObject = ctx->thisObject; - return f->call(d); + return Value::fromReturnedValue(f->call(d)); } return ObjectPrototype::method_toString(ctx); } @@ -648,7 +648,7 @@ Value ArrayPrototype::method_every(SimpleCallContext *ctx) callData->args[1] = Value::fromDouble(k); callData->args[2] = Value::fromObject(instance); callData->thisObject = thisArg; - Value r = callback->call(callData); + Value r = Value::fromReturnedValue(callback->call(callData)); ok = r.toBoolean(); } return Value::fromBoolean(ok); @@ -677,7 +677,7 @@ Value ArrayPrototype::method_some(SimpleCallContext *ctx) callData->args[0] = v; callData->args[1] = Value::fromDouble(k); callData->args[2] = Value::fromObject(instance); - Value r = callback->call(callData); + Value r = Value::fromReturnedValue(callback->call(callData)); if (r.toBoolean()) return Value::fromBoolean(true); } @@ -714,6 +714,7 @@ Value ArrayPrototype::method_forEach(SimpleCallContext *ctx) Value ArrayPrototype::method_map(SimpleCallContext *ctx) { + ValueScope scope(ctx); Object *instance = ctx->thisObject.toObject(ctx); uint len = getLength(ctx, instance); @@ -728,18 +729,20 @@ Value ArrayPrototype::method_map(SimpleCallContext *ctx) a->arrayReserve(len); a->setArrayLengthUnchecked(len); + ScopedValue mapped(scope); + ScopedCallData callData(ctx->engine, 3); + callData->thisObject = thisArg; + callData->args[2] = Value::fromObject(instance); + for (uint k = 0; k < len; ++k) { bool exists; Value v = instance->getIndexed(k, &exists); if (!exists) continue; - ScopedCallData callData(ctx->engine, 3); - callData->thisObject = thisArg; callData->args[0] = v; callData->args[1] = Value::fromDouble(k); - callData->args[2] = Value::fromObject(instance); - Value mapped = callback->call(callData); + mapped = callback->call(callData); a->arraySet(k, mapped); } return Value::fromObject(a); @@ -747,6 +750,7 @@ Value ArrayPrototype::method_map(SimpleCallContext *ctx) Value ArrayPrototype::method_filter(SimpleCallContext *ctx) { + ValueScope scope(ctx); Object *instance = ctx->thisObject.toObject(ctx); uint len = getLength(ctx, instance); @@ -760,6 +764,11 @@ Value ArrayPrototype::method_filter(SimpleCallContext *ctx) ArrayObject *a = ctx->engine->newArrayObject(); a->arrayReserve(len); + ScopedValue selected(scope); + ScopedCallData callData(ctx->engine, 3); + callData->thisObject = thisArg; + callData->args[2] = Value::fromObject(instance); + uint to = 0; for (uint k = 0; k < len; ++k) { bool exists; @@ -767,13 +776,10 @@ Value ArrayPrototype::method_filter(SimpleCallContext *ctx) if (!exists) continue; - ScopedCallData callData(ctx->engine, 3); - callData->thisObject = thisArg; callData->args[0] = v; callData->args[1] = Value::fromDouble(k); - callData->args[2] = Value::fromObject(instance); - Value selected = callback->call(callData); - if (selected.toBoolean()) { + selected = callback->call(callData); + if (selected->toBoolean()) { a->arraySet(to, v); ++to; } @@ -783,6 +789,7 @@ Value ArrayPrototype::method_filter(SimpleCallContext *ctx) Value ArrayPrototype::method_reduce(SimpleCallContext *ctx) { + ValueScope scope(ctx); Object *instance = ctx->thisObject.toObject(ctx); uint len = getLength(ctx, instance); @@ -792,7 +799,7 @@ Value ArrayPrototype::method_reduce(SimpleCallContext *ctx) ctx->throwTypeError(); uint k = 0; - Value acc; + ScopedValue acc(scope); if (ctx->argumentCount > 1) { acc = ctx->argument(1); } else { @@ -807,16 +814,18 @@ Value ArrayPrototype::method_reduce(SimpleCallContext *ctx) ctx->throwTypeError(); } + ScopedCallData callData(ctx->engine, 4); + callData->thisObject = Value::undefinedValue(); + callData->args[0] = acc; + callData->args[3] = Value::fromObject(instance); + while (k < len) { bool kPresent; Value v = instance->getIndexed(k, &kPresent); if (kPresent) { - ScopedCallData callData(ctx->engine, 4); - callData->thisObject = Value::undefinedValue(); callData->args[0] = acc; callData->args[1] = v; callData->args[2] = Value::fromDouble(k); - callData->args[3] = Value::fromObject(instance); acc = callback->call(callData); } ++k; @@ -826,6 +835,7 @@ Value ArrayPrototype::method_reduce(SimpleCallContext *ctx) Value ArrayPrototype::method_reduceRight(SimpleCallContext *ctx) { + ValueScope scope(ctx); Object *instance = ctx->thisObject.toObject(ctx); uint len = getLength(ctx, instance); @@ -841,7 +851,7 @@ Value ArrayPrototype::method_reduceRight(SimpleCallContext *ctx) } uint k = len; - Value acc; + ScopedValue acc(scope); if (ctx->argumentCount > 1) { acc = ctx->argument(1); } else { @@ -856,16 +866,17 @@ Value ArrayPrototype::method_reduceRight(SimpleCallContext *ctx) ctx->throwTypeError(); } + ScopedCallData callData(ctx->engine, 4); + callData->thisObject = Value::undefinedValue(); + callData->args[3] = Value::fromObject(instance); + while (k > 0) { bool kPresent; Value v = instance->getIndexed(k - 1, &kPresent); if (kPresent) { - ScopedCallData callData(ctx->engine, 4); - callData->thisObject = Value::undefinedValue(); callData->args[0] = acc; callData->args[1] = v; callData->args[2] = Value::fromDouble(k - 1); - callData->args[3] = Value::fromObject(instance); acc = callback->call(callData); } --k; diff --git a/src/qml/jsruntime/qv4arrayobject_p.h b/src/qml/jsruntime/qv4arrayobject_p.h index 354ddd0380..e8a8ddda22 100644 --- a/src/qml/jsruntime/qv4arrayobject_p.h +++ b/src/qml/jsruntime/qv4arrayobject_p.h @@ -54,7 +54,7 @@ struct ArrayCtor: FunctionObject ArrayCtor(ExecutionContext *scope); static Value construct(Managed *m, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4booleanobject.cpp b/src/qml/jsruntime/qv4booleanobject.cpp index 6b77db3ca7..aa5ebbd38c 100644 --- a/src/qml/jsruntime/qv4booleanobject.cpp +++ b/src/qml/jsruntime/qv4booleanobject.cpp @@ -57,10 +57,10 @@ Value BooleanCtor::construct(Managed *m, CallData *callData) return Value::fromObject(m->engine()->newBooleanObject(Value::fromBoolean(n))); } -Value BooleanCtor::call(Managed *, CallData *callData) +ReturnedValue BooleanCtor::call(Managed *, CallData *callData) { bool value = callData->argc ? callData->args[0].toBoolean() : 0; - return Value::fromBoolean(value); + return Value::fromBoolean(value).asReturnedValue(); } void BooleanPrototype::init(ExecutionContext *ctx, const Value &ctor) diff --git a/src/qml/jsruntime/qv4booleanobject_p.h b/src/qml/jsruntime/qv4booleanobject_p.h index 35ecf25b6f..7cdd2d741b 100644 --- a/src/qml/jsruntime/qv4booleanobject_p.h +++ b/src/qml/jsruntime/qv4booleanobject_p.h @@ -54,7 +54,7 @@ struct BooleanCtor: FunctionObject BooleanCtor(ExecutionContext *scope); static Value construct(Managed *, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index 1ef4aec246..ec4c0028a0 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -693,10 +693,10 @@ Value DateCtor::construct(Managed *m, CallData *callData) return Value::fromObject(o); } -Value DateCtor::call(Managed *m, CallData *) +ReturnedValue DateCtor::call(Managed *m, CallData *) { double t = currentTime(); - return Value::fromString(m->engine()->current, ToString(t)); + return Value::fromString(m->engine()->current, ToString(t)).asReturnedValue(); } void DatePrototype::init(ExecutionContext *ctx, const Value &ctor) @@ -1305,7 +1305,7 @@ Value DatePrototype::method_toJSON(SimpleCallContext *ctx) ScopedCallData callData(ctx->engine, 0); callData->thisObject = ctx->thisObject; - return toIso->call(callData); + return Value::fromReturnedValue(toIso->call(callData)); } void DatePrototype::timezoneUpdated() diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h index 573326adc4..eff47e60f2 100644 --- a/src/qml/jsruntime/qv4dateobject_p.h +++ b/src/qml/jsruntime/qv4dateobject_p.h @@ -67,7 +67,7 @@ struct DateCtor: FunctionObject DateCtor(ExecutionContext *scope); static Value construct(Managed *, CallData *callData); - static Value call(Managed *that, CallData *); + static ReturnedValue call(Managed *that, CallData *); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 96c5f67120..0f08d6e758 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -245,9 +245,9 @@ Value ErrorCtor::construct(Managed *m, CallData *callData) return Value::fromObject(m->engine()->newErrorObject(callData->argc ? callData->args[0] : Value::undefinedValue())); } -Value ErrorCtor::call(Managed *that, CallData *callData) +ReturnedValue ErrorCtor::call(Managed *that, CallData *callData) { - return that->construct(callData); + return that->construct(callData).asReturnedValue(); } EvalErrorCtor::EvalErrorCtor(ExecutionContext *scope) diff --git a/src/qml/jsruntime/qv4errorobject_p.h b/src/qml/jsruntime/qv4errorobject_p.h index 1d82bb7ba2..7ccb9cb4cf 100644 --- a/src/qml/jsruntime/qv4errorobject_p.h +++ b/src/qml/jsruntime/qv4errorobject_p.h @@ -115,7 +115,7 @@ struct ErrorCtor: FunctionObject ErrorCtor(ExecutionContext *scope, String *name); static Value construct(Managed *, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index c87fad62b3..a2fb4d270b 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -166,9 +166,9 @@ Value FunctionObject::construct(Managed *that, CallData *) return Value::fromObject(obj); } -Value FunctionObject::call(Managed *, CallData *) +ReturnedValue FunctionObject::call(Managed *, CallData *) { - return Value::undefinedValue(); + return Value::undefinedValue().asReturnedValue(); } void FunctionObject::markObjects(Managed *that) @@ -253,9 +253,9 @@ Value FunctionCtor::construct(Managed *that, CallData *callData) } // 15.3.1: This is equivalent to new Function(...) -Value FunctionCtor::call(Managed *that, CallData *callData) +ReturnedValue FunctionCtor::call(Managed *that, CallData *callData) { - return construct(that, callData); + return construct(that, callData).asReturnedValue(); } FunctionPrototype::FunctionPrototype(InternalClass *ic) @@ -324,7 +324,7 @@ Value FunctionPrototype::method_apply(SimpleCallContext *ctx) } callData->thisObject = thisArg; - return o->call(callData); + return Value::fromReturnedValue(o->call(callData)); } Value FunctionPrototype::method_call(SimpleCallContext *ctx) @@ -341,7 +341,7 @@ Value FunctionPrototype::method_call(SimpleCallContext *ctx) ctx->arguments + ctx->argumentCount, callData->args); } callData->thisObject = thisArg; - return o->call(callData); + return Value::fromReturnedValue(o->call(callData)); } Value FunctionPrototype::method_bind(SimpleCallContext *ctx) @@ -434,7 +434,7 @@ Value ScriptFunction::construct(Managed *that, CallData *callData) return Value::fromObject(obj); } -Value ScriptFunction::call(Managed *that, CallData *callData) +ReturnedValue ScriptFunction::call(Managed *that, CallData *callData) { ScriptFunction *f = static_cast(that); void *stackSpace; @@ -460,7 +460,7 @@ Value ScriptFunction::call(Managed *that, CallData *callData) } CHECK_JS_STACK(f->scope); ctx->engine->popContext(); - return result; + return result.asReturnedValue(); } DEFINE_MANAGED_VTABLE(SimpleScriptFunction); @@ -531,7 +531,7 @@ Value SimpleScriptFunction::construct(Managed *that, CallData *callData) return Value::fromObject(obj); } -Value SimpleScriptFunction::call(Managed *that, CallData *callData) +ReturnedValue SimpleScriptFunction::call(Managed *that, CallData *callData) { SimpleScriptFunction *f = static_cast(that); void *stackSpace = alloca(requiredMemoryForExecutionContectSimple(f)); @@ -557,7 +557,7 @@ Value SimpleScriptFunction::call(Managed *that, CallData *callData) } CHECK_JS_STACK(f->scope); ctx->engine->popContext(); - return result; + return result.asReturnedValue(); } @@ -579,7 +579,7 @@ Value BuiltinFunctionOld::construct(Managed *f, CallData *) return Value::undefinedValue(); } -Value BuiltinFunctionOld::call(Managed *that, CallData *callData) +ReturnedValue BuiltinFunctionOld::call(Managed *that, CallData *callData) { BuiltinFunctionOld *f = static_cast(that); ExecutionEngine *v4 = f->engine(); @@ -603,10 +603,10 @@ Value BuiltinFunctionOld::call(Managed *that, CallData *callData) } context->engine->popContext(); - return result; + return result.asReturnedValue(); } -Value IndexedBuiltinFunction::call(Managed *that, CallData *callData) +ReturnedValue IndexedBuiltinFunction::call(Managed *that, CallData *callData) { IndexedBuiltinFunction *f = static_cast(that); ExecutionEngine *v4 = f->engine(); @@ -630,7 +630,7 @@ Value IndexedBuiltinFunction::call(Managed *that, CallData *callData) } context->engine->popContext(); - return result; + return result.asReturnedValue(); } DEFINE_MANAGED_VTABLE(IndexedBuiltinFunction); @@ -661,7 +661,7 @@ void BoundFunction::destroy(Managed *that) static_cast(that)->~BoundFunction(); } -Value BoundFunction::call(Managed *that, CallData *dd) +ReturnedValue BoundFunction::call(Managed *that, CallData *dd) { BoundFunction *f = static_cast(that); diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index d694d28462..bad62af6f3 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -118,11 +118,11 @@ struct Q_QML_EXPORT FunctionObject: Object { Value newInstance(); static Value construct(Managed *that, CallData *); - static Value call(Managed *that, CallData *d); + static ReturnedValue call(Managed *that, CallData *d); inline Value construct(CallData *callData) { return vtbl->construct(this, callData); } - inline Value call(CallData *callData) { + inline ReturnedValue call(CallData *callData) { return vtbl->call(this, callData); } @@ -143,7 +143,7 @@ struct FunctionCtor: FunctionObject FunctionCtor(ExecutionContext *scope); static Value construct(Managed *that, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; @@ -166,7 +166,7 @@ struct BuiltinFunctionOld: FunctionObject { BuiltinFunctionOld(ExecutionContext *scope, String *name, Value (*code)(SimpleCallContext *)); static Value construct(Managed *, CallData *); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; @@ -194,7 +194,7 @@ struct IndexedBuiltinFunction: FunctionObject return Value::undefinedValue(); } - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); }; @@ -202,7 +202,7 @@ struct ScriptFunction: FunctionObject { ScriptFunction(ExecutionContext *scope, Function *function); static Value construct(Managed *, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; @@ -212,7 +212,7 @@ struct SimpleScriptFunction: FunctionObject { SimpleScriptFunction(ExecutionContext *scope, Function *function); static Value construct(Managed *, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; @@ -228,7 +228,7 @@ struct BoundFunction: FunctionObject { static Value construct(Managed *, CallData *d); - static Value call(Managed *that, CallData *dd); + static ReturnedValue call(Managed *that, CallData *dd); static const ManagedVTable static_vtbl; static void destroy(Managed *); diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index 6176893d68..e6f3de712d 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -354,10 +354,10 @@ EvalFunction::EvalFunction(ExecutionContext *scope) defineReadonlyProperty(scope->engine->id_length, Value::fromInt32(1)); } -Value EvalFunction::evalCall(Value /*thisObject*/, Value *args, int argc, bool directCall) +ReturnedValue EvalFunction::evalCall(Value /*thisObject*/, Value *args, int argc, bool directCall) { if (argc < 1) - return Value::undefinedValue(); + return Value::undefinedValue().asReturnedValue(); ExecutionContext *parentContext = engine()->current; ExecutionEngine *engine = parentContext->engine; @@ -371,7 +371,7 @@ Value EvalFunction::evalCall(Value /*thisObject*/, Value *args, int argc, bool d } if (!args[0].isString()) - return args[0]; + return args[0].asReturnedValue(); const QString code = args[0].stringValue()->toQString(); bool inheritContext = !ctx->strictMode; @@ -383,7 +383,7 @@ Value EvalFunction::evalCall(Value /*thisObject*/, Value *args, int argc, bool d Function *function = script.function(); if (!function) - return Value::undefinedValue(); + return Value::undefinedValue().asReturnedValue(); strictMode = function->isStrict() || (ctx->strictMode); @@ -436,11 +436,11 @@ Value EvalFunction::evalCall(Value /*thisObject*/, Value *args, int argc, bool d while (engine->current != parentContext) engine->popContext(); - return result; + return result.asReturnedValue(); } -Value EvalFunction::call(Managed *that, CallData *callData) +ReturnedValue EvalFunction::call(Managed *that, CallData *callData) { // indirect call // ### const_cast diff --git a/src/qml/jsruntime/qv4globalobject_p.h b/src/qml/jsruntime/qv4globalobject_p.h index b777bf8915..c58078c26d 100644 --- a/src/qml/jsruntime/qv4globalobject_p.h +++ b/src/qml/jsruntime/qv4globalobject_p.h @@ -52,10 +52,10 @@ struct Q_QML_EXPORT EvalFunction : FunctionObject { EvalFunction(ExecutionContext *scope); - Value evalCall(Value thisObject, Value *args, int argc, bool directCall); + ReturnedValue evalCall(Value thisObject, Value *args, int argc, bool directCall); using Managed::construct; - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 32b7ba73cc..3048d00ddb 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -706,7 +706,7 @@ QString Stringify::Str(const QString &key, Value value) ScopedCallData callData(ctx->engine, 1); callData->thisObject = value; callData->args[0] = Value::fromString(ctx, key); - value = toJSON->call(callData); + value = Value::fromReturnedValue(toJSON->call(callData)); } } @@ -718,7 +718,7 @@ QString Stringify::Str(const QString &key, Value value) callData->args[0] = Value::fromString(ctx, key); callData->args[1] = value; callData->thisObject = holderValue; - value = replacerFunction->call(callData); + value = Value::fromReturnedValue(replacerFunction->call(callData)); } if (Object *o = value.asObject()) { diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index 2cffa55642..b630bbed5b 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -205,7 +205,7 @@ void Lookup::getterAccessor0(Lookup *l, Value *result, const Value &object) } else { ScopedCallData callData(o->engine(), 0); callData->thisObject = object; - res = getter->call(callData); + res = Value::fromReturnedValue(getter->call(callData)); } if (result) *result = res; @@ -228,7 +228,7 @@ void Lookup::getterAccessor1(Lookup *l, Value *result, const Value &object) } else { ScopedCallData callData(o->engine(), 0); callData->thisObject = object; - res = getter->call(callData); + res = Value::fromReturnedValue(getter->call(callData)); } if (result) *result = res; @@ -254,7 +254,7 @@ void Lookup::getterAccessor2(Lookup *l, Value *result, const Value &object) } else { ScopedCallData callData(o->engine(), 0); callData->thisObject = object; - res = getter->call(callData); + res = Value::fromReturnedValue(getter->call(callData)); } if (result) *result = res; @@ -309,7 +309,7 @@ void Lookup::primitiveGetterAccessor0(Lookup *l, Value *result, const Value &obj } else { ScopedCallData callData(o->engine(), 0); callData->thisObject = object; - res = getter->call(callData); + res = Value::fromReturnedValue(getter->call(callData)); } if (result) *result = res; @@ -333,7 +333,7 @@ void Lookup::primitiveGetterAccessor1(Lookup *l, Value *result, const Value &obj } else { ScopedCallData callData(o->engine(), 0); callData->thisObject = object; - res = getter->call(callData); + res = Value::fromReturnedValue(getter->call(callData)); } if (result) *result = res; @@ -437,7 +437,7 @@ void Lookup::globalGetterAccessor0(Lookup *l, ExecutionContext *ctx, Value *resu } else { ScopedCallData callData(ctx->engine, 0); callData->thisObject = Value::undefinedValue(); - *result = getter->call(callData); + *result = Value::fromReturnedValue(getter->call(callData)); } return; } @@ -456,7 +456,7 @@ void Lookup::globalGetterAccessor1(Lookup *l, ExecutionContext *ctx, Value *resu } else { ScopedCallData callData(ctx->engine, 0); callData->thisObject = Value::undefinedValue(); - *result = getter->call(callData); + *result = Value::fromReturnedValue(getter->call(callData)); } return; } @@ -478,7 +478,7 @@ void Lookup::globalGetterAccessor2(Lookup *l, ExecutionContext *ctx, Value *resu } else { ScopedCallData callData(ctx->engine, 0); callData->thisObject = Value::undefinedValue(); - *result = getter->call(callData); + *result = Value::fromReturnedValue(getter->call(callData)); } return; } diff --git a/src/qml/jsruntime/qv4managed.cpp b/src/qml/jsruntime/qv4managed.cpp index 62491ba7e5..1a86889373 100644 --- a/src/qml/jsruntime/qv4managed.cpp +++ b/src/qml/jsruntime/qv4managed.cpp @@ -181,7 +181,7 @@ Value Managed::construct(Managed *m, CallData *) m->engine()->current->throwTypeError(); } -Value Managed::call(Managed *m, CallData *) +ReturnedValue Managed::call(Managed *m, CallData *) { m->engine()->current->throwTypeError(); } diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index 50325478f5..a71ee717db 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -91,7 +91,7 @@ struct CallData struct ManagedVTable { - Value (*call)(Managed *, CallData *data); + ReturnedValue (*call)(Managed *, CallData *data); Value (*construct)(Managed *, CallData *data); void (*markObjects)(Managed *); void (*destroy)(Managed *); @@ -253,7 +253,7 @@ public: return vtbl->hasInstance(this, v); } Value construct(CallData *d); - Value call(CallData *d); + ReturnedValue call(CallData *d); Value get(String *name, bool *hasProperty = 0); Value getIndexed(uint index, bool *hasProperty = 0); void put(String *name, const Value &value) @@ -282,7 +282,7 @@ public: static void destroy(Managed *that) { that->_data = 0; } static bool hasInstance(Managed *that, const Value &value); static Value construct(Managed *m, CallData *d); - static Value call(Managed *m, CallData *); + static ReturnedValue call(Managed *m, CallData *); static void getLookup(Managed *m, Lookup *, Value *); static void setLookup(Managed *m, Lookup *l, const Value &v); static bool isEqualTo(Managed *m, Managed *other); diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index e581bac35e..ce80d599ae 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -62,10 +62,10 @@ Value NumberCtor::construct(Managed *m, CallData *callData) return Value::fromObject(m->engine()->newNumberObject(Value::fromDouble(dbl))); } -Value NumberCtor::call(Managed *, CallData *callData) +ReturnedValue NumberCtor::call(Managed *, CallData *callData) { double dbl = callData->argc ? callData->args[0].toNumber() : 0.; - return Value::fromDouble(dbl); + return Value::fromDouble(dbl).asReturnedValue(); } void NumberPrototype::init(ExecutionContext *ctx, const Value &ctor) diff --git a/src/qml/jsruntime/qv4numberobject_p.h b/src/qml/jsruntime/qv4numberobject_p.h index a0c2a65e80..a6e622e398 100644 --- a/src/qml/jsruntime/qv4numberobject_p.h +++ b/src/qml/jsruntime/qv4numberobject_p.h @@ -54,7 +54,7 @@ struct NumberCtor: FunctionObject NumberCtor(ExecutionContext *scope); static Value construct(Managed *that, CallData *callData); - static Value call(Managed *, CallData *callData); + static ReturnedValue call(Managed *, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index c4c1b6f7f4..7236307278 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -137,7 +137,7 @@ Value Object::getValue(const Value &thisObject, const Property *p, PropertyAttri ScopedCallData callData(getter->engine(), 0); callData->thisObject = thisObject; - return getter->call(callData); + return Value::fromReturnedValue(getter->call(callData)); } void Object::putValue(Property *pd, PropertyAttributes attrs, const Value &value) diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index cba8141257..5dc4d333ce 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -93,11 +93,11 @@ Value ObjectCtor::construct(Managed *that, CallData *callData) return Value::fromReturnedValue(__qmljs_to_object(v4->current, ValueRef(&callData->args[0]))); } -Value ObjectCtor::call(Managed *m, CallData *callData) +ReturnedValue ObjectCtor::call(Managed *m, CallData *callData) { if (!callData->argc || callData->args[0].isUndefined() || callData->args[0].isNull()) - return Value::fromObject(m->engine()->newObject()); - return Value::fromReturnedValue(__qmljs_to_object(m->engine()->current, ValueRef(&callData->args[0]))); + return Value::fromObject(m->engine()->newObject()).asReturnedValue(); + return __qmljs_to_object(m->engine()->current, ValueRef(&callData->args[0])); } void ObjectPrototype::init(ExecutionContext *ctx, const Value &ctor) @@ -388,7 +388,7 @@ Value ObjectPrototype::method_toLocaleString(SimpleCallContext *ctx) ctx->throwTypeError(); ScopedCallData callData(ctx->engine, 0); callData->thisObject = Value::fromObject(o); - return f->call(callData); + return Value::fromReturnedValue(f->call(callData)); } Value ObjectPrototype::method_valueOf(SimpleCallContext *ctx) diff --git a/src/qml/jsruntime/qv4objectproto_p.h b/src/qml/jsruntime/qv4objectproto_p.h index 33a115f203..06f88db656 100644 --- a/src/qml/jsruntime/qv4objectproto_p.h +++ b/src/qml/jsruntime/qv4objectproto_p.h @@ -54,7 +54,7 @@ struct ObjectCtor: FunctionObject ObjectCtor(ExecutionContext *scope); static Value construct(Managed *that, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 10a2c3de44..0ccb37f48b 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1688,10 +1688,10 @@ QV4::Value QObjectMethod::method_destroy(QV4::ExecutionContext *ctx, const Value return QV4::Value::undefinedValue(); } -Value QObjectMethod::call(Managed *m, CallData *callData) +ReturnedValue QObjectMethod::call(Managed *m, CallData *callData) { QObjectMethod *This = static_cast(m); - return This->callInternal(callData); + return This->callInternal(callData).asReturnedValue(); } Value QObjectMethod::callInternal(CallData *callData) diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 895a7e3dad..4034e14cf5 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -141,7 +141,7 @@ private: int m_index; QV4::PersistentValue m_qmlGlobal; - static Value call(Managed *, CallData *callData); + static ReturnedValue call(Managed *, CallData *callData); Value callInternal(CallData *callData); diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 448d10180c..7497b3e1ba 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -275,14 +275,14 @@ Value RegExpCtor::construct(Managed *m, CallData *callData) return Value::fromObject(o); } -Value RegExpCtor::call(Managed *that, CallData *callData) +ReturnedValue RegExpCtor::call(Managed *that, CallData *callData) { if (callData->argc > 0 && callData->args[0].as()) { if (callData->argc == 1 || callData->args[1].isUndefined()) - return callData->args[0]; + return callData->args[0].asReturnedValue(); } - return construct(that, callData); + return construct(that, callData).asReturnedValue(); } void RegExpPrototype::init(ExecutionContext *ctx, const Value &ctor) diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index a17802e2ff..cbf185ebf0 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -106,7 +106,7 @@ struct RegExpCtor: FunctionObject RegExpCtor(ExecutionContext *scope); static Value construct(Managed *m, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 6771ee752f..a6fc9f8967 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -575,7 +575,7 @@ ReturnedValue __qmljs_object_default_value(Object *object, int typeHint) if (FunctionObject *o = conv.asFunctionObject()) { ScopedCallData callData(engine, 0); callData->thisObject = Value::fromObject(object); - Value r = o->call(callData); + Value r = Value::fromReturnedValue(o->call(callData)); if (r.isPrimitive()) return r.asReturnedValue(); } @@ -584,7 +584,7 @@ ReturnedValue __qmljs_object_default_value(Object *object, int typeHint) if (FunctionObject *o = conv.asFunctionObject()) { ScopedCallData callData(engine, 0); callData->thisObject = Value::fromObject(object); - Value r = o->call(callData); + Value r = Value::fromReturnedValue(o->call(callData)); if (r.isPrimitive()) return r.asReturnedValue(); } @@ -940,9 +940,9 @@ ReturnedValue __qmljs_call_global_lookup(ExecutionContext *context, uint index, context->throwTypeError(); if (o == context->engine->evalFunction && l->name->isEqualTo(context->engine->id_eval)) - return static_cast(o)->evalCall(callData->thisObject, callData->args, callData->argc, true).asReturnedValue(); + return static_cast(o)->evalCall(callData->thisObject, callData->args, callData->argc, true); - return o->call(callData).asReturnedValue(); + return o->call(callData); } @@ -966,10 +966,10 @@ ReturnedValue __qmljs_call_activation_property(ExecutionContext *context, String } if (o == context->engine->evalFunction && name->isEqualTo(context->engine->id_eval)) { - return static_cast(o)->evalCall(callData->thisObject, callData->args, callData->argc, true).asReturnedValue(); + return static_cast(o)->evalCall(callData->thisObject, callData->args, callData->argc, true); } - return o->call(callData).asReturnedValue(); + return o->call(callData); } ReturnedValue __qmljs_call_property(ExecutionContext *context, String *name, CallDataRef callData) @@ -991,7 +991,7 @@ ReturnedValue __qmljs_call_property(ExecutionContext *context, String *name, Cal context->throwTypeError(error); } - return o->call(callData).asReturnedValue(); + return o->call(callData); } ReturnedValue __qmljs_call_property_lookup(ExecutionContext *context, uint index, CallDataRef callData) @@ -1005,7 +1005,7 @@ ReturnedValue __qmljs_call_property_lookup(ExecutionContext *context, uint index if (!o) context->throwTypeError(); - return o->call(callData).asReturnedValue(); + return o->call(callData); } ReturnedValue __qmljs_call_element(ExecutionContext *context, const ValueRef index, CallDataRef callData) @@ -1017,7 +1017,7 @@ ReturnedValue __qmljs_call_element(ExecutionContext *context, const ValueRef ind if (!o) context->throwTypeError(); - return o->call(callData).asReturnedValue(); + return o->call(callData); } ReturnedValue __qmljs_call_value(ExecutionContext *context, const ValueRef func, CallDataRef callData) @@ -1026,7 +1026,7 @@ ReturnedValue __qmljs_call_value(ExecutionContext *context, const ValueRef func, if (!o) context->throwTypeError(); - return o->call(callData).asReturnedValue(); + return o->call(callData); } diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 23d84a8b47..57938ff5b7 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -79,7 +79,7 @@ struct QmlBindingWrapper : FunctionObject scope->engine->popContext(); } - static Value call(Managed *that, CallData *); + static ReturnedValue call(Managed *that, CallData *); static void markObjects(Managed *m) { QmlBindingWrapper *wrapper = static_cast(m); @@ -122,7 +122,7 @@ struct CompilationUnitHolder : public QV4::Object DEFINE_MANAGED_VTABLE(CompilationUnitHolder); -Value QmlBindingWrapper::call(Managed *that, CallData *) +ReturnedValue QmlBindingWrapper::call(Managed *that, CallData *) { ExecutionEngine *engine = that->engine(); ValueScope scope(engine); @@ -134,7 +134,7 @@ Value QmlBindingWrapper::call(Managed *that, CallData *) ScopedValue result(scope, This->function->code(ctx, This->function->codeData)); engine->popContext(); - return result; + return result.asReturnedValue(); } @@ -252,7 +252,7 @@ Value Script::run() FunctionObject *f = new (engine->memoryManager) QmlBindingWrapper(scope, vmFunction, qml.value().asObject()); ScopedCallData callData(scope->engine, 0); callData->thisObject = Value::undefinedValue(); - return f->call(callData); + return Value::fromReturnedValue(f->call(callData)); } } diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index 058964969c..529c395c26 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -354,12 +354,13 @@ public: bool operator()(typename Container::value_type lhs, typename Container::value_type rhs) { QV4::Managed *fun = this->m_compareFn.asManaged(); + ValueScope scope(fun->engine()); ScopedCallData callData(fun->engine(), 2); callData->args[0] = convertElementToValue(this->m_ctx->engine, lhs); callData->args[1] = convertElementToValue(this->m_ctx->engine, rhs); callData->thisObject = QV4::Value::fromObject(this->m_ctx->engine->globalObject); - QV4::Value result = fun->call(callData); - return result.toNumber() < 0; + QV4::ScopedValue result(scope, fun->call(callData)); + return result->toNumber() < 0; } private: diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index d595533714..b66ee6c180 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -170,14 +170,14 @@ Value StringCtor::construct(Managed *m, CallData *callData) return Value::fromObject(m->engine()->newStringObject(value)); } -Value StringCtor::call(Managed *m, CallData *callData) +ReturnedValue StringCtor::call(Managed *m, CallData *callData) { Value value; if (callData->argc) value = Value::fromString(callData->args[0].toString(m->engine()->current)); else value = Value::fromString(m->engine()->current, QString()); - return value; + return value.asReturnedValue(); } void StringPrototype::init(ExecutionEngine *engine, const Value &ctor) @@ -351,6 +351,7 @@ Value StringPrototype::method_match(SimpleCallContext *context) if (context->thisObject.isUndefined() || context->thisObject.isNull()) context->throwTypeError(); + ValueScope scope(context); String *s = context->thisObject.toString(context); Value regexp = context->argumentCount ? context->arguments[0] : Value::undefinedValue(); @@ -374,7 +375,7 @@ Value StringPrototype::method_match(SimpleCallContext *context) callData->thisObject = Value::fromObject(rx); callData->args[0] = Value::fromString(s); if (!global) - return exec->call(callData); + return Value::fromReturnedValue(exec->call(callData)); String *lastIndex = context->engine->newString(QStringLiteral("lastIndex")); rx->put(lastIndex, Value::fromInt32(0)); @@ -382,11 +383,13 @@ Value StringPrototype::method_match(SimpleCallContext *context) double previousLastIndex = 0; uint n = 0; + ScopedValue result(scope); + ScopedValue matchStr(scope); while (1) { - Value result = exec->call(callData); - if (result.isNull()) + result = exec->call(callData); + if (result->isNull()) break; - assert(result.isObject()); + assert(result->isObject()); double thisIndex = rx->get(lastIndex, 0).toInteger(); if (previousLastIndex == thisIndex) { previousLastIndex = thisIndex + 1; @@ -394,7 +397,7 @@ Value StringPrototype::method_match(SimpleCallContext *context) } else { previousLastIndex = thisIndex; } - Value matchStr = result.objectValue()->getIndexed(0); + matchStr = result->objectValue()->getIndexed(0); a->arraySet(n, matchStr); ++n; } @@ -452,6 +455,7 @@ static void appendReplacementString(QString *result, const QString &input, const Value StringPrototype::method_replace(SimpleCallContext *ctx) { + ValueScope scope(ctx); QString string; if (StringObject *thisString = ctx->thisObject.asStringObject()) string = thisString->value.stringValue()->toQString(); @@ -507,6 +511,7 @@ Value StringPrototype::method_replace(SimpleCallContext *ctx) QString result; Value replaceValue = ctx->argument(1); + ScopedValue replacement(scope); if (FunctionObject* searchCallback = replaceValue.asFunctionObject()) { result.reserve(string.length() + 10*numStringMatches); ScopedCallData callData(ctx->engine, numCaptures + 2); @@ -528,9 +533,9 @@ Value StringPrototype::method_replace(SimpleCallContext *ctx) callData->args[numCaptures] = Value::fromUInt32(matchStart); callData->args[numCaptures + 1] = Value::fromString(ctx, string); - Value replacement = searchCallback->call(callData); + replacement = searchCallback->call(callData); result += string.midRef(lastEnd, matchStart - lastEnd); - result += replacement.toString(ctx)->toQString(); + result += replacement->toString(ctx)->toQString(); lastEnd = matchEnd; } result += string.midRef(lastEnd); diff --git a/src/qml/jsruntime/qv4stringobject_p.h b/src/qml/jsruntime/qv4stringobject_p.h index f9cf89e9d9..702900bb36 100644 --- a/src/qml/jsruntime/qv4stringobject_p.h +++ b/src/qml/jsruntime/qv4stringobject_p.h @@ -71,7 +71,7 @@ struct StringCtor: FunctionObject StringCtor(ExecutionContext *scope); static Value construct(Managed *m, CallData *callData); - static Value call(Managed *that, CallData *callData); + static ReturnedValue call(Managed *that, CallData *callData); protected: static const ManagedVTable static_vtbl; diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp index 0347188ae0..6a717cde8d 100644 --- a/src/qml/jsruntime/qv4value.cpp +++ b/src/qml/jsruntime/qv4value.cpp @@ -327,6 +327,11 @@ PersistentValue::PersistentValue(const Value &val) { } +PersistentValue::PersistentValue(ReturnedValue val) + : d(new PersistentValuePrivate(Value::fromReturnedValue(val))) +{ +} + PersistentValue::PersistentValue(const PersistentValue &other) : d(other.d) { @@ -360,6 +365,16 @@ PersistentValue &PersistentValue::operator =(const Value &other) return *this; } +PersistentValue &PersistentValue::operator =(const ReturnedValue &other) +{ + if (!d) { + d = new PersistentValuePrivate(Value::fromReturnedValue(other)); + return *this; + } + d = d->detach(Value::fromReturnedValue(other)); + return *this; +} + PersistentValue::~PersistentValue() { if (d) diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 8d6f26ea57..ecd0c319b9 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -279,7 +279,7 @@ inline ErrorObject *Value::asErrorObject() const inline Value Managed::construct(CallData *d) { return vtbl->construct(this, d); } -inline Value Managed::call(CallData *d) { +inline ReturnedValue Managed::call(CallData *d) { return vtbl->call(this, d); } @@ -311,10 +311,13 @@ class Q_QML_EXPORT PersistentValue { public: PersistentValue() : d(0) {} + PersistentValue(const Value &val); + PersistentValue(ReturnedValue val); PersistentValue(const PersistentValue &other); PersistentValue &operator=(const PersistentValue &other); PersistentValue &operator=(const Value &other); + PersistentValue &operator =(const ReturnedValue &other); ~PersistentValue(); Value value() const { diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index c86309027f..7e726ab96e 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -162,8 +162,9 @@ QQmlJavaScriptExpression::evaluate(QQmlContextData *context, // incase we have been deleted. DeleteWatcher watcher(this); - QV4::Value result = QV4::Value::undefinedValue(); QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); + QV4::ValueScope scope(v4); + QV4::ScopedValue result(scope, QV4::Value::undefinedValue()); QV4::ExecutionContext *ctx = v4->current; try { QV4::Value This = ep->v8engine()->global(); @@ -179,7 +180,7 @@ QQmlJavaScriptExpression::evaluate(QQmlContextData *context, result = function.asFunctionObject()->call(callData); if (isUndefined) - *isUndefined = result.isUndefined(); + *isUndefined = result->isUndefined(); if (!watcher.wasDeleted() && hasDelayedError()) delayedError()->clearError(); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0079b9580f..7ac218772b 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -927,13 +927,14 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QQmlVMEMetaData::MethodData *data = metaData->methodData() + id; + QV4::ValueScope scope(function->engine()); QV4::ScopedCallData callData(function->engine(), data->parameterCount); callData->thisObject = ep->v8engine()->global(); for (int ii = 0; ii < data->parameterCount; ++ii) callData->args[ii] = ep->v8engine()->fromVariant(*(QVariant *)a[ii + 1]); - QV4::Value result = QV4::Value::undefinedValue(); + QV4::ScopedValue result(scope); QV4::ExecutionContext *ctx = function->engine()->current; try { result = function->call(callData); diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 1d62eabf9a..fc3c32fd88 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -1577,8 +1577,8 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject return Value::fromObject(w); } - static Value call(Managed *, QV4::CallData *) { - return Value::undefinedValue(); + static ReturnedValue call(Managed *, QV4::CallData *) { + return Value::undefinedValue().asReturnedValue(); } void setupProto(); diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 35a63ba000..867d63e551 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -1184,7 +1184,7 @@ struct BindingFunction : public QV4::FunctionObject bindingKeyFlag = true; } - static Value call(Managed *that, CallData *callData) + static ReturnedValue call(Managed *that, CallData *callData) { BindingFunction *This = static_cast(that); return This->originalFunction->call(callData); diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index f3a4179374..9c9a2196c7 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -81,7 +81,7 @@ struct DelegateModelGroupFunction: QV4::FunctionObject return QV4::Value::undefinedValue(); } - static QV4::Value call(QV4::Managed *that, QV4::CallData *callData) + static QV4::ReturnedValue call(QV4::Managed *that, QV4::CallData *callData) { DelegateModelGroupFunction *f = static_cast(that); QQmlDelegateModelItemObject *o = callData->thisObject.as(); @@ -89,7 +89,7 @@ struct DelegateModelGroupFunction: QV4::FunctionObject that->engine()->current->throwTypeError(QStringLiteral("Not a valid VisualData object")); QV4::Value v = callData->argc ? callData->args[0] : QV4::Value::undefinedValue(); - return f->code(o->item, f->flag, v); + return f->code(o->item, f->flag, v).asReturnedValue(); } }; diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index 26514ac6db..42548e6ad6 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -244,8 +244,10 @@ void QQuickWorkerScriptEnginePrivate::WorkerEngine::init() QV4::Value QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(int id) { QV4::FunctionObject *f = createsend.value().asFunctionObject(); - QV4::Value v = QV4::Value::undefinedValue(); - QV4::ExecutionContext *ctx = f->internalClass->engine->current; + QV4::ExecutionContext *ctx = f->engine()->current; + QV4::ValueScope scope(ctx->engine); + + QV4::ScopedValue v(scope); try { QV4::ScopedCallData callData(m_v4Engine, 1); callData->args[0] = QV4::Value::fromInt32(id); @@ -346,10 +348,11 @@ void QQuickWorkerScriptEnginePrivate::processMessage(int id, const QByteArray &d if (!script) return; - QV4::Value value = QV4::Serialize::deserialize(data, workerEngine); - QV4::FunctionObject *f = workerEngine->onmessage.value().asFunctionObject(); QV4::ExecutionContext *ctx = f->internalClass->engine->current; + QV4::ValueScope scope(ctx); + + QV4::ScopedValue value(scope, QV4::Serialize::deserialize(data, workerEngine)); try { QV4::ScopedCallData callData(ctx->engine, 2); -- cgit v1.2.3