2
* Copyright (C) 2012 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>
34
typedef uint8_t IndexingType;
36
// Flags for testing the presence of capabilities.
37
static const IndexingType IsArray = 1;
39
// The shape of the indexed property storage.
40
static const IndexingType IndexingShapeMask = 30;
41
static const IndexingType NoIndexingShape = 0;
42
static const IndexingType UndecidedShape = 2; // Only useful for arrays.
43
static const IndexingType Int32Shape = 20;
44
static const IndexingType DoubleShape = 22;
45
static const IndexingType ContiguousShape = 26;
46
static const IndexingType ArrayStorageShape = 28;
47
static const IndexingType SlowPutArrayStorageShape = 30;
49
static const IndexingType IndexingShapeShift = 1;
50
static const IndexingType NumberOfIndexingShapes = 16;
52
// Additional flags for tracking the history of the type. These are usually
53
// masked off unless you ask for them directly.
54
static const IndexingType MayHaveIndexedAccessors = 32;
56
// List of acceptable array types.
57
static const IndexingType NonArray = 0;
58
static const IndexingType NonArrayWithInt32 = Int32Shape;
59
static const IndexingType NonArrayWithDouble = DoubleShape;
60
static const IndexingType NonArrayWithContiguous = ContiguousShape;
61
static const IndexingType NonArrayWithArrayStorage = ArrayStorageShape;
62
static const IndexingType NonArrayWithSlowPutArrayStorage = SlowPutArrayStorageShape;
63
static const IndexingType ArrayClass = IsArray; // I'd want to call this "Array" but this would lead to disastrous namespace pollution.
64
static const IndexingType ArrayWithUndecided = IsArray | UndecidedShape;
65
static const IndexingType ArrayWithInt32 = IsArray | Int32Shape;
66
static const IndexingType ArrayWithDouble = IsArray | DoubleShape;
67
static const IndexingType ArrayWithContiguous = IsArray | ContiguousShape;
68
static const IndexingType ArrayWithArrayStorage = IsArray | ArrayStorageShape;
69
static const IndexingType ArrayWithSlowPutArrayStorage = IsArray | SlowPutArrayStorageShape;
71
#define ALL_BLANK_INDEXING_TYPES \
75
#define ALL_UNDECIDED_INDEXING_TYPES \
78
#define ALL_INT32_INDEXING_TYPES \
82
#define ALL_DOUBLE_INDEXING_TYPES \
86
#define ALL_CONTIGUOUS_INDEXING_TYPES \
87
NonArrayWithContiguous: \
88
case ArrayWithContiguous
90
#define ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES \
91
ArrayWithArrayStorage: \
92
case ArrayWithSlowPutArrayStorage
94
#define ALL_ARRAY_STORAGE_INDEXING_TYPES \
95
NonArrayWithArrayStorage: \
96
case NonArrayWithSlowPutArrayStorage: \
97
case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES
99
static inline bool hasIndexedProperties(IndexingType indexingType)
101
return (indexingType & IndexingShapeMask) != NoIndexingShape;
104
static inline bool hasIndexingHeader(IndexingType type)
106
return hasIndexedProperties(type);
109
static inline bool hasUndecided(IndexingType indexingType)
111
return (indexingType & IndexingShapeMask) == UndecidedShape;
114
static inline bool hasInt32(IndexingType indexingType)
116
return (indexingType & IndexingShapeMask) == Int32Shape;
119
static inline bool hasDouble(IndexingType indexingType)
121
return (indexingType & IndexingShapeMask) == DoubleShape;
124
static inline bool hasContiguous(IndexingType indexingType)
126
return (indexingType & IndexingShapeMask) == ContiguousShape;
129
// FIXME: This is an awkward name. This should really be called hasArrayStorage()
130
// and then next method down should be called hasAnyArrayStorage().
131
static inline bool hasFastArrayStorage(IndexingType indexingType)
133
return (indexingType & IndexingShapeMask) == ArrayStorageShape;
136
static inline bool hasArrayStorage(IndexingType indexingType)
138
return static_cast<uint8_t>((indexingType & IndexingShapeMask) - ArrayStorageShape) <= static_cast<uint8_t>(SlowPutArrayStorageShape - ArrayStorageShape);
141
static inline bool shouldUseSlowPut(IndexingType indexingType)
143
return (indexingType & IndexingShapeMask) == SlowPutArrayStorageShape;
146
// Return an indexing type that can handle all of the elements of both indexing types.
147
IndexingType leastUpperBoundOfIndexingTypes(IndexingType, IndexingType);
149
IndexingType leastUpperBoundOfIndexingTypeAndType(IndexingType, SpeculatedType);
150
IndexingType leastUpperBoundOfIndexingTypeAndValue(IndexingType, JSValue);
152
const char* indexingTypeToString(IndexingType);
154
// Mask of all possible types.
155
static const IndexingType AllArrayTypes = 31;
157
// Mask of all possible types including the history.
158
static const IndexingType AllArrayTypesAndHistory = 127;
162
#endif // IndexingType_h