Exception is a JSCell, not a JSObject.
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSObject.h
1 /*
2  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
4  *  Copyright (C) 2003-2019 Apple Inc. All rights reserved.
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public License
17  *  along with this library; see the file COPYING.LIB.  If not, write to
18  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #pragma once
24
25 #include "ArrayConventions.h"
26 #include "ArrayStorage.h"
27 #include "Butterfly.h"
28 #include "CPU.h"
29 #include "CagedBarrierPtr.h"
30 #include "CallFrame.h"
31 #include "ClassInfo.h"
32 #include "CustomGetterSetter.h"
33 #include "DOMAttributeGetterSetter.h"
34 #include "Heap.h"
35 #include "IndexingHeaderInlines.h"
36 #include "JSCast.h"
37 #include "ObjectInitializationScope.h"
38 #include "PropertySlot.h"
39 #include "PropertyStorage.h"
40 #include "PutDirectIndexMode.h"
41 #include "PutPropertySlot.h"
42 #include "Structure.h"
43 #include "StructureTransitionTable.h"
44 #include "VM.h"
45 #include "JSString.h"
46 #include "SparseArrayValueMap.h"
47 #include <wtf/StdLibExtras.h>
48
49 namespace JSC {
50 namespace DOMJIT {
51 class Signature;
52 }
53
54 inline JSCell* getJSFunction(JSValue value)
55 {
56     if (value.isCell() && (value.asCell()->type() == JSFunctionType))
57         return value.asCell();
58     return 0;
59 }
60
61 class Exception;
62 class GetterSetter;
63 class InternalFunction;
64 class JSFunction;
65 class LLIntOffsetsExtractor;
66 class MarkedBlock;
67 class PropertyDescriptor;
68 class PropertyNameArray;
69 class Structure;
70 class ThrowScope;
71 struct HashTable;
72 struct HashTableValue;
73
74 JS_EXPORT_PRIVATE Exception* throwTypeError(ExecState*, ThrowScope&, const String&);
75 extern JS_EXPORT_PRIVATE const ASCIILiteral NonExtensibleObjectPropertyDefineError;
76 extern JS_EXPORT_PRIVATE const ASCIILiteral ReadonlyPropertyWriteError;
77 extern JS_EXPORT_PRIVATE const ASCIILiteral ReadonlyPropertyChangeError;
78 extern JS_EXPORT_PRIVATE const ASCIILiteral UnableToDeletePropertyError;
79 extern JS_EXPORT_PRIVATE const ASCIILiteral UnconfigurablePropertyChangeAccessMechanismError;
80 extern JS_EXPORT_PRIVATE const ASCIILiteral UnconfigurablePropertyChangeConfigurabilityError;
81 extern JS_EXPORT_PRIVATE const ASCIILiteral UnconfigurablePropertyChangeEnumerabilityError;
82 extern JS_EXPORT_PRIVATE const ASCIILiteral UnconfigurablePropertyChangeWritabilityError;
83
84 COMPILE_ASSERT(PropertyAttribute::None < FirstInternalAttribute, None_is_below_FirstInternalAttribute);
85 COMPILE_ASSERT(PropertyAttribute::ReadOnly < FirstInternalAttribute, ReadOnly_is_below_FirstInternalAttribute);
86 COMPILE_ASSERT(PropertyAttribute::DontEnum < FirstInternalAttribute, DontEnum_is_below_FirstInternalAttribute);
87 COMPILE_ASSERT(PropertyAttribute::DontDelete < FirstInternalAttribute, DontDelete_is_below_FirstInternalAttribute);
88 COMPILE_ASSERT(PropertyAttribute::Accessor < FirstInternalAttribute, Accessor_is_below_FirstInternalAttribute);
89
90 class JSFinalObject;
91
92 class JSObject : public JSCell {
93     friend class BatchedTransitionOptimizer;
94     friend class JIT;
95     friend class JSCell;
96     friend class JSFinalObject;
97     friend class MarkedBlock;
98     JS_EXPORT_PRIVATE friend bool setUpStaticFunctionSlot(VM&, const HashTableValue*, JSObject*, PropertyName, PropertySlot&);
99
100     enum PutMode {
101         PutModePut,
102         PutModeDefineOwnProperty,
103     };
104
105 public:
106     typedef JSCell Base;
107
108     // This is a super dangerous method for JITs. Sometimes the JITs will want to create either a
109     // JSFinalObject or a JSArray. This is the method that will do that.
110     static JSObject* createRawObject(ExecState* exec, Structure* structure, Butterfly* = nullptr);
111
112     JS_EXPORT_PRIVATE static size_t estimatedSize(JSCell*, VM&);
113     JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
114     JS_EXPORT_PRIVATE static void heapSnapshot(JSCell*, HeapSnapshotBuilder&);
115
116     JS_EXPORT_PRIVATE static String className(const JSObject*, VM&);
117     JS_EXPORT_PRIVATE static String calculatedClassName(JSObject*);
118
119     // This function is what Object.prototype.toString() will use to get the name of
120     // an object when using Symbol.toStringTag fails. For the most part there is no
121     // difference between this and className(). The main use case is for new JS language
122     // objects to set the default tag to "Object".
123     JS_EXPORT_PRIVATE static String toStringName(const JSObject*, ExecState*);
124
125     // This is the fully virtual [[GetPrototypeOf]] internal function defined
126     // in the ECMAScript 6 specification. Use this when doing a [[GetPrototypeOf]] 
127     // operation as dictated in the specification.
128     JSValue getPrototype(VM&, ExecState*);
129     JS_EXPORT_PRIVATE static JSValue getPrototype(JSObject*, ExecState*);
130     // This gets the prototype directly off of the structure. This does not do
131     // dynamic dispatch on the getPrototype method table method. It is not valid 
132     // to use this when performing a [[GetPrototypeOf]] operation in the specification.
133     // It is valid to use though when you know that you want to directly get it
134     // without consulting the method table. This is akin to getting the [[Prototype]]
135     // internal field directly as described in the specification.
136     JSValue getPrototypeDirect(VM&) const;
137
138     // This sets the prototype without checking for cycles and without
139     // doing dynamic dispatch on [[SetPrototypeOf]] operation in the specification.
140     // It is not valid to use this when performing a [[SetPrototypeOf]] operation in
141     // the specification. It is valid to use though when you know that you want to directly
142     // set it without consulting the method table and when you definitely won't
143     // introduce a cycle in the prototype chain. This is akin to setting the
144     // [[Prototype]] internal field directly as described in the specification.
145     JS_EXPORT_PRIVATE void setPrototypeDirect(VM&, JSValue prototype);
146 private:
147     // This is OrdinarySetPrototypeOf in the specification. Section 9.1.2.1
148     // https://tc39.github.io/ecma262/#sec-ordinarysetprototypeof
149     JS_EXPORT_PRIVATE bool setPrototypeWithCycleCheck(VM&, ExecState*, JSValue prototype, bool shouldThrowIfCantSet);
150 public:
151     // This is the fully virtual [[SetPrototypeOf]] internal function defined
152     // in the ECMAScript 6 specification. Use this when doing a [[SetPrototypeOf]] 
153     // operation as dictated in the specification.
154     bool setPrototype(VM&, ExecState*, JSValue prototype, bool shouldThrowIfCantSet = false);
155     JS_EXPORT_PRIVATE static bool setPrototype(JSObject*, ExecState*, JSValue prototype, bool shouldThrowIfCantSet);
156         
157     inline bool mayInterceptIndexedAccesses(VM&);
158
159     JSValue get(ExecState*, PropertyName) const;
160     JSValue get(ExecState*, unsigned propertyName) const;
161
162     template<bool checkNullStructure = false>
163     bool getPropertySlot(ExecState*, PropertyName, PropertySlot&);
164     bool getPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
165     template<typename CallbackWhenNoException> typename std::result_of<CallbackWhenNoException(bool, PropertySlot&)>::type getPropertySlot(ExecState*, PropertyName, CallbackWhenNoException) const;
166     template<typename CallbackWhenNoException> typename std::result_of<CallbackWhenNoException(bool, PropertySlot&)>::type getPropertySlot(ExecState*, PropertyName, PropertySlot&, CallbackWhenNoException) const;
167
168     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
169     JS_EXPORT_PRIVATE static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
170     bool getOwnPropertySlotInline(ExecState*, PropertyName, PropertySlot&);
171
172     // The key difference between this and getOwnPropertySlot is that getOwnPropertySlot
173     // currently returns incorrect results for the DOM window (with non-own properties)
174     // being returned. Once this is fixed we should migrate code & remove this method.
175     JS_EXPORT_PRIVATE bool getOwnPropertyDescriptor(ExecState*, PropertyName, PropertyDescriptor&);
176
177     unsigned getArrayLength() const
178     {
179         if (!hasIndexedProperties(indexingType()))
180             return 0;
181         return m_butterfly->publicLength();
182     }
183         
184     unsigned getVectorLength()
185     {
186         if (!hasIndexedProperties(indexingType()))
187             return 0;
188         return m_butterfly->vectorLength();
189     }
190     
191     static bool putInlineForJSObject(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
192     
193     JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
194     // putByIndex assumes that the receiver is this JSCell object.
195     JS_EXPORT_PRIVATE static bool putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
196         
197     // This performs the ECMAScript Set() operation.
198     ALWAYS_INLINE bool putByIndexInline(ExecState* exec, unsigned propertyName, JSValue value, bool shouldThrow)
199     {
200         if (canSetIndexQuickly(propertyName)) {
201             setIndexQuickly(exec->vm(), propertyName, value);
202             return true;
203         }
204         return methodTable(exec->vm())->putByIndex(this, exec, propertyName, value, shouldThrow);
205     }
206         
207     // This is similar to the putDirect* methods:
208     //  - the prototype chain is not consulted
209     //  - accessors are not called.
210     //  - it will ignore extensibility and read-only properties if PutDirectIndexLikePutDirect is passed as the mode (the default).
211     // This method creates a property with attributes writable, enumerable and configurable all set to true if attributes is zero,
212     // otherwise, it creates a property with the provided attributes. Semantically, this is performing defineOwnProperty.
213     bool putDirectIndex(ExecState* exec, unsigned propertyName, JSValue value, unsigned attributes, PutDirectIndexMode mode)
214     {
215         ASSERT(!value.isCustomGetterSetter());
216         auto canSetIndexQuicklyForPutDirect = [&] () -> bool {
217             switch (indexingMode()) {
218             case ALL_BLANK_INDEXING_TYPES:
219             case ALL_UNDECIDED_INDEXING_TYPES:
220                 return false;
221             case ALL_WRITABLE_INT32_INDEXING_TYPES:
222             case ALL_WRITABLE_DOUBLE_INDEXING_TYPES:
223             case ALL_WRITABLE_CONTIGUOUS_INDEXING_TYPES:
224             case ALL_ARRAY_STORAGE_INDEXING_TYPES:
225                 return propertyName < m_butterfly->vectorLength();
226             default:
227                 if (isCopyOnWrite(indexingMode()))
228                     return false;
229                 RELEASE_ASSERT_NOT_REACHED();
230                 return false;
231             }
232         };
233         
234         if (!attributes && canSetIndexQuicklyForPutDirect()) {
235             setIndexQuickly(exec->vm(), propertyName, value);
236             return true;
237         }
238         return putDirectIndexSlowOrBeyondVectorLength(exec, propertyName, value, attributes, mode);
239     }
240     // This is semantically equivalent to performing defineOwnProperty(propertyName, {configurable:true, writable:true, enumerable:true, value:value}).
241     bool putDirectIndex(ExecState* exec, unsigned propertyName, JSValue value)
242     {
243         return putDirectIndex(exec, propertyName, value, 0, PutDirectIndexLikePutDirect);
244     }
245
246     // A generally non-throwing version of putDirect and putDirectIndex.
247     // However, it's only guaranteed to not throw based on what the receiver is.
248     // For example, if the receiver is a ProxyObject, this is not guaranteed, since
249     // it may call into arbitrary JS code. It's the responsibility of the user of
250     // this API to ensure that the receiver object is a well known type if they
251     // want to ensure that this won't throw an exception.
252     JS_EXPORT_PRIVATE bool putDirectMayBeIndex(ExecState*, PropertyName, JSValue);
253         
254     bool hasIndexingHeader(VM& vm) const
255     {
256         return structure(vm)->hasIndexingHeader(this);
257     }
258     
259     bool canGetIndexQuickly(unsigned i)
260     {
261         Butterfly* butterfly = this->butterfly();
262         switch (indexingType()) {
263         case ALL_BLANK_INDEXING_TYPES:
264         case ALL_UNDECIDED_INDEXING_TYPES:
265             return false;
266         case ALL_INT32_INDEXING_TYPES:
267         case ALL_CONTIGUOUS_INDEXING_TYPES:
268             return i < butterfly->vectorLength() && butterfly->contiguous().at(this, i);
269         case ALL_DOUBLE_INDEXING_TYPES: {
270             if (i >= butterfly->vectorLength())
271                 return false;
272             double value = butterfly->contiguousDouble().at(this, i);
273             if (value != value)
274                 return false;
275             return true;
276         }
277         case ALL_ARRAY_STORAGE_INDEXING_TYPES:
278             return i < butterfly->arrayStorage()->vectorLength() && butterfly->arrayStorage()->m_vector[i];
279         default:
280             RELEASE_ASSERT_NOT_REACHED();
281             return false;
282         }
283     }
284         
285     JSValue getIndexQuickly(unsigned i)
286     {
287         Butterfly* butterfly = this->butterfly();
288         switch (indexingType()) {
289         case ALL_INT32_INDEXING_TYPES:
290             return jsNumber(butterfly->contiguous().at(this, i).get().asInt32());
291         case ALL_CONTIGUOUS_INDEXING_TYPES:
292             return butterfly->contiguous().at(this, i).get();
293         case ALL_DOUBLE_INDEXING_TYPES:
294             return JSValue(JSValue::EncodeAsDouble, butterfly->contiguousDouble().at(this, i));
295         case ALL_ARRAY_STORAGE_INDEXING_TYPES:
296             return butterfly->arrayStorage()->m_vector[i].get();
297         default:
298             RELEASE_ASSERT_NOT_REACHED();
299             return JSValue();
300         }
301     }
302         
303     JSValue tryGetIndexQuickly(unsigned i) const
304     {
305         Butterfly* butterfly = const_cast<JSObject*>(this)->butterfly();
306         switch (indexingType()) {
307         case ALL_BLANK_INDEXING_TYPES:
308         case ALL_UNDECIDED_INDEXING_TYPES:
309             break;
310         case ALL_INT32_INDEXING_TYPES:
311             if (i < butterfly->publicLength()) {
312                 JSValue result = butterfly->contiguous().at(this, i).get();
313                 ASSERT(result.isInt32() || !result);
314                 return result;
315             }
316             break;
317         case ALL_CONTIGUOUS_INDEXING_TYPES:
318             if (i < butterfly->publicLength())
319                 return butterfly->contiguous().at(this, i).get();
320             break;
321         case ALL_DOUBLE_INDEXING_TYPES: {
322             if (i >= butterfly->publicLength())
323                 break;
324             double result = butterfly->contiguousDouble().at(this, i);
325             if (result != result)
326                 break;
327             return JSValue(JSValue::EncodeAsDouble, result);
328         }
329         case ALL_ARRAY_STORAGE_INDEXING_TYPES:
330             if (i < butterfly->arrayStorage()->vectorLength())
331                 return butterfly->arrayStorage()->m_vector[i].get();
332             break;
333         default:
334             RELEASE_ASSERT_NOT_REACHED();
335             break;
336         }
337         return JSValue();
338     }
339         
340     JSValue getDirectIndex(ExecState* exec, unsigned i)
341     {
342         if (JSValue result = tryGetIndexQuickly(i))
343             return result;
344         PropertySlot slot(this, PropertySlot::InternalMethodType::Get);
345         if (methodTable(exec->vm())->getOwnPropertySlotByIndex(this, exec, i, slot))
346             return slot.getValue(exec, i);
347         return JSValue();
348     }
349         
350     JSValue getIndex(ExecState* exec, unsigned i) const
351     {
352         if (JSValue result = tryGetIndexQuickly(i))
353             return result;
354         return get(exec, i);
355     }
356         
357     bool canSetIndexQuickly(unsigned i)
358     {
359         Butterfly* butterfly = this->butterfly();
360         switch (indexingMode()) {
361         case ALL_BLANK_INDEXING_TYPES:
362         case ALL_UNDECIDED_INDEXING_TYPES:
363             return false;
364         case ALL_WRITABLE_INT32_INDEXING_TYPES:
365         case ALL_WRITABLE_DOUBLE_INDEXING_TYPES:
366         case ALL_WRITABLE_CONTIGUOUS_INDEXING_TYPES:
367         case NonArrayWithArrayStorage:
368         case ArrayWithArrayStorage:
369             return i < butterfly->vectorLength();
370         case NonArrayWithSlowPutArrayStorage:
371         case ArrayWithSlowPutArrayStorage:
372             return i < butterfly->arrayStorage()->vectorLength()
373                 && !!butterfly->arrayStorage()->m_vector[i];
374         default:
375             if (isCopyOnWrite(indexingMode()))
376                 return false;
377             RELEASE_ASSERT_NOT_REACHED();
378             return false;
379         }
380     }
381         
382     void setIndexQuickly(VM& vm, unsigned i, JSValue v)
383     {
384         Butterfly* butterfly = m_butterfly.get();
385         ASSERT(!isCopyOnWrite(indexingMode()));
386         switch (indexingType()) {
387         case ALL_INT32_INDEXING_TYPES: {
388             ASSERT(i < butterfly->vectorLength());
389             if (!v.isInt32()) {
390                 convertInt32ToDoubleOrContiguousWhilePerformingSetIndex(vm, i, v);
391                 return;
392             }
393             FALLTHROUGH;
394         }
395         case ALL_CONTIGUOUS_INDEXING_TYPES: {
396             ASSERT(i < butterfly->vectorLength());
397             butterfly->contiguous().at(this, i).set(vm, this, v);
398             if (i >= butterfly->publicLength())
399                 butterfly->setPublicLength(i + 1);
400             break;
401         }
402         case ALL_DOUBLE_INDEXING_TYPES: {
403             ASSERT(i < butterfly->vectorLength());
404             if (!v.isNumber()) {
405                 convertDoubleToContiguousWhilePerformingSetIndex(vm, i, v);
406                 return;
407             }
408             double value = v.asNumber();
409             if (value != value) {
410                 convertDoubleToContiguousWhilePerformingSetIndex(vm, i, v);
411                 return;
412             }
413             butterfly->contiguousDouble().at(this, i) = value;
414             if (i >= butterfly->publicLength())
415                 butterfly->setPublicLength(i + 1);
416             break;
417         }
418         case ALL_ARRAY_STORAGE_INDEXING_TYPES: {
419             ArrayStorage* storage = butterfly->arrayStorage();
420             WriteBarrier<Unknown>& x = storage->m_vector[i];
421             JSValue old = x.get();
422             x.set(vm, this, v);
423             if (!old) {
424                 ++storage->m_numValuesInVector;
425                 if (i >= storage->length())
426                     storage->setLength(i + 1);
427             }
428             break;
429         }
430         default:
431             RELEASE_ASSERT_NOT_REACHED();
432         }
433     }
434
435     void initializeIndex(ObjectInitializationScope& scope, unsigned i, JSValue v)
436     {
437         initializeIndex(scope, i, v, indexingType());
438     }
439
440     // NOTE: Clients of this method may call it more than once for any index, and this is supposed
441     // to work.
442     ALWAYS_INLINE void initializeIndex(ObjectInitializationScope& scope, unsigned i, JSValue v, IndexingType indexingType)
443     {
444         VM& vm = scope.vm();
445         Butterfly* butterfly = m_butterfly.get();
446         switch (indexingType) {
447         case ALL_UNDECIDED_INDEXING_TYPES: {
448             setIndexQuicklyToUndecided(vm, i, v);
449             break;
450         }
451         case ALL_INT32_INDEXING_TYPES: {
452             ASSERT(i < butterfly->publicLength());
453             ASSERT(i < butterfly->vectorLength());
454             if (!v.isInt32()) {
455                 convertInt32ToDoubleOrContiguousWhilePerformingSetIndex(vm, i, v);
456                 break;
457             }
458             FALLTHROUGH;
459         }
460         case ALL_CONTIGUOUS_INDEXING_TYPES: {
461             ASSERT(i < butterfly->publicLength());
462             ASSERT(i < butterfly->vectorLength());
463             butterfly->contiguous().at(this, i).set(vm, this, v);
464             break;
465         }
466         case ALL_DOUBLE_INDEXING_TYPES: {
467             ASSERT(i < butterfly->publicLength());
468             ASSERT(i < butterfly->vectorLength());
469             if (!v.isNumber()) {
470                 convertDoubleToContiguousWhilePerformingSetIndex(vm, i, v);
471                 return;
472             }
473             double value = v.asNumber();
474             if (value != value) {
475                 convertDoubleToContiguousWhilePerformingSetIndex(vm, i, v);
476                 return;
477             }
478             butterfly->contiguousDouble().at(this, i) = value;
479             break;
480         }
481         case ALL_ARRAY_STORAGE_INDEXING_TYPES: {
482             ArrayStorage* storage = butterfly->arrayStorage();
483             ASSERT(i < storage->length());
484             ASSERT(i < storage->m_numValuesInVector);
485             storage->m_vector[i].set(vm, this, v);
486             break;
487         }
488         default:
489             RELEASE_ASSERT_NOT_REACHED();
490         }
491     }
492         
493     void initializeIndexWithoutBarrier(ObjectInitializationScope& scope, unsigned i, JSValue v)
494     {
495         initializeIndexWithoutBarrier(scope, i, v, indexingType());
496     }
497
498     // This version of initializeIndex is for cases where you know that you will not need any
499     // barriers. This implies not having any data format conversions.
500     ALWAYS_INLINE void initializeIndexWithoutBarrier(ObjectInitializationScope&, unsigned i, JSValue v, IndexingType indexingType)
501     {
502         Butterfly* butterfly = m_butterfly.get();
503         switch (indexingType) {
504         case ALL_UNDECIDED_INDEXING_TYPES: {
505             RELEASE_ASSERT_NOT_REACHED();
506             break;
507         }
508         case ALL_INT32_INDEXING_TYPES: {
509             ASSERT(i < butterfly->publicLength());
510             ASSERT(i < butterfly->vectorLength());
511             RELEASE_ASSERT(v.isInt32());
512             FALLTHROUGH;
513         }
514         case ALL_CONTIGUOUS_INDEXING_TYPES: {
515             ASSERT(i < butterfly->publicLength());
516             ASSERT(i < butterfly->vectorLength());
517             butterfly->contiguous().at(this, i).setWithoutWriteBarrier(v);
518             break;
519         }
520         case ALL_DOUBLE_INDEXING_TYPES: {
521             ASSERT(i < butterfly->publicLength());
522             ASSERT(i < butterfly->vectorLength());
523             RELEASE_ASSERT(v.isNumber());
524             double value = v.asNumber();
525             RELEASE_ASSERT(value == value);
526             butterfly->contiguousDouble().at(this, i) = value;
527             break;
528         }
529         case ALL_ARRAY_STORAGE_INDEXING_TYPES: {
530             ArrayStorage* storage = butterfly->arrayStorage();
531             ASSERT(i < storage->length());
532             ASSERT(i < storage->m_numValuesInVector);
533             storage->m_vector[i].setWithoutWriteBarrier(v);
534             break;
535         }
536         default:
537             RELEASE_ASSERT_NOT_REACHED();
538         }
539     }
540         
541     bool hasSparseMap()
542     {
543         switch (indexingType()) {
544         case ALL_BLANK_INDEXING_TYPES:
545         case ALL_UNDECIDED_INDEXING_TYPES:
546         case ALL_INT32_INDEXING_TYPES:
547         case ALL_DOUBLE_INDEXING_TYPES:
548         case ALL_CONTIGUOUS_INDEXING_TYPES:
549             return false;
550         case ALL_ARRAY_STORAGE_INDEXING_TYPES:
551             return !!m_butterfly->arrayStorage()->m_sparseMap;
552         default:
553             RELEASE_ASSERT_NOT_REACHED();
554             return false;
555         }
556     }
557         
558     bool inSparseIndexingMode()
559     {
560         switch (indexingType()) {
561         case ALL_BLANK_INDEXING_TYPES:
562         case ALL_UNDECIDED_INDEXING_TYPES:
563         case ALL_INT32_INDEXING_TYPES:
564         case ALL_DOUBLE_INDEXING_TYPES:
565         case ALL_CONTIGUOUS_INDEXING_TYPES:
566             return false;
567         case ALL_ARRAY_STORAGE_INDEXING_TYPES:
568             return m_butterfly->arrayStorage()->inSparseMode();
569         default:
570             RELEASE_ASSERT_NOT_REACHED();
571             return false;
572         }
573     }
574         
575     void enterDictionaryIndexingMode(VM&);
576
577     // putDirect is effectively an unchecked vesion of 'defineOwnProperty':
578     //  - the prototype chain is not consulted
579     //  - accessors are not called.
580     //  - attributes will be respected (after the call the property will exist with the given attributes)
581     //  - the property name is assumed to not be an index.
582     bool putDirect(VM&, PropertyName, JSValue, unsigned attributes = 0);
583     bool putDirect(VM&, PropertyName, JSValue, PutPropertySlot&);
584     void putDirectWithoutTransition(VM&, PropertyName, JSValue, unsigned attributes = 0);
585     bool putDirectNonIndexAccessor(VM&, PropertyName, GetterSetter*, unsigned attributes);
586     bool putDirectAccessor(ExecState*, PropertyName, GetterSetter*, unsigned attributes);
587     JS_EXPORT_PRIVATE bool putDirectCustomAccessor(VM&, PropertyName, JSValue, unsigned attributes);
588
589     bool putGetter(ExecState*, PropertyName, JSValue, unsigned attributes);
590     bool putSetter(ExecState*, PropertyName, JSValue, unsigned attributes);
591
592     JS_EXPORT_PRIVATE bool hasProperty(ExecState*, PropertyName) const;
593     JS_EXPORT_PRIVATE bool hasProperty(ExecState*, unsigned propertyName) const;
594     bool hasPropertyGeneric(ExecState*, PropertyName, PropertySlot::InternalMethodType) const;
595     bool hasPropertyGeneric(ExecState*, unsigned propertyName, PropertySlot::InternalMethodType) const;
596     bool hasOwnProperty(ExecState*, PropertyName, PropertySlot&) const;
597     bool hasOwnProperty(ExecState*, PropertyName) const;
598     bool hasOwnProperty(ExecState*, unsigned) const;
599
600     JS_EXPORT_PRIVATE static bool deleteProperty(JSCell*, ExecState*, PropertyName);
601     JS_EXPORT_PRIVATE static bool deletePropertyByIndex(JSCell*, ExecState*, unsigned propertyName);
602
603     JS_EXPORT_PRIVATE static JSValue defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType);
604     JSValue ordinaryToPrimitive(ExecState*, PreferredPrimitiveType) const;
605
606     JS_EXPORT_PRIVATE bool hasInstance(ExecState*, JSValue value, JSValue hasInstanceValue);
607     JS_EXPORT_PRIVATE bool hasInstance(ExecState*, JSValue);
608     static bool defaultHasInstance(ExecState*, JSValue, JSValue prototypeProperty);
609
610     JS_EXPORT_PRIVATE static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
611     JS_EXPORT_PRIVATE static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
612     JS_EXPORT_PRIVATE static void getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
613
614     JS_EXPORT_PRIVATE static uint32_t getEnumerableLength(ExecState*, JSObject*);
615     JS_EXPORT_PRIVATE static void getStructurePropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
616     JS_EXPORT_PRIVATE static void getGenericPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
617
618     JS_EXPORT_PRIVATE JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
619     bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
620     JS_EXPORT_PRIVATE double toNumber(ExecState*) const;
621     JS_EXPORT_PRIVATE JSString* toString(ExecState*) const;
622
623     JS_EXPORT_PRIVATE static JSValue toThis(JSCell*, ExecState*, ECMAMode);
624
625     // This get function only looks at the property map.
626     JSValue getDirect(VM& vm, PropertyName propertyName) const
627     {
628         Structure* structure = this->structure(vm);
629         PropertyOffset offset = structure->get(vm, propertyName);
630         checkOffset(offset, structure->inlineCapacity());
631         return offset != invalidOffset ? getDirect(offset) : JSValue();
632     }
633     
634     JSValue getDirect(VM& vm, PropertyName propertyName, unsigned& attributes) const
635     {
636         Structure* structure = this->structure(vm);
637         PropertyOffset offset = structure->get(vm, propertyName, attributes);
638         checkOffset(offset, structure->inlineCapacity());
639         return offset != invalidOffset ? getDirect(offset) : JSValue();
640     }
641
642     PropertyOffset getDirectOffset(VM& vm, PropertyName propertyName)
643     {
644         Structure* structure = this->structure(vm);
645         PropertyOffset offset = structure->get(vm, propertyName);
646         checkOffset(offset, structure->inlineCapacity());
647         return offset;
648     }
649
650     PropertyOffset getDirectOffset(VM& vm, PropertyName propertyName, unsigned& attributes)
651     {
652         Structure* structure = this->structure(vm);
653         PropertyOffset offset = structure->get(vm, propertyName, attributes);
654         checkOffset(offset, structure->inlineCapacity());
655         return offset;
656     }
657
658     bool hasInlineStorage() const { return structure()->hasInlineStorage(); }
659     ConstPropertyStorage inlineStorageUnsafe() const
660     {
661         return bitwise_cast<ConstPropertyStorage>(this + 1);
662     }
663     PropertyStorage inlineStorageUnsafe()
664     {
665         return bitwise_cast<PropertyStorage>(this + 1);
666     }
667     ConstPropertyStorage inlineStorage() const
668     {
669         ASSERT(hasInlineStorage());
670         return inlineStorageUnsafe();
671     }
672     PropertyStorage inlineStorage()
673     {
674         ASSERT(hasInlineStorage());
675         return inlineStorageUnsafe();
676     }
677         
678     const Butterfly* butterfly() const { return m_butterfly.get(); }
679     Butterfly* butterfly() { return m_butterfly.get(); }
680     
681     ConstPropertyStorage outOfLineStorage() const { return m_butterfly->propertyStorage(); }
682     PropertyStorage outOfLineStorage() { return m_butterfly->propertyStorage(); }
683
684     ALWAYS_INLINE const WriteBarrierBase<Unknown>* locationForOffset(PropertyOffset offset) const
685     {
686         if (isInlineOffset(offset))
687             return &inlineStorage()[offsetInInlineStorage(offset)];
688         return &outOfLineStorage()[offsetInOutOfLineStorage(offset)];
689     }
690
691     ALWAYS_INLINE WriteBarrierBase<Unknown>* locationForOffset(PropertyOffset offset)
692     {
693         if (isInlineOffset(offset))
694             return &inlineStorage()[offsetInInlineStorage(offset)];
695         return &outOfLineStorage()[offsetInOutOfLineStorage(offset)];
696     }
697
698     void transitionTo(VM&, Structure*);
699
700     bool hasCustomProperties(VM& vm) { return structure(vm)->didTransition(); }
701     bool hasGetterSetterProperties(VM& vm) { return structure(vm)->hasGetterSetterProperties(); }
702     bool hasCustomGetterSetterProperties(VM& vm) { return structure(vm)->hasCustomGetterSetterProperties(); }
703
704     // putOwnDataProperty has 'put' like semantics, however this method:
705     //  - assumes the object contains no own getter/setter properties.
706     //  - provides no special handling for __proto__
707     //  - does not walk the prototype chain (to check for accessors or non-writable properties).
708     // This is used by JSLexicalEnvironment.
709     bool putOwnDataProperty(VM&, PropertyName, JSValue, PutPropertySlot&);
710     bool putOwnDataPropertyMayBeIndex(ExecState*, PropertyName, JSValue, PutPropertySlot&);
711
712     // Fast access to known property offsets.
713     ALWAYS_INLINE JSValue getDirect(PropertyOffset offset) const { return locationForOffset(offset)->get(); }
714     JSValue getDirectConcurrently(Structure* expectedStructure, PropertyOffset) const;
715     void putDirect(VM& vm, PropertyOffset offset, JSValue value) { locationForOffset(offset)->set(vm, this, value); }
716     void putDirectWithoutBarrier(PropertyOffset offset, JSValue value) { locationForOffset(offset)->setWithoutWriteBarrier(value); }
717     void putDirectUndefined(PropertyOffset offset) { locationForOffset(offset)->setUndefined(); }
718
719     JS_EXPORT_PRIVATE bool putDirectNativeIntrinsicGetter(VM&, JSGlobalObject*, Identifier, NativeFunction, Intrinsic, unsigned attributes);
720     JS_EXPORT_PRIVATE bool putDirectNativeFunction(VM&, JSGlobalObject*, const PropertyName&, unsigned functionLength, NativeFunction, Intrinsic, unsigned attributes);
721     JS_EXPORT_PRIVATE bool putDirectNativeFunction(VM&, JSGlobalObject*, const PropertyName&, unsigned functionLength, NativeFunction, Intrinsic, const DOMJIT::Signature*, unsigned attributes);
722     JS_EXPORT_PRIVATE void putDirectNativeFunctionWithoutTransition(VM&, JSGlobalObject*, const PropertyName&, unsigned functionLength, NativeFunction, Intrinsic, unsigned attributes);
723
724     JS_EXPORT_PRIVATE JSFunction* putDirectBuiltinFunction(VM&, JSGlobalObject*, const PropertyName&, FunctionExecutable*, unsigned attributes);
725     JSFunction* putDirectBuiltinFunctionWithoutTransition(VM&, JSGlobalObject*, const PropertyName&, FunctionExecutable*, unsigned attributes);
726
727     JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
728
729     bool isEnvironment() const;
730     bool isGlobalObject() const;
731     bool isJSLexicalEnvironment() const;
732     bool isGlobalLexicalEnvironment() const;
733     bool isStrictEvalActivation() const;
734     bool isWithScope() const;
735
736     bool isErrorInstance() const;
737
738     JS_EXPORT_PRIVATE void seal(VM&);
739     JS_EXPORT_PRIVATE void freeze(VM&);
740     JS_EXPORT_PRIVATE static bool preventExtensions(JSObject*, ExecState*);
741     JS_EXPORT_PRIVATE static bool isExtensible(JSObject*, ExecState*);
742     bool isSealed(VM& vm) { return structure(vm)->isSealed(vm); }
743     bool isFrozen(VM& vm) { return structure(vm)->isFrozen(vm); }
744
745     bool anyObjectInChainMayInterceptIndexedAccesses(VM&) const;
746     JS_EXPORT_PRIVATE bool prototypeChainMayInterceptStoreTo(VM&, PropertyName);
747     bool needsSlowPutIndexing(VM&) const;
748
749 private:
750     NonPropertyTransition suggestedArrayStorageTransition(VM&) const;
751 public:
752     // You should only call isStructureExtensible() when:
753     // - Performing this check in a way that isn't described in the specification 
754     //   as calling the virtual [[IsExtensible]] trap.
755     // - When you're guaranteed that object->methodTable(vm)->isExtensible isn't
756     //   overridden.
757     ALWAYS_INLINE bool isStructureExtensible(VM& vm) { return structure(vm)->isStructureExtensible(); }
758     // You should call this when performing [[IsExtensible]] trap in a place
759     // that is described in the specification. This performs the fully virtual
760     // [[IsExtensible]] trap.
761     bool isExtensible(ExecState*);
762     bool indexingShouldBeSparse(VM& vm)
763     {
764         return !isStructureExtensible(vm)
765             || structure(vm)->typeInfo().interceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero();
766     }
767
768     bool staticPropertiesReified(VM& vm) { return structure(vm)->staticPropertiesReified(); }
769     void reifyAllStaticProperties(ExecState*);
770
771     JS_EXPORT_PRIVATE Butterfly* allocateMoreOutOfLineStorage(VM&, size_t oldSize, size_t newSize);
772
773     // Call this when you do not need to change the structure.
774     void setButterfly(VM&, Butterfly*);
775     
776     // Call this if you do need to change the structure, or if you changed something about a structure
777     // in-place.
778     void nukeStructureAndSetButterfly(VM&, StructureID oldStructureID, Butterfly*);
779
780     void setStructure(VM&, Structure*);
781
782     JS_EXPORT_PRIVATE void convertToDictionary(VM&);
783
784     void flattenDictionaryObject(VM& vm)
785     {
786         structure(vm)->flattenDictionaryStructure(vm, this);
787     }
788     void shiftButterflyAfterFlattening(const GCSafeConcurrentJSLocker&, VM&, Structure* structure, size_t outOfLineCapacityAfter);
789
790     JSGlobalObject* globalObject() const
791     {
792         ASSERT(structure()->globalObject());
793         ASSERT(!isGlobalObject() || ((JSObject*)structure()->globalObject()) == this);
794         return structure()->globalObject();
795     }
796         
797     JSGlobalObject* globalObject(VM& vm) const
798     {
799         ASSERT(structure(vm)->globalObject());
800         ASSERT(!isGlobalObject() || ((JSObject*)structure(vm)->globalObject()) == this);
801         return structure(vm)->globalObject();
802     }
803         
804     void switchToSlowPutArrayStorage(VM&);
805         
806     // The receiver is the prototype in this case. The following:
807     //
808     // asObject(foo->structure()->storedPrototype())->attemptToInterceptPutByIndexOnHoleForPrototype(...)
809     //
810     // is equivalent to:
811     //
812     // foo->attemptToInterceptPutByIndexOnHole(...);
813     bool attemptToInterceptPutByIndexOnHoleForPrototype(ExecState*, JSValue thisValue, unsigned propertyName, JSValue, bool shouldThrow, bool& putResult);
814         
815     // Returns 0 if int32 storage cannot be created - either because
816     // indexing should be sparse, we're having a bad time, or because
817     // we already have a more general form of storage (double,
818     // contiguous, array storage).
819     ContiguousJSValues tryMakeWritableInt32(VM& vm)
820     {
821         if (LIKELY(hasInt32(indexingType()) && !isCopyOnWrite(indexingMode())))
822             return m_butterfly->contiguousInt32();
823             
824         return tryMakeWritableInt32Slow(vm);
825     }
826         
827     // Returns 0 if double storage cannot be created - either because
828     // indexing should be sparse, we're having a bad time, or because
829     // we already have a more general form of storage (contiguous,
830     // or array storage).
831     ContiguousDoubles tryMakeWritableDouble(VM& vm)
832     {
833         if (LIKELY(hasDouble(indexingType()) && !isCopyOnWrite(indexingMode())))
834             return m_butterfly->contiguousDouble();
835             
836         return tryMakeWritableDoubleSlow(vm);
837     }
838         
839     // Returns 0 if contiguous storage cannot be created - either because
840     // indexing should be sparse or because we're having a bad time.
841     ContiguousJSValues tryMakeWritableContiguous(VM& vm)
842     {
843         if (LIKELY(hasContiguous(indexingType()) && !isCopyOnWrite(indexingMode())))
844             return m_butterfly->contiguous();
845             
846         return tryMakeWritableContiguousSlow(vm);
847     }
848
849     // Ensure that the object is in a mode where it has array storage. Use
850     // this if you're about to perform actions that would have required the
851     // object to be converted to have array storage, if it didn't have it
852     // already.
853     ArrayStorage* ensureArrayStorage(VM& vm)
854     {
855         if (LIKELY(hasAnyArrayStorage(indexingType())))
856             return m_butterfly->arrayStorage();
857
858         return ensureArrayStorageSlow(vm);
859     }
860
861     void ensureWritable(VM& vm)
862     {
863         if (isCopyOnWrite(indexingMode()))
864             convertFromCopyOnWrite(vm);
865     }
866         
867     static size_t offsetOfInlineStorage();
868         
869     static ptrdiff_t butterflyOffset()
870     {
871         return OBJECT_OFFSETOF(JSObject, m_butterfly);
872     }
873     void* butterflyAddress()
874     {
875         return &m_butterfly;
876     }
877
878     JS_EXPORT_PRIVATE JSValue getMethod(ExecState*, CallData&, CallType&, const Identifier&, const String& errorMessage);
879
880     bool canPerformFastPutInline(VM&, PropertyName);
881     bool canPerformFastPutInlineExcludingProto(VM&);
882
883     bool mayBePrototype() const;
884     void didBecomePrototype();
885
886     DECLARE_EXPORT_INFO;
887
888 protected:
889     void finishCreation(VM& vm)
890     {
891         Base::finishCreation(vm);
892         ASSERT(jsDynamicCast<JSObject*>(vm, this));
893         ASSERT(structure(vm)->hasPolyProto() || getPrototypeDirect(vm).isNull() || Heap::heap(this) == Heap::heap(getPrototypeDirect(vm)));
894         ASSERT(structure(vm)->isObject());
895         ASSERT(classInfo(vm));
896     }
897
898     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
899     {
900         return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
901     }
902
903     // To instantiate objects you likely want JSFinalObject, below.
904     // To create derived types you likely want JSNonFinalObject, below.
905     JSObject(VM&, Structure*, Butterfly* = nullptr);
906     
907     // Visits the butterfly unless there is a race. Returns the structure if there was no race.
908     Structure* visitButterfly(SlotVisitor&);
909     
910     Structure* visitButterflyImpl(SlotVisitor&);
911     
912     void markAuxiliaryAndVisitOutOfLineProperties(SlotVisitor&, Butterfly*, Structure*, PropertyOffset lastOffset);
913
914     // Call this if you know that the object is in a mode where it has array
915     // storage. This will assert otherwise.
916     ArrayStorage* arrayStorage()
917     {
918         ASSERT(hasAnyArrayStorage(indexingType()));
919         return m_butterfly->arrayStorage();
920     }
921         
922     // Call this if you want to predicate some actions on whether or not the
923     // object is in a mode where it has array storage.
924     ArrayStorage* arrayStorageOrNull()
925     {
926         switch (indexingType()) {
927         case ALL_ARRAY_STORAGE_INDEXING_TYPES:
928             return m_butterfly->arrayStorage();
929                 
930         default:
931             return 0;
932         }
933     }
934         
935     size_t butterflyTotalSize();
936     size_t butterflyPreCapacity();
937
938     Butterfly* createInitialUndecided(VM&, unsigned length);
939     ContiguousJSValues createInitialInt32(VM&, unsigned length);
940     ContiguousDoubles createInitialDouble(VM&, unsigned length);
941     ContiguousJSValues createInitialContiguous(VM&, unsigned length);
942
943     void convertUndecidedForValue(VM&, JSValue);
944     void createInitialForValueAndSet(VM&, unsigned index, JSValue);
945     void convertInt32ForValue(VM&, JSValue);
946     void convertDoubleForValue(VM&, JSValue);
947     void convertFromCopyOnWrite(VM&);
948
949     static Butterfly* createArrayStorageButterfly(VM&, JSObject* intendedOwner, Structure*, unsigned length, unsigned vectorLength, Butterfly* oldButterfly = nullptr);
950     ArrayStorage* createArrayStorage(VM&, unsigned length, unsigned vectorLength);
951     ArrayStorage* createInitialArrayStorage(VM&);
952         
953     ContiguousJSValues convertUndecidedToInt32(VM&);
954     ContiguousDoubles convertUndecidedToDouble(VM&);
955     ContiguousJSValues convertUndecidedToContiguous(VM&);
956     ArrayStorage* convertUndecidedToArrayStorage(VM&, NonPropertyTransition);
957     ArrayStorage* convertUndecidedToArrayStorage(VM&);
958         
959     ContiguousDoubles convertInt32ToDouble(VM&);
960     ContiguousJSValues convertInt32ToContiguous(VM&);
961     ArrayStorage* convertInt32ToArrayStorage(VM&, NonPropertyTransition);
962     ArrayStorage* convertInt32ToArrayStorage(VM&);
963
964     ContiguousJSValues convertDoubleToContiguous(VM&);
965     ArrayStorage* convertDoubleToArrayStorage(VM&, NonPropertyTransition);
966     ArrayStorage* convertDoubleToArrayStorage(VM&);
967         
968     ArrayStorage* convertContiguousToArrayStorage(VM&, NonPropertyTransition);
969     ArrayStorage* convertContiguousToArrayStorage(VM&);
970
971         
972     ArrayStorage* ensureArrayStorageExistsAndEnterDictionaryIndexingMode(VM&);
973         
974     bool defineOwnNonIndexProperty(ExecState*, PropertyName, const PropertyDescriptor&, bool throwException);
975
976     template<IndexingType indexingShape>
977     bool putByIndexBeyondVectorLengthWithoutAttributes(ExecState*, unsigned propertyName, JSValue);
978     bool putByIndexBeyondVectorLengthWithArrayStorage(ExecState*, unsigned propertyName, JSValue, bool shouldThrow, ArrayStorage*);
979
980     bool increaseVectorLength(VM&, unsigned newLength);
981     void deallocateSparseIndexMap();
982     bool defineOwnIndexedProperty(ExecState*, unsigned, const PropertyDescriptor&, bool throwException);
983     SparseArrayValueMap* allocateSparseIndexMap(VM&);
984         
985     void notifyPresenceOfIndexedAccessors(VM&);
986         
987     bool attemptToInterceptPutByIndexOnHole(ExecState*, unsigned index, JSValue, bool shouldThrow, bool& putResult);
988         
989     // Call this if you want setIndexQuickly to succeed and you're sure that
990     // the array is contiguous.
991     bool WARN_UNUSED_RETURN ensureLength(VM& vm, unsigned length)
992     {
993         RELEASE_ASSERT(length <= MAX_STORAGE_VECTOR_LENGTH);
994         ASSERT(hasContiguous(indexingType()) || hasInt32(indexingType()) || hasDouble(indexingType()) || hasUndecided(indexingType()));
995
996         if (m_butterfly->vectorLength() < length || isCopyOnWrite(indexingMode())) {
997             if (!ensureLengthSlow(vm, length))
998                 return false;
999         }
1000             
1001         if (m_butterfly->publicLength() < length)
1002             m_butterfly->setPublicLength(length);
1003         return true;
1004     }
1005         
1006     // Call this if you want to shrink the butterfly backing store, and you're
1007     // sure that the array is contiguous.
1008     void reallocateAndShrinkButterfly(VM&, unsigned length);
1009     
1010     template<IndexingType indexingShape>
1011     unsigned countElements(Butterfly*);
1012         
1013     // This is relevant to undecided, int32, double, and contiguous.
1014     unsigned countElements();
1015         
1016 private:
1017     friend class LLIntOffsetsExtractor;
1018     friend class VMInspector;
1019
1020     // Nobody should ever ask any of these questions on something already known to be a JSObject.
1021     using JSCell::isAPIValueWrapper;
1022     using JSCell::isGetterSetter;
1023     void getObject();
1024     void getString(ExecState* exec);
1025     void isObject();
1026     void isString();
1027         
1028     Butterfly* createInitialIndexedStorage(VM&, unsigned length);
1029         
1030     ArrayStorage* enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(VM&, ArrayStorage*);
1031         
1032     template<PutMode>
1033     bool putDirectInternal(VM&, PropertyName, JSValue, unsigned attr, PutPropertySlot&);
1034
1035     JS_EXPORT_PRIVATE NEVER_INLINE bool putInlineSlow(ExecState*, PropertyName, JSValue, PutPropertySlot&);
1036
1037     bool getNonIndexPropertySlot(ExecState*, PropertyName, PropertySlot&);
1038     bool getOwnNonIndexPropertySlot(VM&, Structure*, PropertyName, PropertySlot&);
1039     JS_EXPORT_PRIVATE void fillGetterPropertySlot(VM&, PropertySlot&, JSCell*, unsigned, PropertyOffset);
1040     void fillCustomGetterPropertySlot(VM&, PropertySlot&, CustomGetterSetter*, unsigned, Structure*);
1041
1042     JS_EXPORT_PRIVATE bool getOwnStaticPropertySlot(VM&, PropertyName, PropertySlot&);
1043     struct PropertyHashEntry {
1044         const HashTable* table;
1045         const HashTableValue* value;
1046     };
1047     Optional<PropertyHashEntry> findPropertyHashEntry(VM&, PropertyName) const;
1048         
1049     bool putByIndexBeyondVectorLength(ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
1050     bool putDirectIndexBeyondVectorLengthWithArrayStorage(ExecState*, unsigned propertyName, JSValue, unsigned attributes, PutDirectIndexMode, ArrayStorage*);
1051     JS_EXPORT_PRIVATE bool putDirectIndexSlowOrBeyondVectorLength(ExecState*, unsigned propertyName, JSValue, unsigned attributes, PutDirectIndexMode);
1052         
1053     unsigned getNewVectorLength(VM&, unsigned indexBias, unsigned currentVectorLength, unsigned currentLength, unsigned desiredLength);
1054     unsigned getNewVectorLength(VM&, unsigned desiredLength);
1055
1056     ArrayStorage* constructConvertedArrayStorageWithoutCopyingElements(VM&, unsigned neededLength);
1057         
1058     JS_EXPORT_PRIVATE void setIndexQuicklyToUndecided(VM&, unsigned index, JSValue);
1059     JS_EXPORT_PRIVATE void convertInt32ToDoubleOrContiguousWhilePerformingSetIndex(VM&, unsigned index, JSValue);
1060     JS_EXPORT_PRIVATE void convertDoubleToContiguousWhilePerformingSetIndex(VM&, unsigned index, JSValue);
1061         
1062     bool ensureLengthSlow(VM&, unsigned length);
1063         
1064     ContiguousJSValues tryMakeWritableInt32Slow(VM&);
1065     ContiguousDoubles tryMakeWritableDoubleSlow(VM&);
1066     ContiguousJSValues tryMakeWritableContiguousSlow(VM&);
1067     JS_EXPORT_PRIVATE ArrayStorage* ensureArrayStorageSlow(VM&);
1068
1069     PropertyOffset prepareToPutDirectWithoutTransition(VM&, PropertyName, unsigned attributes, StructureID, Structure*);
1070
1071     AuxiliaryBarrier<Butterfly*> m_butterfly;
1072 #if CPU(ADDRESS32)
1073     unsigned m_32BitPadding;
1074 #endif
1075 };
1076
1077 // JSNonFinalObject is a type of JSObject that has some internal storage,
1078 // but also preserves some space in the collector cell for additional
1079 // data members in derived types.
1080 class JSNonFinalObject : public JSObject {
1081     friend class JSObject;
1082
1083 public:
1084     typedef JSObject Base;
1085
1086     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
1087     {
1088         return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
1089     }
1090
1091 protected:
1092     explicit JSNonFinalObject(VM& vm, Structure* structure, Butterfly* butterfly = 0)
1093         : JSObject(vm, structure, butterfly)
1094     {
1095     }
1096
1097     void finishCreation(VM& vm)
1098     {
1099         Base::finishCreation(vm);
1100         ASSERT(!this->structure(vm)->hasInlineStorage());
1101         ASSERT(classInfo(vm));
1102     }
1103 };
1104
1105 class JSFinalObject;
1106
1107 // JSFinalObject is a type of JSObject that contains sufficient internal
1108 // storage to fully make use of the collector cell containing it.
1109 class JSFinalObject final : public JSObject {
1110     friend class JSObject;
1111
1112 public:
1113     typedef JSObject Base;
1114     static const unsigned StructureFlags = Base::StructureFlags;
1115
1116     static size_t allocationSize(Checked<size_t> inlineCapacity)
1117     {
1118         return (sizeof(JSObject) + inlineCapacity * sizeof(WriteBarrierBase<Unknown>)).unsafeGet();
1119     }
1120
1121     static inline const TypeInfo typeInfo() { return TypeInfo(FinalObjectType, StructureFlags); }
1122     static const IndexingType defaultIndexingType = NonArray;
1123         
1124     static const unsigned defaultSize = 64;
1125     static inline unsigned defaultInlineCapacity()
1126     {
1127         return (defaultSize - allocationSize(0)) / sizeof(WriteBarrier<Unknown>);
1128     }
1129
1130     static const unsigned maxSize = 512;
1131     static inline unsigned maxInlineCapacity()
1132     {
1133         return (maxSize - allocationSize(0)) / sizeof(WriteBarrier<Unknown>);
1134     }
1135
1136     static JSFinalObject* create(ExecState*, Structure*, Butterfly* = nullptr);
1137     static JSFinalObject* create(VM&, Structure*);
1138     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype, unsigned inlineCapacity)
1139     {
1140         return Structure::create(vm, globalObject, prototype, typeInfo(), info(), defaultIndexingType, inlineCapacity);
1141     }
1142
1143     JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
1144
1145     DECLARE_EXPORT_INFO;
1146
1147 protected:
1148     void visitChildrenCommon(SlotVisitor&);
1149         
1150     void finishCreation(VM& vm)
1151     {
1152         Base::finishCreation(vm);
1153         ASSERT(structure(vm)->totalStorageCapacity() == structure(vm)->inlineCapacity());
1154         ASSERT(classInfo(vm));
1155     }
1156
1157 private:
1158     friend class LLIntOffsetsExtractor;
1159
1160     explicit JSFinalObject(VM& vm, Structure* structure, Butterfly* butterfly = nullptr)
1161         : JSObject(vm, structure, butterfly)
1162     {
1163         memset(inlineStorageUnsafe(), 0, structure->inlineCapacity() * sizeof(EncodedJSValue));
1164     }
1165 };
1166
1167 JS_EXPORT_PRIVATE EncodedJSValue JSC_HOST_CALL objectPrivateFuncInstanceOf(ExecState*);
1168
1169 inline JSObject* JSObject::createRawObject(
1170     ExecState* exec, Structure* structure, Butterfly* butterfly)
1171 {
1172     VM& vm = exec->vm();
1173     JSObject* finalObject = new (
1174         NotNull, 
1175         allocateCell<JSFinalObject>(
1176             vm.heap,
1177             JSFinalObject::allocationSize(structure->inlineCapacity())
1178         )
1179     ) JSObject(vm, structure, butterfly);
1180     finalObject->finishCreation(vm);
1181     return finalObject;
1182 }
1183
1184 inline JSFinalObject* JSFinalObject::create(
1185     ExecState* exec, Structure* structure, Butterfly* butterfly)
1186 {
1187     VM& vm = exec->vm();
1188     JSFinalObject* finalObject = new (
1189         NotNull, 
1190         allocateCell<JSFinalObject>(
1191             vm.heap,
1192             allocationSize(structure->inlineCapacity())
1193         )
1194     ) JSFinalObject(vm, structure, butterfly);
1195     finalObject->finishCreation(vm);
1196     return finalObject;
1197 }
1198
1199 inline JSFinalObject* JSFinalObject::create(VM& vm, Structure* structure)
1200 {
1201     JSFinalObject* finalObject = new (NotNull, allocateCell<JSFinalObject>(vm.heap, allocationSize(structure->inlineCapacity()))) JSFinalObject(vm, structure);
1202     finalObject->finishCreation(vm);
1203     return finalObject;
1204 }
1205
1206 inline size_t JSObject::offsetOfInlineStorage()
1207 {
1208     return sizeof(JSObject);
1209 }
1210
1211 inline bool JSObject::isGlobalObject() const
1212 {
1213     return type() == GlobalObjectType;
1214 }
1215
1216 inline bool JSObject::isJSLexicalEnvironment() const
1217 {
1218     return type() == LexicalEnvironmentType || type() == ModuleEnvironmentType;
1219 }
1220
1221 inline bool JSObject::isGlobalLexicalEnvironment() const
1222 {
1223     return type() == GlobalLexicalEnvironmentType;
1224 }
1225
1226 inline bool JSObject::isStrictEvalActivation() const
1227 {
1228     return type() == StrictEvalActivationType;
1229 }
1230
1231 inline bool JSObject::isEnvironment() const
1232 {
1233     bool result = GlobalObjectType <= type() && type() <= StrictEvalActivationType;
1234     ASSERT((isGlobalObject() || isJSLexicalEnvironment() || isGlobalLexicalEnvironment() || isStrictEvalActivation()) == result);
1235     return result;
1236 }
1237
1238 inline bool JSObject::isErrorInstance() const
1239 {
1240     return type() == ErrorInstanceType;
1241 }
1242
1243 inline bool JSObject::isWithScope() const
1244 {
1245     return type() == WithScopeType;
1246 }
1247
1248 inline void JSObject::setStructure(VM& vm, Structure* structure)
1249 {
1250     ASSERT(structure);
1251     ASSERT(!m_butterfly == !(structure->outOfLineCapacity() || structure->hasIndexingHeader(this)));
1252     JSCell::setStructure(vm, structure);
1253 }
1254
1255 inline void JSObject::setButterfly(VM& vm, Butterfly* butterfly)
1256 {
1257     if (isX86() || vm.heap.mutatorShouldBeFenced()) {
1258         WTF::storeStoreFence();
1259         m_butterfly.set(vm, this, butterfly);
1260         WTF::storeStoreFence();
1261         return;
1262     }
1263
1264     m_butterfly.set(vm, this, butterfly);
1265 }
1266
1267 inline void JSObject::nukeStructureAndSetButterfly(VM& vm, StructureID oldStructureID, Butterfly* butterfly)
1268 {
1269     if (isX86() || vm.heap.mutatorShouldBeFenced()) {
1270         setStructureIDDirectly(nuke(oldStructureID));
1271         WTF::storeStoreFence();
1272         m_butterfly.set(vm, this, butterfly);
1273         WTF::storeStoreFence();
1274         return;
1275     }
1276
1277     m_butterfly.set(vm, this, butterfly);
1278 }
1279
1280 inline CallType getCallData(VM& vm, JSValue value, CallData& callData)
1281 {
1282     CallType result = value.isCell() ? value.asCell()->methodTable(vm)->getCallData(value.asCell(), callData) : CallType::None;
1283     ASSERT(result == CallType::None || value.isValidCallee());
1284     return result;
1285 }
1286
1287 inline ConstructType getConstructData(VM& vm, JSValue value, ConstructData& constructData)
1288 {
1289     ConstructType result = value.isCell() ? value.asCell()->methodTable(vm)->getConstructData(value.asCell(), constructData) : ConstructType::None;
1290     ASSERT(result == ConstructType::None || value.isValidCallee());
1291     return result;
1292 }
1293
1294 inline JSObject* asObject(JSCell* cell)
1295 {
1296     ASSERT(cell->isObject());
1297     return jsCast<JSObject*>(cell);
1298 }
1299
1300 inline JSObject* asObject(JSValue value)
1301 {
1302     return asObject(value.asCell());
1303 }
1304
1305 inline JSObject::JSObject(VM& vm, Structure* structure, Butterfly* butterfly)
1306     : JSCell(vm, structure)
1307     , m_butterfly(vm, this, butterfly)
1308 {
1309 }
1310
1311 inline JSValue JSObject::getPrototypeDirect(VM& vm) const
1312 {
1313     return structure(vm)->storedPrototype(this);
1314 }
1315
1316 inline JSValue JSObject::getPrototype(VM& vm, ExecState* exec)
1317 {
1318     auto getPrototypeMethod = methodTable(vm)->getPrototype;
1319     MethodTable::GetPrototypeFunctionPtr defaultGetPrototype = JSObject::getPrototype;
1320     if (LIKELY(getPrototypeMethod == defaultGetPrototype))
1321         return getPrototypeDirect(vm);
1322     return getPrototypeMethod(this, exec);
1323 }
1324
1325 // Normally, we never shrink the butterfly so if we know an offset is valid for some
1326 // past structure then it should be valid for any new structure. However, we may sometimes
1327 // shrink the butterfly when we are holding the Structure's ConcurrentJSLock, such as when we
1328 // flatten an object.
1329 inline JSValue JSObject::getDirectConcurrently(Structure* structure, PropertyOffset offset) const
1330 {
1331     ConcurrentJSLocker locker(structure->lock());
1332     if (!structure->isValidOffset(offset))
1333         return { };
1334     return getDirect(offset);
1335 }
1336
1337 // It is safe to call this method with a PropertyName that is actually an index,
1338 // but if so will always return false (doesn't search index storage).
1339 ALWAYS_INLINE bool JSObject::getOwnNonIndexPropertySlot(VM& vm, Structure* structure, PropertyName propertyName, PropertySlot& slot)
1340 {
1341     unsigned attributes;
1342     PropertyOffset offset = structure->get(vm, propertyName, attributes);
1343     if (!isValidOffset(offset)) {
1344         if (!TypeInfo::hasStaticPropertyTable(inlineTypeFlags()))
1345             return false;
1346         return getOwnStaticPropertySlot(vm, propertyName, slot);
1347     }
1348     
1349     // getPropertySlot relies on this method never returning index properties!
1350     ASSERT(!parseIndex(propertyName));
1351
1352     JSValue value = getDirect(offset);
1353     if (value.isCell()) {
1354         ASSERT(value);
1355         JSCell* cell = value.asCell();
1356         JSType type = cell->type();
1357         switch (type) {
1358         case GetterSetterType:
1359             fillGetterPropertySlot(vm, slot, cell, attributes, offset);
1360             return true;
1361         case CustomGetterSetterType:
1362             fillCustomGetterPropertySlot(vm, slot, jsCast<CustomGetterSetter*>(cell), attributes, structure);
1363             return true;
1364         default:
1365             break;
1366         }
1367     }
1368     
1369     slot.setValue(this, attributes, value, offset);
1370     return true;
1371 }
1372
1373 ALWAYS_INLINE void JSObject::fillCustomGetterPropertySlot(VM& vm, PropertySlot& slot, CustomGetterSetter* customGetterSetter, unsigned attributes, Structure* structure)
1374 {
1375     ASSERT(attributes & PropertyAttribute::CustomAccessorOrValue);
1376     if (customGetterSetter->inherits<DOMAttributeGetterSetter>(vm)) {
1377         auto* domAttribute = jsCast<DOMAttributeGetterSetter*>(customGetterSetter);
1378         if (structure->isUncacheableDictionary())
1379             slot.setCustom(this, attributes, domAttribute->getter(), domAttribute->domAttribute());
1380         else
1381             slot.setCacheableCustom(this, attributes, domAttribute->getter(), domAttribute->domAttribute());
1382         return;
1383     }
1384
1385     if (structure->isUncacheableDictionary())
1386         slot.setCustom(this, attributes, customGetterSetter->getter());
1387     else
1388         slot.setCacheableCustom(this, attributes, customGetterSetter->getter());
1389 }
1390
1391 // It may seem crazy to inline a function this large, especially a virtual function,
1392 // but it makes a big difference to property lookup that derived classes can inline their
1393 // base class call to this.
1394 ALWAYS_INLINE bool JSObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1395 {
1396     VM& vm = exec->vm();
1397     Structure* structure = object->structure(vm);
1398     if (object->getOwnNonIndexPropertySlot(vm, structure, propertyName, slot))
1399         return true;
1400     if (Optional<uint32_t> index = parseIndex(propertyName))
1401         return getOwnPropertySlotByIndex(object, exec, index.value(), slot);
1402     return false;
1403 }
1404
1405 // It may seem crazy to inline a function this large but it makes a big difference
1406 // since this is function very hot in variable lookup
1407 template<bool checkNullStructure>
1408 ALWAYS_INLINE bool JSObject::getPropertySlot(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1409 {
1410     VM& vm = exec->vm();
1411     auto& structureIDTable = vm.heap.structureIDTable();
1412     JSObject* object = this;
1413     while (true) {
1414         if (UNLIKELY(TypeInfo::overridesGetOwnPropertySlot(object->inlineTypeFlags()))) {
1415             // If propertyName is an index then we may have missed it (as this loop is using
1416             // getOwnNonIndexPropertySlot), so we cannot safely call the overridden getOwnPropertySlot
1417             // (lest we return a property from a prototype that is shadowed). Check now for an index,
1418             // if so we need to start afresh from this object.
1419             if (Optional<uint32_t> index = parseIndex(propertyName))
1420                 return getPropertySlot(exec, index.value(), slot);
1421             // Safe to continue searching from current position; call getNonIndexPropertySlot to avoid
1422             // parsing the int again.
1423             return object->getNonIndexPropertySlot(exec, propertyName, slot);
1424         }
1425         ASSERT(object->type() != ProxyObjectType);
1426         Structure* structure = structureIDTable.get(object->structureID());
1427 #if USE(JSVALUE64)
1428         if (checkNullStructure && UNLIKELY(!structure))
1429             CRASH_WITH_INFO(object->type(), object->structureID(), structureIDTable.size());
1430 #endif
1431         if (object->getOwnNonIndexPropertySlot(vm, structure, propertyName, slot))
1432             return true;
1433         // FIXME: This doesn't look like it's following the specification:
1434         // https://bugs.webkit.org/show_bug.cgi?id=172572
1435         JSValue prototype = structure->storedPrototype(object);
1436         if (!prototype.isObject())
1437             break;
1438         object = asObject(prototype);
1439     }
1440
1441     if (Optional<uint32_t> index = parseIndex(propertyName))
1442         return getPropertySlot(exec, index.value(), slot);
1443     return false;
1444 }
1445
1446 inline JSValue JSObject::get(ExecState* exec, PropertyName propertyName) const
1447 {
1448     VM& vm = exec->vm();
1449     auto scope = DECLARE_THROW_SCOPE(vm);
1450     PropertySlot slot(this, PropertySlot::InternalMethodType::Get);
1451     bool hasProperty = const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot);
1452     EXCEPTION_ASSERT(!scope.exception() || !hasProperty);
1453     if (hasProperty)
1454         RELEASE_AND_RETURN(scope, slot.getValue(exec, propertyName));
1455
1456     return jsUndefined();
1457 }
1458
1459 inline JSValue JSObject::get(ExecState* exec, unsigned propertyName) const
1460 {
1461     VM& vm = exec->vm();
1462     auto scope = DECLARE_THROW_SCOPE(vm);
1463     PropertySlot slot(this, PropertySlot::InternalMethodType::Get);
1464     bool hasProperty = const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot);
1465     EXCEPTION_ASSERT(!scope.exception() || !hasProperty);
1466     if (hasProperty)
1467         RELEASE_AND_RETURN(scope, slot.getValue(exec, propertyName));
1468
1469     return jsUndefined();
1470 }
1471
1472 inline bool JSObject::putOwnDataProperty(VM& vm, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
1473 {
1474     ASSERT(value);
1475     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
1476     ASSERT(!structure(vm)->hasGetterSetterProperties());
1477     ASSERT(!structure(vm)->hasCustomGetterSetterProperties());
1478
1479     return putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot);
1480 }
1481
1482 inline bool JSObject::putOwnDataPropertyMayBeIndex(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
1483 {
1484     VM& vm = exec->vm();
1485     ASSERT(value);
1486     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
1487     ASSERT(!structure(vm)->hasGetterSetterProperties());
1488     ASSERT(!structure(vm)->hasCustomGetterSetterProperties());
1489
1490     if (Optional<uint32_t> index = parseIndex(propertyName))
1491         return putDirectIndex(exec, index.value(), value, 0, PutDirectIndexLikePutDirect);
1492
1493     return putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot);
1494 }
1495
1496 inline bool JSObject::putDirect(VM& vm, PropertyName propertyName, JSValue value, unsigned attributes)
1497 {
1498     ASSERT(!value.isGetterSetter() && !(attributes & PropertyAttribute::Accessor));
1499     ASSERT(!value.isCustomGetterSetter() && !(attributes & PropertyAttribute::CustomAccessorOrValue));
1500     PutPropertySlot slot(this);
1501     return putDirectInternal<PutModeDefineOwnProperty>(vm, propertyName, value, attributes, slot);
1502 }
1503
1504 inline bool JSObject::putDirect(VM& vm, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
1505 {
1506     ASSERT(!value.isGetterSetter());
1507     ASSERT(!value.isCustomGetterSetter());
1508     return putDirectInternal<PutModeDefineOwnProperty>(vm, propertyName, value, 0, slot);
1509 }
1510
1511 ALWAYS_INLINE JSObject* Register::object() const
1512 {
1513     return asObject(jsValue());
1514 }
1515
1516 ALWAYS_INLINE Register& Register::operator=(JSObject* object)
1517 {
1518     u.value = JSValue::encode(JSValue(object));
1519     return *this;
1520 }
1521
1522 inline size_t offsetInButterfly(PropertyOffset offset)
1523 {
1524     return offsetInOutOfLineStorage(offset) + Butterfly::indexOfPropertyStorage();
1525 }
1526
1527 inline size_t JSObject::butterflyPreCapacity()
1528 {
1529     VM& vm = *this->vm();
1530     if (UNLIKELY(hasIndexingHeader(vm)))
1531         return butterfly()->indexingHeader()->preCapacity(structure(vm));
1532     return 0;
1533 }
1534
1535 inline size_t JSObject::butterflyTotalSize()
1536 {
1537     VM& vm = *this->vm();
1538     Structure* structure = this->structure(vm);
1539     Butterfly* butterfly = this->butterfly();
1540     size_t preCapacity;
1541     size_t indexingPayloadSizeInBytes;
1542     bool hasIndexingHeader = this->hasIndexingHeader(vm);
1543
1544     if (UNLIKELY(hasIndexingHeader)) {
1545         preCapacity = butterfly->indexingHeader()->preCapacity(structure);
1546         indexingPayloadSizeInBytes = butterfly->indexingHeader()->indexingPayloadSizeInBytes(structure);
1547     } else {
1548         preCapacity = 0;
1549         indexingPayloadSizeInBytes = 0;
1550     }
1551
1552     return Butterfly::totalSize(preCapacity, structure->outOfLineCapacity(), hasIndexingHeader, indexingPayloadSizeInBytes);
1553 }
1554
1555 inline int indexRelativeToBase(PropertyOffset offset)
1556 {
1557     if (isOutOfLineOffset(offset))
1558         return offsetInOutOfLineStorage(offset) + Butterfly::indexOfPropertyStorage();
1559     ASSERT(!(JSObject::offsetOfInlineStorage() % sizeof(EncodedJSValue)));
1560     return JSObject::offsetOfInlineStorage() / sizeof(EncodedJSValue) + offsetInInlineStorage(offset);
1561 }
1562
1563 inline int offsetRelativeToBase(PropertyOffset offset)
1564 {
1565     if (isOutOfLineOffset(offset))
1566         return offsetInOutOfLineStorage(offset) * sizeof(EncodedJSValue) + Butterfly::offsetOfPropertyStorage();
1567     return JSObject::offsetOfInlineStorage() + offsetInInlineStorage(offset) * sizeof(EncodedJSValue);
1568 }
1569
1570 // Returns the maximum offset (away from zero) a load instruction will encode.
1571 inline size_t maxOffsetRelativeToBase(PropertyOffset offset)
1572 {
1573     ptrdiff_t addressOffset = offsetRelativeToBase(offset);
1574 #if USE(JSVALUE32_64)
1575     if (addressOffset >= 0)
1576         return static_cast<size_t>(addressOffset) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag);
1577 #endif
1578     return static_cast<size_t>(addressOffset);
1579 }
1580
1581 COMPILE_ASSERT(!(sizeof(JSObject) % sizeof(WriteBarrierBase<Unknown>)), JSObject_inline_storage_has_correct_alignment);
1582
1583 template<unsigned charactersCount>
1584 ALWAYS_INLINE Identifier makeIdentifier(VM& vm, const char (&characters)[charactersCount])
1585 {
1586     return Identifier::fromString(&vm, characters);
1587 }
1588
1589 ALWAYS_INLINE Identifier makeIdentifier(VM& vm, const char* name)
1590 {
1591     return Identifier::fromString(&vm, name);
1592 }
1593
1594 ALWAYS_INLINE Identifier makeIdentifier(VM&, const Identifier& name)
1595 {
1596     return name;
1597 }
1598
1599 bool validateAndApplyPropertyDescriptor(ExecState*, JSObject*, PropertyName, bool isExtensible,
1600     const PropertyDescriptor& descriptor, bool isCurrentDefined, const PropertyDescriptor& current, bool throwException);
1601
1602 JS_EXPORT_PRIVATE NEVER_INLINE bool ordinarySetSlow(ExecState*, JSObject*, PropertyName, JSValue, JSValue receiver, bool shouldThrow);
1603
1604 // Helper for defining native functions, if you're not using a static hash table.
1605 // Use this macro from within finishCreation() methods in prototypes. This assumes
1606 // you've defined variables called exec, globalObject, and vm, and they
1607 // have the expected meanings.
1608 #define JSC_NATIVE_INTRINSIC_FUNCTION(jsName, cppName, attributes, length, intrinsic) \
1609     putDirectNativeFunction(\
1610         vm, globalObject, makeIdentifier(vm, (jsName)), (length), cppName, \
1611         (intrinsic), (attributes))
1612
1613 #define JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(jsName, cppName, attributes, length, intrinsic) \
1614     putDirectNativeFunctionWithoutTransition(\
1615         vm, globalObject, makeIdentifier(vm, (jsName)), (length), cppName, \
1616         (intrinsic), (attributes))
1617
1618 // As above, but this assumes that the function you're defining doesn't have an
1619 // intrinsic.
1620 #define JSC_NATIVE_FUNCTION(jsName, cppName, attributes, length) \
1621     JSC_NATIVE_INTRINSIC_FUNCTION(jsName, cppName, (attributes), (length), NoIntrinsic)
1622
1623 #define JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(jsName, cppName, attributes, length) \
1624     JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(jsName, cppName, (attributes), (length), NoIntrinsic)
1625
1626 // Identical helpers but for builtins. Note that currently, we don't support builtins that are
1627 // also intrinsics, but we probably will do that eventually.
1628 #define JSC_BUILTIN_FUNCTION(jsName, generatorName, attributes) \
1629     putDirectBuiltinFunction(\
1630         vm, globalObject, makeIdentifier(vm, (jsName)), (generatorName)(vm), (attributes))
1631
1632 #define JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(jsName, generatorName, attributes) \
1633     putDirectBuiltinFunctionWithoutTransition(\
1634         vm, globalObject, makeIdentifier(vm, (jsName)), (generatorName)(vm), (attributes))
1635
1636 // Helper for defining native getters on properties.
1637 #define JSC_NATIVE_INTRINSIC_GETTER(jsName, cppName, attributes, intrinsic)  \
1638     putDirectNativeIntrinsicGetter(\
1639         vm, globalObject, makeIdentifier(vm, (jsName)), (cppName), \
1640         (intrinsic), ((attributes) | PropertyAttribute::Accessor))
1641
1642 #define JSC_NATIVE_GETTER(jsName, cppName, attributes) \
1643     JSC_NATIVE_INTRINSIC_GETTER((jsName), (cppName), (attributes), NoIntrinsic)
1644
1645 } // namespace JSC