2 * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef IndexingType_h
27 #define IndexingType_h
29 #include "SpeculatedType.h"
30 #include <wtf/StdLibExtras.h>
35 Structure of the IndexingType
36 =============================
37 Conceptually, the IndexingType looks like this:
40 uint8_t isArray:1; // bit 0
41 uint8_t shape:4; // bit 1 - 4
42 uint8_t mayHaveIndexedAccessors:1; // bit 5
45 The shape values (e.g. Int32Shape, ContiguousShape, etc) are an enumeration of
46 various shapes (though not necessarily sequential in terms of their values).
47 Hence, shape values are not bitwise exclusive with respect to each other.
50 typedef uint8_t IndexingType;
52 // Flags for testing the presence of capabilities.
53 static const IndexingType IsArray = 0x01;
55 // The shape of the indexed property storage.
56 static const IndexingType IndexingShapeMask = 0x1E;
57 static const IndexingType NoIndexingShape = 0x00;
58 static const IndexingType UndecidedShape = 0x02; // Only useful for arrays.
59 static const IndexingType Int32Shape = 0x14;
60 static const IndexingType DoubleShape = 0x16;
61 static const IndexingType ContiguousShape = 0x1A;
62 static const IndexingType ArrayStorageShape = 0x1C;
63 static const IndexingType SlowPutArrayStorageShape = 0x1E;
65 static const IndexingType IndexingShapeShift = 1;
66 static const IndexingType NumberOfIndexingShapes = 16;
68 // Additional flags for tracking the history of the type. These are usually
69 // masked off unless you ask for them directly.
70 static const IndexingType MayHaveIndexedAccessors = 0x20;
72 // List of acceptable array types.
73 static const IndexingType NonArray = 0x0;
74 static const IndexingType NonArrayWithInt32 = Int32Shape;
75 static const IndexingType NonArrayWithDouble = DoubleShape;
76 static const IndexingType NonArrayWithContiguous = ContiguousShape;
77 static const IndexingType NonArrayWithArrayStorage = ArrayStorageShape;
78 static const IndexingType NonArrayWithSlowPutArrayStorage = SlowPutArrayStorageShape;
79 static const IndexingType ArrayClass = IsArray; // I'd want to call this "Array" but this would lead to disastrous namespace pollution.
80 static const IndexingType ArrayWithUndecided = IsArray | UndecidedShape;
81 static const IndexingType ArrayWithInt32 = IsArray | Int32Shape;
82 static const IndexingType ArrayWithDouble = IsArray | DoubleShape;
83 static const IndexingType ArrayWithContiguous = IsArray | ContiguousShape;
84 static const IndexingType ArrayWithArrayStorage = IsArray | ArrayStorageShape;
85 static const IndexingType ArrayWithSlowPutArrayStorage = IsArray | SlowPutArrayStorageShape;
87 #define ALL_BLANK_INDEXING_TYPES \
91 #define ALL_UNDECIDED_INDEXING_TYPES \
94 #define ALL_INT32_INDEXING_TYPES \
98 #define ALL_DOUBLE_INDEXING_TYPES \
102 #define ALL_CONTIGUOUS_INDEXING_TYPES \
103 NonArrayWithContiguous: \
104 case ArrayWithContiguous
106 #define ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES \
107 ArrayWithArrayStorage: \
108 case ArrayWithSlowPutArrayStorage
110 #define ALL_ARRAY_STORAGE_INDEXING_TYPES \
111 NonArrayWithArrayStorage: \
112 case NonArrayWithSlowPutArrayStorage: \
113 case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES
115 static inline bool hasIndexedProperties(IndexingType indexingType)
117 return (indexingType & IndexingShapeMask) != NoIndexingShape;
120 static inline bool hasUndecided(IndexingType indexingType)
122 return (indexingType & IndexingShapeMask) == UndecidedShape;
125 static inline bool hasInt32(IndexingType indexingType)
127 return (indexingType & IndexingShapeMask) == Int32Shape;
130 static inline bool hasDouble(IndexingType indexingType)
132 return (indexingType & IndexingShapeMask) == DoubleShape;
135 static inline bool hasContiguous(IndexingType indexingType)
137 return (indexingType & IndexingShapeMask) == ContiguousShape;
140 static inline bool hasArrayStorage(IndexingType indexingType)
142 return (indexingType & IndexingShapeMask) == ArrayStorageShape;
145 static inline bool hasAnyArrayStorage(IndexingType indexingType)
147 return static_cast<uint8_t>(indexingType & IndexingShapeMask) >= ArrayStorageShape;
150 static inline bool shouldUseSlowPut(IndexingType indexingType)
152 return (indexingType & IndexingShapeMask) == SlowPutArrayStorageShape;
155 // Return an indexing type that can handle all of the elements of both indexing types.
156 IndexingType leastUpperBoundOfIndexingTypes(IndexingType, IndexingType);
158 IndexingType leastUpperBoundOfIndexingTypeAndType(IndexingType, SpeculatedType);
159 IndexingType leastUpperBoundOfIndexingTypeAndValue(IndexingType, JSValue);
161 void dumpIndexingType(PrintStream&, IndexingType);
162 MAKE_PRINT_ADAPTOR(IndexingTypeDump, IndexingType, dumpIndexingType);
164 // Mask of all possible types.
165 static const IndexingType AllArrayTypes = 31;
167 // Mask of all possible types including the history.
168 static const IndexingType AllArrayTypesAndHistory = 127;
172 #endif // IndexingType_h