From 62d1b5a08aa2c21c95a2a77afbe34c38ed37a2aa Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 26 Sep 2013 13:05:25 +0200 Subject: Fix API for Object::define*Property use ValueRef instead of const Value &. Change-Id: I3fd0ca829870db27f036825d713c53dc0600be07 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4argumentsobject.cpp | 2 +- src/qml/jsruntime/qv4arrayobject.cpp | 12 ++++++---- src/qml/jsruntime/qv4arrayobject_p.h | 2 +- src/qml/jsruntime/qv4booleanobject.cpp | 10 ++++---- src/qml/jsruntime/qv4booleanobject_p.h | 2 +- src/qml/jsruntime/qv4dateobject.cpp | 16 +++++++------ src/qml/jsruntime/qv4dateobject_p.h | 2 +- src/qml/jsruntime/qv4engine.cpp | 10 ++++---- src/qml/jsruntime/qv4errorobject.cpp | 41 ++++++++++++++++---------------- src/qml/jsruntime/qv4errorobject_p.h | 16 ++++++------- src/qml/jsruntime/qv4functionobject.cpp | 11 +++++---- src/qml/jsruntime/qv4functionobject_p.h | 2 +- src/qml/jsruntime/qv4numberobject.cpp | 20 +++++++++------- src/qml/jsruntime/qv4numberobject_p.h | 2 +- src/qml/jsruntime/qv4object.cpp | 16 ++++++------- src/qml/jsruntime/qv4object_p.h | 8 +++---- src/qml/jsruntime/qv4objectproto.cpp | 39 +++++++++++++++--------------- src/qml/jsruntime/qv4objectproto_p.h | 2 +- src/qml/jsruntime/qv4regexpobject.cpp | 15 +++++++----- src/qml/jsruntime/qv4regexpobject_p.h | 2 +- src/qml/jsruntime/qv4scopedvalue_p.h | 3 +++ src/qml/jsruntime/qv4stringobject.cpp | 19 +++++++++------ src/qml/jsruntime/qv4stringobject_p.h | 2 +- src/qml/jsruntime/qv4value_def_p.h | 2 +- src/qml/jsruntime/qv4value_p.h | 2 +- 25 files changed, 142 insertions(+), 116 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp index 9f3675e817..7e4b828833 100644 --- a/src/qml/jsruntime/qv4argumentsobject.cpp +++ b/src/qml/jsruntime/qv4argumentsobject.cpp @@ -172,7 +172,7 @@ ReturnedValue ArgumentsSetterFunction::call(Managed *setter, CallData *callData) setter->engine()->current->throwTypeError(); assert(s->index < o->context->callData->argc); - o->context->callData->args[s->index] = callData->argc ? callData->args[0] : Primitive::undefinedValue(); + o->context->callData->args[s->index] = callData->argc ? callData->args[0].asReturnedValue() : Encode::undefined(); return Primitive::undefinedValue().asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index ea4d174bb7..7051276f4c 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -91,12 +91,14 @@ ArrayPrototype::ArrayPrototype(InternalClass *ic) { } -void ArrayPrototype::init(ExecutionEngine *engine, const Value &ctor) +void ArrayPrototype::init(ExecutionEngine *engine, ObjectRef ctor) { - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("isArray"), method_isArray, 1); - defineDefaultProperty(QStringLiteral("constructor"), ctor); + Scope scope(engine); + ScopedObject o(scope); + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); + ctor->defineReadonlyProperty(engine->id_prototype, (o = this)); + ctor->defineDefaultProperty(QStringLiteral("isArray"), method_isArray, 1); + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(engine->id_toString, method_toString, 0); defineDefaultProperty(QStringLiteral("toLocaleString"), method_toLocaleString, 0); defineDefaultProperty(QStringLiteral("concat"), method_concat, 1); diff --git a/src/qml/jsruntime/qv4arrayobject_p.h b/src/qml/jsruntime/qv4arrayobject_p.h index 62a731f4e0..121e0dd344 100644 --- a/src/qml/jsruntime/qv4arrayobject_p.h +++ b/src/qml/jsruntime/qv4arrayobject_p.h @@ -62,7 +62,7 @@ struct ArrayPrototype: ArrayObject { ArrayPrototype(InternalClass *ic); - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static uint getLength(ExecutionContext *ctx, Object *o); diff --git a/src/qml/jsruntime/qv4booleanobject.cpp b/src/qml/jsruntime/qv4booleanobject.cpp index e4274b2ed9..341e3003c6 100644 --- a/src/qml/jsruntime/qv4booleanobject.cpp +++ b/src/qml/jsruntime/qv4booleanobject.cpp @@ -65,11 +65,13 @@ ReturnedValue BooleanCtor::call(Managed *, CallData *callData) return Encode(value); } -void BooleanPrototype::init(ExecutionEngine *engine, const Value &ctor) +void BooleanPrototype::init(ExecutionEngine *engine, ObjectRef ctor) { - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); - defineDefaultProperty(QStringLiteral("constructor"), ctor); + Scope scope(engine); + ScopedObject o(scope); + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); + ctor->defineReadonlyProperty(engine->id_prototype, (o = this)); + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(engine->id_toString, method_toString); defineDefaultProperty(engine->id_valueOf, method_valueOf); } diff --git a/src/qml/jsruntime/qv4booleanobject_p.h b/src/qml/jsruntime/qv4booleanobject_p.h index a7b85deace..6766fae830 100644 --- a/src/qml/jsruntime/qv4booleanobject_p.h +++ b/src/qml/jsruntime/qv4booleanobject_p.h @@ -61,7 +61,7 @@ struct BooleanCtor: FunctionObject struct BooleanPrototype: BooleanObject { BooleanPrototype(InternalClass *ic): BooleanObject(ic) {} - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static ReturnedValue method_toString(SimpleCallContext *ctx); static ReturnedValue method_valueOf(SimpleCallContext *ctx); diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index cb5c37d421..ffc5fa891a 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -701,17 +701,19 @@ ReturnedValue DateCtor::call(Managed *m, CallData *) return m->engine()->newString(ToString(t))->asReturnedValue(); } -void DatePrototype::init(ExecutionEngine *engine, const Value &ctor) +void DatePrototype::init(ExecutionEngine *engine, ObjectRef ctor) { - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(7)); + Scope scope(engine); + ScopedObject o(scope); + ctor->defineReadonlyProperty(engine->id_prototype, (o = this)); + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(7)); LocalTZA = getLocalTZA(); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("parse"), method_parse, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("UTC"), method_UTC, 7); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("now"), method_now, 0); + ctor->defineDefaultProperty(QStringLiteral("parse"), method_parse, 1); + ctor->defineDefaultProperty(QStringLiteral("UTC"), method_UTC, 7); + ctor->defineDefaultProperty(QStringLiteral("now"), method_now, 0); - defineDefaultProperty(QStringLiteral("constructor"), ctor); + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(engine->id_toString, method_toString, 0); defineDefaultProperty(QStringLiteral("toDateString"), method_toDateString, 0); defineDefaultProperty(QStringLiteral("toTimeString"), method_toTimeString, 0); diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h index b560a26b7f..56588580ff 100644 --- a/src/qml/jsruntime/qv4dateobject_p.h +++ b/src/qml/jsruntime/qv4dateobject_p.h @@ -81,7 +81,7 @@ struct DateCtor: FunctionObject struct DatePrototype: DateObject { DatePrototype(InternalClass *ic): DateObject(ic) {} - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static double getThisDate(ExecutionContext *ctx); diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 4b02f89b88..62d8a2cf0c 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -124,6 +124,8 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) jsStackBase = (SafeValue *)jsStack->base(); jsStackTop = jsStackBase; + Scope scope(this); + identifierTable = new IdentifierTable(this); emptyClass = new (classPool.allocate(sizeof(InternalClass))) InternalClass(this); @@ -277,15 +279,16 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) globalObject->defineDefaultProperty(QStringLiteral("SyntaxError"), syntaxErrorCtor); globalObject->defineDefaultProperty(QStringLiteral("TypeError"), typeErrorCtor); globalObject->defineDefaultProperty(QStringLiteral("URIError"), uRIErrorCtor); - globalObject->defineDefaultProperty(QStringLiteral("Math"), Value::fromObject(new (memoryManager) MathObject(this))); - globalObject->defineDefaultProperty(QStringLiteral("JSON"), Value::fromObject(new (memoryManager) JsonObject(this))); + ScopedObject o(scope); + globalObject->defineDefaultProperty(QStringLiteral("Math"), (o = new (memoryManager) MathObject(this))); + globalObject->defineDefaultProperty(QStringLiteral("JSON"), (o = new (memoryManager) JsonObject(this))); globalObject->defineReadonlyProperty(QStringLiteral("undefined"), Primitive::undefinedValue()); globalObject->defineReadonlyProperty(QStringLiteral("NaN"), Primitive::fromDouble(std::numeric_limits::quiet_NaN())); globalObject->defineReadonlyProperty(QStringLiteral("Infinity"), Primitive::fromDouble(Q_INFINITY)); evalFunction = new (memoryManager) EvalFunction(rootContext); - globalObject->defineDefaultProperty(QStringLiteral("eval"), Value::fromObject(evalFunction)); + globalObject->defineDefaultProperty(QStringLiteral("eval"), (o = evalFunction)); globalObject->defineDefaultProperty(QStringLiteral("parseInt"), GlobalFunctions::method_parseInt, 2); globalObject->defineDefaultProperty(QStringLiteral("parseFloat"), GlobalFunctions::method_parseFloat, 1); @@ -298,7 +301,6 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) globalObject->defineDefaultProperty(QStringLiteral("escape"), GlobalFunctions::method_escape, 1); globalObject->defineDefaultProperty(QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1); - Scope scope(this); Scoped name(scope, newString(QStringLiteral("thrower"))); thrower = newBuiltinFunction(rootContext, name, throwTypeError)->getPointer(); } diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 88c47a0c3a..b247c1533d 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -83,7 +83,7 @@ ErrorObject::ErrorObject(InternalClass *ic) ScopedValue protectThis(scope, this); ScopedString s(scope, ic->engine->newString("Error")); - defineDefaultProperty(QStringLiteral("name"), s.asValue()); + defineDefaultProperty(QStringLiteral("name"), s); } ErrorObject::ErrorObject(InternalClass *ic, const ValueRef message, ErrorType t) @@ -100,13 +100,13 @@ ErrorObject::ErrorObject(InternalClass *ic, const ValueRef message, ErrorType t) defineAccessorProperty(QStringLiteral("stack"), ErrorObject::method_get_stack, 0); if (!message->isUndefined()) - defineDefaultProperty(QStringLiteral("message"), *message); + defineDefaultProperty(QStringLiteral("message"), message); ScopedString s(scope); - defineDefaultProperty(QStringLiteral("name"), (s = ic->engine->newString(className())).asValue()); + defineDefaultProperty(QStringLiteral("name"), (s = ic->engine->newString(className()))); stackTrace = ic->engine->stackTrace(); if (!stackTrace.isEmpty()) { - defineDefaultProperty(QStringLiteral("fileName"), (s = ic->engine->newString(stackTrace.at(0).source)).asValue()); + defineDefaultProperty(QStringLiteral("fileName"), (s = ic->engine->newString(stackTrace.at(0).source))); defineDefaultProperty(QStringLiteral("lineNumber"), Primitive::fromInt32(stackTrace.at(0).line)); } } @@ -127,11 +127,11 @@ ErrorObject::ErrorObject(InternalClass *ic, const QString &message, ErrorObject: ScopedValue v(scope, ic->engine->newString(message)); defineDefaultProperty(QStringLiteral("message"), v); - defineDefaultProperty(QStringLiteral("name"), (s = ic->engine->newString(className())).asValue()); + defineDefaultProperty(QStringLiteral("name"), (s = ic->engine->newString(className()))); stackTrace = ic->engine->stackTrace(); if (!stackTrace.isEmpty()) { - defineDefaultProperty(QStringLiteral("fileName"), (s = ic->engine->newString(stackTrace.at(0).source)).asValue()); + defineDefaultProperty(QStringLiteral("fileName"), (s = ic->engine->newString(stackTrace.at(0).source))); defineDefaultProperty(QStringLiteral("lineNumber"), Primitive::fromInt32(stackTrace.at(0).line)); } } @@ -149,7 +149,7 @@ ErrorObject::ErrorObject(InternalClass *ic, const QString &message, const QStrin ScopedString s(scope); defineAccessorProperty(QStringLiteral("stack"), ErrorObject::method_get_stack, 0); - defineDefaultProperty(QStringLiteral("name"), (s = ic->engine->newString(className())).asValue()); + defineDefaultProperty(QStringLiteral("name"), (s = ic->engine->newString(className()))); stackTrace = ic->engine->stackTrace(); ExecutionEngine::StackFrame frame; @@ -159,7 +159,7 @@ ErrorObject::ErrorObject(InternalClass *ic, const QString &message, const QStrin stackTrace.prepend(frame); if (!stackTrace.isEmpty()) { - defineDefaultProperty(QStringLiteral("fileName"), (s = ic->engine->newString(stackTrace.at(0).source)).asValue()); + defineDefaultProperty(QStringLiteral("fileName"), (s = ic->engine->newString(stackTrace.at(0).source))); defineDefaultProperty(QStringLiteral("lineNumber"), Primitive::fromInt32(stackTrace.at(0).line)); } @@ -283,7 +283,7 @@ ErrorCtor::ErrorCtor(ExecutionContext *scope, const QString &name) ReturnedValue ErrorCtor::construct(Managed *m, CallData *callData) { Scope scope(m->engine()); - ScopedValue v(scope, callData->argc ? callData->args[0] : Primitive::undefinedValue()); + ScopedValue v(scope, callData->argument(0)); return Encode(m->engine()->newErrorObject(v)); } @@ -301,7 +301,7 @@ EvalErrorCtor::EvalErrorCtor(ExecutionContext *scope) ReturnedValue EvalErrorCtor::construct(Managed *m, CallData *callData) { Scope scope(m->engine()); - ScopedValue v(scope, callData->argc ? callData->args[0] : Primitive::undefinedValue()); + ScopedValue v(scope, callData->argument(0)); return (new (m->engine()->memoryManager) EvalErrorObject(m->engine(), v))->asReturnedValue(); } @@ -314,7 +314,7 @@ RangeErrorCtor::RangeErrorCtor(ExecutionContext *scope) ReturnedValue RangeErrorCtor::construct(Managed *m, CallData *callData) { Scope scope(m->engine()); - ScopedValue v(scope, callData->argc ? callData->args[0] : Primitive::undefinedValue()); + ScopedValue v(scope, callData->argument(0)); return (new (m->engine()->memoryManager) RangeErrorObject(scope.engine, v))->asReturnedValue(); } @@ -327,7 +327,7 @@ ReferenceErrorCtor::ReferenceErrorCtor(ExecutionContext *scope) ReturnedValue ReferenceErrorCtor::construct(Managed *m, CallData *callData) { Scope scope(m->engine()); - ScopedValue v(scope, callData->argc ? callData->args[0] : Primitive::undefinedValue()); + ScopedValue v(scope, callData->argument(0)); return (new (m->engine()->memoryManager) ReferenceErrorObject(scope.engine, v))->asReturnedValue(); } @@ -340,7 +340,7 @@ SyntaxErrorCtor::SyntaxErrorCtor(ExecutionContext *scope) ReturnedValue SyntaxErrorCtor::construct(Managed *m, CallData *callData) { Scope scope(m->engine()); - ScopedValue v(scope, callData->argc ? callData->args[0] : Primitive::undefinedValue()); + ScopedValue v(scope, callData->argument(0)); return (new (m->engine()->memoryManager) SyntaxErrorObject(scope.engine, v))->asReturnedValue(); } @@ -353,7 +353,7 @@ TypeErrorCtor::TypeErrorCtor(ExecutionContext *scope) ReturnedValue TypeErrorCtor::construct(Managed *m, CallData *callData) { Scope scope(m->engine()); - ScopedValue v(scope, callData->argc ? callData->args[0] : Primitive::undefinedValue()); + ScopedValue v(scope, callData->argument(0)); return (new (m->engine()->memoryManager) TypeErrorObject(scope.engine, v))->asReturnedValue(); } @@ -366,19 +366,20 @@ URIErrorCtor::URIErrorCtor(ExecutionContext *scope) ReturnedValue URIErrorCtor::construct(Managed *m, CallData *callData) { Scope scope(m->engine()); - ScopedValue v(scope, callData->argc ? callData->args[0] : Primitive::undefinedValue()); + ScopedValue v(scope, callData->argument(0)); return (new (m->engine()->memoryManager) URIErrorObject(scope.engine, v))->asReturnedValue(); } -void ErrorPrototype::init(ExecutionEngine *engine, const Value &ctor, Object *obj) +void ErrorPrototype::init(ExecutionEngine *engine, ObjectRef ctor, Object *obj) { Scope scope(engine); ScopedString s(scope); - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(obj)); - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); - obj->defineDefaultProperty(QStringLiteral("constructor"), ctor); + ScopedObject o(scope); + ctor->defineReadonlyProperty(engine->id_prototype, (o = obj)); + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); + obj->defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); obj->defineDefaultProperty(engine->id_toString, method_toString, 0); - obj->defineDefaultProperty(QStringLiteral("message"), (s = engine->newString(QString())).asValue()); + obj->defineDefaultProperty(QStringLiteral("message"), (s = engine->newString(QString()))); } ReturnedValue ErrorPrototype::method_toString(SimpleCallContext *ctx) diff --git a/src/qml/jsruntime/qv4errorobject_p.h b/src/qml/jsruntime/qv4errorobject_p.h index dbe33d0bd8..d48edfa15e 100644 --- a/src/qml/jsruntime/qv4errorobject_p.h +++ b/src/qml/jsruntime/qv4errorobject_p.h @@ -176,46 +176,46 @@ struct ErrorPrototype: ErrorObject { // ### shouldn't be undefined ErrorPrototype(InternalClass *ic): ErrorObject(ic) {} - void init(ExecutionEngine *engine, const Value &ctor) { init(engine, ctor, this); } + void init(ExecutionEngine *engine, ObjectRef ctor) { init(engine, ctor, this); } - static void init(ExecutionEngine *engine, const Value &ctor, Object *obj); + static void init(ExecutionEngine *engine, ObjectRef ctor, Object *obj); static ReturnedValue method_toString(SimpleCallContext *ctx); }; struct EvalErrorPrototype: ErrorObject { EvalErrorPrototype(InternalClass *ic): ErrorObject(ic) { vtbl = &static_vtbl; } - void init(ExecutionEngine *engine, const Value &ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, ObjectRef ctor) { ErrorPrototype::init(engine, ctor, this); } }; struct RangeErrorPrototype: ErrorObject { RangeErrorPrototype(InternalClass *ic): ErrorObject(ic) { vtbl = &static_vtbl; } - void init(ExecutionEngine *engine, const Value &ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, ObjectRef ctor) { ErrorPrototype::init(engine, ctor, this); } }; struct ReferenceErrorPrototype: ErrorObject { ReferenceErrorPrototype(InternalClass *ic): ErrorObject(ic) { vtbl = &static_vtbl; } - void init(ExecutionEngine *engine, const Value &ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, ObjectRef ctor) { ErrorPrototype::init(engine, ctor, this); } }; struct SyntaxErrorPrototype: ErrorObject { SyntaxErrorPrototype(InternalClass *ic): ErrorObject(ic) { vtbl = &static_vtbl; } - void init(ExecutionEngine *engine, const Value &ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, ObjectRef ctor) { ErrorPrototype::init(engine, ctor, this); } }; struct TypeErrorPrototype: ErrorObject { TypeErrorPrototype(InternalClass *ic): ErrorObject(ic) { vtbl = &static_vtbl; } - void init(ExecutionEngine *engine, const Value &ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, ObjectRef ctor) { ErrorPrototype::init(engine, ctor, this); } }; struct URIErrorPrototype: ErrorObject { URIErrorPrototype(InternalClass *ic): ErrorObject(ic) { vtbl = &static_vtbl; } - void init(ExecutionEngine *engine, const Value &ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, ObjectRef ctor) { ErrorPrototype::init(engine, ctor, this); } }; diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 888be1733e..02ea3ff788 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -293,13 +293,16 @@ FunctionPrototype::FunctionPrototype(InternalClass *ic) { } -void FunctionPrototype::init(ExecutionEngine *engine, const Value &ctor) +void FunctionPrototype::init(ExecutionEngine *engine, ObjectRef ctor) { - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); + Scope scope(engine); + ScopedObject o(scope); + + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); + ctor->defineReadonlyProperty(engine->id_prototype, (o = this)); defineReadonlyProperty(engine->id_length, Primitive::fromInt32(0)); - defineDefaultProperty(QStringLiteral("constructor"), ctor); + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(engine->id_toString, method_toString, 0); defineDefaultProperty(QStringLiteral("apply"), method_apply, 2); defineDefaultProperty(QStringLiteral("call"), method_call, 1); diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 1b8a6c51ed..7fece1d2f4 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -162,7 +162,7 @@ struct FunctionCtor: FunctionObject struct FunctionPrototype: FunctionObject { FunctionPrototype(InternalClass *ic); - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static ReturnedValue method_toString(SimpleCallContext *ctx); static ReturnedValue method_apply(SimpleCallContext *ctx); diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index 38cf899427..5f25406987 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -70,26 +70,28 @@ ReturnedValue NumberCtor::call(Managed *, CallData *callData) return Primitive::fromDouble(dbl).asReturnedValue(); } -void NumberPrototype::init(ExecutionEngine *engine, const Value &ctor) +void NumberPrototype::init(ExecutionEngine *engine, ObjectRef ctor) { - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); + Scope scope(engine); + ScopedObject o(scope); + ctor->defineReadonlyProperty(engine->id_prototype, (o = this)); + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); - ctor.objectValue()->defineReadonlyProperty(QStringLiteral("NaN"), Primitive::fromDouble(qSNaN())); - ctor.objectValue()->defineReadonlyProperty(QStringLiteral("NEGATIVE_INFINITY"), Primitive::fromDouble(-qInf())); - ctor.objectValue()->defineReadonlyProperty(QStringLiteral("POSITIVE_INFINITY"), Primitive::fromDouble(qInf())); - ctor.objectValue()->defineReadonlyProperty(QStringLiteral("MAX_VALUE"), Primitive::fromDouble(1.7976931348623158e+308)); + ctor->defineReadonlyProperty(QStringLiteral("NaN"), Primitive::fromDouble(qSNaN())); + ctor->defineReadonlyProperty(QStringLiteral("NEGATIVE_INFINITY"), Primitive::fromDouble(-qInf())); + ctor->defineReadonlyProperty(QStringLiteral("POSITIVE_INFINITY"), Primitive::fromDouble(qInf())); + ctor->defineReadonlyProperty(QStringLiteral("MAX_VALUE"), Primitive::fromDouble(1.7976931348623158e+308)); #ifdef __INTEL_COMPILER # pragma warning( push ) # pragma warning(disable: 239) #endif - ctor.objectValue()->defineReadonlyProperty(QStringLiteral("MIN_VALUE"), Primitive::fromDouble(5e-324)); + ctor->defineReadonlyProperty(QStringLiteral("MIN_VALUE"), Primitive::fromDouble(5e-324)); #ifdef __INTEL_COMPILER # pragma warning( pop ) #endif - defineDefaultProperty(QStringLiteral("constructor"), ctor); + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(engine->id_toString, method_toString); defineDefaultProperty(QStringLiteral("toLocaleString"), method_toLocaleString); defineDefaultProperty(engine->id_valueOf, method_valueOf); diff --git a/src/qml/jsruntime/qv4numberobject_p.h b/src/qml/jsruntime/qv4numberobject_p.h index d5a0cda287..a4d13267bd 100644 --- a/src/qml/jsruntime/qv4numberobject_p.h +++ b/src/qml/jsruntime/qv4numberobject_p.h @@ -61,7 +61,7 @@ struct NumberCtor: FunctionObject struct NumberPrototype: NumberObject { NumberPrototype(InternalClass *ic): NumberObject(ic) {} - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static ReturnedValue method_toString(SimpleCallContext *ctx); static ReturnedValue method_toLocaleString(SimpleCallContext *ctx); diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 05dc24e5e4..3fdbf66523 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -215,13 +215,13 @@ void Object::inplaceBinOpValue(ExecutionContext *ctx, BinOpContext op, const Val inplaceBinOp(ctx, op, name, rhs); } -void Object::defineDefaultProperty(const StringRef name, Value value) +void Object::defineDefaultProperty(const StringRef name, ValueRef value) { Property *pd = insertMember(name, Attr_Data|Attr_NotEnumerable); - pd->value = value; + pd->value = *value; } -void Object::defineDefaultProperty(const QString &name, Value value) +void Object::defineDefaultProperty(const QString &name, ValueRef value) { ExecutionEngine *e = engine(); Scope scope(e); @@ -236,7 +236,7 @@ void Object::defineDefaultProperty(const QString &name, ReturnedValue (*code)(Si ScopedString s(scope, e->newIdentifier(name)); Scoped function(scope, e->newBuiltinFunction(e->rootContext, s, code)); function->defineReadonlyProperty(e->id_length, Primitive::fromInt32(argumentCount)); - defineDefaultProperty(s, function.asValue()); + defineDefaultProperty(s, function); } void Object::defineDefaultProperty(const StringRef name, ReturnedValue (*code)(SimpleCallContext *), int argumentCount) @@ -245,7 +245,7 @@ void Object::defineDefaultProperty(const StringRef name, ReturnedValue (*code)(S Scope scope(e); Scoped function(scope, e->newBuiltinFunction(e->rootContext, name, code)); function->defineReadonlyProperty(e->id_length, Primitive::fromInt32(argumentCount)); - defineDefaultProperty(name, function.asValue()); + defineDefaultProperty(name, function); } void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(SimpleCallContext *), ReturnedValue (*setter)(SimpleCallContext *)) @@ -267,7 +267,7 @@ void Object::defineAccessorProperty(const StringRef name, ReturnedValue (*getter p->setSetter(v4->newBuiltinFunction(v4->rootContext, name, setter)->getPointer()); } -void Object::defineReadonlyProperty(const QString &name, Value value) +void Object::defineReadonlyProperty(const QString &name, ValueRef value) { QV4::ExecutionEngine *e = engine(); Scope scope(e); @@ -275,10 +275,10 @@ void Object::defineReadonlyProperty(const QString &name, Value value) defineReadonlyProperty(s, value); } -void Object::defineReadonlyProperty(const StringRef name, Value value) +void Object::defineReadonlyProperty(const StringRef name, ValueRef value) { Property *pd = insertMember(name, Attr_ReadOnly); - pd->value = value; + pd->value = *value; } void Object::markObjects(Managed *that) diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 1ec747de34..bbf0786113 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -162,15 +162,15 @@ struct Q_QML_EXPORT Object: Managed { void inplaceBinOpValue(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs); /* The spec default: Writable: true, Enumerable: false, Configurable: true */ - void defineDefaultProperty(const StringRef name, Value value); - void defineDefaultProperty(const QString &name, Value value); + void defineDefaultProperty(const StringRef name, ValueRef value); + void defineDefaultProperty(const QString &name, ValueRef value); void defineDefaultProperty(const QString &name, ReturnedValue (*code)(SimpleCallContext *), int argumentCount = 0); void defineDefaultProperty(const StringRef name, ReturnedValue (*code)(SimpleCallContext *), int argumentCount = 0); void defineAccessorProperty(const QString &name, ReturnedValue (*getter)(SimpleCallContext *), ReturnedValue (*setter)(SimpleCallContext *)); void defineAccessorProperty(const StringRef name, ReturnedValue (*getter)(SimpleCallContext *), ReturnedValue (*setter)(SimpleCallContext *)); /* Fixed: Writable: false, Enumerable: false, Configurable: false */ - void defineReadonlyProperty(const QString &name, Value value); - void defineReadonlyProperty(const StringRef name, Value value); + void defineReadonlyProperty(const QString &name, ValueRef value); + void defineReadonlyProperty(const StringRef name, ValueRef value); Property *insertMember(const StringRef s, PropertyAttributes attributes); diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index 49bee363a3..02f8cb6e95 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -101,27 +101,28 @@ ReturnedValue ObjectCtor::call(Managed *m, CallData *callData) return __qmljs_to_object(m->engine()->current, ValueRef(&callData->args[0])); } -void ObjectPrototype::init(ExecutionEngine *v4, const Value &ctor) +void ObjectPrototype::init(ExecutionEngine *v4, ObjectRef ctor) { Scope scope(v4); - - ctor.objectValue()->defineReadonlyProperty(v4->id_prototype, Value::fromObject(this)); - ctor.objectValue()->defineReadonlyProperty(v4->id_length, Primitive::fromInt32(1)); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("getPrototypeOf"), method_getPrototypeOf, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("getOwnPropertyDescriptor"), method_getOwnPropertyDescriptor, 2); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("getOwnPropertyNames"), method_getOwnPropertyNames, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("create"), method_create, 2); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("defineProperty"), method_defineProperty, 3); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("defineProperties"), method_defineProperties, 2); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("seal"), method_seal, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("freeze"), method_freeze, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("preventExtensions"), method_preventExtensions, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("isSealed"), method_isSealed, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("isFrozen"), method_isFrozen, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("isExtensible"), method_isExtensible, 1); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("keys"), method_keys, 1); - - defineDefaultProperty(QStringLiteral("constructor"), ctor); + ScopedObject o(scope); + + ctor->defineReadonlyProperty(v4->id_prototype, (o = this)); + ctor->defineReadonlyProperty(v4->id_length, Primitive::fromInt32(1)); + ctor->defineDefaultProperty(QStringLiteral("getPrototypeOf"), method_getPrototypeOf, 1); + ctor->defineDefaultProperty(QStringLiteral("getOwnPropertyDescriptor"), method_getOwnPropertyDescriptor, 2); + ctor->defineDefaultProperty(QStringLiteral("getOwnPropertyNames"), method_getOwnPropertyNames, 1); + ctor->defineDefaultProperty(QStringLiteral("create"), method_create, 2); + ctor->defineDefaultProperty(QStringLiteral("defineProperty"), method_defineProperty, 3); + ctor->defineDefaultProperty(QStringLiteral("defineProperties"), method_defineProperties, 2); + ctor->defineDefaultProperty(QStringLiteral("seal"), method_seal, 1); + ctor->defineDefaultProperty(QStringLiteral("freeze"), method_freeze, 1); + ctor->defineDefaultProperty(QStringLiteral("preventExtensions"), method_preventExtensions, 1); + ctor->defineDefaultProperty(QStringLiteral("isSealed"), method_isSealed, 1); + ctor->defineDefaultProperty(QStringLiteral("isFrozen"), method_isFrozen, 1); + ctor->defineDefaultProperty(QStringLiteral("isExtensible"), method_isExtensible, 1); + ctor->defineDefaultProperty(QStringLiteral("keys"), method_keys, 1); + + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(v4->id_toString, method_toString, 0); defineDefaultProperty(QStringLiteral("toLocaleString"), method_toLocaleString, 0); defineDefaultProperty(v4->id_valueOf, method_valueOf, 0); diff --git a/src/qml/jsruntime/qv4objectproto_p.h b/src/qml/jsruntime/qv4objectproto_p.h index 2f3041ab6a..8994ba558c 100644 --- a/src/qml/jsruntime/qv4objectproto_p.h +++ b/src/qml/jsruntime/qv4objectproto_p.h @@ -62,7 +62,7 @@ struct ObjectPrototype: Object { ObjectPrototype(InternalClass *ic) : Object(ic) {} - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static ReturnedValue method_getPrototypeOf(SimpleCallContext *ctx); static ReturnedValue method_getOwnPropertyDescriptor(SimpleCallContext *ctx); diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 126188fcb7..bab4a32073 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -241,8 +241,8 @@ ReturnedValue RegExpCtor::construct(Managed *m, CallData *callData) ExecutionContext *ctx = m->engine()->current; Scope scope(ctx); - ScopedValue r(scope, callData->argc > 0 ? callData->args[0] : Primitive::undefinedValue()); - ScopedValue f(scope, callData->argc > 1 ? callData->args[1] : Primitive::undefinedValue()); + ScopedValue r(scope, callData->argument(0)); + ScopedValue f(scope, callData->argument(1)); if (RegExpObject *re = r->as()) { if (!f->isUndefined()) ctx->throwTypeError(); @@ -290,11 +290,14 @@ ReturnedValue RegExpCtor::call(Managed *that, CallData *callData) return construct(that, callData); } -void RegExpPrototype::init(ExecutionEngine *engine, const Value &ctor) +void RegExpPrototype::init(ExecutionEngine *engine, ObjectRef ctor) { - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(2)); - defineDefaultProperty(QStringLiteral("constructor"), ctor); + Scope scope(engine); + ScopedObject o(scope); + + ctor->defineReadonlyProperty(engine->id_prototype, (o = this)); + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(2)); + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(QStringLiteral("exec"), method_exec, 1); defineDefaultProperty(QStringLiteral("test"), method_test, 1); defineDefaultProperty(engine->id_toString, method_toString, 0); diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index 299be31f52..764470e776 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -113,7 +113,7 @@ struct RegExpCtor: FunctionObject struct RegExpPrototype: RegExpObject { RegExpPrototype(InternalClass *ic): RegExpObject(ic) {} - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static ReturnedValue method_exec(SimpleCallContext *ctx); static ReturnedValue method_test(SimpleCallContext *ctx); diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index b629c2fa54..0f6c738411 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -353,6 +353,9 @@ struct CallData #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN uint tag; #endif + inline ReturnedValue argument(int i) { + return i < argc ? args[i].asReturnedValue() : Primitive::undefinedValue().asReturnedValue(); + } SafeValue thisObject; SafeValue args[1]; diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index adff8e3978..5c36ddd7a2 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -188,13 +188,16 @@ ReturnedValue StringCtor::call(Managed *m, CallData *callData) return value.asReturnedValue(); } -void StringPrototype::init(ExecutionEngine *engine, const Value &ctor) +void StringPrototype::init(ExecutionEngine *engine, ObjectRef ctor) { - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); - ctor.objectValue()->defineDefaultProperty(QStringLiteral("fromCharCode"), method_fromCharCode, 1); + Scope scope(engine); + ScopedObject o(scope); - defineDefaultProperty(QStringLiteral("constructor"), ctor); + ctor->defineReadonlyProperty(engine->id_prototype, (o = this)); + ctor->defineReadonlyProperty(engine->id_length, Primitive::fromInt32(1)); + ctor->defineDefaultProperty(QStringLiteral("fromCharCode"), method_fromCharCode, 1); + + defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(engine->id_toString, method_toString); defineDefaultProperty(engine->id_valueOf, method_toString); // valueOf and toString are identical defineDefaultProperty(QStringLiteral("charAt"), method_charAt, 1); @@ -334,8 +337,10 @@ ReturnedValue StringPrototype::method_lastIndexOf(SimpleCallContext *context) ReturnedValue StringPrototype::method_localeCompare(SimpleCallContext *context) { + Scope scope(context); const QString value = getThisString(context); - const QString that = (context->callData->argc ? context->callData->args[0] : Primitive::undefinedValue()).toQString(); + ScopedValue v(scope, context->callData->argument(0)); + const QString that = v->toQString(); return Encode(QString::localeAwareCompare(value, that)); } @@ -347,7 +352,7 @@ ReturnedValue StringPrototype::method_match(SimpleCallContext *context) Scope scope(context); ScopedString s(scope, context->callData->thisObject.toString(context)); - ScopedValue regexp(scope, context->callData->argc ? context->callData->args[0] : Primitive::undefinedValue()); + ScopedValue regexp(scope, context->callData->argument(0)); Scoped rx(scope, regexp); if (!rx) { ScopedCallData callData(scope, 1); diff --git a/src/qml/jsruntime/qv4stringobject_p.h b/src/qml/jsruntime/qv4stringobject_p.h index 2e1e461ecc..e02a6a759f 100644 --- a/src/qml/jsruntime/qv4stringobject_p.h +++ b/src/qml/jsruntime/qv4stringobject_p.h @@ -78,7 +78,7 @@ struct StringCtor: FunctionObject struct StringPrototype: StringObject { StringPrototype(InternalClass *ic): StringObject(ic) {} - void init(ExecutionEngine *engine, const Value &ctor); + void init(ExecutionEngine *engine, ObjectRef ctor); static ReturnedValue method_toString(SimpleCallContext *context); static ReturnedValue method_charAt(SimpleCallContext *context); diff --git a/src/qml/jsruntime/qv4value_def_p.h b/src/qml/jsruntime/qv4value_def_p.h index 3e6c19207a..4ee277ca38 100644 --- a/src/qml/jsruntime/qv4value_def_p.h +++ b/src/qml/jsruntime/qv4value_def_p.h @@ -359,7 +359,7 @@ struct Q_QML_EXPORT Primitive : public Value { static Primitive fromBoolean(bool b); static Primitive fromInt32(int i); - static Value undefinedValue(); + static Primitive undefinedValue(); static Primitive nullValue(); static Primitive fromDouble(double d); static Primitive fromUInt32(uint i); diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 7ad4e94044..604062b4a2 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -97,7 +97,7 @@ inline void Value::mark() const { m->mark(); } -inline Value Primitive::undefinedValue() +inline Primitive Primitive::undefinedValue() { Primitive v; #if QT_POINTER_SIZE == 8 -- cgit v1.2.3