~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/runtime/IndexingType.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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. 
 
24
 */
 
25
 
 
26
#ifndef IndexingType_h
 
27
#define IndexingType_h
 
28
 
 
29
#include "SpeculatedType.h"
 
30
#include <wtf/StdLibExtras.h>
 
31
 
 
32
namespace JSC {
 
33
 
 
34
typedef uint8_t IndexingType;
 
35
 
 
36
// Flags for testing the presence of capabilities.
 
37
static const IndexingType IsArray                  = 1;
 
38
 
 
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;
 
48
 
 
49
static const IndexingType IndexingShapeShift       = 1;
 
50
static const IndexingType NumberOfIndexingShapes   = 16;
 
51
 
 
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;
 
55
 
 
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;
 
70
 
 
71
#define ALL_BLANK_INDEXING_TYPES \
 
72
    NonArray:                    \
 
73
    case ArrayClass
 
74
 
 
75
#define ALL_UNDECIDED_INDEXING_TYPES \
 
76
    ArrayWithUndecided
 
77
 
 
78
#define ALL_INT32_INDEXING_TYPES      \
 
79
    NonArrayWithInt32:                \
 
80
    case ArrayWithInt32
 
81
 
 
82
#define ALL_DOUBLE_INDEXING_TYPES     \
 
83
    NonArrayWithDouble:               \
 
84
    case ArrayWithDouble
 
85
 
 
86
#define ALL_CONTIGUOUS_INDEXING_TYPES \
 
87
    NonArrayWithContiguous:           \
 
88
    case ArrayWithContiguous
 
89
 
 
90
#define ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES \
 
91
    ArrayWithArrayStorage:                      \
 
92
    case ArrayWithSlowPutArrayStorage
 
93
    
 
94
#define ALL_ARRAY_STORAGE_INDEXING_TYPES                \
 
95
    NonArrayWithArrayStorage:                           \
 
96
    case NonArrayWithSlowPutArrayStorage:               \
 
97
    case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES
 
98
 
 
99
static inline bool hasIndexedProperties(IndexingType indexingType)
 
100
{
 
101
    return (indexingType & IndexingShapeMask) != NoIndexingShape;
 
102
}
 
103
 
 
104
static inline bool hasIndexingHeader(IndexingType type)
 
105
{
 
106
    return hasIndexedProperties(type);
 
107
}
 
108
 
 
109
static inline bool hasUndecided(IndexingType indexingType)
 
110
{
 
111
    return (indexingType & IndexingShapeMask) == UndecidedShape;
 
112
}
 
113
 
 
114
static inline bool hasInt32(IndexingType indexingType)
 
115
{
 
116
    return (indexingType & IndexingShapeMask) == Int32Shape;
 
117
}
 
118
 
 
119
static inline bool hasDouble(IndexingType indexingType)
 
120
{
 
121
    return (indexingType & IndexingShapeMask) == DoubleShape;
 
122
}
 
123
 
 
124
static inline bool hasContiguous(IndexingType indexingType)
 
125
{
 
126
    return (indexingType & IndexingShapeMask) == ContiguousShape;
 
127
}
 
128
 
 
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)
 
132
{
 
133
    return (indexingType & IndexingShapeMask) == ArrayStorageShape;
 
134
}
 
135
 
 
136
static inline bool hasArrayStorage(IndexingType indexingType)
 
137
{
 
138
    return static_cast<uint8_t>((indexingType & IndexingShapeMask) - ArrayStorageShape) <= static_cast<uint8_t>(SlowPutArrayStorageShape - ArrayStorageShape);
 
139
}
 
140
 
 
141
static inline bool shouldUseSlowPut(IndexingType indexingType)
 
142
{
 
143
    return (indexingType & IndexingShapeMask) == SlowPutArrayStorageShape;
 
144
}
 
145
 
 
146
// Return an indexing type that can handle all of the elements of both indexing types.
 
147
IndexingType leastUpperBoundOfIndexingTypes(IndexingType, IndexingType);
 
148
 
 
149
IndexingType leastUpperBoundOfIndexingTypeAndType(IndexingType, SpeculatedType);
 
150
IndexingType leastUpperBoundOfIndexingTypeAndValue(IndexingType, JSValue);
 
151
 
 
152
const char* indexingTypeToString(IndexingType);
 
153
 
 
154
// Mask of all possible types.
 
155
static const IndexingType AllArrayTypes            = 31;
 
156
 
 
157
// Mask of all possible types including the history.
 
158
static const IndexingType AllArrayTypesAndHistory  = 127;
 
159
 
 
160
} // namespace JSC
 
161
 
 
162
#endif // IndexingType_h
 
163