diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-09-30 06:37:33 (GMT) |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-09-30 06:37:33 (GMT) |
commit | 828b776f0a9ff84288e6be1bbbdb91448ca1bd4d (patch) | |
tree | ce4419b9c72a9a53c3ad3de9568b9cc89f9cf0bf /src/3rdparty/webkit/JavaScriptCore/runtime/JSArray.cpp | |
parent | 3c3745c29d9fbae98b55a88b5ebccb0b29b4eed5 (diff) | |
parent | b83ea4276a242893c01586a5f1a2d62d54369cfa (diff) | |
download | Qt-828b776f0a9ff84288e6be1bbbdb91448ca1bd4d.zip Qt-828b776f0a9ff84288e6be1bbbdb91448ca1bd4d.tar.gz Qt-828b776f0a9ff84288e6be1bbbdb91448ca1bd4d.tar.bz2 |
Merge branch '4.6' of git@scm.dev.troll.no:qt/qt into 4.6
Diffstat (limited to 'src/3rdparty/webkit/JavaScriptCore/runtime/JSArray.cpp')
-rw-r--r-- | src/3rdparty/webkit/JavaScriptCore/runtime/JSArray.cpp | 144 |
1 files changed, 70 insertions, 74 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/JSArray.cpp b/src/3rdparty/webkit/JavaScriptCore/runtime/JSArray.cpp index a8207e3..7671c96 100644 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/JSArray.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/JSArray.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) - * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2007, 2008, 2009 Apple Inc. All rights reserved. * Copyright (C) 2003 Peter Kelly (pmk@post.com) * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) * @@ -25,6 +25,8 @@ #include "ArrayPrototype.h" #include "CachedCall.h" +#include "Error.h" +#include "Executable.h" #include "PropertyNameArray.h" #include <wtf/AVLTree.h> #include <wtf/Assertions.h> @@ -134,9 +136,9 @@ JSArray::JSArray(PassRefPtr<Structure> structure) unsigned initialCapacity = 0; m_storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity))); - m_fastAccessCutoff = 0; m_storage->m_vectorLength = initialCapacity; - m_storage->m_length = 0; + + m_fastAccessCutoff = 0; checkConsistency(); } @@ -146,40 +148,45 @@ JSArray::JSArray(PassRefPtr<Structure> structure, unsigned initialLength) { unsigned initialCapacity = min(initialLength, MIN_SPARSE_ARRAY_INDEX); - m_storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity))); - m_fastAccessCutoff = 0; - m_storage->m_vectorLength = initialCapacity; + m_storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity))); m_storage->m_length = initialLength; + m_storage->m_vectorLength = initialCapacity; + m_storage->m_numValuesInVector = 0; + m_storage->m_sparseValueMap = 0; + m_storage->lazyCreationData = 0; - Heap::heap(this)->reportExtraMemoryCost(initialCapacity * sizeof(JSValue)); + JSValue* vector = m_storage->m_vector; + for (size_t i = 0; i < initialCapacity; ++i) + vector[i] = JSValue(); + + m_fastAccessCutoff = 0; checkConsistency(); + + Heap::heap(this)->reportExtraMemoryCost(initialCapacity * sizeof(JSValue)); } JSArray::JSArray(PassRefPtr<Structure> structure, const ArgList& list) : JSObject(structure) { - unsigned length = list.size(); + unsigned initialCapacity = list.size(); - m_fastAccessCutoff = length; - - ArrayStorage* storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(length))); - - storage->m_vectorLength = length; - storage->m_numValuesInVector = length; - storage->m_sparseValueMap = 0; - storage->m_length = length; + m_storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity))); + m_storage->m_length = initialCapacity; + m_storage->m_vectorLength = initialCapacity; + m_storage->m_numValuesInVector = initialCapacity; + m_storage->m_sparseValueMap = 0; size_t i = 0; ArgList::const_iterator end = list.end(); for (ArgList::const_iterator it = list.begin(); it != end; ++it, ++i) - storage->m_vector[i] = *it; + m_storage->m_vector[i] = *it; - m_storage = storage; - - Heap::heap(this)->reportExtraMemoryCost(storageSize(length)); + m_fastAccessCutoff = initialCapacity; checkConsistency(); + + Heap::heap(this)->reportExtraMemoryCost(storageSize(initialCapacity)); } JSArray::~JSArray() @@ -216,7 +223,7 @@ bool JSArray::getOwnPropertySlot(ExecState* exec, unsigned i, PropertySlot& slot } } - return false; + return JSObject::getOwnPropertySlot(exec, Identifier::from(exec, i), slot); } bool JSArray::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) @@ -234,6 +241,37 @@ bool JSArray::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName return JSObject::getOwnPropertySlot(exec, propertyName, slot); } +bool JSArray::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + if (propertyName == exec->propertyNames().length) { + descriptor.setDescriptor(jsNumber(exec, length()), DontDelete | DontEnum); + return true; + } + + bool isArrayIndex; + unsigned i = propertyName.toArrayIndex(&isArrayIndex); + if (isArrayIndex) { + if (i >= m_storage->m_length) + return false; + if (i < m_storage->m_vectorLength) { + JSValue value = m_storage->m_vector[i]; + if (value) { + descriptor.setDescriptor(value, 0); + return true; + } + } else if (SparseArrayValueMap* map = m_storage->m_sparseValueMap) { + if (i >= MIN_SPARSE_ARRAY_INDEX) { + SparseArrayValueMap::iterator it = map->find(i); + if (it != map->end()) { + descriptor.setDescriptor(it->second, 0); + return true; + } + } + } + } + return JSObject::getOwnPropertyDescriptor(exec, propertyName, descriptor); +} + // ECMA 15.4.5.1 void JSArray::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) { @@ -343,8 +381,7 @@ NEVER_INLINE void JSArray::putSlowCase(ExecState* exec, unsigned i, JSValue valu } } - storage = static_cast<ArrayStorage*>(tryFastRealloc(storage, storageSize(newVectorLength))); - if (!storage) { + if (!tryFastRealloc(storage, storageSize(newVectorLength)).getValue(storage)) { throwOutOfMemoryError(exec); return; } @@ -375,20 +412,20 @@ NEVER_INLINE void JSArray::putSlowCase(ExecState* exec, unsigned i, JSValue valu checkConsistency(); } -bool JSArray::deleteProperty(ExecState* exec, const Identifier& propertyName, bool checkDontDelete) +bool JSArray::deleteProperty(ExecState* exec, const Identifier& propertyName) { bool isArrayIndex; unsigned i = propertyName.toArrayIndex(&isArrayIndex); if (isArrayIndex) - return deleteProperty(exec, i, checkDontDelete); + return deleteProperty(exec, i); if (propertyName == exec->propertyNames().length) return false; - return JSObject::deleteProperty(exec, propertyName, checkDontDelete); + return JSObject::deleteProperty(exec, propertyName); } -bool JSArray::deleteProperty(ExecState* exec, unsigned i, bool checkDontDelete) +bool JSArray::deleteProperty(ExecState* exec, unsigned i) { checkConsistency(); @@ -422,12 +459,12 @@ bool JSArray::deleteProperty(ExecState* exec, unsigned i, bool checkDontDelete) checkConsistency(); if (i > MAX_ARRAY_INDEX) - return deleteProperty(exec, Identifier::from(exec, i), checkDontDelete); + return deleteProperty(exec, Identifier::from(exec, i)); return false; } -void JSArray::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, unsigned listedAttributes) +void JSArray::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) { // FIXME: Filling PropertyNameArray with an identifier for every integer // is incredibly inefficient for large arrays. We need a different approach, @@ -447,7 +484,7 @@ void JSArray::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames propertyNames.add(Identifier::from(exec, it->first)); } - JSObject::getPropertyNames(exec, propertyNames, listedAttributes); + JSObject::getOwnPropertyNames(exec, propertyNames); } bool JSArray::increaseVectorLength(unsigned newLength) @@ -462,8 +499,7 @@ bool JSArray::increaseVectorLength(unsigned newLength) ASSERT(newLength <= MAX_STORAGE_VECTOR_INDEX); unsigned newVectorLength = increasedVectorLength(newLength); - storage = static_cast<ArrayStorage*>(tryFastRealloc(storage, storageSize(newVectorLength))); - if (!storage) + if (!tryFastRealloc(storage, storageSize(newVectorLength)).getValue(storage)) return false; Heap::heap(this)->reportExtraMemoryCost(storageSize(newVectorLength) - storageSize(vectorLength)); @@ -596,27 +632,9 @@ void JSArray::push(ExecState* exec, JSValue value) putSlowCase(exec, m_storage->m_length++, value); } -void JSArray::mark() +void JSArray::markChildren(MarkStack& markStack) { - JSObject::mark(); - - ArrayStorage* storage = m_storage; - - unsigned usedVectorLength = min(storage->m_length, storage->m_vectorLength); - for (unsigned i = 0; i < usedVectorLength; ++i) { - JSValue value = storage->m_vector[i]; - if (value && !value.marked()) - value.mark(); - } - - if (SparseArrayValueMap* map = storage->m_sparseValueMap) { - SparseArrayValueMap::iterator end = map->end(); - for (SparseArrayValueMap::iterator it = map->begin(); it != end; ++it) { - JSValue value = it->second; - if (!value.marked()) - value.mark(); - } - } + markChildrenDirect(markStack); } static int compareNumbersForQSort(const void* a, const void* b) @@ -1048,26 +1066,4 @@ void JSArray::checkConsistency(ConsistencyCheckType type) #endif -JSArray* constructEmptyArray(ExecState* exec) -{ - return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure()); -} - -JSArray* constructEmptyArray(ExecState* exec, unsigned initialLength) -{ - return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure(), initialLength); -} - -JSArray* constructArray(ExecState* exec, JSValue singleItemValue) -{ - MarkedArgumentBuffer values; - values.append(singleItemValue); - return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure(), values); -} - -JSArray* constructArray(ExecState* exec, const ArgList& values) -{ - return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure(), values); -} - } // namespace JSC |