]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 | 1 | /* |
ed1e77d3 | 2 | * Copyright (C) 2011, 2015 Apple Inc. All rights reserved. |
6fe7ccc8 A |
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 DataFormat_h | |
27 | #define DataFormat_h | |
28 | ||
29 | #include <wtf/Assertions.h> | |
30 | ||
31 | namespace JSC { | |
32 | ||
33 | // === DataFormat === | |
34 | // | |
35 | // This enum tracks the current representation in which a value is being held. | |
36 | // Values may be unboxed primitives (int32, double, or cell), or boxed as a JSValue. | |
37 | // For boxed values, we may know the type of boxing that has taken place. | |
38 | // (May also need bool, array, object, string types!) | |
39 | enum DataFormat { | |
40 | DataFormatNone = 0, | |
81345200 A |
41 | DataFormatInt32 = 1, |
42 | DataFormatInt52 = 2, // Int52's are left-shifted by 16 by default. | |
43 | DataFormatStrictInt52 = 3, // "Strict" Int52 means it's not shifted. | |
44 | DataFormatDouble = 4, | |
45 | DataFormatBoolean = 5, | |
46 | DataFormatCell = 6, | |
47 | DataFormatStorage = 7, | |
6fe7ccc8 | 48 | DataFormatJS = 8, |
81345200 | 49 | DataFormatJSInt32 = DataFormatJS | DataFormatInt32, |
6fe7ccc8 A |
50 | DataFormatJSDouble = DataFormatJS | DataFormatDouble, |
51 | DataFormatJSCell = DataFormatJS | DataFormatCell, | |
93a37866 A |
52 | DataFormatJSBoolean = DataFormatJS | DataFormatBoolean, |
53 | ||
54 | // Marker deliminating ordinary data formats and OSR-only data formats. | |
55 | DataFormatOSRMarker = 32, | |
56 | ||
57 | // Special data formats used only for OSR. | |
58 | DataFormatDead = 33, // Implies jsUndefined(). | |
6fe7ccc8 A |
59 | }; |
60 | ||
61 | inline const char* dataFormatToString(DataFormat dataFormat) | |
62 | { | |
63 | switch (dataFormat) { | |
64 | case DataFormatNone: | |
65 | return "None"; | |
81345200 A |
66 | case DataFormatInt32: |
67 | return "Int32"; | |
68 | case DataFormatInt52: | |
69 | return "Int52"; | |
70 | case DataFormatStrictInt52: | |
71 | return "StrictInt52"; | |
6fe7ccc8 A |
72 | case DataFormatDouble: |
73 | return "Double"; | |
74 | case DataFormatCell: | |
75 | return "Cell"; | |
76 | case DataFormatBoolean: | |
77 | return "Boolean"; | |
78 | case DataFormatStorage: | |
79 | return "Storage"; | |
80 | case DataFormatJS: | |
81 | return "JS"; | |
81345200 A |
82 | case DataFormatJSInt32: |
83 | return "JSInt32"; | |
6fe7ccc8 A |
84 | case DataFormatJSDouble: |
85 | return "JSDouble"; | |
86 | case DataFormatJSCell: | |
87 | return "JSCell"; | |
88 | case DataFormatJSBoolean: | |
89 | return "JSBoolean"; | |
93a37866 A |
90 | case DataFormatDead: |
91 | return "Dead"; | |
6fe7ccc8 | 92 | default: |
93a37866 | 93 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 A |
94 | return "Unknown"; |
95 | } | |
96 | } | |
97 | ||
6fe7ccc8 A |
98 | inline bool isJSFormat(DataFormat format, DataFormat expectedFormat) |
99 | { | |
100 | ASSERT(expectedFormat & DataFormatJS); | |
101 | return (format | DataFormatJS) == expectedFormat; | |
102 | } | |
103 | ||
81345200 | 104 | inline bool isJSInt32(DataFormat format) |
6fe7ccc8 | 105 | { |
81345200 | 106 | return isJSFormat(format, DataFormatJSInt32); |
6fe7ccc8 A |
107 | } |
108 | ||
109 | inline bool isJSDouble(DataFormat format) | |
110 | { | |
111 | return isJSFormat(format, DataFormatJSDouble); | |
112 | } | |
113 | ||
114 | inline bool isJSCell(DataFormat format) | |
115 | { | |
116 | return isJSFormat(format, DataFormatJSCell); | |
117 | } | |
118 | ||
119 | inline bool isJSBoolean(DataFormat format) | |
120 | { | |
121 | return isJSFormat(format, DataFormatJSBoolean); | |
122 | } | |
123 | ||
124 | } | |
125 | ||
126 | #endif // DataFormat_h |