OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 | 152 |
153 | 153 |
154 // AstValue is either a string, a number, a string array, a boolean, or a | 154 // AstValue is either a string, a number, a string array, a boolean, or a |
155 // special value (null, undefined, the hole). | 155 // special value (null, undefined, the hole). |
156 class AstValue : public ZoneObject { | 156 class AstValue : public ZoneObject { |
157 public: | 157 public: |
158 bool IsString() const { | 158 bool IsString() const { |
159 return type_ == STRING; | 159 return type_ == STRING; |
160 } | 160 } |
161 | 161 |
162 bool IsNumber() const { | 162 bool IsNumber() const { return IsSmi() || IsHeapNumber(); } |
163 return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI || | |
164 type_ == SMI_WITH_DOT; | |
165 } | |
166 | 163 |
167 bool ContainsDot() const { | 164 bool ContainsDot() const { |
168 return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT; | 165 return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT; |
169 } | 166 } |
170 | 167 |
171 const AstRawString* AsString() const { | 168 const AstRawString* AsString() const { |
172 CHECK_EQ(STRING, type_); | 169 CHECK_EQ(STRING, type_); |
173 return string_; | 170 return string_; |
174 } | 171 } |
175 | 172 |
176 double AsNumber() const { | 173 double AsNumber() const { |
177 if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) | 174 if (IsHeapNumber()) return number_; |
178 return number_; | 175 if (IsSmi()) return smi_; |
179 if (type_ == SMI || type_ == SMI_WITH_DOT) | |
180 return smi_; | |
181 UNREACHABLE(); | 176 UNREACHABLE(); |
182 return 0; | 177 return 0; |
183 } | 178 } |
184 | 179 |
185 Smi* AsSmi() const { | 180 Smi* AsSmi() const { |
186 CHECK(type_ == SMI || type_ == SMI_WITH_DOT); | 181 CHECK(IsSmi()); |
187 return Smi::FromInt(smi_); | 182 return Smi::FromInt(smi_); |
188 } | 183 } |
189 | 184 |
185 bool ToUint32(uint32_t* value) const { | |
186 if (IsSmi()) { | |
187 int num = smi_; | |
188 if (num < 0) return false; | |
189 *value = static_cast<uint32_t>(num); | |
190 return true; | |
191 } | |
192 if (IsHeapNumber()) { | |
193 double num = number_; | |
194 if (num < 0) return false; | |
195 uint32_t uint_value = FastD2UI(num); | |
196 if (FastUI2D(uint_value) == num) { | |
197 *value = uint_value; | |
198 return true; | |
199 } | |
rmcilroy
2017/01/13 09:53:57
You need to be careful to check for minus 0.0 as w
Leszek Swirski
2017/01/13 10:58:10
Done, and amended the code in objects-inl.h that I
| |
200 } | |
201 return false; | |
202 } | |
203 | |
190 bool EqualsString(const AstRawString* string) const { | 204 bool EqualsString(const AstRawString* string) const { |
191 return type_ == STRING && string_ == string; | 205 return type_ == STRING && string_ == string; |
192 } | 206 } |
193 | 207 |
194 bool IsPropertyName() const; | 208 bool IsPropertyName() const; |
195 | 209 |
196 bool BooleanValue() const; | 210 bool BooleanValue() const; |
197 | 211 |
198 bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; } | 212 bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; } |
213 bool IsHeapNumber() const { | |
214 return type_ == NUMBER || type_ == NUMBER_WITH_DOT; | |
215 } | |
199 bool IsFalse() const { return type_ == BOOLEAN && !bool_; } | 216 bool IsFalse() const { return type_ == BOOLEAN && !bool_; } |
200 bool IsTrue() const { return type_ == BOOLEAN && bool_; } | 217 bool IsTrue() const { return type_ == BOOLEAN && bool_; } |
201 bool IsUndefined() const { return type_ == UNDEFINED; } | 218 bool IsUndefined() const { return type_ == UNDEFINED; } |
202 bool IsTheHole() const { return type_ == THE_HOLE; } | 219 bool IsTheHole() const { return type_ == THE_HOLE; } |
203 bool IsNull() const { return type_ == NULL_TYPE; } | 220 bool IsNull() const { return type_ == NULL_TYPE; } |
204 | 221 |
205 void Internalize(Isolate* isolate); | 222 void Internalize(Isolate* isolate); |
206 | 223 |
207 // Can be called after Internalize has been called. | 224 // Can be called after Internalize has been called. |
208 V8_INLINE Handle<Object> value() const { | 225 V8_INLINE Handle<Object> value() const { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 OTHER_CONSTANTS(F) | 463 OTHER_CONSTANTS(F) |
447 #undef F | 464 #undef F |
448 }; | 465 }; |
449 } // namespace internal | 466 } // namespace internal |
450 } // namespace v8 | 467 } // namespace v8 |
451 | 468 |
452 #undef STRING_CONSTANTS | 469 #undef STRING_CONSTANTS |
453 #undef OTHER_CONSTANTS | 470 #undef OTHER_CONSTANTS |
454 | 471 |
455 #endif // V8_AST_AST_VALUE_FACTORY_H_ | 472 #endif // V8_AST_AST_VALUE_FACTORY_H_ |
OLD | NEW |