diff options
author | Lars Knoll <[email protected]> | 2014-05-06 09:23:59 +0200 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2014-07-22 13:49:11 +0200 |
commit | 9744e8bd423d528165f5e78704c6e017852b8e9a (patch) | |
tree | b1210199c698d3b09d80b9267d9aaab2b12ac5ab /src/qml/jsruntime/qv4arrayobject.cpp | |
parent | f3f31957b79c55f3e076473b0d4c41c8872535b3 (diff) |
Convert ExecutionContext to new storage scheme
Change-Id: I9fcc13da5360f37cef3149b114ed9263b9b74281
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4arrayobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4arrayobject.cpp | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index 74712f9b3f..88700e17d0 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -122,21 +122,21 @@ void ArrayPrototype::init(ExecutionEngine *engine, ObjectRef ctor) ReturnedValue ArrayPrototype::method_isArray(CallContext *ctx) { - bool isArray = ctx->callData->argc && ctx->callData->args[0].asArrayObject(); + bool isArray = ctx->d()->callData->argc && ctx->d()->callData->args[0].asArrayObject(); return Encode(isArray); } ReturnedValue ArrayPrototype::method_toString(CallContext *ctx) { Scope scope(ctx); - ScopedObject o(scope, ctx->callData->thisObject, ScopedObject::Convert); - if (ctx->engine->hasException) + ScopedObject o(scope, ctx->d()->callData->thisObject, ScopedObject::Convert); + if (ctx->d()->engine->hasException) return Encode::undefined(); - ScopedString s(scope, ctx->engine->newString(QStringLiteral("join"))); + ScopedString s(scope, ctx->d()->engine->newString(QStringLiteral("join"))); ScopedFunctionObject f(scope, o->get(s)); if (!!f) { ScopedCallData d(scope, 0); - d->thisObject = ctx->callData->thisObject; + d->thisObject = ctx->d()->callData->thisObject; return f->call(d); } return ObjectPrototype::method_toString(ctx); @@ -150,9 +150,9 @@ ReturnedValue ArrayPrototype::method_toLocaleString(CallContext *ctx) ReturnedValue ArrayPrototype::method_concat(CallContext *ctx) { Scope scope(ctx); - ScopedObject result(scope, ctx->engine->newArrayObject()); + ScopedObject result(scope, ctx->d()->engine->newArrayObject()); - ScopedObject thisObject(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject thisObject(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!thisObject) return Encode::undefined(); ScopedArrayObject instance(scope, thisObject); @@ -165,9 +165,9 @@ ReturnedValue ArrayPrototype::method_concat(CallContext *ctx) ScopedArrayObject elt(scope); ScopedObject eltAsObj(scope); ScopedValue entry(scope); - for (int i = 0; i < ctx->callData->argc; ++i) { - eltAsObj = ctx->callData->args[i]; - elt = ctx->callData->args[i]; + for (int i = 0; i < ctx->d()->callData->argc; ++i) { + eltAsObj = ctx->d()->callData->args[i]; + elt = ctx->d()->callData->args[i]; if (elt) { uint n = elt->getLength(); uint newLen = ArrayData::append(result.getPointer(), elt.getPointer(), n); @@ -179,7 +179,7 @@ ReturnedValue ArrayPrototype::method_concat(CallContext *ctx) result->putIndexed(startIndex + i, entry); } } else { - result->arraySet(result->getLength(), ValueRef(ctx->callData->args[i])); + result->arraySet(result->getLength(), ValueRef(ctx->d()->callData->args[i])); } } @@ -197,12 +197,12 @@ ReturnedValue ArrayPrototype::method_join(CallContext *ctx) else r4 = arg->toQString(); - ScopedObject self(scope, ctx->callData->thisObject); - ScopedValue length(scope, self->get(ctx->engine->id_length)); + ScopedObject self(scope, ctx->d()->callData->thisObject); + ScopedValue length(scope, self->get(ctx->d()->engine->id_length)); const quint32 r2 = length->isUndefined() ? 0 : length->toUInt32(); if (!r2) - return ctx->engine->newString(QString())->asReturnedValue(); + return ctx->d()->engine->newString(QString())->asReturnedValue(); QString R; @@ -223,7 +223,7 @@ ReturnedValue ArrayPrototype::method_join(CallContext *ctx) // // crazy! // - ScopedString name(scope, ctx->engine->newString(QStringLiteral("0"))); + ScopedString name(scope, ctx->d()->engine->newString(QStringLiteral("0"))); ScopedValue r6(scope, self->get(name)); if (!r6->isNullOrUndefined()) R = r6->toString(ctx)->toQString(); @@ -242,20 +242,20 @@ ReturnedValue ArrayPrototype::method_join(CallContext *ctx) } } - return ctx->engine->newString(R)->asReturnedValue(); + return ctx->d()->engine->newString(R)->asReturnedValue(); } ReturnedValue ArrayPrototype::method_pop(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); uint len = instance->getLength(); if (!len) { if (!instance->isArrayObject()) - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromInt32(0))); + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromInt32(0))); return Encode::undefined(); } @@ -269,14 +269,14 @@ ReturnedValue ArrayPrototype::method_pop(CallContext *ctx) if (instance->isArrayObject()) instance->setArrayLength(len - 1); else - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len - 1))); + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len - 1))); return result.asReturnedValue(); } ReturnedValue ArrayPrototype::method_push(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -284,38 +284,38 @@ ReturnedValue ArrayPrototype::method_push(CallContext *ctx) uint len = instance->getLength(); - if (len + ctx->callData->argc < len) { + if (len + ctx->d()->callData->argc < len) { // ughh... double l = len; ScopedString s(scope); - for (int i = 0; i < ctx->callData->argc; ++i) { + for (int i = 0; i < ctx->d()->callData->argc; ++i) { s = Primitive::fromDouble(l + i).toString(ctx); - instance->put(s, ctx->callData->args[i]); + instance->put(s, ctx->d()->callData->args[i]); } - double newLen = l + ctx->callData->argc; + double newLen = l + ctx->d()->callData->argc; if (!instance->isArrayObject()) - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromDouble(newLen))); + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromDouble(newLen))); else { - ScopedString str(scope, ctx->engine->newString(QStringLiteral("Array.prototype.push: Overflow"))); + ScopedString str(scope, ctx->d()->engine->newString(QStringLiteral("Array.prototype.push: Overflow"))); return ctx->throwRangeError(str); } return Encode(newLen); } - if (!ctx->callData->argc) { + if (!ctx->d()->callData->argc) { ; } else if (!instance->protoHasArray() && instance->arrayData()->length() <= len && instance->arrayType() == ArrayData::Simple) { - instance->arrayData()->vtable()->putArray(instance.getPointer(), len, ctx->callData->args, ctx->callData->argc); + instance->arrayData()->vtable()->putArray(instance.getPointer(), len, ctx->d()->callData->args, ctx->d()->callData->argc); len = instance->arrayData()->length(); } else { - for (int i = 0; i < ctx->callData->argc; ++i) - instance->putIndexed(len + i, ctx->callData->args[i]); - len += ctx->callData->argc; + for (int i = 0; i < ctx->d()->callData->argc; ++i) + instance->putIndexed(len + i, ctx->d()->callData->args[i]); + len += ctx->d()->callData->argc; } if (instance->isArrayObject()) instance->setArrayLengthUnchecked(len); else - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len))); + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len))); return Encode(len); } @@ -323,7 +323,7 @@ ReturnedValue ArrayPrototype::method_push(CallContext *ctx) ReturnedValue ArrayPrototype::method_reverse(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); uint length = instance->getLength(); @@ -355,7 +355,7 @@ ReturnedValue ArrayPrototype::method_reverse(CallContext *ctx) ReturnedValue ArrayPrototype::method_shift(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -365,7 +365,7 @@ ReturnedValue ArrayPrototype::method_shift(CallContext *ctx) if (!len) { if (!instance->isArrayObject()) - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromInt32(0))); + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromInt32(0))); return Encode::undefined(); } @@ -399,18 +399,18 @@ ReturnedValue ArrayPrototype::method_shift(CallContext *ctx) if (instance->isArrayObject()) instance->setArrayLengthUnchecked(len - 1); else - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len - 1))); + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len - 1))); return result.asReturnedValue(); } ReturnedValue ArrayPrototype::method_slice(CallContext *ctx) { Scope scope(ctx); - ScopedObject o(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject o(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!o) return Encode::undefined(); - Scoped<ArrayObject> result(scope, ctx->engine->newArrayObject()); + Scoped<ArrayObject> result(scope, ctx->d()->engine->newArrayObject()); uint len = o->getLength(); double s = ScopedValue(scope, ctx->argument(0))->toInteger(); uint start; @@ -421,8 +421,8 @@ ReturnedValue ArrayPrototype::method_slice(CallContext *ctx) else start = (uint) s; uint end = len; - if (ctx->callData->argc > 1 && !ctx->callData->args[1].isUndefined()) { - double e = ctx->callData->args[1].toInteger(); + if (ctx->d()->callData->argc > 1 && !ctx->d()->callData->args[1].isUndefined()) { + double e = ctx->d()->callData->args[1].toInteger(); if (e < 0) end = (uint)qMax(len + e, 0.); else if (e > len) @@ -448,7 +448,7 @@ ReturnedValue ArrayPrototype::method_slice(CallContext *ctx) ReturnedValue ArrayPrototype::method_sort(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -456,18 +456,18 @@ ReturnedValue ArrayPrototype::method_sort(CallContext *ctx) ScopedValue comparefn(scope, ctx->argument(0)); ArrayData::sort(ctx, instance, comparefn, len); - return ctx->callData->thisObject.asReturnedValue(); + return ctx->d()->callData->thisObject.asReturnedValue(); } ReturnedValue ArrayPrototype::method_splice(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); uint len = instance->getLength(); - Scoped<ArrayObject> newArray(scope, ctx->engine->newArrayObject()); + Scoped<ArrayObject> newArray(scope, ctx->d()->engine->newArrayObject()); double rs = ScopedValue(scope, ctx->argument(0))->toInteger(); uint start; @@ -490,7 +490,7 @@ ReturnedValue ArrayPrototype::method_splice(CallContext *ctx) } newArray->setArrayLengthUnchecked(deleteCount); - uint itemCount = ctx->callData->argc < 2 ? 0 : ctx->callData->argc - 2; + uint itemCount = ctx->d()->callData->argc < 2 ? 0 : ctx->d()->callData->argc - 2; if (itemCount < deleteCount) { for (uint k = start; k < len - deleteCount; ++k) { @@ -528,13 +528,13 @@ ReturnedValue ArrayPrototype::method_splice(CallContext *ctx) } for (uint i = 0; i < itemCount; ++i) { - instance->putIndexed(start + i, ctx->callData->args[i + 2]); + instance->putIndexed(start + i, ctx->d()->callData->args[i + 2]); if (scope.hasException()) return Encode::undefined(); } - ctx->strictMode = true; - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len - deleteCount + itemCount))); + ctx->d()->strictMode = true; + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromDouble(len - deleteCount + itemCount))); return newArray.asReturnedValue(); } @@ -542,7 +542,7 @@ ReturnedValue ArrayPrototype::method_splice(CallContext *ctx) ReturnedValue ArrayPrototype::method_unshift(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -551,26 +551,26 @@ ReturnedValue ArrayPrototype::method_unshift(CallContext *ctx) uint len = instance->getLength(); if (!instance->protoHasArray() && !instance->arrayData()->hasAttributes() && instance->arrayData()->length() <= len) { - instance->arrayData()->vtable()->push_front(instance.getPointer(), ctx->callData->args, ctx->callData->argc); + instance->arrayData()->vtable()->push_front(instance.getPointer(), ctx->d()->callData->args, ctx->d()->callData->argc); } else { ScopedValue v(scope); for (uint k = len; k > 0; --k) { bool exists; v = instance->getIndexed(k - 1, &exists); if (exists) - instance->putIndexed(k + ctx->callData->argc - 1, v); + instance->putIndexed(k + ctx->d()->callData->argc - 1, v); else - instance->deleteIndexedProperty(k + ctx->callData->argc - 1); + instance->deleteIndexedProperty(k + ctx->d()->callData->argc - 1); } - for (int i = 0; i < ctx->callData->argc; ++i) - instance->putIndexed(i, ctx->callData->args[i]); + for (int i = 0; i < ctx->d()->callData->argc; ++i) + instance->putIndexed(i, ctx->d()->callData->args[i]); } - uint newLen = len + ctx->callData->argc; + uint newLen = len + ctx->d()->callData->argc; if (instance->isArrayObject()) instance->setArrayLengthUnchecked(newLen); else - instance->put(ctx->engine->id_length, ScopedValue(scope, Primitive::fromDouble(newLen))); + instance->put(ctx->d()->engine->id_length, ScopedValue(scope, Primitive::fromDouble(newLen))); return Encode(newLen); } @@ -579,18 +579,18 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); uint len = instance->getLength(); if (!len) return Encode(-1); - ScopedValue searchValue(scope, ctx->callData->argument(0)); + ScopedValue searchValue(scope, ctx->d()->callData->argument(0)); uint fromIndex = 0; - if (ctx->callData->argc >= 2) { - double f = ctx->callData->args[1].toInteger(); + if (ctx->d()->callData->argc >= 2) { + double f = ctx->d()->callData->args[1].toInteger(); if (scope.hasException()) return Encode::undefined(); if (f >= len) @@ -650,7 +650,7 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(CallContext *ctx) { Scope scope(ctx); - ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx)); + ScopedObject instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); uint len = instance->getLength(); @@ -660,13 +660,13 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(CallContext *ctx) ScopedValue searchValue(scope); uint fromIndex = len; - if (ctx->callData->argc >= 1) + if (ctx->d()->callData->argc >= 1) searchValue = ctx->argument(0); else searchValue = Primitive::undefinedValue(); - if (ctx->callData->argc >= 2) { - double f = ctx->callData->args[1].toInteger(); + if (ctx->d()->callData->argc >= 2) { + double f = ctx->d()->callData->args[1].toInteger(); if (scope.hasException()) return Encode::undefined(); if (f > 0) @@ -695,7 +695,7 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(CallContext *ctx) ReturnedValue ArrayPrototype::method_every(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -729,7 +729,7 @@ ReturnedValue ArrayPrototype::method_every(CallContext *ctx) ReturnedValue ArrayPrototype::method_some(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -763,7 +763,7 @@ ReturnedValue ArrayPrototype::method_some(CallContext *ctx) ReturnedValue ArrayPrototype::method_forEach(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -794,7 +794,7 @@ ReturnedValue ArrayPrototype::method_forEach(CallContext *ctx) ReturnedValue ArrayPrototype::method_map(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -804,7 +804,7 @@ ReturnedValue ArrayPrototype::method_map(CallContext *ctx) if (!callback) return ctx->throwTypeError(); - Scoped<ArrayObject> a(scope, ctx->engine->newArrayObject()); + Scoped<ArrayObject> a(scope, ctx->d()->engine->newArrayObject()); a->arrayReserve(len); a->setArrayLengthUnchecked(len); @@ -831,7 +831,7 @@ ReturnedValue ArrayPrototype::method_map(CallContext *ctx) ReturnedValue ArrayPrototype::method_filter(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -841,7 +841,7 @@ ReturnedValue ArrayPrototype::method_filter(CallContext *ctx) if (!callback) return ctx->throwTypeError(); - Scoped<ArrayObject> a(scope, ctx->engine->newArrayObject()); + Scoped<ArrayObject> a(scope, ctx->d()->engine->newArrayObject()); a->arrayReserve(len); ScopedValue selected(scope); @@ -872,7 +872,7 @@ ReturnedValue ArrayPrototype::method_filter(CallContext *ctx) ReturnedValue ArrayPrototype::method_reduce(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -886,7 +886,7 @@ ReturnedValue ArrayPrototype::method_reduce(CallContext *ctx) ScopedValue acc(scope); ScopedValue v(scope); - if (ctx->callData->argc > 1) { + if (ctx->d()->callData->argc > 1) { acc = ctx->argument(1); } else { bool kPresent = false; @@ -922,7 +922,7 @@ ReturnedValue ArrayPrototype::method_reduce(CallContext *ctx) ReturnedValue ArrayPrototype::method_reduceRight(CallContext *ctx) { Scope scope(ctx); - Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx)); + Scoped<Object> instance(scope, ctx->d()->callData->thisObject.toObject(ctx)); if (!instance) return Encode::undefined(); @@ -933,7 +933,7 @@ ReturnedValue ArrayPrototype::method_reduceRight(CallContext *ctx) return ctx->throwTypeError(); if (len == 0) { - if (ctx->callData->argc == 1) + if (ctx->d()->callData->argc == 1) return ctx->throwTypeError(); return ctx->argument(1); } @@ -941,7 +941,7 @@ ReturnedValue ArrayPrototype::method_reduceRight(CallContext *ctx) uint k = len; ScopedValue acc(scope); ScopedValue v(scope); - if (ctx->callData->argc > 1) { + if (ctx->d()->callData->argc > 1) { acc = ctx->argument(1); } else { bool kPresent = false; |