diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-25 10:09:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-28 13:33:08 +0200 |
commit | 0f2cf9074d4f0220f5c707eed478f99334814789 (patch) | |
tree | 685ea2295b8728b3545523e2625a4cf65f39b9ee /src/qml/jsruntime | |
parent | 1ef957834bf9040ccd001fa6d80e483b9b21452c (diff) |
Fix CallContext to not hold arguments on the C stack anymore
Change-Id: I35f46cce4f243d4b8b2bac9244f8fc26836f413b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
22 files changed, 381 insertions, 376 deletions
diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp index be4fbe60b8..34ccd0af49 100644 --- a/src/qml/jsruntime/qv4argumentsobject.cpp +++ b/src/qml/jsruntime/qv4argumentsobject.cpp @@ -64,28 +64,28 @@ ArgumentsObject::ArgumentsObject(CallContext *context) memberData[CalleePropertyIndex] = pd; memberData[CallerPropertyIndex] = pd; - arrayReserve(context->argumentCount); - for (unsigned int i = 0; i < context->argumentCount; ++i) - arrayData[i].value = context->arguments[i]; - arrayDataLen = context->argumentCount; + arrayReserve(context->callData->argc); + for (unsigned int i = 0; i < context->callData->argc; ++i) + arrayData[i].value = context->callData->args[i]; + arrayDataLen = context->callData->argc; } else { internalClass = engine()->argumentsObjectClass; Q_ASSERT(CalleePropertyIndex == internalClass->find(context->engine->id_callee)); memberData[CalleePropertyIndex].value = Value::fromObject(context->function); isNonStrictArgumentsObject = true; - uint numAccessors = qMin(context->function->formalParameterCount, context->realArgumentCount); - uint argCount = qMin((uint)context->realArgumentCount, context->argumentCount); + uint numAccessors = qMin((int)context->function->formalParameterCount, context->realArgumentCount); + uint argCount = qMin(context->realArgumentCount, context->callData->argc); arrayReserve(argCount); ensureArrayAttributes(); context->engine->requireArgumentsAccessors(numAccessors); for (uint i = 0; i < (uint)numAccessors; ++i) { - mappedArguments.append(context->arguments[i]); + mappedArguments.append(context->callData->args[i]); arrayData[i] = context->engine->argumentsAccessors.at(i); arrayAttributes[i] = Attr_Accessor; } for (uint i = numAccessors; i < argCount; ++i) { - arrayData[i] = Property::fromValue(context->arguments[i]); + arrayData[i] = Property::fromValue(context->callData->args[i]); arrayAttributes[i] = Attr_Data; } arrayDataLen = argCount; @@ -155,7 +155,7 @@ ReturnedValue ArgumentsGetterFunction::call(Managed *getter, CallData *callData) if (!o) getter->engine()->current->throwTypeError(); - assert(g->index < o->context->argumentCount); + assert(g->index < o->context->callData->argc); return o->context->argument(g->index); } @@ -171,8 +171,8 @@ ReturnedValue ArgumentsSetterFunction::call(Managed *setter, CallData *callData) if (!o) setter->engine()->current->throwTypeError(); - assert(s->index < o->context->argumentCount); - o->context->arguments[s->index] = callData->argc ? callData->args[0] : Value::undefinedValue(); + assert(s->index < o->context->callData->argc); + o->context->callData->args[s->index] = callData->argc ? callData->args[0] : Value::undefinedValue(); return Value::undefinedValue().asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index 44687463e2..2c5670ef92 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -131,19 +131,19 @@ uint ArrayPrototype::getLength(ExecutionContext *ctx, Object *o) ReturnedValue ArrayPrototype::method_isArray(SimpleCallContext *ctx) { - bool isArray = ctx->argumentCount ? ctx->arguments[0].asArrayObject() : false; + bool isArray = ctx->callData->argc ? ctx->callData->args[0].asArrayObject() : false; return Encode(isArray); } ReturnedValue ArrayPrototype::method_toString(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject o(scope, ctx->thisObject, ScopedObject::Convert); + ScopedObject o(scope, ctx->callData->thisObject, ScopedObject::Convert); ScopedString s(scope, ctx->engine->newString("join")); ScopedFunctionObject f(scope, o->get(s)); if (!!f) { ScopedCallData d(scope, 0); - d->thisObject = ctx->thisObject; + d->thisObject = ctx->callData->thisObject; return f->call(d); } return ObjectPrototype::method_toString(ctx); @@ -159,7 +159,7 @@ ReturnedValue ArrayPrototype::method_concat(SimpleCallContext *ctx) Scope scope(ctx); Scoped<ArrayObject> result(scope, ctx->engine->newArrayObject()); - ScopedObject thisObject(scope, ctx->thisObject.toObject(ctx)); + ScopedObject thisObject(scope, ctx->callData->thisObject.toObject(ctx)); ScopedArrayObject instance(scope, thisObject); if (instance) { result->copyArrayData(instance.getPointer()); @@ -168,12 +168,12 @@ ReturnedValue ArrayPrototype::method_concat(SimpleCallContext *ctx) } ScopedArrayObject elt(scope); - for (uint i = 0; i < ctx->argumentCount; ++i) { - elt = ctx->arguments[i]; + for (uint i = 0; i < ctx->callData->argc; ++i) { + elt = ctx->callData->args[i]; if (elt) result->arrayConcat(elt.getPointer()); else - result->arraySet(getLength(ctx, result.getPointer()), ctx->arguments[i]); + result->arraySet(getLength(ctx, result.getPointer()), ctx->callData->args[i]); } return result.asReturnedValue(); @@ -190,7 +190,7 @@ ReturnedValue ArrayPrototype::method_join(SimpleCallContext *ctx) else r4 = arg->toQString(); - ScopedObject self(scope, ctx->thisObject); + ScopedObject self(scope, ctx->callData->thisObject); ScopedValue length(scope, self->get(ctx->engine->id_length)); const quint32 r2 = length->isUndefined() ? 0 : length->toUInt32(); @@ -237,7 +237,7 @@ ReturnedValue ArrayPrototype::method_join(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_pop(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); if (!len) { @@ -259,18 +259,18 @@ ReturnedValue ArrayPrototype::method_pop(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_push(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); - if (len + ctx->argumentCount < len) { + if (len + ctx->callData->argc < len) { // ughh... double l = len; ScopedString s(scope); - for (int i = 0; i < ctx->argumentCount; ++i) { + for (int i = 0; i < ctx->callData->argc; ++i) { s = Value::fromDouble(l + i).toString(ctx); - instance->put(s, ctx->arguments[i]); + instance->put(s, ctx->callData->args[i]); } - double newLen = l + ctx->argumentCount; + double newLen = l + ctx->callData->argc; if (!instance->isArrayObject()) instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(newLen))); else @@ -279,24 +279,24 @@ ReturnedValue ArrayPrototype::method_push(SimpleCallContext *ctx) } if (!instance->protoHasArray() && instance->arrayDataLen <= len) { - for (uint i = 0; i < ctx->argumentCount; ++i) { + for (uint i = 0; i < ctx->callData->argc; ++i) { if (!instance->sparseArray) { if (len >= instance->arrayAlloc) instance->arrayReserve(len + 1); - instance->arrayData[len].value = ctx->arguments[i]; + instance->arrayData[len].value = ctx->callData->args[i]; if (instance->arrayAttributes) instance->arrayAttributes[len] = Attr_Data; instance->arrayDataLen = len + 1; } else { - uint i = instance->allocArrayValue(ctx->arguments[i]); + uint i = instance->allocArrayValue(ctx->callData->args[i]); instance->sparseArray->push_back(i, len); } ++len; } } else { - for (uint i = 0; i < ctx->argumentCount; ++i) - instance->putIndexed(len + i, ctx->arguments[i]); - len += ctx->argumentCount; + for (uint i = 0; i < ctx->callData->argc; ++i) + instance->putIndexed(len + i, ctx->callData->args[i]); + len += ctx->callData->argc; } if (instance->isArrayObject()) instance->setArrayLengthUnchecked(len); @@ -309,7 +309,7 @@ ReturnedValue ArrayPrototype::method_push(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_reverse(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint length = getLength(ctx, instance.getPointer()); int lo = 0, hi = length - 1; @@ -335,7 +335,7 @@ ReturnedValue ArrayPrototype::method_reverse(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_shift(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); if (!len) { @@ -389,7 +389,7 @@ ReturnedValue ArrayPrototype::method_shift(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_slice(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject o(scope, ctx->thisObject.toObject(ctx)); + ScopedObject o(scope, ctx->callData->thisObject.toObject(ctx)); Scoped<ArrayObject> result(scope, ctx->engine->newArrayObject()); uint len = getLength(ctx, o.getPointer()); @@ -402,8 +402,8 @@ ReturnedValue ArrayPrototype::method_slice(SimpleCallContext *ctx) else start = (uint) s; uint end = len; - if (ctx->argumentCount > 1 && !ctx->arguments[1].isUndefined()) { - double e = ctx->arguments[1].toInteger(); + if (ctx->callData->argc > 1 && !ctx->callData->args[1].isUndefined()) { + double e = ctx->callData->args[1].toInteger(); if (e < 0) end = (uint)qMax(len + e, 0.); else if (e > len) @@ -428,19 +428,19 @@ ReturnedValue ArrayPrototype::method_slice(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_sort(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); ScopedValue comparefn(scope, ctx->argument(0)); instance->arraySort(ctx, instance, comparefn, len); - return ctx->thisObject.asReturnedValue(); + return ctx->callData->thisObject.asReturnedValue(); } ReturnedValue ArrayPrototype::method_splice(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); Scoped<ArrayObject> newArray(scope, ctx->engine->newArrayObject()); @@ -461,7 +461,7 @@ ReturnedValue ArrayPrototype::method_splice(SimpleCallContext *ctx) } newArray->setArrayLengthUnchecked(deleteCount); - uint itemCount = ctx->argumentCount < 2 ? 0 : ctx->argumentCount - 2; + uint itemCount = ctx->callData->argc < 2 ? 0 : ctx->callData->argc - 2; ScopedValue v(scope); if (itemCount < deleteCount) { @@ -489,7 +489,7 @@ ReturnedValue ArrayPrototype::method_splice(SimpleCallContext *ctx) } for (uint i = 0; i < itemCount; ++i) - instance->putIndexed(start + i, ctx->arguments[i + 2]); + instance->putIndexed(start + i, ctx->callData->args[i + 2]); ctx->strictMode = true; instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(len - deleteCount + itemCount))); @@ -500,12 +500,12 @@ ReturnedValue ArrayPrototype::method_splice(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_unshift(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); ScopedValue v(scope); if (!instance->protoHasArray() && instance->arrayDataLen <= len) { - for (int i = ctx->argumentCount - 1; i >= 0; --i) { + for (int i = ctx->callData->argc - 1; i >= 0; --i) { v = ctx->argument(i); if (!instance->sparseArray) { @@ -530,15 +530,15 @@ ReturnedValue ArrayPrototype::method_unshift(SimpleCallContext *ctx) bool exists; v = instance->getIndexed(k - 1, &exists); if (exists) - instance->putIndexed(k + ctx->argumentCount - 1, v); + instance->putIndexed(k + ctx->callData->argc - 1, v); else - instance->deleteIndexedProperty(k + ctx->argumentCount - 1); + instance->deleteIndexedProperty(k + ctx->callData->argc - 1); } - for (uint i = 0; i < ctx->argumentCount; ++i) - instance->putIndexed(i, ctx->arguments[i]); + for (uint i = 0; i < ctx->callData->argc; ++i) + instance->putIndexed(i, ctx->callData->args[i]); } - uint newLen = len + ctx->argumentCount; + uint newLen = len + ctx->callData->argc; if (instance->isArrayObject()) instance->setArrayLengthUnchecked(newLen); else @@ -551,7 +551,7 @@ ReturnedValue ArrayPrototype::method_indexOf(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); if (!len) return Value::fromInt32(-1).asReturnedValue(); @@ -559,13 +559,13 @@ ReturnedValue ArrayPrototype::method_indexOf(SimpleCallContext *ctx) ScopedValue searchValue(scope); uint fromIndex = 0; - if (ctx->argumentCount >= 1) - searchValue = ctx->arguments[0]; + if (ctx->callData->argc >= 1) + searchValue = ctx->callData->args[0]; else searchValue = Value::undefinedValue(); - if (ctx->argumentCount >= 2) { - double f = ctx->arguments[1].toInteger(); + if (ctx->callData->argc >= 2) { + double f = ctx->callData->args[1].toInteger(); if (f >= len) return Encode(-1); if (f < 0) @@ -591,7 +591,7 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); if (!len) return Value::fromInt32(-1).asReturnedValue(); @@ -599,13 +599,13 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(SimpleCallContext *ctx) ScopedValue searchValue(scope); uint fromIndex = len; - if (ctx->argumentCount >= 1) + if (ctx->callData->argc >= 1) searchValue = ctx->argument(0); else searchValue = Value::undefinedValue(); - if (ctx->argumentCount >= 2) { - double f = ctx->arguments[1].toInteger(); + if (ctx->callData->argc >= 2) { + double f = ctx->callData->args[1].toInteger(); if (f > 0) f = qMin(f, (double)(len - 1)); else if (f < 0) { @@ -630,7 +630,7 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_every(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); @@ -662,7 +662,7 @@ ReturnedValue ArrayPrototype::method_every(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_some(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); @@ -693,7 +693,7 @@ ReturnedValue ArrayPrototype::method_some(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_forEach(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); @@ -722,7 +722,7 @@ ReturnedValue ArrayPrototype::method_forEach(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_map(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); @@ -757,7 +757,7 @@ ReturnedValue ArrayPrototype::method_map(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_filter(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); @@ -796,7 +796,7 @@ ReturnedValue ArrayPrototype::method_filter(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_reduce(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); @@ -808,7 +808,7 @@ ReturnedValue ArrayPrototype::method_reduce(SimpleCallContext *ctx) ScopedValue acc(scope); ScopedValue v(scope); - if (ctx->argumentCount > 1) { + if (ctx->callData->argc > 1) { acc = ctx->argument(1); } else { bool kPresent = false; @@ -844,7 +844,7 @@ ReturnedValue ArrayPrototype::method_reduce(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_reduceRight(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); uint len = getLength(ctx, instance.getPointer()); @@ -853,7 +853,7 @@ ReturnedValue ArrayPrototype::method_reduceRight(SimpleCallContext *ctx) ctx->throwTypeError(); if (len == 0) { - if (ctx->argumentCount == 1) + if (ctx->callData->argc == 1) ctx->throwTypeError(); return ctx->argument(1); } @@ -861,7 +861,7 @@ ReturnedValue ArrayPrototype::method_reduceRight(SimpleCallContext *ctx) uint k = len; ScopedValue acc(scope); ScopedValue v(scope); - if (ctx->argumentCount > 1) { + if (ctx->callData->argc > 1) { acc = ctx->argument(1); } else { bool kPresent = false; diff --git a/src/qml/jsruntime/qv4booleanobject.cpp b/src/qml/jsruntime/qv4booleanobject.cpp index be801a67c2..7e0831232c 100644 --- a/src/qml/jsruntime/qv4booleanobject.cpp +++ b/src/qml/jsruntime/qv4booleanobject.cpp @@ -77,10 +77,10 @@ void BooleanPrototype::init(ExecutionEngine *engine, const Value &ctor) ReturnedValue BooleanPrototype::method_toString(SimpleCallContext *ctx) { bool result; - if (ctx->thisObject.isBoolean()) { - result = ctx->thisObject.booleanValue(); + if (ctx->callData->thisObject.isBoolean()) { + result = ctx->callData->thisObject.booleanValue(); } else { - BooleanObject *thisObject = ctx->thisObject.asBooleanObject(); + BooleanObject *thisObject = ctx->callData->thisObject.asBooleanObject(); if (!thisObject) ctx->throwTypeError(); result = thisObject->value.booleanValue(); @@ -91,7 +91,7 @@ ReturnedValue BooleanPrototype::method_toString(SimpleCallContext *ctx) ReturnedValue BooleanPrototype::method_valueOf(SimpleCallContext *ctx) { - BooleanObject *thisObject = ctx->thisObject.asBooleanObject(); + BooleanObject *thisObject = ctx->callData->thisObject.asBooleanObject(); if (!thisObject) ctx->throwTypeError(); diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 8d07c5220a..ae9a72d760 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -51,7 +51,7 @@ using namespace QV4; -CallContext *ExecutionContext::newCallContext(void *stackSpace, FunctionObject *function, CallData *callData) +CallContext *ExecutionContext::newCallContext(void *stackSpace, Value *locals, FunctionObject *function, CallData *callData) { CallContext *c = (CallContext *)stackSpace; #ifndef QT_NO_DEBUG @@ -63,11 +63,8 @@ CallContext *ExecutionContext::newCallContext(void *stackSpace, FunctionObject * c->initBaseContext(Type_CallContext, engine, this); c->function = function; - // ### - c->arguments = const_cast<SafeValue *>(callData->args); + c->callData = callData; c->realArgumentCount = callData->argc; - c->argumentCount = callData->argc; - c->thisObject = callData->thisObject; c->strictMode = function->strictMode; c->marked = false; @@ -85,7 +82,7 @@ CallContext *ExecutionContext::newCallContext(void *stackSpace, FunctionObject * c->runtimeStrings = c->compilationUnit->runtimeStrings; } - c->locals = (Value *)(c + 1); + c->locals = locals; if (function->varCount) std::fill(c->locals, c->locals + function->varCount, Value::undefinedValue()); @@ -94,8 +91,8 @@ CallContext *ExecutionContext::newCallContext(void *stackSpace, FunctionObject * #ifndef QT_NO_DEBUG Q_ASSERT(function->formalParameterCount <= QV4::Global::ReservedArgumentCount); #endif - std::fill(c->arguments + callData->argc, c->arguments + function->formalParameterCount, Value::undefinedValue()); - c->argumentCount = function->formalParameterCount; + std::fill(c->callData->args + callData->argc, c->callData->args + function->formalParameterCount, Value::undefinedValue()); + c->callData->argc = function->formalParameterCount; } return c; @@ -111,7 +108,6 @@ CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData c->function = function; c->realArgumentCount = callData->argc; - c->thisObject = callData->thisObject; c->strictMode = function->strictMode; c->marked = false; @@ -134,12 +130,11 @@ CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData if (function->varCount) std::fill(c->locals, c->locals + function->varCount, Value::undefinedValue()); - c->argumentCount = qMax((uint)callData->argc, function->formalParameterCount); - c->arguments = static_cast<SafeValue *>(c->locals + function->varCount); - if (callData->argc) - ::memcpy(c->arguments, callData->args, callData->argc * sizeof(Value)); + c->callData = reinterpret_cast<CallData *>(c->locals + function->varCount); + ::memcpy(c->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(Value)); if (callData->argc < function->formalParameterCount) - std::fill(c->arguments + callData->argc, c->arguments + function->formalParameterCount, Value::undefinedValue()); + std::fill(c->callData->args + c->callData->argc, c->callData->args + function->formalParameterCount, Value::undefinedValue()); + c->callData->argc = qMax((uint)callData->argc, function->formalParameterCount); return c; } @@ -222,14 +217,17 @@ unsigned int ExecutionContext::variableCount() const void GlobalContext::initGlobalContext(ExecutionEngine *eng) { initBaseContext(Type_GlobalContext, eng, /*parentContext*/0); - thisObject = Value::fromObject(eng->globalObject); + callData = reinterpret_cast<CallData *>(this + 1); + callData->tag = QV4::Value::Integer_Type; + callData->argc = 0; + callData->thisObject = Value::fromObject(eng->globalObject); global = 0; } void WithContext::initWithContext(ExecutionContext *p, Object *with) { initBaseContext(Type_WithContext, p->engine, p); - thisObject = p->thisObject; + callData = p->callData; outer = p; lookups = p->lookups; runtimeStrings = p->runtimeStrings; @@ -243,7 +241,7 @@ void CatchContext::initCatchContext(ExecutionContext *p, String *exceptionVarNam { initBaseContext(Type_CatchContext, p->engine, p); strictMode = p->strictMode; - thisObject = p->thisObject; + callData = p->callData; outer = p; lookups = p->lookups; runtimeStrings = p->runtimeStrings; @@ -259,9 +257,10 @@ void CallContext::initQmlContext(ExecutionContext *parentContext, Object *qml, F initBaseContext(Type_QmlContext, parentContext->engine, parentContext); this->function = function; - this->arguments = 0; - this->argumentCount = 0; - this->thisObject = Value::undefinedValue(); + this->callData = reinterpret_cast<CallData *>(this + 1); + this->callData->tag = QV4::Value::Integer_Type; + this->callData->argc = 0; + this->callData->thisObject = Value::undefinedValue(); strictMode = true; marked = false; @@ -326,7 +325,7 @@ bool ExecutionContext::deleteProperty(const StringRef name) bool CallContext::needsOwnArguments() const { - return function->needsActivation || argumentCount < function->formalParameterCount; + return function->needsActivation || callData->argc < function->formalParameterCount; } void ExecutionContext::mark() @@ -338,19 +337,17 @@ void ExecutionContext::mark() if (type != Type_SimpleCallContext && outer) outer->mark(); - thisObject.mark(); + callData->thisObject.mark(); + for (unsigned arg = 0; arg < callData->argc; ++arg) + callData->args[arg].mark(); - if (type >= Type_SimpleCallContext) { + if (type >= Type_CallContext) { QV4::CallContext *c = static_cast<CallContext *>(this); - for (unsigned arg = 0, lastArg = c->argumentCount; arg < lastArg; ++arg) - c->arguments[arg].mark(); - if (type >= Type_CallContext) { - for (unsigned local = 0, lastLocal = c->variableCount(); local < lastLocal; ++local) - c->locals[local].mark(); - if (c->activation) - c->activation->mark(); - c->function->mark(); - } + for (unsigned local = 0, lastLocal = c->variableCount(); local < lastLocal; ++local) + c->locals[local].mark(); + if (c->activation) + c->activation->mark(); + c->function->mark(); } else if (type == Type_WithContext) { WithContext *w = static_cast<WithContext *>(this); w->withObject->mark(); @@ -389,7 +386,7 @@ void ExecutionContext::setProperty(const StringRef name, const ValueRef value) } for (int i = (int)c->function->formalParameterCount - 1; i >= 0; --i) if (c->function->formalParameterList[i]->isEqualTo(name)) { - c->arguments[i] = *value; + c->callData->args[i] = *value; return; } activation = c->activation; @@ -417,7 +414,7 @@ ReturnedValue ExecutionContext::getProperty(const StringRef name) name->makeIdentifier(); if (name->isEqualTo(engine->id_this)) - return thisObject.asReturnedValue(); + return callData->thisObject.asReturnedValue(); bool hasWith = false; bool hasCatchScope = false; @@ -449,7 +446,7 @@ ReturnedValue ExecutionContext::getProperty(const StringRef name) return c->locals[i].asReturnedValue(); for (int i = (int)f->formalParameterCount - 1; i >= 0; --i) if (f->formalParameterList[i]->isEqualTo(name)) - return c->arguments[i].asReturnedValue(); + return c->callData->args[i].asReturnedValue(); } if (c->activation) { bool hasProperty = false; @@ -482,7 +479,7 @@ ReturnedValue ExecutionContext::getPropertyNoThrow(const StringRef name) name->makeIdentifier(); if (name->isEqualTo(engine->id_this)) - return thisObject.asReturnedValue(); + return callData->thisObject.asReturnedValue(); bool hasWith = false; bool hasCatchScope = false; @@ -514,7 +511,7 @@ ReturnedValue ExecutionContext::getPropertyNoThrow(const StringRef name) return c->locals[i].asReturnedValue(); for (int i = (int)f->formalParameterCount - 1; i >= 0; --i) if (f->formalParameterList[i]->isEqualTo(name)) - return c->arguments[i].asReturnedValue(); + return c->callData->args[i].asReturnedValue(); } if (c->activation) { bool hasProperty = false; @@ -546,7 +543,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, Object name->makeIdentifier(); if (name->isEqualTo(engine->id_this)) - return thisObject.asReturnedValue(); + return callData->thisObject.asReturnedValue(); bool hasWith = false; bool hasCatchScope = false; @@ -579,7 +576,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, Object return c->locals[i].asReturnedValue(); for (int i = (int)f->formalParameterCount - 1; i >= 0; --i) if (f->formalParameterList[i]->isEqualTo(name)) - return c->arguments[i].asReturnedValue(); + return c->callData->args[i].asReturnedValue(); } if (c->activation) { bool hasProperty = false; @@ -695,6 +692,4 @@ void SimpleCallContext::initSimpleCallContext(ExecutionEngine *engine) { initBaseContext(Type_SimpleCallContext, engine, engine->current); function = 0; - arguments = 0; - argumentCount = 0; } diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index f216746212..efa7a07c1d 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -80,7 +80,7 @@ struct Q_QML_EXPORT ExecutionContext bool strictMode; bool marked; - Value thisObject; + CallData *callData; ExecutionEngine *engine; ExecutionContext *parent; @@ -105,7 +105,6 @@ struct Q_QML_EXPORT ExecutionContext this->type = type; strictMode = false; marked = false; - thisObject = Value::undefinedValue(); this->engine = engine; parent = parentContext; outer = 0; @@ -117,7 +116,7 @@ struct Q_QML_EXPORT ExecutionContext interpreterInstructionPointer = 0; } - CallContext *newCallContext(void *stackSpace, FunctionObject *f, CallData *callData); + CallContext *newCallContext(void *stackSpace, Value *locals, FunctionObject *f, CallData *callData); CallContext *newCallContext(FunctionObject *f, CallData *callData); WithContext *newWithContext(Object *with); CatchContext *newCatchContext(String* exceptionVarName, const QV4::Value &exceptionValue); @@ -158,13 +157,9 @@ struct SimpleCallContext : public ExecutionContext { void initSimpleCallContext(ExecutionEngine *engine); FunctionObject *function; - SafeValue *arguments; - unsigned int realArgumentCount; - unsigned int argumentCount; + int realArgumentCount; - ReturnedValue argument(uint i) { - return i < argumentCount ? arguments[i].asReturnedValue() : Value::undefinedValue().asReturnedValue(); - } + inline ReturnedValue argument(int i); }; struct CallContext : public SimpleCallContext @@ -210,9 +205,9 @@ inline const CallContext *ExecutionContext::asCallContext() const /* Function *f, int argc */ #define requiredMemoryForExecutionContect(f, argc) \ - sizeof(CallContext) + sizeof(Value) * (f->varCount + qMax((uint)argc, f->formalParameterCount)) + sizeof(CallContext) + sizeof(Value) * (f->varCount + qMax((uint)argc, f->formalParameterCount)) + sizeof(CallData) #define requiredMemoryForExecutionContectSimple(f) \ - sizeof(CallContext) + sizeof(Value) * f->varCount + sizeof(CallContext) #define requiredMemoryForQmlExecutionContect(f) \ sizeof(CallContext) + sizeof(Value) * (f->locals.size()) #define stackContextSize (sizeof(CallContext) + 32*sizeof(Value)) diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index 8bc92c6c4e..05d4b6ee7f 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -762,7 +762,7 @@ void DatePrototype::init(ExecutionEngine *engine, const Value &ctor) double DatePrototype::getThisDate(ExecutionContext *ctx) { - if (DateObject *thisObject = ctx->thisObject.asDateObject()) + if (DateObject *thisObject = ctx->callData->thisObject.asDateObject()) return thisObject->value.asDouble(); else { ctx->throwTypeError(); @@ -772,22 +772,22 @@ double DatePrototype::getThisDate(ExecutionContext *ctx) ReturnedValue DatePrototype::method_parse(SimpleCallContext *ctx) { - if (!ctx->argumentCount) + if (!ctx->callData->argc) return Encode(qSNaN()); - return Encode(ParseString(ctx->arguments[0].toString(ctx)->toQString())); + return Encode(ParseString(ctx->callData->args[0].toString(ctx)->toQString())); } ReturnedValue DatePrototype::method_UTC(SimpleCallContext *ctx) { - const int numArgs = ctx->argumentCount; + const int numArgs = ctx->callData->argc; if (numArgs >= 2) { - double year = ctx->arguments[0].toNumber(); - double month = ctx->arguments[1].toNumber(); - double day = numArgs >= 3 ? ctx->arguments[2].toNumber() : 1; - double hours = numArgs >= 4 ? ctx->arguments[3].toNumber() : 0; - double mins = numArgs >= 5 ? ctx->arguments[4].toNumber() : 0; - double secs = numArgs >= 6 ? ctx->arguments[5].toNumber() : 0; - double ms = numArgs >= 7 ? ctx->arguments[6].toNumber() : 0; + double year = ctx->callData->args[0].toNumber(); + double month = ctx->callData->args[1].toNumber(); + double day = numArgs >= 3 ? ctx->callData->args[2].toNumber() : 1; + double hours = numArgs >= 4 ? ctx->callData->args[3].toNumber() : 0; + double mins = numArgs >= 5 ? ctx->callData->args[4].toNumber() : 0; + double secs = numArgs >= 6 ? ctx->callData->args[5].toNumber() : 0; + double ms = numArgs >= 7 ? ctx->callData->args[6].toNumber() : 0; if (year >= 0 && year <= 99) year += 1900; double t = MakeDate(MakeDay(year, month, day), @@ -999,11 +999,11 @@ ReturnedValue DatePrototype::method_getTimezoneOffset(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setTime(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<DateObject> self(scope, ctx->thisObject); + Scoped<DateObject> self(scope, ctx->callData->thisObject); if (!self) ctx->throwTypeError(); - double t = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); + double t = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); self->value.setDouble(TimeClip(t)); return self->value.asReturnedValue(); } @@ -1011,37 +1011,37 @@ ReturnedValue DatePrototype::method_setTime(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setMilliseconds(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<DateObject> self(scope, ctx->thisObject); + Scoped<DateObject> self(scope, ctx->callData->thisObject); if (!self) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); - double ms = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); + double ms = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); self->value.setDouble(TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms))))); return self->value.asReturnedValue(); } ReturnedValue DatePrototype::method_setUTCMilliseconds(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); - double ms = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); + double ms = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); self->value.setDouble(TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms))))); return self->value.asReturnedValue(); } ReturnedValue DatePrototype::method_setSeconds(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); - double sec = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double ms = (ctx->argumentCount < 2) ? msFromTime(t) : ctx->arguments[1].toNumber(); + double sec = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double ms = (ctx->callData->argc < 2) ? msFromTime(t) : ctx->callData->args[1].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1049,13 +1049,13 @@ ReturnedValue DatePrototype::method_setSeconds(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setUTCSeconds(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); - double sec = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double ms = (ctx->argumentCount < 2) ? msFromTime(t) : ctx->arguments[1].toNumber(); + double sec = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double ms = (ctx->callData->argc < 2) ? msFromTime(t) : ctx->callData->args[1].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1063,14 +1063,14 @@ ReturnedValue DatePrototype::method_setUTCSeconds(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setMinutes(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); - double min = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double sec = (ctx->argumentCount < 2) ? SecFromTime(t) : ctx->arguments[1].toNumber(); - double ms = (ctx->argumentCount < 3) ? msFromTime(t) : ctx->arguments[2].toNumber(); + double min = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double sec = (ctx->callData->argc < 2) ? SecFromTime(t) : ctx->callData->args[1].toNumber(); + double ms = (ctx->callData->argc < 3) ? msFromTime(t) : ctx->callData->args[2].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1078,14 +1078,14 @@ ReturnedValue DatePrototype::method_setMinutes(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setUTCMinutes(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); - double min = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double sec = (ctx->argumentCount < 2) ? SecFromTime(t) : ctx->arguments[1].toNumber(); - double ms = (ctx->argumentCount < 3) ? msFromTime(t) : ctx->arguments[2].toNumber(); + double min = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double sec = (ctx->callData->argc < 2) ? SecFromTime(t) : ctx->callData->args[1].toNumber(); + double ms = (ctx->callData->argc < 3) ? msFromTime(t) : ctx->callData->args[2].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1093,15 +1093,15 @@ ReturnedValue DatePrototype::method_setUTCMinutes(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setHours(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); - double hour = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double min = (ctx->argumentCount < 2) ? MinFromTime(t) : ctx->arguments[1].toNumber(); - double sec = (ctx->argumentCount < 3) ? SecFromTime(t) : ctx->arguments[2].toNumber(); - double ms = (ctx->argumentCount < 4) ? msFromTime(t) : ctx->arguments[3].toNumber(); + double hour = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double min = (ctx->callData->argc < 2) ? MinFromTime(t) : ctx->callData->args[1].toNumber(); + double sec = (ctx->callData->argc < 3) ? SecFromTime(t) : ctx->callData->args[2].toNumber(); + double ms = (ctx->callData->argc < 4) ? msFromTime(t) : ctx->callData->args[3].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(hour, min, sec, ms)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1109,15 +1109,15 @@ ReturnedValue DatePrototype::method_setHours(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setUTCHours(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); - double hour = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double min = (ctx->argumentCount < 2) ? MinFromTime(t) : ctx->arguments[1].toNumber(); - double sec = (ctx->argumentCount < 3) ? SecFromTime(t) : ctx->arguments[2].toNumber(); - double ms = (ctx->argumentCount < 4) ? msFromTime(t) : ctx->arguments[3].toNumber(); + double hour = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double min = (ctx->callData->argc < 2) ? MinFromTime(t) : ctx->callData->args[1].toNumber(); + double sec = (ctx->callData->argc < 3) ? SecFromTime(t) : ctx->callData->args[2].toNumber(); + double ms = (ctx->callData->argc < 4) ? msFromTime(t) : ctx->callData->args[3].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(hour, min, sec, ms)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1125,12 +1125,12 @@ ReturnedValue DatePrototype::method_setUTCHours(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setDate(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); - double date = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); + double date = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1138,12 +1138,12 @@ ReturnedValue DatePrototype::method_setDate(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setUTCDate(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); - double date = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); + double date = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1151,13 +1151,13 @@ ReturnedValue DatePrototype::method_setUTCDate(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setMonth(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); - double month = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double date = (ctx->argumentCount < 2) ? DateFromTime(t) : ctx->arguments[1].toNumber(); + double month = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double date = (ctx->callData->argc < 2) ? DateFromTime(t) : ctx->callData->args[1].toNumber(); t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1165,13 +1165,13 @@ ReturnedValue DatePrototype::method_setMonth(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setUTCMonth(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); - double month = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double date = (ctx->argumentCount < 2) ? DateFromTime(t) : ctx->arguments[1].toNumber(); + double month = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double date = (ctx->callData->argc < 2) ? DateFromTime(t) : ctx->callData->args[1].toNumber(); t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1179,7 +1179,7 @@ ReturnedValue DatePrototype::method_setUTCMonth(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setYear(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); @@ -1188,7 +1188,7 @@ ReturnedValue DatePrototype::method_setYear(SimpleCallContext *ctx) t = 0; else t = LocalTime(t); - double year = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); + double year = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); double r; if (std::isnan(year)) { r = qSNaN(); @@ -1205,14 +1205,14 @@ ReturnedValue DatePrototype::method_setYear(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setUTCFullYear(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); - double year = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double month = (ctx->argumentCount < 2) ? MonthFromTime(t) : ctx->arguments[1].toNumber(); - double date = (ctx->argumentCount < 3) ? DateFromTime(t) : ctx->arguments[2].toNumber(); + double year = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double month = (ctx->callData->argc < 2) ? MonthFromTime(t) : ctx->callData->args[1].toNumber(); + double date = (ctx->callData->argc < 3) ? DateFromTime(t) : ctx->callData->args[2].toNumber(); t = TimeClip(UTC(MakeDate(MakeDay(year, month, date), TimeWithinDay(t)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1220,16 +1220,16 @@ ReturnedValue DatePrototype::method_setUTCFullYear(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_setFullYear(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); if (std::isnan(t)) t = 0; - double year = ctx->argumentCount ? ctx->arguments[0].toNumber() : qSNaN(); - double month = (ctx->argumentCount < 2) ? MonthFromTime(t) : ctx->arguments[1].toNumber(); - double date = (ctx->argumentCount < 3) ? DateFromTime(t) : ctx->arguments[2].toNumber(); + double year = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); + double month = (ctx->callData->argc < 2) ? MonthFromTime(t) : ctx->callData->args[1].toNumber(); + double date = (ctx->callData->argc < 3) ? DateFromTime(t) : ctx->callData->args[2].toNumber(); t = TimeClip(UTC(MakeDate(MakeDay(year, month, date), TimeWithinDay(t)))); self->value.setDouble(t); return self->value.asReturnedValue(); @@ -1237,7 +1237,7 @@ ReturnedValue DatePrototype::method_setFullYear(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_toUTCString(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); @@ -1260,13 +1260,13 @@ static void addZeroPrefixedInt(QString &str, int num, int nDigits) ReturnedValue DatePrototype::method_toISOString(SimpleCallContext *ctx) { - DateObject *self = ctx->thisObject.asDateObject(); + DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) ctx->throwTypeError(); double t = self->value.asDouble(); if (!std::isfinite(t)) - ctx->throwRangeError(ctx->thisObject); + ctx->throwRangeError(ctx->callData->thisObject); QString result; int year = (int)YearFromTime(t); @@ -1299,7 +1299,7 @@ ReturnedValue DatePrototype::method_toISOString(SimpleCallContext *ctx) ReturnedValue DatePrototype::method_toJSON(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedValue O(scope, __qmljs_to_object(ctx, ValueRef(&ctx->thisObject))); + ScopedValue O(scope, __qmljs_to_object(ctx, ValueRef(&ctx->callData->thisObject))); ScopedValue tv(scope, __qmljs_to_primitive(O, NUMBER_HINT)); if (tv->isNumber() && !std::isfinite(tv->toNumber())) @@ -1313,7 +1313,7 @@ ReturnedValue DatePrototype::method_toJSON(SimpleCallContext *ctx) ctx->throwTypeError(); ScopedCallData callData(scope, 0); - callData->thisObject = ctx->thisObject; + callData->thisObject = ctx->callData->thisObject; return toIso->call(callData); } diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 363f0a45c0..62738c23bf 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -260,7 +260,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) // globalObject = newObject()->getPointer(); rootContext->global = globalObject; - rootContext->thisObject = Value::fromObject(globalObject); + rootContext->callData->thisObject = Value::fromObject(globalObject); globalObject->defineDefaultProperty(QStringLiteral("Object"), objectCtor); globalObject->defineDefaultProperty(QStringLiteral("String"), stringCtor); @@ -335,7 +335,7 @@ void ExecutionEngine::enableDebugger() void ExecutionEngine::initRootContext() { - rootContext = static_cast<GlobalContext *>(memoryManager->allocContext(sizeof(GlobalContext))); + rootContext = static_cast<GlobalContext *>(memoryManager->allocContext(sizeof(GlobalContext) + sizeof(CallData))); current = rootContext; current->parent = 0; rootContext->initGlobalContext(this); diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 7ffc4feb9e..c4870e13bb 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -140,7 +140,7 @@ ErrorObject::ErrorObject(InternalClass *ic, const QString &message, const QStrin ReturnedValue ErrorObject::method_get_stack(SimpleCallContext *ctx) { - ErrorObject *This = ctx->thisObject.asErrorObject(); + ErrorObject *This = ctx->callData->thisObject.asErrorObject(); if (!This) ctx->throwTypeError(); if (!This->stack) { @@ -341,7 +341,7 @@ ReturnedValue ErrorPrototype::method_toString(SimpleCallContext *ctx) { Scope scope(ctx); - Object *o = ctx->thisObject.asObject(); + Object *o = ctx->callData->thisObject.asObject(); if (!o) ctx->throwTypeError(); diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 6c60a9964a..7f4c419ddc 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -309,7 +309,7 @@ void FunctionPrototype::init(ExecutionEngine *engine, const Value &ctor) ReturnedValue FunctionPrototype::method_toString(SimpleCallContext *ctx) { - FunctionObject *fun = ctx->thisObject.asFunctionObject(); + FunctionObject *fun = ctx->callData->thisObject.asFunctionObject(); if (!fun) ctx->throwTypeError(); @@ -319,7 +319,7 @@ ReturnedValue FunctionPrototype::method_toString(SimpleCallContext *ctx) ReturnedValue FunctionPrototype::method_apply(SimpleCallContext *ctx) { Scope scope(ctx); - FunctionObject *o = ctx->thisObject.asFunctionObject(); + FunctionObject *o = ctx->callData->thisObject.asFunctionObject(); if (!o) ctx->throwTypeError(); @@ -361,14 +361,14 @@ ReturnedValue FunctionPrototype::method_call(SimpleCallContext *ctx) { Scope scope(ctx); - FunctionObject *o = ctx->thisObject.asFunctionObject(); + FunctionObject *o = ctx->callData->thisObject.asFunctionObject(); if (!o) ctx->throwTypeError(); - ScopedCallData callData(scope, ctx->argumentCount ? ctx->argumentCount - 1 : 0); - if (ctx->argumentCount) { - std::copy(ctx->arguments + 1, - ctx->arguments + ctx->argumentCount, callData->args); + ScopedCallData callData(scope, ctx->callData->argc ? ctx->callData->argc - 1 : 0); + if (ctx->callData->argc) { + std::copy(ctx->callData->args + 1, + ctx->callData->args + ctx->callData->argc, callData->args); } callData->thisObject = ctx->argument(0); return o->call(callData); @@ -377,14 +377,14 @@ ReturnedValue FunctionPrototype::method_call(SimpleCallContext *ctx) ReturnedValue FunctionPrototype::method_bind(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<FunctionObject> target(scope, ctx->thisObject); + Scoped<FunctionObject> target(scope, ctx->callData->thisObject); if (!target) ctx->throwTypeError(); ScopedValue boundThis(scope, ctx->argument(0)); QVector<Value> boundArgs; - for (uint i = 1; i < ctx->argumentCount; ++i) - boundArgs += ctx->arguments[i]; + for (uint i = 1; i < ctx->callData->argc; ++i) + boundArgs += ctx->callData->args[i]; return ctx->engine->newBoundFunction(ctx->engine->rootContext, target.getPointer(), boundThis, boundArgs)->asReturnedValue(); } @@ -469,9 +469,9 @@ ReturnedValue ScriptFunction::call(Managed *that, CallData *callData) if (!f->strictMode && !callData->thisObject.isObject()) { if (callData->thisObject.isNullOrUndefined()) { - ctx->thisObject = Value::fromObject(f->engine()->globalObject); + ctx->callData->thisObject = Value::fromObject(f->engine()->globalObject); } else { - ctx->thisObject = Value::fromObject(callData->thisObject.toObject(context)); + ctx->callData->thisObject = Value::fromObject(callData->thisObject.toObject(context)); } } @@ -541,7 +541,7 @@ ReturnedValue SimpleScriptFunction::construct(Managed *that, CallData *callData) ExecutionContext *context = v4->current; void *stackSpace = alloca(requiredMemoryForExecutionContectSimple(f)); callData->thisObject = obj; - ExecutionContext *ctx = context->newCallContext(stackSpace, f.getPointer(), callData); + ExecutionContext *ctx = context->newCallContext(stackSpace, scope.alloc(f->varCount), f.getPointer(), callData); try { Scoped<Object> result(scope, f->function->code(ctx, f->function->codeData)); @@ -558,17 +558,19 @@ ReturnedValue SimpleScriptFunction::construct(Managed *that, CallData *callData) ReturnedValue SimpleScriptFunction::call(Managed *that, CallData *callData) { - SimpleScriptFunction *f = static_cast<SimpleScriptFunction *>(that); + ExecutionEngine *v4 = that->engine(); + Scope scope(v4); + Scoped<SimpleScriptFunction> f(scope, static_cast<SimpleScriptFunction *>(that)); + void *stackSpace = alloca(requiredMemoryForExecutionContectSimple(f)); - ExecutionContext *context = f->engine()->current; - Scope scope(context); - ExecutionContext *ctx = context->newCallContext(stackSpace, f, callData); + ExecutionContext *context = v4->current; + ExecutionContext *ctx = context->newCallContext(stackSpace, scope.alloc(f->varCount), f.getPointer(), callData); if (!f->strictMode && !callData->thisObject.isObject()) { if (callData->thisObject.isNullOrUndefined()) { - ctx->thisObject = Value::fromObject(f->engine()->globalObject); + ctx->callData->thisObject = Value::fromObject(f->engine()->globalObject); } else { - ctx->thisObject = Value::fromObject(callData->thisObject.toObject(context)); + ctx->callData->thisObject = Value::fromObject(callData->thisObject.toObject(context)); } } @@ -614,10 +616,7 @@ ReturnedValue BuiltinFunction::call(Managed *that, CallData *callData) SimpleCallContext ctx; ctx.initSimpleCallContext(f->scope->engine); ctx.strictMode = f->scope->strictMode; // ### needed? scope or parent context? - ctx.thisObject = callData->thisObject; - // ### const_cast - ctx.arguments = const_cast<SafeValue *>(callData->args); - ctx.argumentCount = callData->argc; + ctx.callData = callData; v4->pushContext(&ctx); ScopedValue result(scope); @@ -642,10 +641,7 @@ ReturnedValue IndexedBuiltinFunction::call(Managed *that, CallData *callData) SimpleCallContext ctx; ctx.initSimpleCallContext(f->scope->engine); ctx.strictMode = f->scope->strictMode; // ### needed? scope or parent context? - ctx.thisObject = callData->thisObject; - // ### const_cast - ctx.arguments = const_cast<SafeValue *>(callData->args); - ctx.argumentCount = callData->argc; + ctx.callData = callData; v4->pushContext(&ctx); ScopedValue result(scope); diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index ae91b11991..f6f59b2f05 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -393,7 +393,7 @@ ReturnedValue EvalFunction::evalCall(Value /*thisObject*/, Value *args, int argc if (strictMode) { FunctionObject *e = FunctionObject::creatScriptFunction(ctx, function); ScopedCallData callData(scope, 0); - callData->thisObject = ctx->thisObject; + callData->thisObject = ctx->callData->thisObject; return e->call(callData); } @@ -573,38 +573,38 @@ ReturnedValue GlobalFunctions::method_parseFloat(SimpleCallContext *ctx) /// isNaN [15.1.2.4] ReturnedValue GlobalFunctions::method_isNaN(SimpleCallContext *ctx) { - if (!ctx->argumentCount) + if (!ctx->callData->argc) // undefined gets converted to NaN return Encode(true); - if (ctx->arguments[0].integerCompatible()) + if (ctx->callData->args[0].integerCompatible()) return Encode(false); - double d = ctx->arguments[0].toNumber(); + double d = ctx->callData->args[0].toNumber(); return Encode((bool)std::isnan(d)); } /// isFinite [15.1.2.5] ReturnedValue GlobalFunctions::method_isFinite(SimpleCallContext *ctx) { - if (!ctx->argumentCount) + if (!ctx->callData->argc) // undefined gets converted to NaN return Encode(false); - if (ctx->arguments[0].integerCompatible()) + if (ctx->callData->args[0].integerCompatible()) return Encode(true); - double d = ctx->arguments[0].toNumber(); + double d = ctx->callData->args[0].toNumber(); return Encode((bool)std::isfinite(d)); } /// decodeURI [15.1.3.1] ReturnedValue GlobalFunctions::method_decodeURI(SimpleCallContext *context) { - if (context->argumentCount == 0) + if (context->callData->argc == 0) return Encode::undefined(); - QString uriString = context->arguments[0].toString(context)->toQString(); + QString uriString = context->callData->args[0].toString(context)->toQString(); bool ok; QString out = decode(uriString, DecodeNonReserved, &ok); if (!ok) @@ -616,10 +616,10 @@ ReturnedValue GlobalFunctions::method_decodeURI(SimpleCallContext *context) /// decodeURIComponent [15.1.3.2] ReturnedValue GlobalFunctions::method_decodeURIComponent(SimpleCallContext *context) { - if (context->argumentCount == 0) + if (context->callData->argc == 0) return Encode::undefined(); - QString uriString = context->arguments[0].toString(context)->toQString(); + QString uriString = context->callData->args[0].toString(context)->toQString(); bool ok; QString out = decode(uriString, DecodeAll, &ok); if (!ok) @@ -631,10 +631,10 @@ ReturnedValue GlobalFunctions::method_decodeURIComponent(SimpleCallContext *cont /// encodeURI [15.1.3.3] ReturnedValue GlobalFunctions::method_encodeURI(SimpleCallContext *context) { - if (context->argumentCount == 0) + if (context->callData->argc == 0) return Encode::undefined(); - QString uriString = context->arguments[0].toString(context)->toQString(); + QString uriString = context->callData->args[0].toString(context)->toQString(); bool ok; QString out = encode(uriString, uriUnescapedReserved, &ok); if (!ok) @@ -646,10 +646,10 @@ ReturnedValue GlobalFunctions::method_encodeURI(SimpleCallContext *context) /// encodeURIComponent [15.1.3.4] ReturnedValue GlobalFunctions::method_encodeURIComponent(SimpleCallContext *context) { - if (context->argumentCount == 0) + if (context->callData->argc == 0) return Encode::undefined(); - QString uriString = context->arguments[0].toString(context)->toQString(); + QString uriString = context->callData->args[0].toString(context)->toQString(); bool ok; QString out = encode(uriString, uriUnescaped, &ok); if (!ok) @@ -660,18 +660,18 @@ ReturnedValue GlobalFunctions::method_encodeURIComponent(SimpleCallContext *cont ReturnedValue GlobalFunctions::method_escape(SimpleCallContext *context) { - if (!context->argumentCount) + if (!context->callData->argc) return Value::fromString(context, QStringLiteral("undefined")).asReturnedValue(); - QString str = context->arguments[0].toString(context)->toQString(); + QString str = context->callData->args[0].toString(context)->toQString(); return Value::fromString(context, escape(str)).asReturnedValue(); } ReturnedValue GlobalFunctions::method_unescape(SimpleCallContext *context) { - if (!context->argumentCount) + if (!context->callData->argc) return Value::fromString(context, QStringLiteral("undefined")).asReturnedValue(); - QString str = context->arguments[0].toString(context)->toQString(); + QString str = context->callData->args[0].toString(context)->toQString(); return Value::fromString(context, unescape(str)).asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index d6f01bf369..bde9c23e6b 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -181,7 +181,7 @@ void QV4Include::finished() */ QV4::ReturnedValue QV4Include::method_include(QV4::SimpleCallContext *ctx) { - if (!ctx->argumentCount) + if (!ctx->callData->argc) return QV4::Encode::undefined(); QV4::ExecutionEngine *v4 = ctx->engine; @@ -192,11 +192,11 @@ QV4::ReturnedValue QV4Include::method_include(QV4::SimpleCallContext *ctx) if (!context || !context->isJSContext) V4THROW_ERROR("Qt.include(): Can only be called from JavaScript files"); - QUrl url(ctx->engine->resolvedUrl(ctx->arguments[0].toQStringNoThrow())); + QUrl url(ctx->engine->resolvedUrl(ctx->callData->args[0].toQStringNoThrow())); QV4::Value callbackFunction = QV4::Value::undefinedValue(); - if (ctx->argumentCount >= 2 && ctx->arguments[1].asFunctionObject()) - callbackFunction = ctx->arguments[1]; + if (ctx->callData->argc >= 2 && ctx->callData->args[1].asFunctionObject()) + callbackFunction = ctx->callData->args[1]; QString localFile = QQmlFile::urlToLocalFileOrQrc(url); diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 3d57b5fb2f..57a84d008a 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -98,15 +98,15 @@ static double copySign(double x, double y) ReturnedValue MathObject::method_abs(SimpleCallContext *context) { - if (!context->argumentCount) + if (!context->callData->argc) return Encode(qSNaN()); - if (context->arguments[0].isInteger()) { - int i = context->arguments[0].integerValue(); + if (context->callData->args[0].isInteger()) { + int i = context->callData->args[0].integerValue(); return Encode(i < 0 ? - i : i); } - double v = context->arguments[0].toNumber(); + double v = context->callData->args[0].toNumber(); if (v == 0) // 0 | -0 return Encode(0); @@ -115,7 +115,7 @@ ReturnedValue MathObject::method_abs(SimpleCallContext *context) ReturnedValue MathObject::method_acos(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : 2; + double v = context->callData->argc ? context->callData->args[0].toNumber() : 2; if (v > 1) return Encode(qSNaN()); @@ -124,7 +124,7 @@ ReturnedValue MathObject::method_acos(SimpleCallContext *context) ReturnedValue MathObject::method_asin(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : 2; + double v = context->callData->argc ? context->callData->args[0].toNumber() : 2; if (v > 1) return Encode(qSNaN()); else @@ -133,7 +133,7 @@ ReturnedValue MathObject::method_asin(SimpleCallContext *context) ReturnedValue MathObject::method_atan(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); if (v == 0.0) return Encode(v); else @@ -142,8 +142,8 @@ ReturnedValue MathObject::method_atan(SimpleCallContext *context) ReturnedValue MathObject::method_atan2(SimpleCallContext *context) { - double v1 = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); - double v2 = context->argumentCount > 1 ? context->arguments[1].toNumber() : qSNaN(); + double v1 = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); + double v2 = context->callData->argc > 1 ? context->callData->args[1].toNumber() : qSNaN(); if ((v1 < 0) && qIsFinite(v1) && qIsInf(v2) && (copySign(1.0, v2) == 1.0)) return Encode(copySign(0, -1.0)); @@ -160,7 +160,7 @@ ReturnedValue MathObject::method_atan2(SimpleCallContext *context) ReturnedValue MathObject::method_ceil(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); if (v < 0.0 && v > -1.0) return Encode(copySign(0, -1.0)); else @@ -169,13 +169,13 @@ ReturnedValue MathObject::method_ceil(SimpleCallContext *context) ReturnedValue MathObject::method_cos(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); return Encode(::cos(v)); } ReturnedValue MathObject::method_exp(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); if (qIsInf(v)) { if (copySign(1.0, v) == -1.0) return Encode(0); @@ -188,13 +188,13 @@ ReturnedValue MathObject::method_exp(SimpleCallContext *context) ReturnedValue MathObject::method_floor(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); return Encode(::floor(v)); } ReturnedValue MathObject::method_log(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); if (v < 0) return Encode(qSNaN()); else @@ -204,8 +204,8 @@ ReturnedValue MathObject::method_log(SimpleCallContext *context) ReturnedValue MathObject::method_max(SimpleCallContext *context) { double mx = -qInf(); - for (unsigned i = 0; i < context->argumentCount; ++i) { - double x = context->arguments[i].toNumber(); + for (unsigned i = 0; i < context->callData->argc; ++i) { + double x = context->callData->args[i].toNumber(); if (x > mx || std::isnan(x)) mx = x; } @@ -215,8 +215,8 @@ ReturnedValue MathObject::method_max(SimpleCallContext *context) ReturnedValue MathObject::method_min(SimpleCallContext *context) { double mx = qInf(); - for (unsigned i = 0; i < context->argumentCount; ++i) { - double x = context->arguments[i].toNumber(); + for (unsigned i = 0; i < context->callData->argc; ++i) { + double x = context->callData->args[i].toNumber(); if ((x == 0 && mx == x && copySign(1.0, x) == -1.0) || (x < mx) || std::isnan(x)) { mx = x; @@ -227,8 +227,8 @@ ReturnedValue MathObject::method_min(SimpleCallContext *context) ReturnedValue MathObject::method_pow(SimpleCallContext *context) { - double x = context->argumentCount > 0 ? context->arguments[0].toNumber() : qSNaN(); - double y = context->argumentCount > 1 ? context->arguments[1].toNumber() : qSNaN(); + double x = context->callData->argc > 0 ? context->callData->args[0].toNumber() : qSNaN(); + double y = context->callData->argc > 1 ? context->callData->args[1].toNumber() : qSNaN(); if (std::isnan(y)) return Encode(qSNaN()); @@ -282,26 +282,26 @@ ReturnedValue MathObject::method_random(SimpleCallContext *) ReturnedValue MathObject::method_round(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); v = copySign(::floor(v + 0.5), v); return Encode(v); } ReturnedValue MathObject::method_sin(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); return Encode(::sin(v)); } ReturnedValue MathObject::method_sqrt(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); return Encode(::sqrt(v)); } ReturnedValue MathObject::method_tan(SimpleCallContext *context) { - double v = context->argumentCount ? context->arguments[0].toNumber() : qSNaN(); + double v = context->callData->argc ? context->callData->args[0].toNumber() : qSNaN(); if (v == 0.0) return Encode(v); else diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index f946b3180a..bc5e225f9b 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -100,9 +100,9 @@ void NumberPrototype::init(ExecutionEngine *engine, const Value &ctor) inline Value thisNumberValue(ExecutionContext *ctx) { - if (ctx->thisObject.isNumber()) - return ctx->thisObject; - NumberObject *n = ctx->thisObject.asNumberObject(); + if (ctx->callData->thisObject.isNumber()) + return ctx->callData->thisObject; + NumberObject *n = ctx->callData->thisObject.asNumberObject(); if (!n) ctx->throwTypeError(); return n->value; @@ -112,8 +112,8 @@ ReturnedValue NumberPrototype::method_toString(SimpleCallContext *ctx) { double num = thisNumberValue(ctx).asDouble(); - if (ctx->argumentCount && !ctx->arguments[0].isUndefined()) { - int radix = ctx->arguments[0].toInt32(); + if (ctx->callData->argc && !ctx->callData->args[0].isUndefined()) { + int radix = ctx->callData->args[0].toInt32(); if (radix < 2 || radix > 36) { ctx->throwError(QString::fromLatin1("Number.prototype.toString: %0 is not a valid radix") .arg(radix)); @@ -180,14 +180,14 @@ ReturnedValue NumberPrototype::method_toFixed(SimpleCallContext *ctx) double fdigits = 0; - if (ctx->argumentCount > 0) - fdigits = ctx->arguments[0].toInteger(); + if (ctx->callData->argc > 0) + fdigits = ctx->callData->args[0].toInteger(); if (std::isnan(fdigits)) fdigits = 0; if (fdigits < 0 || fdigits > 20) - ctx->throwRangeError(ctx->thisObject); + ctx->throwRangeError(ctx->callData->thisObject); QString str; if (std::isnan(v)) @@ -207,8 +207,8 @@ ReturnedValue NumberPrototype::method_toExponential(SimpleCallContext *ctx) int fdigits = -1; - if (ctx->argumentCount && !ctx->arguments[0].isUndefined()) { - int fdigits = ctx->arguments[0].toInt32(); + if (ctx->callData->argc && !ctx->callData->args[0].isUndefined()) { + int fdigits = ctx->callData->args[0].toInt32(); if (fdigits < 0 || fdigits > 20) { String *error = ctx->engine->newString(QStringLiteral("Number.prototype.toExponential: fractionDigits out of range")); ctx->throwRangeError(Value::fromString(error)); @@ -229,10 +229,10 @@ ReturnedValue NumberPrototype::method_toPrecision(SimpleCallContext *ctx) ScopedValue v(scope, thisNumberValue(ctx)); - if (!ctx->argumentCount || ctx->arguments[0].isUndefined()) + if (!ctx->callData->argc || ctx->callData->args[0].isUndefined()) return __qmljs_to_string(v, ctx); - double precision = ctx->arguments[0].toInt32(); + double precision = ctx->callData->args[0].toInt32(); if (precision < 1 || precision > 21) { String *error = ctx->engine->newString(QStringLiteral("Number.prototype.toPrecision: precision out of range")); ctx->throwRangeError(Value::fromString(error)); diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index befc01936d..96426cabfb 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -169,7 +169,7 @@ ReturnedValue ObjectPrototype::method_getOwnPropertyNames(SimpleCallContext *con if (!O) context->throwTypeError(); - ScopedArrayObject array(scope, getOwnPropertyNames(context->engine, context->arguments[0])); + ScopedArrayObject array(scope, getOwnPropertyNames(context->engine, context->callData->args[0])); return array.asReturnedValue(); } @@ -183,8 +183,8 @@ ReturnedValue ObjectPrototype::method_create(SimpleCallContext *ctx) Scoped<Object> newObject(scope, ctx->engine->newObject()); newObject->setPrototype(O->asObject()); - if (ctx->argumentCount > 1 && !ctx->arguments[1].isUndefined()) { - ctx->arguments[0] = newObject.asValue(); + if (ctx->callData->argc > 1 && !ctx->callData->args[1].isUndefined()) { + ctx->callData->args[0] = newObject.asValue(); return method_defineProperties(ctx); } @@ -387,12 +387,12 @@ ReturnedValue ObjectPrototype::method_keys(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_toString(SimpleCallContext *ctx) { Scope scope(ctx); - if (ctx->thisObject.isUndefined()) { + if (ctx->callData->thisObject.isUndefined()) { return Value::fromString(ctx, QStringLiteral("[object Undefined]")).asReturnedValue(); - } else if (ctx->thisObject.isNull()) { + } else if (ctx->callData->thisObject.isNull()) { return Value::fromString(ctx, QStringLiteral("[object Null]")).asReturnedValue(); } else { - ScopedObject obj(scope, __qmljs_to_object(ctx, ValueRef(&ctx->thisObject))); + ScopedObject obj(scope, __qmljs_to_object(ctx, ValueRef(&ctx->callData->thisObject))); QString className = obj->className(); return Value::fromString(ctx, QString::fromUtf8("[object %1]").arg(className)).asReturnedValue(); } @@ -401,7 +401,7 @@ ReturnedValue ObjectPrototype::method_toString(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_toLocaleString(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject o(scope, ctx->thisObject.toObject(ctx)); + ScopedObject o(scope, ctx->callData->thisObject.toObject(ctx)); Scoped<FunctionObject> f(scope, o->get(ctx->engine->id_toString)); if (!f) ctx->throwTypeError(); @@ -412,14 +412,14 @@ ReturnedValue ObjectPrototype::method_toLocaleString(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_valueOf(SimpleCallContext *ctx) { - return Value::fromObject(ctx->thisObject.toObject(ctx)).asReturnedValue(); + return Value::fromObject(ctx->callData->thisObject.toObject(ctx)).asReturnedValue(); } ReturnedValue ObjectPrototype::method_hasOwnProperty(SimpleCallContext *ctx) { Scope scope(ctx); Scoped<String> P(scope, ctx->argument(0), Scoped<String>::Convert); - Scoped<Object> O(scope, ctx->thisObject, Scoped<Object>::Convert); + Scoped<Object> O(scope, ctx->callData->thisObject, Scoped<Object>::Convert); bool r = O->__getOwnProperty__(P) != 0; if (!r) r = !O->query(P).isEmpty(); @@ -433,7 +433,7 @@ ReturnedValue ObjectPrototype::method_isPrototypeOf(SimpleCallContext *ctx) if (!V) return Encode(false); - Scoped<Object> O(scope, ctx->thisObject, Scoped<Object>::Convert); + Scoped<Object> O(scope, ctx->callData->thisObject, Scoped<Object>::Convert); Scoped<Object> proto(scope, V->prototype()); while (proto) { if (O.getPointer() == proto.getPointer()) @@ -448,7 +448,7 @@ ReturnedValue ObjectPrototype::method_propertyIsEnumerable(SimpleCallContext *ct Scope scope(ctx); Scoped<String> p(scope, ctx->argument(0), Scoped<String>::Convert); - Scoped<Object> o(scope, ctx->thisObject, Scoped<Object>::Convert); + Scoped<Object> o(scope, ctx->callData->thisObject, Scoped<Object>::Convert); PropertyAttributes attrs; o->__getOwnProperty__(p, &attrs); return Encode(attrs.isEnumerable()); @@ -456,7 +456,7 @@ ReturnedValue ObjectPrototype::method_propertyIsEnumerable(SimpleCallContext *ct ReturnedValue ObjectPrototype::method_defineGetter(SimpleCallContext *ctx) { - if (ctx->argumentCount < 2) + if (ctx->callData->argc < 2) ctx->throwTypeError(); Scope scope(ctx); @@ -466,9 +466,9 @@ ReturnedValue ObjectPrototype::method_defineGetter(SimpleCallContext *ctx) if (!f) ctx->throwTypeError(); - Scoped<Object> o(scope, ctx->thisObject); + Scoped<Object> o(scope, ctx->callData->thisObject); if (!o) { - if (!ctx->thisObject.isUndefined()) + if (!ctx->callData->thisObject.isUndefined()) return Encode::undefined(); o = ctx->engine->globalObject; } @@ -480,7 +480,7 @@ ReturnedValue ObjectPrototype::method_defineGetter(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_defineSetter(SimpleCallContext *ctx) { - if (ctx->argumentCount < 2) + if (ctx->callData->argc < 2) ctx->throwTypeError(); Scope scope(ctx); @@ -490,9 +490,9 @@ ReturnedValue ObjectPrototype::method_defineSetter(SimpleCallContext *ctx) if (!f) ctx->throwTypeError(); - Scoped<Object> o(scope, ctx->thisObject); + Scoped<Object> o(scope, ctx->callData->thisObject); if (!o) { - if (!ctx->thisObject.isUndefined()) + if (!ctx->callData->thisObject.isUndefined()) return Encode::undefined(); o = ctx->engine->globalObject; } @@ -505,7 +505,7 @@ ReturnedValue ObjectPrototype::method_defineSetter(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_get_proto(SimpleCallContext *ctx) { Scope scope(ctx); - ScopedObject o(scope, ctx->thisObject.asObject()); + ScopedObject o(scope, ctx->callData->thisObject.asObject()); if (!o) ctx->throwTypeError(); @@ -515,16 +515,16 @@ ReturnedValue ObjectPrototype::method_get_proto(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_set_proto(SimpleCallContext *ctx) { Scope scope(ctx); - Scoped<Object> o(scope, ctx->thisObject); - if (!o || !ctx->argumentCount) + Scoped<Object> o(scope, ctx->callData->thisObject); + if (!o || !ctx->callData->argc) ctx->throwTypeError(); - if (ctx->arguments[0].isNull()) { + if (ctx->callData->args[0].isNull()) { o->setPrototype(0); return Encode::undefined(); } - Scoped<Object> p(scope, ctx->arguments[0]); + Scoped<Object> p(scope, ctx->callData->args[0]); bool ok = false; if (!!p) { if (o->prototype() == p.getPointer()) { diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index b7a696cc33..876bda3163 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -788,10 +788,10 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase ReturnedValue QObjectWrapper::method_connect(SimpleCallContext *ctx) { - if (ctx->argumentCount == 0) + if (ctx->callData->argc == 0) V4THROW_ERROR("Function.prototype.connect: no arguments given"); - QPair<QObject *, int> signalInfo = extractQtSignal(ctx->thisObject); + QPair<QObject *, int> signalInfo = extractQtSignal(ctx->callData->thisObject); QObject *signalObject = signalInfo.first; int signalIndex = signalInfo.second; @@ -808,11 +808,11 @@ ReturnedValue QObjectWrapper::method_connect(SimpleCallContext *ctx) QV4::ScopedFunctionObject f(scope); QV4::ScopedValue thisObject (scope, QV4::Encode::undefined()); - if (ctx->argumentCount == 1) { - f = ctx->arguments[0]; - } else if (ctx->argumentCount >= 2) { - thisObject = ctx->arguments[0]; - f = ctx->arguments[1]; + if (ctx->callData->argc == 1) { + f = ctx->callData->args[0]; + } else if (ctx->callData->argc >= 2) { + thisObject = ctx->callData->args[0]; + f = ctx->callData->args[1]; } if (!f) @@ -834,10 +834,10 @@ ReturnedValue QObjectWrapper::method_connect(SimpleCallContext *ctx) ReturnedValue QObjectWrapper::method_disconnect(SimpleCallContext *ctx) { - if (ctx->argumentCount == 0) + if (ctx->callData->argc == 0) V4THROW_ERROR("Function.prototype.disconnect: no arguments given"); - QPair<QObject *, int> signalInfo = extractQtSignal(ctx->thisObject); + QPair<QObject *, int> signalInfo = extractQtSignal(ctx->callData->thisObject); QObject *signalObject = signalInfo.first; int signalIndex = signalInfo.second; @@ -853,11 +853,11 @@ ReturnedValue QObjectWrapper::method_disconnect(SimpleCallContext *ctx) QV4::Value functionValue = QV4::Value::undefinedValue(); QV4::Value functionThisValue = QV4::Value::undefinedValue(); - if (ctx->argumentCount == 1) { - functionValue = ctx->arguments[0]; - } else if (ctx->argumentCount >= 2) { - functionThisValue = ctx->arguments[0]; - functionValue = ctx->arguments[1]; + if (ctx->callData->argc == 1) { + functionValue = ctx->callData->args[0]; + } else if (ctx->callData->argc >= 2) { + functionThisValue = ctx->callData->args[0]; + functionValue = ctx->callData->args[1]; } if (!functionValue.asFunctionObject()) diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 3f58f28b4b..fee66d9d09 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -303,8 +303,7 @@ void RegExpPrototype::init(ExecutionEngine *engine, const Value &ctor) ReturnedValue RegExpPrototype::method_exec(SimpleCallContext *ctx) { Scope scope(ctx); - - RegExpObject *r = ctx->thisObject.as<RegExpObject>(); + Scoped<RegExpObject> r(scope, ctx->callData->thisObject.as<RegExpObject>()); if (!r) ctx->throwTypeError(); @@ -355,7 +354,8 @@ ReturnedValue RegExpPrototype::method_test(SimpleCallContext *ctx) ReturnedValue RegExpPrototype::method_toString(SimpleCallContext *ctx) { - RegExpObject *r = ctx->thisObject.as<RegExpObject>(); + Scope scope(ctx); + Scoped<RegExpObject> r(scope, ctx->callData->thisObject.as<RegExpObject>()); if (!r) ctx->throwTypeError(); @@ -365,12 +365,12 @@ ReturnedValue RegExpPrototype::method_toString(SimpleCallContext *ctx) ReturnedValue RegExpPrototype::method_compile(SimpleCallContext *ctx) { Scope scope(ctx); - RegExpObject *r = ctx->thisObject.as<RegExpObject>(); + Scoped<RegExpObject> r(scope, ctx->callData->thisObject.as<RegExpObject>()); if (!r) ctx->throwTypeError(); - ScopedCallData callData(scope, ctx->argumentCount); - memcpy(callData->args, ctx->arguments, ctx->argumentCount*sizeof(Value)); + ScopedCallData callData(scope, ctx->callData->argc); + memcpy(callData->args, ctx->callData->args, ctx->callData->argc*sizeof(Value)); RegExpObject *re = Value::fromReturnedValue(ctx->engine->regExpCtor.asFunctionObject()->construct(callData)).as<RegExpObject>(); r->value = re->value; diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index a8e18dac78..30a9aa8b38 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -60,13 +60,13 @@ struct Scope { , size(0) #endif { - mark = ctx->engine->jsStackTop; + mark = engine->jsStackTop; } explicit Scope(ExecutionEngine *e) : engine(e) { - mark = e->jsStackTop; + mark = engine->jsStackTop; } ~Scope() { @@ -77,6 +77,15 @@ struct Scope { engine->jsStackTop = mark; } + Value *alloc(int nValues) { + Value *ptr = engine->jsStackTop; + engine->jsStackTop += nValues; +#ifndef QT_NO_DEBUG + size += nValues; +#endif + return ptr; + } + ExecutionEngine *engine; Value *mark; #ifndef QT_NO_DEBUG @@ -683,6 +692,10 @@ inline WeakValue &WeakValue::operator=(Returned<T> *obj) return operator=(QV4::Value::fromManaged(obj->getPointer()).asReturnedValue()); } +inline ReturnedValue SimpleCallContext::argument(int i) { + return i < callData->argc ? callData->args[i].asReturnedValue() : Value::undefinedValue().asReturnedValue(); +} + } diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index e8ba80de35..6ad13efbdd 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -376,8 +376,8 @@ public: loadReference(); } - if (ctx->argumentCount == 1 && ctx->arguments[0].asFunctionObject()) { - QV4::Value compareFn = ctx->arguments[0]; + if (ctx->callData->argc == 1 && ctx->callData->args[0].asFunctionObject()) { + QV4::Value compareFn = ctx->callData->args[0]; CompareFunctor cf(ctx, compareFn); std::sort(m_container.begin(), m_container.end(), cf); } else { @@ -391,7 +391,8 @@ public: static QV4::ReturnedValue method_get_length(QV4::SimpleCallContext *ctx) { - QQmlSequence<Container> *This = ctx->thisObject.as<QQmlSequence<Container> >(); + QV4::Scope scope(ctx); + QV4::Scoped<QQmlSequence<Container> > This(scope, ctx->callData->thisObject.as<QQmlSequence<Container> >()); if (!This) ctx->throwTypeError(); @@ -405,11 +406,12 @@ public: static QV4::ReturnedValue method_set_length(QV4::SimpleCallContext* ctx) { - QQmlSequence<Container> *This = ctx->thisObject.as<QQmlSequence<Container> >(); + QV4::Scope scope(ctx); + QV4::Scoped<QQmlSequence<Container> > This(scope, ctx->callData->thisObject.as<QQmlSequence<Container> >()); if (!This) ctx->throwTypeError(); - quint32 newLength = ctx->arguments[0].toUInt32(); + quint32 newLength = ctx->callData->args[0].toUInt32(); /* Qt containers have int (rather than uint) allowable indexes. */ if (newLength > INT_MAX) { generateWarning(ctx, QLatin1String("Index out of range during length set")); @@ -542,12 +544,12 @@ void SequencePrototype::init() QV4::ReturnedValue SequencePrototype::method_sort(QV4::SimpleCallContext *ctx) { - QV4::Object *o = ctx->thisObject.asObject(); + QV4::Object *o = ctx->callData->thisObject.asObject(); if (!o || !o->isListType()) ctx->throwTypeError(); - if (ctx->argumentCount >= 2) - return ctx->thisObject.asReturnedValue(); + if (ctx->callData->argc >= 2) + return ctx->callData->thisObject.asReturnedValue(); #define CALL_SORT(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \ if (QQml##SequenceElementTypeName##List *s = o->as<QQml##SequenceElementTypeName##List>()) { \ @@ -557,7 +559,7 @@ QV4::ReturnedValue SequencePrototype::method_sort(QV4::SimpleCallContext *ctx) FOREACH_QML_SEQUENCE_TYPE(CALL_SORT) #undef CALL_SORT - return ctx->thisObject.asReturnedValue(); + return ctx->callData->thisObject.asReturnedValue(); } #define IS_SEQUENCE(unused1, unused2, SequenceType, unused3) \ diff --git a/src/qml/jsruntime/qv4sequenceobject_p.h b/src/qml/jsruntime/qv4sequenceobject_p.h index ca58b11090..a743bac247 100644 --- a/src/qml/jsruntime/qv4sequenceobject_p.h +++ b/src/qml/jsruntime/qv4sequenceobject_p.h @@ -71,7 +71,7 @@ struct SequencePrototype : public QV4::Object static ReturnedValue method_valueOf(QV4::SimpleCallContext *ctx) { - return QV4::Value::fromString(ctx->thisObject.toString(ctx)).asReturnedValue(); + return QV4::Value::fromString(ctx->callData->thisObject.toString(ctx)).asReturnedValue(); } static ReturnedValue method_sort(QV4::SimpleCallContext *ctx); diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index a7343bc8c1..05a1ef4100 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -218,7 +218,7 @@ void StringPrototype::init(ExecutionEngine *engine, const Value &ctor) static QString getThisString(ExecutionContext *ctx) { Scope scope(ctx); - ScopedValue t(scope, ctx->thisObject); + ScopedValue t(scope, ctx->callData->thisObject); if (t->isString()) return t->stringValue()->toQString(); if (StringObject *thisString = t->asStringObject()) @@ -230,10 +230,10 @@ static QString getThisString(ExecutionContext *ctx) ReturnedValue StringPrototype::method_toString(SimpleCallContext *context) { - if (context->thisObject.isString()) - return context->thisObject.asReturnedValue(); + if (context->callData->thisObject.isString()) + return context->callData->thisObject.asReturnedValue(); - StringObject *o = context->thisObject.asStringObject(); + StringObject *o = context->callData->thisObject.asStringObject(); if (!o) context->throwTypeError(); return o->value.asReturnedValue(); @@ -244,8 +244,8 @@ ReturnedValue StringPrototype::method_charAt(SimpleCallContext *context) const QString str = getThisString(context); int pos = 0; - if (context->argumentCount > 0) - pos = (int) context->arguments[0].toInteger(); + if (context->callData->argc > 0) + pos = (int) context->callData->args[0].toInteger(); QString result; if (pos >= 0 && pos < str.length()) @@ -259,8 +259,8 @@ ReturnedValue StringPrototype::method_charCodeAt(SimpleCallContext *context) const QString str = getThisString(context); int pos = 0; - if (context->argumentCount > 0) - pos = (int) context->arguments[0].toInteger(); + if (context->callData->argc > 0) + pos = (int) context->callData->args[0].toInteger(); if (pos >= 0 && pos < str.length()) @@ -276,8 +276,8 @@ ReturnedValue StringPrototype::method_concat(SimpleCallContext *context) QString value = getThisString(context); ScopedValue v(scope); - for (int i = 0; i < context->argumentCount; ++i) { - v = __qmljs_to_string(ValueRef(&context->arguments[i]), context); + for (int i = 0; i < context->callData->argc; ++i) { + v = __qmljs_to_string(ValueRef(&context->callData->args[i]), context); assert(v->isString()); value += v->stringValue()->toQString(); } @@ -290,12 +290,12 @@ ReturnedValue StringPrototype::method_indexOf(SimpleCallContext *context) QString value = getThisString(context); QString searchString; - if (context->argumentCount) - searchString = context->arguments[0].toString(context)->toQString(); + if (context->callData->argc) + searchString = context->callData->args[0].toString(context)->toQString(); int pos = 0; - if (context->argumentCount > 1) - pos = (int) context->arguments[1].toInteger(); + if (context->callData->argc > 1) + pos = (int) context->callData->args[1].toInteger(); int index = -1; if (! value.isEmpty()) @@ -311,8 +311,8 @@ ReturnedValue StringPrototype::method_lastIndexOf(SimpleCallContext *context) const QString value = getThisString(context); QString searchString; - if (context->argumentCount) - searchString = context->arguments[0].toQString(); + if (context->callData->argc) + searchString = context->callData->args[0].toQString(); ScopedValue posArg(scope, context->argument(1)); double position = __qmljs_to_number(posArg); @@ -333,19 +333,19 @@ ReturnedValue StringPrototype::method_lastIndexOf(SimpleCallContext *context) ReturnedValue StringPrototype::method_localeCompare(SimpleCallContext *context) { const QString value = getThisString(context); - const QString that = (context->argumentCount ? context->arguments[0] : Value::undefinedValue()).toQString(); + const QString that = (context->callData->argc ? context->callData->args[0] : Value::undefinedValue()).toQString(); return Encode(QString::localeAwareCompare(value, that)); } ReturnedValue StringPrototype::method_match(SimpleCallContext *context) { - if (context->thisObject.isUndefined() || context->thisObject.isNull()) + if (context->callData->thisObject.isUndefined() || context->callData->thisObject.isNull()) context->throwTypeError(); Scope scope(context); - ScopedString s(scope, context->thisObject.toString(context)); + ScopedString s(scope, context->callData->thisObject.toString(context)); - ScopedValue regexp(scope, context->argumentCount ? context->arguments[0] : Value::undefinedValue()); + ScopedValue regexp(scope, context->callData->argc ? context->callData->args[0] : Value::undefinedValue()); Scoped<RegExpObject> rx(scope, regexp); if (!rx) { ScopedCallData callData(scope, 1); @@ -451,10 +451,10 @@ ReturnedValue StringPrototype::method_replace(SimpleCallContext *ctx) { Scope scope(ctx); QString string; - if (StringObject *thisString = ctx->thisObject.asStringObject()) + if (StringObject *thisString = ctx->callData->thisObject.asStringObject()) string = thisString->value.stringValue()->toQString(); else - string = ctx->thisObject.toString(ctx)->toQString(); + string = ctx->callData->thisObject.toString(ctx)->toQString(); int numCaptures = 0; int numStringMatches = 0; @@ -585,9 +585,9 @@ ReturnedValue StringPrototype::method_slice(SimpleCallContext *ctx) const QString text = getThisString(ctx); const double length = text.length(); - double start = ctx->argumentCount ? ctx->arguments[0].toInteger() : 0; - double end = (ctx->argumentCount < 2 || ctx->arguments[1].isUndefined()) - ? length : ctx->arguments[1].toInteger(); + double start = ctx->callData->argc ? ctx->callData->args[0].toInteger() : 0; + double end = (ctx->callData->argc < 2 || ctx->callData->args[1].isUndefined()) + ? length : ctx->callData->args[1].toInteger(); if (start < 0) start = qMax(length + start, 0.); @@ -690,12 +690,12 @@ ReturnedValue StringPrototype::method_substr(SimpleCallContext *context) const QString value = getThisString(context); double start = 0; - if (context->argumentCount > 0) - start = context->arguments[0].toInteger(); + if (context->callData->argc > 0) + start = context->callData->args[0].toInteger(); double length = +qInf(); - if (context->argumentCount > 1) - length = context->arguments[1].toInteger(); + if (context->callData->argc > 1) + length = context->callData->args[1].toInteger(); double count = value.length(); if (start < 0) @@ -716,8 +716,8 @@ ReturnedValue StringPrototype::method_substring(SimpleCallContext *context) double start = 0; double end = length; - if (context->argumentCount > 0) - start = context->arguments[0].toInteger(); + if (context->callData->argc > 0) + start = context->callData->args[0].toInteger(); Scope scope(context); ScopedValue endValue(scope, context->argument(1)); @@ -771,10 +771,10 @@ ReturnedValue StringPrototype::method_toLocaleUpperCase(SimpleCallContext *ctx) ReturnedValue StringPrototype::method_fromCharCode(SimpleCallContext *context) { - QString str(context->argumentCount, Qt::Uninitialized); + QString str(context->callData->argc, Qt::Uninitialized); QChar *ch = str.data(); - for (int i = 0; i < context->argumentCount; ++i) { - *ch = QChar(context->arguments[i].toUInt16()); + for (int i = 0; i < context->callData->argc; ++i) { + *ch = QChar(context->callData->args[i].toUInt16()); ++ch; } return Value::fromString(context, str).asReturnedValue(); diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp index de72de2f07..720e4fa3a6 100644 --- a/src/qml/jsruntime/qv4variantobject.cpp +++ b/src/qml/jsruntime/qv4variantobject.cpp @@ -155,7 +155,8 @@ void VariantPrototype::init() QV4::ReturnedValue VariantPrototype::method_preserve(SimpleCallContext *ctx) { - VariantObject *o = ctx->thisObject.as<QV4::VariantObject>(); + Scope scope(ctx); + Scoped<VariantObject> o(scope, ctx->callData->thisObject.as<QV4::VariantObject>()); if (o && o->isScarce()) o->node.remove(); return Encode::undefined(); @@ -163,7 +164,8 @@ QV4::ReturnedValue VariantPrototype::method_preserve(SimpleCallContext *ctx) QV4::ReturnedValue VariantPrototype::method_destroy(SimpleCallContext *ctx) { - VariantObject *o = ctx->thisObject.as<QV4::VariantObject>(); + Scope scope(ctx); + Scoped<VariantObject> o(scope, ctx->callData->thisObject.as<QV4::VariantObject>()); if (o) { if (o->isScarce()) o->node.remove(); @@ -174,7 +176,8 @@ QV4::ReturnedValue VariantPrototype::method_destroy(SimpleCallContext *ctx) QV4::ReturnedValue VariantPrototype::method_toString(SimpleCallContext *ctx) { - VariantObject *o = ctx->thisObject.as<QV4::VariantObject>(); + Scope scope(ctx); + Scoped<VariantObject> o(scope, ctx->callData->thisObject.as<QV4::VariantObject>()); if (!o) return Encode::undefined(); QString result = o->data.toString(); @@ -185,7 +188,8 @@ QV4::ReturnedValue VariantPrototype::method_toString(SimpleCallContext *ctx) QV4::ReturnedValue VariantPrototype::method_valueOf(SimpleCallContext *ctx) { - VariantObject *o = ctx->thisObject.as<QV4::VariantObject>(); + Scope scope(ctx); + Scoped<VariantObject> o(scope, ctx->callData->thisObject.as<QV4::VariantObject>()); if (o) { QVariant v = o->data; switch (v.type()) { @@ -204,7 +208,7 @@ QV4::ReturnedValue VariantPrototype::method_valueOf(SimpleCallContext *ctx) break; } } - return ctx->thisObject.asReturnedValue(); + return ctx->callData->thisObject.asReturnedValue(); } QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index 868158717c..ce2f76042f 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -170,9 +170,9 @@ static inline QV4::Value *getValueRef(QV4::ExecutionContext *context, QV4::CallContext *cc = static_cast<QV4::CallContext *>(c); const unsigned arg = param.index; Q_ASSERT(arg >= 0); - Q_ASSERT((unsigned) arg < cc->argumentCount); - Q_ASSERT(cc->arguments); - return cc->arguments + arg; + Q_ASSERT((unsigned) arg < cc->callData->argc); + Q_ASSERT(cc->callData->args); + return cc->callData->args + arg; } else if (param.isLocal()) { VMSTATS(paramIsLocal); const unsigned index = param.index; @@ -546,7 +546,7 @@ QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *&code, MOTH_END_INSTR(Ret) MOTH_BEGIN_INSTR(LoadThis) - VALUE(instr.result) = context->thisObject; + VALUE(instr.result) = context->callData->thisObject; MOTH_END_INSTR(LoadThis) MOTH_BEGIN_INSTR(InplaceElementOp) |