diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/JavaScriptCore/runtime/JSObject.cpp | |
parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSObject.cpp')
-rw-r--r-- | Source/JavaScriptCore/runtime/JSObject.cpp | 959 |
1 files changed, 387 insertions, 572 deletions
diff --git a/Source/JavaScriptCore/runtime/JSObject.cpp b/Source/JavaScriptCore/runtime/JSObject.cpp index 52dea7801..6910b7e04 100644 --- a/Source/JavaScriptCore/runtime/JSObject.cpp +++ b/Source/JavaScriptCore/runtime/JSObject.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) * Copyright (C) 2001 Peter Kelly (pmk@post.com) - * Copyright (C) 2003-2006, 2008, 2009, 2012-2015 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2012, 2013 Apple Inc. All rights reserved. * Copyright (C) 2007 Eric Seidel (eric@webkit.org) * * This library is free software; you can redistribute it and/or @@ -28,10 +28,8 @@ #include "CopiedSpaceInlines.h" #include "CopyVisitor.h" #include "CopyVisitorInlines.h" -#include "CustomGetterSetter.h" #include "DatePrototype.h" #include "ErrorConstructor.h" -#include "Exception.h" #include "Executable.h" #include "GetterSetter.h" #include "IndexingHeaderInlines.h" @@ -41,7 +39,7 @@ #include "NativeErrorConstructor.h" #include "Nodes.h" #include "ObjectPrototype.h" -#include "JSCInlines.h" +#include "Operations.h" #include "PropertyDescriptor.h" #include "PropertyNameArray.h" #include "Reject.h" @@ -57,28 +55,40 @@ namespace JSC { // ArrayConventions.h. static unsigned lastArraySize = 0; +JSCell* getCallableObjectSlow(JSCell* cell) +{ + Structure* structure = cell->structure(); + if (structure->typeInfo().type() == JSFunctionType) + return cell; + if (structure->classInfo()->isSubClassOf(InternalFunction::info())) + return cell; + return 0; +} + STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSObject); STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSFinalObject); const char* StrictModeReadonlyPropertyWriteError = "Attempted to assign to readonly property."; -const ClassInfo JSObject::s_info = { "Object", 0, 0, CREATE_METHOD_TABLE(JSObject) }; +const ClassInfo JSObject::s_info = { "Object", 0, 0, 0, CREATE_METHOD_TABLE(JSObject) }; -const ClassInfo JSFinalObject::s_info = { "Object", &Base::s_info, 0, CREATE_METHOD_TABLE(JSFinalObject) }; +const ClassInfo JSFinalObject::s_info = { "Object", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSFinalObject) }; static inline void getClassPropertyNames(ExecState* exec, const ClassInfo* classInfo, PropertyNameArray& propertyNames, EnumerationMode mode, bool didReify) { - VM& vm = exec->vm(); - // Add properties from the static hashtables of properties for (; classInfo; classInfo = classInfo->parentClass) { - const HashTable* table = classInfo->staticPropHashTable; + const HashTable* table = classInfo->propHashTable(exec); if (!table) continue; - - for (auto iter = table->begin(); iter != table->end(); ++iter) { - if ((!(iter->attributes() & DontEnum) || mode.includeDontEnumProperties()) && !((iter->attributes() & BuiltinOrFunctionOrAccessor) && didReify)) - propertyNames.add(Identifier::fromString(&vm, iter.key())); + table->initializeIfNeeded(exec); + ASSERT(table->table); + + int hashSizeMask = table->compactSize - 1; + const HashEntry* entry = table->table; + for (int i = 0; i <= hashSizeMask; ++i, ++entry) { + if (entry->key() && (!(entry->attributes() & DontEnum) || (mode == IncludeDontEnumProperties)) && !((entry->attributes() & Function) && didReify)) + propertyNames.add(entry->key()); } } } @@ -119,7 +129,7 @@ ALWAYS_INLINE void JSObject::copyButterfly(CopyVisitor& visitor, Butterfly* butt WriteBarrier<Unknown>* currentSource; size_t count; - switch (this->indexingType()) { + switch (structure->indexingType()) { case ALL_UNDECIDED_INDEXING_TYPES: case ALL_CONTIGUOUS_INDEXING_TYPES: case ALL_INT32_INDEXING_TYPES: @@ -158,7 +168,7 @@ ALWAYS_INLINE void JSObject::visitButterfly(SlotVisitor& visitor, Butterfly* but { ASSERT(butterfly); - Structure* structure = this->structure(visitor.vm()); + Structure* structure = this->structure(); size_t propertyCapacity = structure->outOfLineCapacity(); size_t preCapacity; @@ -180,7 +190,7 @@ ALWAYS_INLINE void JSObject::visitButterfly(SlotVisitor& visitor, Butterfly* but butterfly->base(preCapacity, propertyCapacity), capacityInBytes); // Mark the array if appropriate. - switch (this->indexingType()) { + switch (structure->indexingType()) { case ALL_CONTIGUOUS_INDEXING_TYPES: visitor.appendValues(butterfly->contiguous().data(), butterfly->publicLength()); break; @@ -207,7 +217,7 @@ void JSObject::visitChildren(JSCell* cell, SlotVisitor& visitor) Butterfly* butterfly = thisObject->butterfly(); if (butterfly) - thisObject->visitButterfly(visitor, butterfly, thisObject->structure(visitor.vm())->outOfLineSize()); + thisObject->visitButterfly(visitor, butterfly, thisObject->structure()->outOfLineSize()); #if !ASSERT_DISABLED visitor.m_isCheckingForDefaultMarkViolation = wasCheckingForDefaultMarkViolation; @@ -238,12 +248,11 @@ void JSFinalObject::visitChildren(JSCell* cell, SlotVisitor& visitor) JSCell::visitChildren(thisObject, visitor); - Structure* structure = thisObject->structure(); Butterfly* butterfly = thisObject->butterfly(); if (butterfly) - thisObject->visitButterfly(visitor, butterfly, structure->outOfLineSize()); + thisObject->visitButterfly(visitor, butterfly, thisObject->structure()->outOfLineSize()); - size_t storageSize = structure->inlineSize(); + size_t storageSize = thisObject->structure()->inlineSize(); visitor.appendValues(thisObject->inlineStorage(), storageSize); #if !ASSERT_DISABLED @@ -258,44 +267,6 @@ String JSObject::className(const JSObject* object) return info->className; } -String JSObject::calculatedClassName(JSObject* object) -{ - String prototypeFunctionName; - ExecState* exec = object->globalObject()->globalExec(); - PropertySlot slot(object->structure()->storedPrototype()); - PropertyName constructor(exec->propertyNames().constructor); - if (object->getPropertySlot(exec, constructor, slot)) { - if (slot.isValue()) { - JSValue constructorValue = slot.getValue(exec, constructor); - if (constructorValue.isCell()) { - if (JSCell* constructorCell = constructorValue.asCell()) { - if (JSObject* ctorObject = constructorCell->getObject()) { - if (JSFunction* constructorFunction = jsDynamicCast<JSFunction*>(ctorObject)) - prototypeFunctionName = constructorFunction->calculatedDisplayName(exec); - else if (InternalFunction* constructorFunction = jsDynamicCast<InternalFunction*>(ctorObject)) - prototypeFunctionName = constructorFunction->calculatedDisplayName(exec); - } - } - } - } - } - - if (prototypeFunctionName.isNull() || prototypeFunctionName == "Object") { - String tableClassName = object->methodTable()->className(object); - if (!tableClassName.isNull() && tableClassName != "Object") - return tableClassName; - - String classInfoName = object->classInfo()->className; - if (!classInfoName.isNull()) - return classInfoName; - - if (prototypeFunctionName.isNull()) - return ASCIILiteral("Object"); - } - - return prototypeFunctionName; -} - bool JSObject::getOwnPropertySlotByIndex(JSObject* thisObject, ExecState* exec, unsigned i, PropertySlot& slot) { // NB. The fact that we're directly consulting our indexed storage implies that it is not @@ -303,9 +274,9 @@ bool JSObject::getOwnPropertySlotByIndex(JSObject* thisObject, ExecState* exec, // getOwnPropertySlotByIndex(). if (i > MAX_ARRAY_INDEX) - return thisObject->methodTable(exec->vm())->getOwnPropertySlot(thisObject, exec, Identifier::from(exec, i), slot); + return thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, Identifier::from(exec, i), slot); - switch (thisObject->indexingType()) { + switch (thisObject->structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: case ALL_UNDECIDED_INDEXING_TYPES: break; @@ -378,19 +349,20 @@ void JSObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSV // Try indexed put first. This is required for correctness, since loads on property names that appear like // valid indices will never look in the named property storage. - if (Optional<uint32_t> index = parseIndex(propertyName)) { - putByIndex(thisObject, exec, index.value(), value, slot.isStrictMode()); + unsigned i = propertyName.asIndex(); + if (i != PropertyName::NotAnIndex) { + putByIndex(thisObject, exec, i, value, slot.isStrictMode()); return; } // Check if there are any setters or getters in the prototype chain JSValue prototype; if (propertyName != exec->propertyNames().underscoreProto) { - for (JSObject* obj = thisObject; !obj->structure(vm)->hasReadOnlyOrGetterSetterPropertiesExcludingProto(); obj = asObject(prototype)) { + for (JSObject* obj = thisObject; !obj->structure()->hasReadOnlyOrGetterSetterPropertiesExcludingProto(); obj = asObject(prototype)) { prototype = obj->prototype(); if (prototype.isNull()) { - ASSERT(!thisObject->structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName)); - if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot) + ASSERT(!thisObject->structure()->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName)); + if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot, getCallableObject(value)) && slot.isStrictMode()) throwTypeError(exec, ASCIILiteral(StrictModeReadonlyPropertyWriteError)); return; @@ -401,10 +373,11 @@ void JSObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSV JSObject* obj; for (obj = thisObject; ; obj = asObject(prototype)) { unsigned attributes; - PropertyOffset offset = obj->structure(vm)->get(vm, propertyName, attributes); + JSCell* specificValue; + PropertyOffset offset = obj->structure()->get(vm, propertyName, attributes, specificValue); if (isValidOffset(offset)) { if (attributes & ReadOnly) { - ASSERT(thisObject->structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName) || obj == thisObject); + ASSERT(thisObject->structure()->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName) || obj == thisObject); if (slot.isStrictMode()) exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral(StrictModeReadonlyPropertyWriteError))); return; @@ -413,28 +386,19 @@ void JSObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSV JSValue gs = obj->getDirect(offset); if (gs.isGetterSetter()) { callSetter(exec, cell, gs, value, slot.isStrictMode() ? StrictMode : NotStrictMode); - if (!thisObject->structure()->isDictionary()) - slot.setCacheableSetter(obj, offset); - return; - } - if (gs.isCustomGetterSetter()) { - callCustomSetter(exec, gs, obj, slot.thisValue(), value); - slot.setCustomProperty(obj, jsCast<CustomGetterSetter*>(gs.asCell())->setter()); return; - } - ASSERT(!(attributes & Accessor)); + } else + ASSERT(!(attributes & Accessor)); // If there's an existing property on the object or one of its // prototypes it should be replaced, so break here. break; } const ClassInfo* info = obj->classInfo(); - if (info->hasStaticSetterOrReadonlyProperties()) { - if (const HashTableValue* entry = obj->findPropertyHashEntry(propertyName)) { - if (!obj->staticFunctionsReified() || !(entry->attributes() & BuiltinOrFunctionOrAccessor)) { - putEntry(exec, entry, obj, propertyName, value, slot); - return; - } + if (info->hasStaticSetterOrReadonlyProperties(vm)) { + if (const HashEntry* entry = obj->findPropertyHashEntry(exec, propertyName)) { + putEntry(exec, entry, obj, propertyName, value, slot); + return; } } prototype = obj->prototype(); @@ -442,8 +406,8 @@ void JSObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSV break; } - ASSERT(!thisObject->structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName) || obj == thisObject); - if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot) && slot.isStrictMode()) + ASSERT(!thisObject->structure()->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName) || obj == thisObject); + if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot, getCallableObject(value)) && slot.isStrictMode()) throwTypeError(exec, ASCIILiteral(StrictModeReadonlyPropertyWriteError)); return; } @@ -458,7 +422,7 @@ void JSObject::putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, return; } - switch (thisObject->indexingType()) { + switch (thisObject->structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: break; @@ -585,11 +549,11 @@ ArrayStorage* JSObject::enterDictionaryIndexingModeWhenArrayStorageAlreadyExists // This will always be a new entry in the map, so no need to check we can write, // and attributes are default so no need to set them. if (value) - map->add(this, i).iterator->value.set(vm, map, value); + map->add(this, i).iterator->value.set(vm, this, value); } DeferGC deferGC(vm.heap); - Butterfly* newButterfly = storage->butterfly()->resizeArray(vm, this, structure(vm), 0, ArrayStorage::sizeFor(0)); + Butterfly* newButterfly = storage->butterfly()->resizeArray(vm, this, structure(), 0, ArrayStorage::sizeFor(0)); RELEASE_ASSERT(newButterfly); newButterfly->arrayStorage()->m_indexBias = 0; newButterfly->arrayStorage()->setVectorLength(0); @@ -601,7 +565,7 @@ ArrayStorage* JSObject::enterDictionaryIndexingModeWhenArrayStorageAlreadyExists void JSObject::enterDictionaryIndexingMode(VM& vm) { - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: case ALL_UNDECIDED_INDEXING_TYPES: case ALL_INT32_INDEXING_TYPES: @@ -625,7 +589,7 @@ void JSObject::notifyPresenceOfIndexedAccessors(VM& vm) if (mayInterceptIndexedAccesses()) return; - setStructure(vm, Structure::nonPropertyTransition(vm, structure(vm), AddIndexedAccessors)); + setStructure(vm, Structure::nonPropertyTransition(vm, structure(), AddIndexedAccessors)); if (!vm.prototypeMap.isPrototype(this)) return; @@ -636,7 +600,7 @@ void JSObject::notifyPresenceOfIndexedAccessors(VM& vm) Butterfly* JSObject::createInitialIndexedStorage(VM& vm, unsigned length, size_t elementSize) { ASSERT(length < MAX_ARRAY_INDEX); - IndexingType oldType = indexingType(); + IndexingType oldType = structure()->indexingType(); ASSERT_UNUSED(oldType, !hasIndexedProperties(oldType)); ASSERT(!structure()->needsSlowPutIndexing()); ASSERT(!indexingShouldBeSparse()); @@ -653,7 +617,7 @@ Butterfly* JSObject::createInitialUndecided(VM& vm, unsigned length) { DeferGC deferGC(vm.heap); Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(EncodedJSValue)); - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), AllocateUndecided); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), AllocateUndecided); setStructureAndButterfly(vm, newStructure, newButterfly); return newButterfly; } @@ -662,7 +626,7 @@ ContiguousJSValues JSObject::createInitialInt32(VM& vm, unsigned length) { DeferGC deferGC(vm.heap); Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(EncodedJSValue)); - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), AllocateInt32); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), AllocateInt32); setStructureAndButterfly(vm, newStructure, newButterfly); return newButterfly->contiguousInt32(); } @@ -672,8 +636,8 @@ ContiguousDoubles JSObject::createInitialDouble(VM& vm, unsigned length) DeferGC deferGC(vm.heap); Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(double)); for (unsigned i = newButterfly->vectorLength(); i--;) - newButterfly->contiguousDouble()[i] = PNaN; - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), AllocateDouble); + newButterfly->contiguousDouble()[i] = QNaN; + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), AllocateDouble); setStructureAndButterfly(vm, newStructure, newButterfly); return newButterfly->contiguousDouble(); } @@ -682,7 +646,7 @@ ContiguousJSValues JSObject::createInitialContiguous(VM& vm, unsigned length) { DeferGC deferGC(vm.heap); Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(EncodedJSValue)); - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), AllocateContiguous); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), AllocateContiguous); setStructureAndButterfly(vm, newStructure, newButterfly); return newButterfly->contiguous(); } @@ -690,11 +654,10 @@ ContiguousJSValues JSObject::createInitialContiguous(VM& vm, unsigned length) ArrayStorage* JSObject::createArrayStorage(VM& vm, unsigned length, unsigned vectorLength) { DeferGC deferGC(vm.heap); - Structure* structure = this->structure(vm); - IndexingType oldType = indexingType(); + IndexingType oldType = structure()->indexingType(); ASSERT_UNUSED(oldType, !hasIndexedProperties(oldType)); Butterfly* newButterfly = Butterfly::createOrGrowArrayRight( - m_butterfly.get(), vm, this, structure, structure->outOfLineCapacity(), false, 0, + m_butterfly.get(), vm, this, structure(), structure()->outOfLineCapacity(), false, 0, ArrayStorage::sizeFor(vectorLength)); RELEASE_ASSERT(newButterfly); @@ -704,7 +667,7 @@ ArrayStorage* JSObject::createArrayStorage(VM& vm, unsigned length, unsigned vec result->m_sparseMap.clear(); result->m_numValuesInVector = 0; result->m_indexBias = 0; - Structure* newStructure = Structure::nonPropertyTransition(vm, structure, structure->suggestedArrayStorageTransition()); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), structure()->suggestedArrayStorageTransition()); setStructureAndButterfly(vm, newStructure, newButterfly); return result; } @@ -716,35 +679,34 @@ ArrayStorage* JSObject::createInitialArrayStorage(VM& vm) ContiguousJSValues JSObject::convertUndecidedToInt32(VM& vm) { - ASSERT(hasUndecided(indexingType())); - setStructure(vm, Structure::nonPropertyTransition(vm, structure(vm), AllocateInt32)); + ASSERT(hasUndecided(structure()->indexingType())); + setStructure(vm, Structure::nonPropertyTransition(vm, structure(), AllocateInt32)); return m_butterfly->contiguousInt32(); } ContiguousDoubles JSObject::convertUndecidedToDouble(VM& vm) { - ASSERT(hasUndecided(indexingType())); + ASSERT(hasUndecided(structure()->indexingType())); for (unsigned i = m_butterfly->vectorLength(); i--;) - m_butterfly->contiguousDouble()[i] = PNaN; + m_butterfly->contiguousDouble()[i] = QNaN; - setStructure(vm, Structure::nonPropertyTransition(vm, structure(vm), AllocateDouble)); + setStructure(vm, Structure::nonPropertyTransition(vm, structure(), AllocateDouble)); return m_butterfly->contiguousDouble(); } ContiguousJSValues JSObject::convertUndecidedToContiguous(VM& vm) { - ASSERT(hasUndecided(indexingType())); - setStructure(vm, Structure::nonPropertyTransition(vm, structure(vm), AllocateContiguous)); + ASSERT(hasUndecided(structure()->indexingType())); + setStructure(vm, Structure::nonPropertyTransition(vm, structure(), AllocateContiguous)); return m_butterfly->contiguous(); } ArrayStorage* JSObject::constructConvertedArrayStorageWithoutCopyingElements(VM& vm, unsigned neededLength) { - Structure* structure = this->structure(vm); unsigned publicLength = m_butterfly->publicLength(); - unsigned propertyCapacity = structure->outOfLineCapacity(); - unsigned propertySize = structure->outOfLineSize(); + unsigned propertyCapacity = structure()->outOfLineCapacity(); + unsigned propertySize = structure()->outOfLineSize(); Butterfly* newButterfly = Butterfly::createUninitialized( vm, this, 0, propertyCapacity, true, ArrayStorage::sizeFor(neededLength)); @@ -764,82 +726,90 @@ ArrayStorage* JSObject::constructConvertedArrayStorageWithoutCopyingElements(VM& return newStorage; } -ArrayStorage* JSObject::convertUndecidedToArrayStorage(VM& vm, NonPropertyTransition transition) +ArrayStorage* JSObject::convertUndecidedToArrayStorage(VM& vm, NonPropertyTransition transition, unsigned neededLength) { DeferGC deferGC(vm.heap); - ASSERT(hasUndecided(indexingType())); - - unsigned vectorLength = m_butterfly->vectorLength(); - ArrayStorage* storage = constructConvertedArrayStorageWithoutCopyingElements(vm, vectorLength); + ASSERT(hasUndecided(structure()->indexingType())); + + ArrayStorage* storage = constructConvertedArrayStorageWithoutCopyingElements(vm, neededLength); // No need to copy elements. - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), transition); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), transition); setStructureAndButterfly(vm, newStructure, storage->butterfly()); return storage; } +ArrayStorage* JSObject::convertUndecidedToArrayStorage(VM& vm, NonPropertyTransition transition) +{ + return convertUndecidedToArrayStorage(vm, transition, m_butterfly->vectorLength()); +} + ArrayStorage* JSObject::convertUndecidedToArrayStorage(VM& vm) { - return convertUndecidedToArrayStorage(vm, structure(vm)->suggestedArrayStorageTransition()); + return convertUndecidedToArrayStorage(vm, structure()->suggestedArrayStorageTransition()); } ContiguousDoubles JSObject::convertInt32ToDouble(VM& vm) { - ASSERT(hasInt32(indexingType())); + ASSERT(hasInt32(structure()->indexingType())); for (unsigned i = m_butterfly->vectorLength(); i--;) { WriteBarrier<Unknown>* current = &m_butterfly->contiguousInt32()[i]; double* currentAsDouble = bitwise_cast<double*>(current); JSValue v = current->get(); if (!v) { - *currentAsDouble = PNaN; + *currentAsDouble = QNaN; continue; } ASSERT(v.isInt32()); *currentAsDouble = v.asInt32(); } - setStructure(vm, Structure::nonPropertyTransition(vm, structure(vm), AllocateDouble)); + setStructure(vm, Structure::nonPropertyTransition(vm, structure(), AllocateDouble)); return m_butterfly->contiguousDouble(); } ContiguousJSValues JSObject::convertInt32ToContiguous(VM& vm) { - ASSERT(hasInt32(indexingType())); + ASSERT(hasInt32(structure()->indexingType())); - setStructure(vm, Structure::nonPropertyTransition(vm, structure(vm), AllocateContiguous)); + setStructure(vm, Structure::nonPropertyTransition(vm, structure(), AllocateContiguous)); return m_butterfly->contiguous(); } -ArrayStorage* JSObject::convertInt32ToArrayStorage(VM& vm, NonPropertyTransition transition) +ArrayStorage* JSObject::convertInt32ToArrayStorage(VM& vm, NonPropertyTransition transition, unsigned neededLength) { + ASSERT(hasInt32(structure()->indexingType())); + DeferGC deferGC(vm.heap); - ASSERT(hasInt32(indexingType())); - - unsigned vectorLength = m_butterfly->vectorLength(); - ArrayStorage* newStorage = constructConvertedArrayStorageWithoutCopyingElements(vm, vectorLength); - for (unsigned i = 0; i < m_butterfly->publicLength(); i++) { + ArrayStorage* newStorage = constructConvertedArrayStorageWithoutCopyingElements(vm, neededLength); + for (unsigned i = m_butterfly->publicLength(); i--;) { JSValue v = m_butterfly->contiguous()[i].get(); - if (v) { - newStorage->m_vector[i].setWithoutWriteBarrier(v); - newStorage->m_numValuesInVector++; - } else - ASSERT(newStorage->m_vector[i].get().isEmpty()); + if (!v) + continue; + newStorage->m_vector[i].setWithoutWriteBarrier(v); + newStorage->m_numValuesInVector++; } - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), transition); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), transition); setStructureAndButterfly(vm, newStructure, newStorage->butterfly()); return newStorage; } +ArrayStorage* JSObject::convertInt32ToArrayStorage(VM& vm, NonPropertyTransition transition) +{ + return convertInt32ToArrayStorage(vm, transition, m_butterfly->vectorLength()); +} + ArrayStorage* JSObject::convertInt32ToArrayStorage(VM& vm) { - return convertInt32ToArrayStorage(vm, structure(vm)->suggestedArrayStorageTransition()); + return convertInt32ToArrayStorage(vm, structure()->suggestedArrayStorageTransition()); } -ContiguousJSValues JSObject::convertDoubleToContiguous(VM& vm) +template<JSObject::DoubleToContiguousMode mode> +ContiguousJSValues JSObject::genericConvertDoubleToContiguous(VM& vm) { - ASSERT(hasDouble(indexingType())); + ASSERT(hasDouble(structure()->indexingType())); for (unsigned i = m_butterfly->vectorLength(); i--;) { double* current = &m_butterfly->contiguousDouble()[i]; @@ -849,64 +819,89 @@ ContiguousJSValues JSObject::convertDoubleToContiguous(VM& vm) currentAsValue->clear(); continue; } - JSValue v = JSValue(JSValue::EncodeAsDouble, value); + JSValue v; + switch (mode) { + case EncodeValueAsDouble: + v = JSValue(JSValue::EncodeAsDouble, value); + break; + case RageConvertDoubleToValue: + v = jsNumber(value); + break; + } + ASSERT(v.isNumber()); currentAsValue->setWithoutWriteBarrier(v); } - setStructure(vm, Structure::nonPropertyTransition(vm, structure(vm), AllocateContiguous)); + setStructure(vm, Structure::nonPropertyTransition(vm, structure(), AllocateContiguous)); return m_butterfly->contiguous(); } -ArrayStorage* JSObject::convertDoubleToArrayStorage(VM& vm, NonPropertyTransition transition) +ContiguousJSValues JSObject::convertDoubleToContiguous(VM& vm) { - DeferGC deferGC(vm.heap); - ASSERT(hasDouble(indexingType())); + return genericConvertDoubleToContiguous<EncodeValueAsDouble>(vm); +} - unsigned vectorLength = m_butterfly->vectorLength(); - ArrayStorage* newStorage = constructConvertedArrayStorageWithoutCopyingElements(vm, vectorLength); - for (unsigned i = 0; i < m_butterfly->publicLength(); i++) { +ContiguousJSValues JSObject::rageConvertDoubleToContiguous(VM& vm) +{ + return genericConvertDoubleToContiguous<RageConvertDoubleToValue>(vm); +} + +ArrayStorage* JSObject::convertDoubleToArrayStorage(VM& vm, NonPropertyTransition transition, unsigned neededLength) +{ + DeferGC deferGC(vm.heap); + ASSERT(hasDouble(structure()->indexingType())); + + ArrayStorage* newStorage = constructConvertedArrayStorageWithoutCopyingElements(vm, neededLength); + for (unsigned i = m_butterfly->publicLength(); i--;) { double value = m_butterfly->contiguousDouble()[i]; - if (value == value) { - newStorage->m_vector[i].setWithoutWriteBarrier(JSValue(JSValue::EncodeAsDouble, value)); - newStorage->m_numValuesInVector++; - } else - ASSERT(newStorage->m_vector[i].get().isEmpty()); + if (value != value) + continue; + newStorage->m_vector[i].setWithoutWriteBarrier(JSValue(JSValue::EncodeAsDouble, value)); + newStorage->m_numValuesInVector++; } - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), transition); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), transition); setStructureAndButterfly(vm, newStructure, newStorage->butterfly()); return newStorage; } +ArrayStorage* JSObject::convertDoubleToArrayStorage(VM& vm, NonPropertyTransition transition) +{ + return convertDoubleToArrayStorage(vm, transition, m_butterfly->vectorLength()); +} + ArrayStorage* JSObject::convertDoubleToArrayStorage(VM& vm) { - return convertDoubleToArrayStorage(vm, structure(vm)->suggestedArrayStorageTransition()); + return convertDoubleToArrayStorage(vm, structure()->suggestedArrayStorageTransition()); } -ArrayStorage* JSObject::convertContiguousToArrayStorage(VM& vm, NonPropertyTransition transition) +ArrayStorage* JSObject::convertContiguousToArrayStorage(VM& vm, NonPropertyTransition transition, unsigned neededLength) { DeferGC deferGC(vm.heap); - ASSERT(hasContiguous(indexingType())); - - unsigned vectorLength = m_butterfly->vectorLength(); - ArrayStorage* newStorage = constructConvertedArrayStorageWithoutCopyingElements(vm, vectorLength); - for (unsigned i = 0; i < m_butterfly->publicLength(); i++) { + ASSERT(hasContiguous(structure()->indexingType())); + + ArrayStorage* newStorage = constructConvertedArrayStorageWithoutCopyingElements(vm, neededLength); + for (unsigned i = m_butterfly->publicLength(); i--;) { JSValue v = m_butterfly->contiguous()[i].get(); - if (v) { - newStorage->m_vector[i].setWithoutWriteBarrier(v); - newStorage->m_numValuesInVector++; - } else - ASSERT(newStorage->m_vector[i].get().isEmpty()); + if (!v) + continue; + newStorage->m_vector[i].setWithoutWriteBarrier(v); + newStorage->m_numValuesInVector++; } - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), transition); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), transition); setStructureAndButterfly(vm, newStructure, newStorage->butterfly()); return newStorage; } +ArrayStorage* JSObject::convertContiguousToArrayStorage(VM& vm, NonPropertyTransition transition) +{ + return convertContiguousToArrayStorage(vm, transition, m_butterfly->vectorLength()); +} + ArrayStorage* JSObject::convertContiguousToArrayStorage(VM& vm) { - return convertContiguousToArrayStorage(vm, structure(vm)->suggestedArrayStorageTransition()); + return convertContiguousToArrayStorage(vm, structure()->suggestedArrayStorageTransition()); } void JSObject::convertUndecidedForValue(VM& vm, JSValue value) @@ -946,7 +941,7 @@ void JSObject::convertInt32ForValue(VM& vm, JSValue value) { ASSERT(!value.isInt32()); - if (value.isDouble() && !std::isnan(value.asDouble())) { + if (value.isDouble()) { convertInt32ToDouble(vm); return; } @@ -980,9 +975,9 @@ ContiguousJSValues JSObject::ensureInt32Slow(VM& vm) { ASSERT(inherits(info())); - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: - if (UNLIKELY(indexingShouldBeSparse() || structure(vm)->needsSlowPutIndexing())) + if (UNLIKELY(indexingShouldBeSparse() || structure()->needsSlowPutIndexing())) return ContiguousJSValues(); return createInitialInt32(vm, 0); @@ -1004,9 +999,9 @@ ContiguousDoubles JSObject::ensureDoubleSlow(VM& vm) { ASSERT(inherits(info())); - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: - if (UNLIKELY(indexingShouldBeSparse() || structure(vm)->needsSlowPutIndexing())) + if (UNLIKELY(indexingShouldBeSparse() || structure()->needsSlowPutIndexing())) return ContiguousDoubles(); return createInitialDouble(vm, 0); @@ -1026,13 +1021,13 @@ ContiguousDoubles JSObject::ensureDoubleSlow(VM& vm) } } -ContiguousJSValues JSObject::ensureContiguousSlow(VM& vm) +ContiguousJSValues JSObject::ensureContiguousSlow(VM& vm, DoubleToContiguousMode mode) { ASSERT(inherits(info())); - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: - if (UNLIKELY(indexingShouldBeSparse() || structure(vm)->needsSlowPutIndexing())) + if (UNLIKELY(indexingShouldBeSparse() || structure()->needsSlowPutIndexing())) return ContiguousJSValues(); return createInitialContiguous(vm, 0); @@ -1043,6 +1038,8 @@ ContiguousJSValues JSObject::ensureContiguousSlow(VM& vm) return convertInt32ToContiguous(vm); case ALL_DOUBLE_INDEXING_TYPES: + if (mode == RageConvertDoubleToValue) + return rageConvertDoubleToContiguous(vm); return convertDoubleToContiguous(vm); case ALL_ARRAY_STORAGE_INDEXING_TYPES: @@ -1054,11 +1051,21 @@ ContiguousJSValues JSObject::ensureContiguousSlow(VM& vm) } } +ContiguousJSValues JSObject::ensureContiguousSlow(VM& vm) +{ + return ensureContiguousSlow(vm, EncodeValueAsDouble); +} + +ContiguousJSValues JSObject::rageEnsureContiguousSlow(VM& vm) +{ + return ensureContiguousSlow(vm, RageConvertDoubleToValue); +} + ArrayStorage* JSObject::ensureArrayStorageSlow(VM& vm) { ASSERT(inherits(info())); - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: if (UNLIKELY(indexingShouldBeSparse())) return ensureArrayStorageExistsAndEnterDictionaryIndexingMode(vm); @@ -1066,22 +1073,22 @@ ArrayStorage* JSObject::ensureArrayStorageSlow(VM& vm) case ALL_UNDECIDED_INDEXING_TYPES: ASSERT(!indexingShouldBeSparse()); - ASSERT(!structure(vm)->needsSlowPutIndexing()); + ASSERT(!structure()->needsSlowPutIndexing()); return convertUndecidedToArrayStorage(vm); case ALL_INT32_INDEXING_TYPES: ASSERT(!indexingShouldBeSparse()); - ASSERT(!structure(vm)->needsSlowPutIndexing()); + ASSERT(!structure()->needsSlowPutIndexing()); return convertInt32ToArrayStorage(vm); case ALL_DOUBLE_INDEXING_TYPES: ASSERT(!indexingShouldBeSparse()); - ASSERT(!structure(vm)->needsSlowPutIndexing()); + ASSERT(!structure()->needsSlowPutIndexing()); return convertDoubleToArrayStorage(vm); case ALL_CONTIGUOUS_INDEXING_TYPES: ASSERT(!indexingShouldBeSparse()); - ASSERT(!structure(vm)->needsSlowPutIndexing()); + ASSERT(!structure()->needsSlowPutIndexing()); return convertContiguousToArrayStorage(vm); default: @@ -1092,7 +1099,7 @@ ArrayStorage* JSObject::ensureArrayStorageSlow(VM& vm) ArrayStorage* JSObject::ensureArrayStorageExistsAndEnterDictionaryIndexingMode(VM& vm) { - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: { createArrayStorage(vm, 0, 0); SparseArrayValueMap* map = allocateSparseIndexMap(vm); @@ -1123,7 +1130,7 @@ ArrayStorage* JSObject::ensureArrayStorageExistsAndEnterDictionaryIndexingMode(V void JSObject::switchToSlowPutArrayStorage(VM& vm) { - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_UNDECIDED_INDEXING_TYPES: convertUndecidedToArrayStorage(vm, AllocateSlowPutArrayStorage); break; @@ -1142,7 +1149,7 @@ void JSObject::switchToSlowPutArrayStorage(VM& vm) case NonArrayWithArrayStorage: case ArrayWithArrayStorage: { - Structure* newStructure = Structure::nonPropertyTransition(vm, structure(vm), SwitchToSlowPutArrayStorage); + Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), SwitchToSlowPutArrayStorage); setStructure(vm, newStructure); break; } @@ -1159,7 +1166,7 @@ void JSObject::setPrototype(VM& vm, JSValue prototype) if (prototype.isObject()) vm.prototypeMap.addPrototype(asObject(prototype)); - Structure* newStructure = Structure::changePrototypeTransition(vm, structure(vm), prototype); + Structure* newStructure = Structure::changePrototypeTransition(vm, structure(), prototype); setStructure(vm, newStructure); if (!newStructure->anyObjectInChainMayInterceptIndexedAccesses()) @@ -1170,10 +1177,10 @@ void JSObject::setPrototype(VM& vm, JSValue prototype) return; } - if (!hasIndexedProperties(indexingType())) + if (!hasIndexedProperties(structure()->indexingType())) return; - if (shouldUseSlowPut(indexingType())) + if (shouldUseSlowPut(structure()->indexingType())) return; switchToSlowPutArrayStorage(vm); @@ -1181,7 +1188,7 @@ void JSObject::setPrototype(VM& vm, JSValue prototype) bool JSObject::setPrototypeWithCycleCheck(ExecState* exec, JSValue prototype) { - ASSERT(methodTable(exec->vm())->toThis(this, exec, NotStrictMode) == this); + ASSERT(methodTable()->toThis(this, exec, NotStrictMode) == this); JSValue nextPrototype = prototype; while (nextPrototype && nextPrototype.isObject()) { if (nextPrototype == this) @@ -1198,61 +1205,34 @@ bool JSObject::allowsAccessFrom(ExecState* exec) return globalObject->globalObjectMethodTable()->allowsAccessFrom(globalObject, exec); } -void JSObject::putGetter(ExecState* exec, PropertyName propertyName, JSValue getter) -{ - PropertyDescriptor descriptor; - descriptor.setGetter(getter); - descriptor.setEnumerable(true); - descriptor.setConfigurable(true); - defineOwnProperty(this, exec, propertyName, descriptor, false); -} - -void JSObject::putSetter(ExecState* exec, PropertyName propertyName, JSValue setter) -{ - PropertyDescriptor descriptor; - descriptor.setSetter(setter); - descriptor.setEnumerable(true); - descriptor.setConfigurable(true); - defineOwnProperty(this, exec, propertyName, descriptor, false); -} - void JSObject::putDirectAccessor(ExecState* exec, PropertyName propertyName, JSValue value, unsigned attributes) { ASSERT(value.isGetterSetter() && (attributes & Accessor)); - if (Optional<uint32_t> index = parseIndex(propertyName)) { - putDirectIndex(exec, index.value(), value, attributes, PutDirectIndexLikePutDirect); + unsigned index = propertyName.asIndex(); + if (index != PropertyName::NotAnIndex) { + putDirectIndex(exec, index, value, attributes, PutDirectIndexLikePutDirect); return; } putDirectNonIndexAccessor(exec->vm(), propertyName, value, attributes); } -void JSObject::putDirectCustomAccessor(VM& vm, PropertyName propertyName, JSValue value, unsigned attributes) -{ - ASSERT(!parseIndex(propertyName)); - - PutPropertySlot slot(this); - putDirectInternal<PutModeDefineOwnProperty>(vm, propertyName, value, attributes, slot); - - ASSERT(slot.type() == PutPropertySlot::NewProperty); - - Structure* structure = this->structure(vm); - if (attributes & ReadOnly) - structure->setContainsReadOnlyProperties(); - structure->setHasCustomGetterSetterPropertiesWithProtoCheck(propertyName == vm.propertyNames->underscoreProto); -} - void JSObject::putDirectNonIndexAccessor(VM& vm, PropertyName propertyName, JSValue value, unsigned attributes) { PutPropertySlot slot(this); - putDirectInternal<PutModeDefineOwnProperty>(vm, propertyName, value, attributes, slot); + putDirectInternal<PutModeDefineOwnProperty>(vm, propertyName, value, attributes, slot, getCallableObject(value)); + + // putDirect will change our Structure if we add a new property. For + // getters and setters, though, we also need to change our Structure + // if we override an existing non-getter or non-setter. + if (slot.type() != PutPropertySlot::NewProperty) + setStructure(vm, Structure::attributeChangeTransition(vm, structure(), propertyName, attributes)); - Structure* structure = this->structure(vm); if (attributes & ReadOnly) - structure->setContainsReadOnlyProperties(); + structure()->setContainsReadOnlyProperties(); - structure->setHasGetterSetterPropertiesWithProtoCheck(propertyName == vm.propertyNames->underscoreProto); + structure()->setHasGetterSetterProperties(propertyName == vm.propertyNames->underscoreProto); } bool JSObject::hasProperty(ExecState* exec, PropertyName propertyName) const @@ -1272,32 +1252,30 @@ bool JSObject::deleteProperty(JSCell* cell, ExecState* exec, PropertyName proper { JSObject* thisObject = jsCast<JSObject*>(cell); - if (Optional<uint32_t> index = parseIndex(propertyName)) - return thisObject->methodTable(exec->vm())->deletePropertyByIndex(thisObject, exec, index.value()); + unsigned i = propertyName.asIndex(); + if (i != PropertyName::NotAnIndex) + return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, i); if (!thisObject->staticFunctionsReified()) thisObject->reifyStaticFunctionsForDelete(exec); unsigned attributes; - VM& vm = exec->vm(); - if (isValidOffset(thisObject->structure(vm)->get(vm, propertyName, attributes))) { - if (attributes & DontDelete && !vm.isInDefineOwnProperty()) + JSCell* specificValue; + if (isValidOffset(thisObject->structure()->get(exec->vm(), propertyName, attributes, specificValue))) { + if (attributes & DontDelete && !exec->vm().isInDefineOwnProperty()) return false; - thisObject->removeDirect(vm, propertyName); + thisObject->removeDirect(exec->vm(), propertyName); return true; } // Look in the static hashtable of properties - const HashTableValue* entry = thisObject->findPropertyHashEntry(propertyName); + const HashEntry* entry = thisObject->findPropertyHashEntry(exec, propertyName); if (entry) { - if (entry->attributes() & DontDelete && !vm.isInDefineOwnProperty()) + if (entry->attributes() & DontDelete && !exec->vm().isInDefineOwnProperty()) return false; // this builtin property can't be deleted PutPropertySlot slot(thisObject); - if (!(entry->attributes() & BuiltinOrFunctionOrAccessor)) { - ASSERT(thisObject->staticFunctionsReified()); - putEntry(exec, entry, thisObject, propertyName, jsUndefined(), slot); - } + putEntry(exec, entry, thisObject, propertyName, jsUndefined(), slot); } return true; @@ -1306,13 +1284,7 @@ bool JSObject::deleteProperty(JSCell* cell, ExecState* exec, PropertyName proper bool JSObject::hasOwnProperty(ExecState* exec, PropertyName propertyName) const { PropertySlot slot(this); - return const_cast<JSObject*>(this)->methodTable(exec->vm())->getOwnPropertySlot(const_cast<JSObject*>(this), exec, propertyName, slot); -} - -bool JSObject::hasOwnProperty(ExecState* exec, unsigned propertyName) const -{ - PropertySlot slot(this); - return const_cast<JSObject*>(this)->methodTable(exec->vm())->getOwnPropertySlotByIndex(const_cast<JSObject*>(this), exec, propertyName, slot); + return const_cast<JSObject*>(this)->methodTable()->getOwnPropertySlot(const_cast<JSObject*>(this), exec, propertyName, slot); } bool JSObject::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned i) @@ -1320,9 +1292,9 @@ bool JSObject::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned i) JSObject* thisObject = jsCast<JSObject*>(cell); if (i > MAX_ARRAY_INDEX) - return thisObject->methodTable(exec->vm())->deleteProperty(thisObject, exec, Identifier::from(exec, i)); + return thisObject->methodTable()->deleteProperty(thisObject, exec, Identifier::from(exec, i)); - switch (thisObject->indexingType()) { + switch (thisObject->structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: case ALL_UNDECIDED_INDEXING_TYPES: return true; @@ -1340,7 +1312,7 @@ bool JSObject::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned i) Butterfly* butterfly = thisObject->butterfly(); if (i >= butterfly->vectorLength()) return true; - butterfly->contiguousDouble()[i] = PNaN; + butterfly->contiguousDouble()[i] = QNaN; return true; } @@ -1395,7 +1367,7 @@ static ALWAYS_INLINE JSValue callDefaultValueFunction(ExecState* exec, const JSO bool JSObject::getPrimitiveNumber(ExecState* exec, double& number, JSValue& result) const { - result = methodTable(exec->vm())->defaultValue(this, exec, PreferNumber); + result = methodTable()->defaultValue(this, exec, PreferNumber); number = result.toNumber(exec); return !result.isString(); } @@ -1403,10 +1375,6 @@ bool JSObject::getPrimitiveNumber(ExecState* exec, double& number, JSValue& resu // ECMA 8.6.2.6 JSValue JSObject::defaultValue(const JSObject* object, ExecState* exec, PreferredPrimitiveType hint) { - // Make sure that whatever default value methods there are on object's prototype chain are - // being watched. - object->structure()->startWatchingInternalPropertiesIfNecessaryForEntireChain(exec->vm()); - // Must call toString first for Date objects. if ((hint == PreferString) || (hint != PreferNumber && object->prototype() == exec->lexicalGlobalObject()->datePrototype())) { JSValue value = callDefaultValueFunction(exec, object, exec->propertyNames().toString); @@ -1429,11 +1397,11 @@ JSValue JSObject::defaultValue(const JSObject* object, ExecState* exec, Preferre return exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("No default value"))); } -const HashTableValue* JSObject::findPropertyHashEntry(PropertyName propertyName) const +const HashEntry* JSObject::findPropertyHashEntry(ExecState* exec, PropertyName propertyName) const { for (const ClassInfo* info = classInfo(); info; info = info->parentClass) { - if (const HashTable* propHashTable = info->staticPropHashTable) { - if (const HashTableValue* entry = propHashTable->entry(propertyName)) + if (const HashTable* propHashTable = info->propHashTable(exec)) { + if (const HashEntry* entry = propHashTable->entry(exec, propertyName)) return entry; } } @@ -1442,13 +1410,12 @@ const HashTableValue* JSObject::findPropertyHashEntry(PropertyName propertyName) bool JSObject::hasInstance(ExecState* exec, JSValue value) { - VM& vm = exec->vm(); - TypeInfo info = structure(vm)->typeInfo(); + TypeInfo info = structure()->typeInfo(); if (info.implementsDefaultHasInstance()) return defaultHasInstance(exec, value, get(exec, exec->propertyNames().prototype)); if (info.implementsHasInstance()) - return methodTable(vm)->customHasInstance(this, exec, value); - vm.throwException(exec, createInvalidInstanceofParameterError(exec, this)); + return methodTable()->customHasInstance(this, exec, value); + exec->vm().throwException(exec, createInvalidParameterError(exec, "instanceof" , this)); return false; } @@ -1470,21 +1437,34 @@ bool JSObject::defaultHasInstance(ExecState* exec, JSValue value, JSValue proto) return false; } +bool JSObject::getPropertySpecificValue(ExecState* exec, PropertyName propertyName, JSCell*& specificValue) const +{ + unsigned attributes; + if (isValidOffset(structure()->get(exec->vm(), propertyName, attributes, specificValue))) + return true; + + // This could be a function within the static table? - should probably + // also look in the hash? This currently should not be a problem, since + // we've currently always call 'get' first, which should have populated + // the normal storage. + return false; +} + void JSObject::getPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { - object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, propertyNames, mode); + propertyNames.setBaseObject(object); + object->methodTable()->getOwnPropertyNames(object, exec, propertyNames, mode); if (object->prototype().isNull()) return; - VM& vm = exec->vm(); JSObject* prototype = asObject(object->prototype()); while(1) { - if (prototype->structure(vm)->typeInfo().overridesGetPropertyNames()) { - prototype->methodTable(vm)->getPropertyNames(prototype, exec, propertyNames, mode); + if (prototype->structure()->typeInfo().overridesGetPropertyNames()) { + prototype->methodTable()->getPropertyNames(prototype, exec, propertyNames, mode); break; } - prototype->methodTable(vm)->getOwnPropertyNames(prototype, exec, propertyNames, mode); + prototype->methodTable()->getOwnPropertyNames(prototype, exec, propertyNames, mode); JSValue nextProto = prototype->prototype(); if (nextProto.isNull()) break; @@ -1494,89 +1474,81 @@ void JSObject::getPropertyNames(JSObject* object, ExecState* exec, PropertyNameA void JSObject::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { - if (!mode.includeJSObjectProperties()) { - // We still have to get non-indexed properties from any subclasses of JSObject that have them. - object->methodTable(exec->vm())->getOwnNonIndexPropertyNames(object, exec, propertyNames, mode); - return; + // Add numeric properties first. That appears to be the accepted convention. + // FIXME: Filling PropertyNameArray with an identifier for every integer + // is incredibly inefficient for large arrays. We need a different approach, + // which almost certainly means a different structure for PropertyNameArray. + switch (object->structure()->indexingType()) { + case ALL_BLANK_INDEXING_TYPES: + case ALL_UNDECIDED_INDEXING_TYPES: + break; + + case ALL_INT32_INDEXING_TYPES: + case ALL_CONTIGUOUS_INDEXING_TYPES: { + Butterfly* butterfly = object->butterfly(); + unsigned usedLength = butterfly->publicLength(); + for (unsigned i = 0; i < usedLength; ++i) { + if (!butterfly->contiguous()[i]) + continue; + propertyNames.add(Identifier::from(exec, i)); + } + break; } - - if (propertyNames.includeStringProperties()) { - // Add numeric properties first. That appears to be the accepted convention. - // FIXME: Filling PropertyNameArray with an identifier for every integer - // is incredibly inefficient for large arrays. We need a different approach, - // which almost certainly means a different structure for PropertyNameArray. - switch (object->indexingType()) { - case ALL_BLANK_INDEXING_TYPES: - case ALL_UNDECIDED_INDEXING_TYPES: - break; - - case ALL_INT32_INDEXING_TYPES: - case ALL_CONTIGUOUS_INDEXING_TYPES: { - Butterfly* butterfly = object->butterfly(); - unsigned usedLength = butterfly->publicLength(); - for (unsigned i = 0; i < usedLength; ++i) { - if (!butterfly->contiguous()[i]) - continue; - propertyNames.add(i); - } - break; + + case ALL_DOUBLE_INDEXING_TYPES: { + Butterfly* butterfly = object->butterfly(); + unsigned usedLength = butterfly->publicLength(); + for (unsigned i = 0; i < usedLength; ++i) { + double value = butterfly->contiguousDouble()[i]; + if (value != value) + continue; + propertyNames.add(Identifier::from(exec, i)); } - - case ALL_DOUBLE_INDEXING_TYPES: { - Butterfly* butterfly = object->butterfly(); - unsigned usedLength = butterfly->publicLength(); - for (unsigned i = 0; i < usedLength; ++i) { - double value = butterfly->contiguousDouble()[i]; - if (value != value) - continue; - propertyNames.add(i); - } - break; + break; + } + + case ALL_ARRAY_STORAGE_INDEXING_TYPES: { + ArrayStorage* storage = object->m_butterfly->arrayStorage(); + + unsigned usedVectorLength = std::min(storage->length(), storage->vectorLength()); + for (unsigned i = 0; i < usedVectorLength; ++i) { + if (storage->m_vector[i]) + propertyNames.add(Identifier::from(exec, i)); } + + if (SparseArrayValueMap* map = storage->m_sparseMap.get()) { + Vector<unsigned, 0, UnsafeVectorOverflow> keys; + keys.reserveInitialCapacity(map->size()); - case ALL_ARRAY_STORAGE_INDEXING_TYPES: { - ArrayStorage* storage = object->m_butterfly->arrayStorage(); - - unsigned usedVectorLength = std::min(storage->length(), storage->vectorLength()); - for (unsigned i = 0; i < usedVectorLength; ++i) { - if (storage->m_vector[i]) - propertyNames.add(i); - } - - if (SparseArrayValueMap* map = storage->m_sparseMap.get()) { - Vector<unsigned, 0, UnsafeVectorOverflow> keys; - keys.reserveInitialCapacity(map->size()); - - SparseArrayValueMap::const_iterator end = map->end(); - for (SparseArrayValueMap::const_iterator it = map->begin(); it != end; ++it) { - if (mode.includeDontEnumProperties() || !(it->value.attributes & DontEnum)) - keys.uncheckedAppend(static_cast<unsigned>(it->key)); - } - - std::sort(keys.begin(), keys.end()); - for (unsigned i = 0; i < keys.size(); ++i) - propertyNames.add(keys[i]); + SparseArrayValueMap::const_iterator end = map->end(); + for (SparseArrayValueMap::const_iterator it = map->begin(); it != end; ++it) { + if (mode == IncludeDontEnumProperties || !(it->value.attributes & DontEnum)) + keys.uncheckedAppend(static_cast<unsigned>(it->key)); } - break; - } - default: - RELEASE_ASSERT_NOT_REACHED(); + std::sort(keys.begin(), keys.end()); + for (unsigned i = 0; i < keys.size(); ++i) + propertyNames.add(Identifier::from(exec, keys[i])); } + break; } - - object->methodTable(exec->vm())->getOwnNonIndexPropertyNames(object, exec, propertyNames, mode); + + default: + RELEASE_ASSERT_NOT_REACHED(); + } + + object->methodTable()->getOwnNonIndexPropertyNames(object, exec, propertyNames, mode); } void JSObject::getOwnNonIndexPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { getClassPropertyNames(exec, object->classInfo(), propertyNames, mode, object->staticFunctionsReified()); - if (!mode.includeJSObjectProperties()) - return; - - VM& vm = exec->vm(); - object->structure(vm)->getPropertyNamesFromStructure(vm, propertyNames, mode); + bool canCachePropertiesFromStructure = !propertyNames.size(); + object->structure()->getPropertyNamesFromStructure(exec->vm(), propertyNames, mode); + + if (canCachePropertiesFromStructure) + propertyNames.setNumCacheableSlotsForObject(object, propertyNames.size()); } double JSObject::toNumber(ExecState* exec) const @@ -1605,7 +1577,7 @@ void JSObject::seal(VM& vm) if (isSealed(vm)) return; preventExtensions(vm); - setStructure(vm, Structure::sealTransition(vm, structure(vm))); + setStructure(vm, Structure::sealTransition(vm, structure())); } void JSObject::freeze(VM& vm) @@ -1613,14 +1585,14 @@ void JSObject::freeze(VM& vm) if (isFrozen(vm)) return; preventExtensions(vm); - setStructure(vm, Structure::freezeTransition(vm, structure(vm))); + setStructure(vm, Structure::freezeTransition(vm, structure())); } void JSObject::preventExtensions(VM& vm) { enterDictionaryIndexingMode(vm); if (isExtensible()) - setStructure(vm, Structure::preventExtensionsTransition(vm, structure(vm))); + setStructure(vm, Structure::preventExtensionsTransition(vm, structure())); } // This presently will flatten to an uncachable dictionary; this is suitable @@ -1633,43 +1605,42 @@ void JSObject::reifyStaticFunctionsForDelete(ExecState* exec) // If this object's ClassInfo has no static properties, then nothing to reify! // We can safely set the flag to avoid the expensive check again in the future. if (!classInfo()->hasStaticProperties()) { - structure(vm)->setStaticFunctionsReified(true); + structure()->setStaticFunctionsReified(); return; } - if (!structure(vm)->isUncacheableDictionary()) - setStructure(vm, Structure::toUncacheableDictionaryTransition(vm, structure(vm))); + if (!structure()->isUncacheableDictionary()) + setStructure(vm, Structure::toUncacheableDictionaryTransition(vm, structure())); for (const ClassInfo* info = classInfo(); info; info = info->parentClass) { - const HashTable* hashTable = info->staticPropHashTable; + const HashTable* hashTable = info->propHashTable(globalObject()->globalExec()); if (!hashTable) continue; PropertySlot slot(this); - for (auto iter = hashTable->begin(); iter != hashTable->end(); ++iter) { - if (iter->attributes() & BuiltinOrFunctionOrAccessor) - setUpStaticFunctionSlot(globalObject()->globalExec(), iter.value(), this, Identifier::fromString(&vm, iter.key()), slot); + for (HashTable::ConstIterator iter = hashTable->begin(vm); iter != hashTable->end(vm); ++iter) { + if (iter->attributes() & Function) + setUpStaticFunctionSlot(globalObject()->globalExec(), *iter, this, Identifier(&vm, iter->key()), slot); } } - structure(vm)->setStaticFunctionsReified(true); + structure()->setStaticFunctionsReified(); } bool JSObject::removeDirect(VM& vm, PropertyName propertyName) { - Structure* structure = this->structure(vm); - if (!isValidOffset(structure->get(vm, propertyName))) + if (!isValidOffset(structure()->get(vm, propertyName))) return false; PropertyOffset offset; - if (structure->isUncacheableDictionary()) { - offset = structure->removePropertyWithoutTransition(vm, propertyName); + if (structure()->isUncacheableDictionary()) { + offset = structure()->removePropertyWithoutTransition(vm, propertyName); if (offset == invalidOffset) return false; putDirectUndefined(offset); return true; } - setStructure(vm, Structure::removePropertyTransition(vm, structure, propertyName, offset)); + setStructure(vm, Structure::removePropertyTransition(vm, structure(), propertyName, offset)); if (offset == invalidOffset) return false; putDirectUndefined(offset); @@ -1682,19 +1653,19 @@ NEVER_INLINE void JSObject::fillGetterPropertySlot(PropertySlot& slot, JSValue g slot.setGetterSlot(this, attributes, jsCast<GetterSetter*>(getterSetter)); return; } + slot.setCacheableGetterSlot(this, attributes, jsCast<GetterSetter*>(getterSetter), offset); } void JSObject::putIndexedDescriptor(ExecState* exec, SparseArrayEntry* entryInMap, const PropertyDescriptor& descriptor, PropertyDescriptor& oldDescriptor) { VM& vm = exec->vm(); - auto map = m_butterfly->arrayStorage()->m_sparseMap.get(); if (descriptor.isDataDescriptor()) { if (descriptor.value()) - entryInMap->set(vm, map, descriptor.value()); + entryInMap->set(vm, this, descriptor.value()); else if (oldDescriptor.isAccessorDescriptor()) - entryInMap->set(vm, map, jsUndefined()); + entryInMap->set(vm, this, jsUndefined()); entryInMap->attributes = descriptor.attributesOverridingCurrent(oldDescriptor) & ~Accessor; return; } @@ -1711,13 +1682,13 @@ void JSObject::putIndexedDescriptor(ExecState* exec, SparseArrayEntry* entryInMa else if (oldDescriptor.isAccessorDescriptor()) setter = oldDescriptor.setterObject(); - GetterSetter* accessor = GetterSetter::create(vm, exec->lexicalGlobalObject()); + GetterSetter* accessor = GetterSetter::create(vm); if (getter) - accessor->setGetter(vm, exec->lexicalGlobalObject(), getter); + accessor->setGetter(vm, getter); if (setter) - accessor->setSetter(vm, exec->lexicalGlobalObject(), setter); + accessor->setSetter(vm, setter); - entryInMap->set(vm, map, accessor); + entryInMap->set(vm, this, accessor); entryInMap->attributes = descriptor.attributesOverridingCurrent(oldDescriptor) & ~ReadOnly; return; } @@ -1898,7 +1869,7 @@ bool JSObject::attemptToInterceptPutByIndexOnHole(ExecState* exec, unsigned i, J template<IndexingType indexingShape> void JSObject::putByIndexBeyondVectorLengthWithoutAttributes(ExecState* exec, unsigned i, JSValue value) { - ASSERT((indexingType() & IndexingShapeMask) == indexingShape); + ASSERT((structure()->indexingType() & IndexingShapeMask) == indexingShape); ASSERT(!indexingShouldBeSparse()); // For us to get here, the index is either greater than the public length, or greater than @@ -1946,11 +1917,6 @@ void JSObject::putByIndexBeyondVectorLengthWithoutAttributes(ExecState* exec, un } } -// Explicit instantiations needed by JSArray.cpp. -template void JSObject::putByIndexBeyondVectorLengthWithoutAttributes<Int32Shape>(ExecState*, unsigned, JSValue); -template void JSObject::putByIndexBeyondVectorLengthWithoutAttributes<DoubleShape>(ExecState*, unsigned, JSValue); -template void JSObject::putByIndexBeyondVectorLengthWithoutAttributes<ContiguousShape>(ExecState*, unsigned, JSValue); - void JSObject::putByIndexBeyondVectorLengthWithArrayStorage(ExecState* exec, unsigned i, JSValue value, bool shouldThrow, ArrayStorage* storage) { VM& vm = exec->vm(); @@ -2032,7 +1998,7 @@ void JSObject::putByIndexBeyondVectorLength(ExecState* exec, unsigned i, JSValue // i should be a valid array index that is outside of the current vector. ASSERT(i <= MAX_ARRAY_INDEX); - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: { if (indexingShouldBeSparse()) { putByIndexBeyondVectorLengthWithArrayStorage( @@ -2045,10 +2011,10 @@ void JSObject::putByIndexBeyondVectorLength(ExecState* exec, unsigned i, JSValue exec, i, value, shouldThrow, createArrayStorage(vm, 0, 0)); break; } - if (structure(vm)->needsSlowPutIndexing()) { - // Convert the indexing type to the SlowPutArrayStorage and retry. - createArrayStorage(vm, i + 1, getNewVectorLength(0, 0, i + 1)); - putByIndex(this, exec, i, value, shouldThrow); + if (structure()->needsSlowPutIndexing()) { + ArrayStorage* storage = createArrayStorage(vm, i + 1, getNewVectorLength(0, 0, i + 1)); + storage->m_vector[i].set(vm, this, value); + storage->m_numValuesInVector++; break; } @@ -2100,7 +2066,7 @@ bool JSObject::putDirectIndexBeyondVectorLengthWithArrayStorage(ExecState* exec, VM& vm = exec->vm(); // i should be a valid array index that is outside of the current vector. - ASSERT(hasAnyArrayStorage(indexingType())); + ASSERT(hasArrayStorage(structure()->indexingType())); ASSERT(arrayStorage() == storage); ASSERT(i >= storage->vectorLength() || attributes); ASSERT(i <= MAX_ARRAY_INDEX); @@ -2182,7 +2148,7 @@ bool JSObject::putDirectIndexBeyondVectorLength(ExecState* exec, unsigned i, JSV if (attributes & (ReadOnly | Accessor)) notifyPresenceOfIndexedAccessors(vm); - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: { if (indexingShouldBeSparse() || attributes) { return putDirectIndexBeyondVectorLengthWithArrayStorage( @@ -2193,7 +2159,7 @@ bool JSObject::putDirectIndexBeyondVectorLength(ExecState* exec, unsigned i, JSV return putDirectIndexBeyondVectorLengthWithArrayStorage( exec, i, value, attributes, mode, createArrayStorage(vm, 0, 0)); } - if (structure(vm)->needsSlowPutIndexing()) { + if (structure()->needsSlowPutIndexing()) { ArrayStorage* storage = createArrayStorage(vm, i + 1, getNewVectorLength(0, 0, i + 1)); storage->m_vector[i].set(vm, this, value); storage->m_numValuesInVector++; @@ -2211,10 +2177,9 @@ bool JSObject::putDirectIndexBeyondVectorLength(ExecState* exec, unsigned i, JSV } case ALL_INT32_INDEXING_TYPES: { - if (attributes) { - if (i < m_butterfly->vectorLength()) - return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, ensureArrayStorageExistsAndEnterDictionaryIndexingMode(vm)); - return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, convertInt32ToArrayStorage(vm)); + if (attributes & (ReadOnly | Accessor)) { + return putDirectIndexBeyondVectorLengthWithArrayStorage( + exec, i, value, attributes, mode, convertInt32ToArrayStorage(vm)); } if (!value.isInt32()) { convertInt32ForValue(vm, value); @@ -2225,10 +2190,9 @@ bool JSObject::putDirectIndexBeyondVectorLength(ExecState* exec, unsigned i, JSV } case ALL_DOUBLE_INDEXING_TYPES: { - if (attributes) { - if (i < m_butterfly->vectorLength()) - return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, ensureArrayStorageExistsAndEnterDictionaryIndexingMode(vm)); - return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, convertDoubleToArrayStorage(vm)); + if (attributes & (ReadOnly | Accessor)) { + return putDirectIndexBeyondVectorLengthWithArrayStorage( + exec, i, value, attributes, mode, convertDoubleToArrayStorage(vm)); } if (!value.isNumber()) { convertDoubleToContiguous(vm); @@ -2244,20 +2208,15 @@ bool JSObject::putDirectIndexBeyondVectorLength(ExecState* exec, unsigned i, JSV } case ALL_CONTIGUOUS_INDEXING_TYPES: { - if (attributes) { - if (i < m_butterfly->vectorLength()) - return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, ensureArrayStorageExistsAndEnterDictionaryIndexingMode(vm)); - return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, convertContiguousToArrayStorage(vm)); + if (attributes & (ReadOnly | Accessor)) { + return putDirectIndexBeyondVectorLengthWithArrayStorage( + exec, i, value, attributes, mode, convertContiguousToArrayStorage(vm)); } putByIndexBeyondVectorLengthWithoutAttributes<ContiguousShape>(exec, i, value); return true; } case ALL_ARRAY_STORAGE_INDEXING_TYPES: - if (attributes) { - if (i < m_butterfly->vectorLength()) - return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, ensureArrayStorageExistsAndEnterDictionaryIndexingMode(vm)); - } return putDirectIndexBeyondVectorLengthWithArrayStorage(exec, i, value, attributes, mode, arrayStorage()); default: @@ -2277,28 +2236,6 @@ void JSObject::putDirectNativeFunction(VM& vm, JSGlobalObject* globalObject, con putDirect(vm, propertyName, function, attributes); } -JSFunction* JSObject::putDirectBuiltinFunction(VM& vm, JSGlobalObject* globalObject, const PropertyName& propertyName, FunctionExecutable* functionExecutable, unsigned attributes) -{ - StringImpl* name = propertyName.publicName(); - if (!name) - name = vm.propertyNames->anonymous.impl(); - ASSERT(name); - JSFunction* function = JSFunction::createBuiltinFunction(vm, static_cast<FunctionExecutable*>(functionExecutable), globalObject); - putDirect(vm, propertyName, function, attributes); - return function; -} - -JSFunction* JSObject::putDirectBuiltinFunctionWithoutTransition(VM& vm, JSGlobalObject* globalObject, const PropertyName& propertyName, FunctionExecutable* functionExecutable, unsigned attributes) -{ - StringImpl* name = propertyName.publicName(); - if (!name) - name = vm.propertyNames->anonymous.impl(); - ASSERT(name); - JSFunction* function = JSFunction::createBuiltinFunction(vm, static_cast<FunctionExecutable*>(functionExecutable), globalObject); - putDirectWithoutTransition(vm, propertyName, function, attributes); - return function; -} - void JSObject::putDirectNativeFunctionWithoutTransition(VM& vm, JSGlobalObject* globalObject, const PropertyName& propertyName, unsigned functionLength, NativeFunction nativeFunction, Intrinsic intrinsic, unsigned attributes) { StringImpl* name = propertyName.publicName(); @@ -2335,7 +2272,7 @@ ALWAYS_INLINE unsigned JSObject::getNewVectorLength(unsigned desiredLength) unsigned vectorLength; unsigned length; - if (hasIndexedProperties(indexingType())) { + if (hasIndexedProperties(structure()->indexingType())) { vectorLength = m_butterfly->vectorLength(); length = m_butterfly->publicLength(); } else { @@ -2374,7 +2311,7 @@ unsigned JSObject::countElements(Butterfly* butterfly) unsigned JSObject::countElements() { - switch (indexingType()) { + switch (structure()->indexingType()) { case ALL_BLANK_INDEXING_TYPES: case ALL_UNDECIDED_INDEXING_TYPES: return 0; @@ -2413,11 +2350,10 @@ bool JSObject::increaseVectorLength(VM& vm, unsigned newLength) unsigned newVectorLength = getNewVectorLength(newLength); // Fast case - there is no precapacity. In these cases a realloc makes sense. - Structure* structure = this->structure(vm); if (LIKELY(!indexBias)) { DeferGC deferGC(vm.heap); Butterfly* newButterfly = storage->butterfly()->growArrayRight( - vm, this, structure, structure->outOfLineCapacity(), true, + vm, this, structure(), structure()->outOfLineCapacity(), true, ArrayStorage::sizeFor(vectorLength), ArrayStorage::sizeFor(newVectorLength)); if (!newButterfly) return false; @@ -2431,7 +2367,7 @@ bool JSObject::increaseVectorLength(VM& vm, unsigned newLength) unsigned newIndexBias = std::min(indexBias >> 1, MAX_STORAGE_VECTOR_LENGTH - newVectorLength); Butterfly* newButterfly = storage->butterfly()->resizeArray( vm, this, - structure->outOfLineCapacity(), true, ArrayStorage::sizeFor(vectorLength), + structure()->outOfLineCapacity(), true, ArrayStorage::sizeFor(vectorLength), newIndexBias, true, ArrayStorage::sizeFor(newVectorLength)); if (!newButterfly) return false; @@ -2444,7 +2380,7 @@ bool JSObject::increaseVectorLength(VM& vm, unsigned newLength) void JSObject::ensureLengthSlow(VM& vm, unsigned length) { ASSERT(length < MAX_ARRAY_INDEX); - ASSERT(hasContiguous(indexingType()) || hasInt32(indexingType()) || hasDouble(indexingType()) || hasUndecided(indexingType())); + ASSERT(hasContiguous(structure()->indexingType()) || hasInt32(structure()->indexingType()) || hasDouble(structure()->indexingType()) || hasUndecided(structure()->indexingType())); ASSERT(length > m_butterfly->vectorLength()); unsigned newVectorLength = std::min( @@ -2459,27 +2395,12 @@ void JSObject::ensureLengthSlow(VM& vm, unsigned length) m_butterfly->setVectorLength(newVectorLength); - if (hasDouble(indexingType())) { + if (hasDouble(structure()->indexingType())) { for (unsigned i = oldVectorLength; i < newVectorLength; ++i) - m_butterfly->contiguousDouble().data()[i] = PNaN; + m_butterfly->contiguousDouble().data()[i] = QNaN; } } -void JSObject::reallocateAndShrinkButterfly(VM& vm, unsigned length) -{ - ASSERT(length < MAX_ARRAY_INDEX); - ASSERT(length < MAX_STORAGE_VECTOR_LENGTH); - ASSERT(hasContiguous(indexingType()) || hasInt32(indexingType()) || hasDouble(indexingType()) || hasUndecided(indexingType())); - ASSERT(m_butterfly->vectorLength() > length); - ASSERT(!m_butterfly->indexingHeader()->preCapacity(structure())); - - DeferGC deferGC(vm.heap); - Butterfly* newButterfly = m_butterfly->resizeArray(vm, this, structure(), 0, ArrayStorage::sizeFor(length)); - m_butterfly.set(vm, this, newButterfly); - m_butterfly->setVectorLength(length); - m_butterfly->setPublicLength(length); -} - Butterfly* JSObject::growOutOfLineStorage(VM& vm, size_t oldSize, size_t newSize) { ASSERT(newSize > oldSize); @@ -2487,21 +2408,19 @@ Butterfly* JSObject::growOutOfLineStorage(VM& vm, size_t oldSize, size_t newSize // It's important that this function not rely on structure(), for the property // capacity, since we might have already mutated the structure in-place. - return Butterfly::createOrGrowPropertyStorage(m_butterfly.get(), vm, this, structure(vm), oldSize, newSize); + return m_butterfly->growPropertyStorage(vm, this, structure(), oldSize, newSize); } bool JSObject::getOwnPropertyDescriptor(ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) { JSC::PropertySlot slot(this); - if (!methodTable(exec->vm())->getOwnPropertySlot(this, exec, propertyName, slot)) + if (!methodTable()->getOwnPropertySlot(this, exec, propertyName, slot)) return false; /* Workaround, JSDOMWindow::getOwnPropertySlot searches the prototype chain. :-( */ - if (slot.slotBase() != this && slot.slotBase() && slot.slotBase()->methodTable(exec->vm())->toThis(slot.slotBase(), exec, NotStrictMode) != this) + if (slot.slotBase() != this && slot.slotBase() && slot.slotBase()->methodTable()->toThis(slot.slotBase(), exec, NotStrictMode) != this) return false; if (slot.isAccessor()) descriptor.setAccessorDescriptor(slot.getterSetter(), slot.attributes()); - else if (slot.attributes() & CustomAccessor) - descriptor.setCustomDescriptor(slot.attributes()); else descriptor.setDescriptor(slot.getValue(exec, propertyName), slot.attributes()); return true; @@ -2512,11 +2431,11 @@ static bool putDescriptor(ExecState* exec, JSObject* target, PropertyName proper VM& vm = exec->vm(); if (descriptor.isGenericDescriptor() || descriptor.isDataDescriptor()) { if (descriptor.isGenericDescriptor() && oldDescriptor.isAccessorDescriptor()) { - GetterSetter* accessor = GetterSetter::create(vm, exec->lexicalGlobalObject()); + GetterSetter* accessor = GetterSetter::create(vm); if (oldDescriptor.getterPresent()) - accessor->setGetter(vm, exec->lexicalGlobalObject(), oldDescriptor.getterObject()); + accessor->setGetter(vm, oldDescriptor.getterObject()); if (oldDescriptor.setterPresent()) - accessor->setSetter(vm, exec->lexicalGlobalObject(), oldDescriptor.setterObject()); + accessor->setSetter(vm, oldDescriptor.setterObject()); target->putDirectAccessor(exec, propertyName, accessor, attributes | Accessor); return true; } @@ -2527,20 +2446,20 @@ static bool putDescriptor(ExecState* exec, JSObject* target, PropertyName proper newValue = oldDescriptor.value(); target->putDirect(vm, propertyName, newValue, attributes & ~Accessor); if (attributes & ReadOnly) - target->structure(vm)->setContainsReadOnlyProperties(); + target->structure()->setContainsReadOnlyProperties(); return true; } attributes &= ~ReadOnly; - GetterSetter* accessor = GetterSetter::create(vm, exec->lexicalGlobalObject()); + GetterSetter* accessor = GetterSetter::create(vm); if (descriptor.getterPresent()) - accessor->setGetter(vm, exec->lexicalGlobalObject(), descriptor.getterObject()); + accessor->setGetter(vm, descriptor.getterObject()); else if (oldDescriptor.getterPresent()) - accessor->setGetter(vm, exec->lexicalGlobalObject(), oldDescriptor.getterObject()); + accessor->setGetter(vm, oldDescriptor.getterObject()); if (descriptor.setterPresent()) - accessor->setSetter(vm, exec->lexicalGlobalObject(), descriptor.setterObject()); + accessor->setSetter(vm, descriptor.setterObject()); else if (oldDescriptor.setterPresent()) - accessor->setSetter(vm, exec->lexicalGlobalObject(), oldDescriptor.setterObject()); + accessor->setSetter(vm, oldDescriptor.setterObject()); target->putDirectAccessor(exec, propertyName, accessor, attributes | Accessor); return true; @@ -2548,10 +2467,11 @@ static bool putDescriptor(ExecState* exec, JSObject* target, PropertyName proper void JSObject::putDirectMayBeIndex(ExecState* exec, PropertyName propertyName, JSValue value) { - if (Optional<uint32_t> index = parseIndex(propertyName)) - putDirectIndex(exec, index.value(), value); - else + unsigned asIndex = propertyName.asIndex(); + if (asIndex == PropertyName::NotAnIndex) putDirect(exec->vm(), propertyName, value); + else + putDirectIndex(exec, asIndex, value); } class DefineOwnPropertyScope { @@ -2603,7 +2523,7 @@ bool JSObject::defineOwnNonIndexProperty(ExecState* exec, PropertyName propertyN if (!current.configurable()) { if (descriptor.configurable()) { if (throwException) - exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Attempting to change configurable attribute of unconfigurable property."))); + exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Attempting to configurable attribute of unconfigurable property."))); return false; } if (descriptor.enumerablePresent() && descriptor.enumerable() != current.enumerable()) { @@ -2616,7 +2536,7 @@ bool JSObject::defineOwnNonIndexProperty(ExecState* exec, PropertyName propertyN // A generic descriptor is simply changing the attributes of an existing property if (descriptor.isGenericDescriptor()) { if (!current.attributesEqual(descriptor)) { - methodTable(exec->vm())->deleteProperty(this, exec, propertyName); + methodTable()->deleteProperty(this, exec, propertyName); return putDescriptor(exec, this, propertyName, descriptor, descriptor.attributesOverridingCurrent(current), current); } return true; @@ -2629,7 +2549,7 @@ bool JSObject::defineOwnNonIndexProperty(ExecState* exec, PropertyName propertyN exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Attempting to change access mechanism for an unconfigurable property."))); return false; } - methodTable(exec->vm())->deleteProperty(this, exec, propertyName); + methodTable()->deleteProperty(this, exec, propertyName); return putDescriptor(exec, this, propertyName, descriptor, descriptor.attributesOverridingCurrent(current), current); } @@ -2651,7 +2571,7 @@ bool JSObject::defineOwnNonIndexProperty(ExecState* exec, PropertyName propertyN } if (current.attributesEqual(descriptor) && !descriptor.value()) return true; - methodTable(exec->vm())->deleteProperty(this, exec, propertyName); + methodTable()->deleteProperty(this, exec, propertyName); return putDescriptor(exec, this, propertyName, descriptor, descriptor.attributesOverridingCurrent(current), current); } @@ -2668,34 +2588,18 @@ bool JSObject::defineOwnNonIndexProperty(ExecState* exec, PropertyName propertyN exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Attempting to change the getter of an unconfigurable property."))); return false; } - if (current.attributes() & CustomAccessor) { - if (throwException) - exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Attempting to change access mechanism for an unconfigurable property."))); - return false; - } } JSValue accessor = getDirect(exec->vm(), propertyName); if (!accessor) return false; - GetterSetter* getterSetter; - bool getterSetterChanged = false; - if (accessor.isCustomGetterSetter()) - getterSetter = GetterSetter::create(exec->vm(), exec->lexicalGlobalObject()); - else { - ASSERT(accessor.isGetterSetter()); - getterSetter = asGetterSetter(accessor); - } - if (descriptor.setterPresent()) { - getterSetter = getterSetter->withSetter(exec->vm(), exec->lexicalGlobalObject(), descriptor.setterObject()); - getterSetterChanged = true; - } - if (descriptor.getterPresent()) { - getterSetter = getterSetter->withGetter(exec->vm(), exec->lexicalGlobalObject(), descriptor.getterObject()); - getterSetterChanged = true; - } - if (current.attributesEqual(descriptor) && !getterSetterChanged) + GetterSetter* getterSetter = asGetterSetter(accessor); + if (descriptor.setterPresent()) + getterSetter->setSetter(exec->vm(), descriptor.setterObject()); + if (descriptor.getterPresent()) + getterSetter->setGetter(exec->vm(), descriptor.getterObject()); + if (current.attributesEqual(descriptor)) return true; - methodTable(exec->vm())->deleteProperty(this, exec, propertyName); + methodTable()->deleteProperty(this, exec, propertyName); unsigned attrs = descriptor.attributesOverridingCurrent(current); putDirectAccessor(exec, propertyName, getterSetter, attrs | Accessor); return true; @@ -2704,120 +2608,31 @@ bool JSObject::defineOwnNonIndexProperty(ExecState* exec, PropertyName propertyN bool JSObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool throwException) { // If it's an array index, then use the indexed property storage. - if (Optional<uint32_t> index = parseIndex(propertyName)) { + unsigned index = propertyName.asIndex(); + if (index != PropertyName::NotAnIndex) { // c. Let succeeded be the result of calling the default [[DefineOwnProperty]] internal method (8.12.9) on A passing P, Desc, and false as arguments. // d. Reject if succeeded is false. // e. If index >= oldLen // e.i. Set oldLenDesc.[[Value]] to index + 1. // e.ii. Call the default [[DefineOwnProperty]] internal method (8.12.9) on A passing "length", oldLenDesc, and false as arguments. This call will always return true. // f. Return true. - return object->defineOwnIndexedProperty(exec, index.value(), descriptor, throwException); + return object->defineOwnIndexedProperty(exec, index, descriptor, throwException); } return object->defineOwnNonIndexProperty(exec, propertyName, descriptor, throwException); } -JSObject* throwTypeError(ExecState* exec, const String& message) -{ - return exec->vm().throwException(exec, createTypeError(exec, message)); -} - -void JSObject::convertToDictionary(VM& vm) -{ - DeferredStructureTransitionWatchpointFire deferredWatchpointFire; - setStructure( - vm, Structure::toCacheableDictionaryTransition(vm, structure(vm), &deferredWatchpointFire)); -} - -void JSObject::shiftButterflyAfterFlattening(VM& vm, size_t outOfLineCapacityBefore, size_t outOfLineCapacityAfter) +bool JSObject::getOwnPropertySlotSlow(ExecState* exec, PropertyName propertyName, PropertySlot& slot) { - Butterfly* butterfly = this->butterfly(); - size_t preCapacity = this->butterflyPreCapacity(); - void* currentBase = butterfly->base(preCapacity, outOfLineCapacityAfter); - void* newBase = butterfly->base(preCapacity, outOfLineCapacityBefore); - - memmove(newBase, currentBase, this->butterflyTotalSize()); - setButterflyWithoutChangingStructure(vm, Butterfly::fromBase(newBase, preCapacity, outOfLineCapacityAfter)); -} - -uint32_t JSObject::getEnumerableLength(ExecState* exec, JSObject* object) -{ - VM& vm = exec->vm(); - Structure* structure = object->structure(vm); - if (structure->holesMustForwardToPrototype(vm)) - return 0; - switch (object->indexingType()) { - case ALL_BLANK_INDEXING_TYPES: - case ALL_UNDECIDED_INDEXING_TYPES: - return 0; - - case ALL_INT32_INDEXING_TYPES: - case ALL_CONTIGUOUS_INDEXING_TYPES: { - Butterfly* butterfly = object->butterfly(); - unsigned usedLength = butterfly->publicLength(); - for (unsigned i = 0; i < usedLength; ++i) { - if (!butterfly->contiguous()[i]) - return 0; - } - return usedLength; - } - - case ALL_DOUBLE_INDEXING_TYPES: { - Butterfly* butterfly = object->butterfly(); - unsigned usedLength = butterfly->publicLength(); - for (unsigned i = 0; i < usedLength; ++i) { - double value = butterfly->contiguousDouble()[i]; - if (value != value) - return 0; - } - return usedLength; - } - - case ALL_ARRAY_STORAGE_INDEXING_TYPES: { - ArrayStorage* storage = object->m_butterfly->arrayStorage(); - if (storage->m_sparseMap.get()) - return 0; - - unsigned usedVectorLength = std::min(storage->length(), storage->vectorLength()); - for (unsigned i = 0; i < usedVectorLength; ++i) { - if (!storage->m_vector[i]) - return 0; - } - return usedVectorLength; - } - - default: - RELEASE_ASSERT_NOT_REACHED(); - return 0; - } -} - -void JSObject::getStructurePropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) -{ - VM& vm = exec->vm(); - object->structure(vm)->getPropertyNamesFromStructure(vm, propertyNames, mode); + unsigned i = propertyName.asIndex(); + if (i != PropertyName::NotAnIndex) + return getOwnPropertySlotByIndex(this, exec, i, slot); + return false; } -void JSObject::getGenericPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +JSObject* throwTypeError(ExecState* exec, const String& message) { - VM& vm = exec->vm(); - object->methodTable(vm)->getOwnPropertyNames(object, exec, propertyNames, EnumerationMode(mode, JSObjectPropertiesMode::Exclude)); - - if (object->prototype().isNull()) - return; - - JSObject* prototype = asObject(object->prototype()); - while (true) { - if (prototype->structure(vm)->typeInfo().overridesGetPropertyNames()) { - prototype->methodTable(vm)->getPropertyNames(prototype, exec, propertyNames, mode); - break; - } - prototype->methodTable(vm)->getOwnPropertyNames(prototype, exec, propertyNames, mode); - JSValue nextProto = prototype->prototype(); - if (nextProto.isNull()) - break; - prototype = asObject(nextProto); - } + return exec->vm().throwException(exec, createTypeError(exec, message)); } } // namespace JSC |