diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
commit | 32761a6cee1d0dee366b885b7b9c777e67885688 (patch) | |
tree | d6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/runtime/JSArray.h | |
parent | a4e969f4965059196ca948db781e52f7cfebf19e (diff) | |
download | WebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz |
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSArray.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/JSArray.h | 97 |
1 files changed, 44 insertions, 53 deletions
diff --git a/Source/JavaScriptCore/runtime/JSArray.h b/Source/JavaScriptCore/runtime/JSArray.h index 3dd0797b0..fe30d9f96 100644 --- a/Source/JavaScriptCore/runtime/JSArray.h +++ b/Source/JavaScriptCore/runtime/JSArray.h @@ -1,6 +1,6 @@ /* * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) - * Copyright (C) 2003, 2007, 2008, 2009, 2012, 2015 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -37,7 +37,6 @@ class JSArray : public JSNonFinalObject { public: typedef JSNonFinalObject Base; - static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames; static size_t allocationSize(size_t inlineCapacity) { @@ -53,7 +52,6 @@ protected: public: static JSArray* create(VM&, Structure*, unsigned initialLength = 0); - static JSArray* createWithButterfly(VM&, Structure*, Butterfly*); // tryCreateUninitialized is used for fast construction of arrays whose size and // contents are known at time of creation. Clients of this interface must: @@ -63,34 +61,20 @@ public: JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool throwException); - JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&); + static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&); DECLARE_EXPORT_INFO; - - // OK if we know this is a JSArray, but not if it could be an object of a derived class; for RuntimeArray this always returns 0. + unsigned length() const { return getArrayLength(); } + // OK to use on new arrays, but not if it might be a RegExpMatchArray. + bool setLength(ExecState*, unsigned, bool throwException = false); - // OK to use on new arrays, but not if it might be a RegExpMatchArray or RuntimeArray. - JS_EXPORT_PRIVATE bool setLength(ExecState*, unsigned, bool throwException = false); - - JS_EXPORT_PRIVATE void push(ExecState*, JSValue); - JS_EXPORT_PRIVATE JSValue pop(ExecState*); + void sort(ExecState*); + void sort(ExecState*, JSValue compareFunction, CallType, const CallData&); + void sortNumeric(ExecState*, JSValue compareFunction, CallType, const CallData&); - JSArray* fastSlice(ExecState&, unsigned startIndex, unsigned count); - - static IndexingType fastConcatType(VM& vm, JSArray& firstArray, JSArray& secondArray) - { - IndexingType type = firstArray.indexingType(); - if (type != secondArray.indexingType()) - return NonArray; - if (type != ArrayWithDouble && type != ArrayWithInt32 && type != ArrayWithContiguous) - return NonArray; - if (firstArray.structure(vm)->holesMustForwardToPrototype(vm) - || secondArray.structure(vm)->holesMustForwardToPrototype(vm)) - return NonArray; - return type; - } - EncodedJSValue fastConcatWith(ExecState&, JSArray&); + void push(ExecState*, JSValue); + JSValue pop(ExecState*); enum ShiftCountMode { // This form of shift hints that we're doing queueing. With this assumption in hand, @@ -105,14 +89,14 @@ public: bool shiftCountForShift(ExecState* exec, unsigned startIndex, unsigned count) { - return shiftCountWithArrayStorage(exec->vm(), startIndex, count, ensureArrayStorage(exec->vm())); + return shiftCountWithArrayStorage(startIndex, count, ensureArrayStorage(exec->vm())); } - bool shiftCountForSplice(ExecState* exec, unsigned& startIndex, unsigned count) + bool shiftCountForSplice(ExecState* exec, unsigned startIndex, unsigned count) { return shiftCountWithAnyIndexingType(exec, startIndex, count); } template<ShiftCountMode shiftCountMode> - bool shiftCount(ExecState* exec, unsigned& startIndex, unsigned count) + bool shiftCount(ExecState* exec, unsigned startIndex, unsigned count) { switch (shiftCountMode) { case ShiftCountForShift: @@ -147,8 +131,8 @@ public: } } - JS_EXPORT_PRIVATE void fillArgList(ExecState*, MarkedArgumentBuffer&); - JS_EXPORT_PRIVATE void copyToArguments(ExecState*, VirtualRegister firstElementDest, unsigned offset, unsigned length); + void fillArgList(ExecState*, MarkedArgumentBuffer&); + void copyToArguments(ExecState*, CallFrame*, uint32_t length); static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype, IndexingType indexingType) { @@ -156,6 +140,7 @@ public: } protected: + static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSObject::StructureFlags; static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&); static bool deleteProperty(JSCell*, ExecState*, PropertyName); @@ -171,15 +156,27 @@ private: return !map || !map->lengthIsReadOnly(); } - bool shiftCountWithAnyIndexingType(ExecState*, unsigned& startIndex, unsigned count); - JS_EXPORT_PRIVATE bool shiftCountWithArrayStorage(VM&, unsigned startIndex, unsigned count, ArrayStorage*); + bool shiftCountWithAnyIndexingType(ExecState*, unsigned startIndex, unsigned count); + bool shiftCountWithArrayStorage(unsigned startIndex, unsigned count, ArrayStorage*); bool unshiftCountWithAnyIndexingType(ExecState*, unsigned startIndex, unsigned count); bool unshiftCountWithArrayStorage(ExecState*, unsigned startIndex, unsigned count, ArrayStorage*); bool unshiftCountSlowCase(VM&, bool, unsigned); + template<IndexingType indexingType> + void sortNumericVector(ExecState*, JSValue compareFunction, CallType, const CallData&); + + template<IndexingType indexingType, typename StorageType> + void sortCompactedVector(ExecState*, ContiguousData<StorageType>, unsigned relevantLength); + + template<IndexingType indexingType> + void sortVector(ExecState*, JSValue compareFunction, CallType, const CallData&); + bool setLengthWithArrayStorage(ExecState*, unsigned newLength, bool throwException, ArrayStorage*); void setLengthWritable(ExecState*, bool writable); + + template<IndexingType indexingType> + void compactForSorting(unsigned& numDefined, unsigned& newRelevantLength); }; inline Butterfly* createContiguousArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned length, unsigned& vectorLength) @@ -211,7 +208,7 @@ Butterfly* createArrayButterflyInDictionaryIndexingMode( inline JSArray* JSArray::create(VM& vm, Structure* structure, unsigned initialLength) { Butterfly* butterfly; - if (LIKELY(!hasAnyArrayStorage(structure->indexingType()))) { + if (LIKELY(!hasArrayStorage(structure->indexingType()))) { ASSERT( hasUndecided(structure->indexingType()) || hasInt32(structure->indexingType()) @@ -219,10 +216,10 @@ inline JSArray* JSArray::create(VM& vm, Structure* structure, unsigned initialLe || hasContiguous(structure->indexingType())); unsigned vectorLength; butterfly = createContiguousArrayButterfly(vm, 0, initialLength, vectorLength); - ASSERT(initialLength < MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH); + ASSERT(initialLength < MIN_SPARSE_ARRAY_INDEX); if (hasDouble(structure->indexingType())) { for (unsigned i = 0; i < vectorLength; ++i) - butterfly->contiguousDouble()[i] = PNaN; + butterfly->contiguousDouble()[i] = QNaN; } } else { ASSERT( @@ -230,8 +227,9 @@ inline JSArray* JSArray::create(VM& vm, Structure* structure, unsigned initialLe || structure->indexingType() == ArrayWithArrayStorage); butterfly = createArrayButterfly(vm, 0, initialLength); } - - return createWithButterfly(vm, structure, butterfly); + JSArray* array = new (NotNull, allocateCell<JSArray>(vm.heap)) JSArray(vm, structure, butterfly); + array->finishCreation(vm); + return array; } inline JSArray* JSArray::tryCreateUninitialized(VM& vm, Structure* structure, unsigned initialLength) @@ -239,11 +237,9 @@ inline JSArray* JSArray::tryCreateUninitialized(VM& vm, Structure* structure, un unsigned vectorLength = std::max(BASE_VECTOR_LEN, initialLength); if (vectorLength > MAX_STORAGE_VECTOR_LENGTH) return 0; - - unsigned outOfLineStorage = structure->outOfLineCapacity(); - + Butterfly* butterfly; - if (LIKELY(!hasAnyArrayStorage(structure->indexingType()))) { + if (LIKELY(!hasArrayStorage(structure->indexingType()))) { ASSERT( hasUndecided(structure->indexingType()) || hasInt32(structure->indexingType()) @@ -251,32 +247,27 @@ inline JSArray* JSArray::tryCreateUninitialized(VM& vm, Structure* structure, un || hasContiguous(structure->indexingType())); void* temp; - if (!vm.heap.tryAllocateStorage(0, Butterfly::totalSize(0, outOfLineStorage, true, vectorLength * sizeof(EncodedJSValue)), &temp)) + if (!vm.heap.tryAllocateStorage(0, Butterfly::totalSize(0, 0, true, vectorLength * sizeof(EncodedJSValue)), &temp)) return 0; - butterfly = Butterfly::fromBase(temp, 0, outOfLineStorage); + butterfly = Butterfly::fromBase(temp, 0, 0); butterfly->setVectorLength(vectorLength); butterfly->setPublicLength(initialLength); if (hasDouble(structure->indexingType())) { for (unsigned i = initialLength; i < vectorLength; ++i) - butterfly->contiguousDouble()[i] = PNaN; + butterfly->contiguousDouble()[i] = QNaN; } } else { void* temp; - if (!vm.heap.tryAllocateStorage(0, Butterfly::totalSize(0, outOfLineStorage, true, ArrayStorage::sizeFor(vectorLength)), &temp)) + if (!vm.heap.tryAllocateStorage(0, Butterfly::totalSize(0, 0, true, ArrayStorage::sizeFor(vectorLength)), &temp)) return 0; - butterfly = Butterfly::fromBase(temp, 0, outOfLineStorage); + butterfly = Butterfly::fromBase(temp, 0, 0); *butterfly->indexingHeader() = indexingHeaderForArray(initialLength, vectorLength); ArrayStorage* storage = butterfly->arrayStorage(); storage->m_indexBias = 0; storage->m_sparseMap.clear(); storage->m_numValuesInVector = initialLength; } - - return createWithButterfly(vm, structure, butterfly); -} - -inline JSArray* JSArray::createWithButterfly(VM& vm, Structure* structure, Butterfly* butterfly) -{ + JSArray* array = new (NotNull, allocateCell<JSArray>(vm.heap)) JSArray(vm, structure, butterfly); array->finishCreation(vm); return array; |