diff options
author | Lars Knoll <[email protected]> | 2014-01-13 09:09:14 +0100 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-01-20 21:14:31 +0100 |
commit | bf6191f090b326eb0776cd4e921ddb56c8daa8a9 (patch) | |
tree | 7e0b3084366aa35542f591d2ffcc0dc0c70efe75 /src/qml/jsruntime/qv4arrayobject.cpp | |
parent | 5c25379cd1889dc16187c0ec62f32d2b17a320cf (diff) |
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 <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4arrayobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4arrayobject.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
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); |