2 * Copyright (C) 2011 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.
29 #include <wtf/Assertions.h>
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!)
41 DataFormatInteger
= 1,
43 DataFormatBoolean
= 3,
45 DataFormatStorage
= 5,
47 DataFormatJSInteger
= DataFormatJS
| DataFormatInteger
,
48 DataFormatJSDouble
= DataFormatJS
| DataFormatDouble
,
49 DataFormatJSCell
= DataFormatJS
| DataFormatCell
,
50 DataFormatJSBoolean
= DataFormatJS
| DataFormatBoolean
53 inline const char* dataFormatToString(DataFormat dataFormat
)
58 case DataFormatInteger
:
60 case DataFormatDouble
:
64 case DataFormatBoolean
:
66 case DataFormatStorage
:
70 case DataFormatJSInteger
:
72 case DataFormatJSDouble
:
74 case DataFormatJSCell
:
76 case DataFormatJSBoolean
:
84 inline bool needDataFormatConversion(DataFormat from
, DataFormat to
)
86 ASSERT(from
!= DataFormatNone
);
87 ASSERT(to
!= DataFormatNone
);
89 case DataFormatInteger
:
90 case DataFormatDouble
:
94 case DataFormatJSInteger
:
95 case DataFormatJSDouble
:
96 case DataFormatJSCell
:
97 case DataFormatJSBoolean
:
99 case DataFormatInteger
:
100 case DataFormatDouble
:
104 case DataFormatJSInteger
:
105 case DataFormatJSDouble
:
106 case DataFormatJSCell
:
107 case DataFormatJSBoolean
:
110 // This captures DataFormatBoolean, which is currently unused.
111 ASSERT_NOT_REACHED();
113 case DataFormatStorage
:
114 ASSERT(to
== DataFormatStorage
);
117 // This captures DataFormatBoolean, which is currently unused.
118 ASSERT_NOT_REACHED();
123 #elif USE(JSVALUE32_64)
124 inline bool needDataFormatConversion(DataFormat from
, DataFormat to
)
126 ASSERT(from
!= DataFormatNone
);
127 ASSERT(to
!= DataFormatNone
);
129 case DataFormatInteger
:
131 case DataFormatBoolean
:
132 return ((to
& DataFormatJS
) || to
== DataFormatDouble
);
133 case DataFormatDouble
:
134 case DataFormatJSDouble
:
135 return (to
!= DataFormatDouble
&& to
!= DataFormatJSDouble
);
137 case DataFormatJSInteger
:
138 case DataFormatJSCell
:
139 case DataFormatJSBoolean
:
140 return (!(to
& DataFormatJS
) || to
== DataFormatJSDouble
);
141 case DataFormatStorage
:
142 ASSERT(to
== DataFormatStorage
);
145 ASSERT_NOT_REACHED();
151 inline bool isJSFormat(DataFormat format
, DataFormat expectedFormat
)
153 ASSERT(expectedFormat
& DataFormatJS
);
154 return (format
| DataFormatJS
) == expectedFormat
;
157 inline bool isJSInteger(DataFormat format
)
159 return isJSFormat(format
, DataFormatJSInteger
);
162 inline bool isJSDouble(DataFormat format
)
164 return isJSFormat(format
, DataFormatJSDouble
);
167 inline bool isJSCell(DataFormat format
)
169 return isJSFormat(format
, DataFormatJSCell
);
172 inline bool isJSBoolean(DataFormat format
)
174 return isJSFormat(format
, DataFormatJSBoolean
);
179 #endif // DataFormat_h