From bf6191f090b326eb0776cd4e921ddb56c8daa8a9 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 13 Jan 2014 09:09:14 +0100 Subject: Add a SimpleArrayData class This makes the ArrayData class 'pure virtual'. SimpleArrayData now contains the implementation of simple arrays. This makes the separation between simple and sparse arrays a lot cleaner. It also allows us to move len and offset from the base class into the SimpleArrayClass. This fixes some bugs where we accessed len for sparse arrays leading to some buggy behavior. Added a virtual length() method to ArrayData to query the highes used index in the Array. Change-Id: Iab2ba2a48ebe5b7031759eeb4ebe02b4d86233f0 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4arrayobject.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/qml/jsruntime/qv4arrayobject.cpp') diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index 4ea979d16e..b79e4b13fe 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -73,7 +73,6 @@ ReturnedValue ArrayCtor::construct(Managed *m, CallData *callData) len = callData->argc; a->arrayReserve(len); a->arrayData->put(0, callData->args, len); - a->arrayData->setLength(len); } a->setArrayLengthUnchecked(len); @@ -303,7 +302,9 @@ ReturnedValue ArrayPrototype::method_push(CallContext *ctx) return Encode(newLen); } - if (!instance->protoHasArray() && instance->arrayData->length() <= len) { + if (!ctx->callData->argc) { + ; + } else if (!instance->protoHasArray() && instance->arrayData->length() <= len) { len = instance->arrayData->push_back(len, ctx->callData->argc, ctx->callData->args); } else { for (int i = 0; i < ctx->callData->argc; ++i) @@ -483,10 +484,8 @@ ReturnedValue ArrayPrototype::method_splice(CallContext *ctx) v = instance->getIndexed(start + i, &exists); if (scope.hasException()) return Encode::undefined(); - if (exists) { + if (exists) newArray->arrayData->put(i, v); - newArray->arrayData->setLength(i + 1); - } } newArray->setArrayLengthUnchecked(deleteCount); -- cgit v1.2.3