OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_GLOBALS_H_ | 5 #ifndef V8_GLOBALS_H_ |
6 #define V8_GLOBALS_H_ | 6 #define V8_GLOBALS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // (sorted alphabetically) | 236 // (sorted alphabetically) |
237 | 237 |
238 class FreeStoreAllocationPolicy; | 238 class FreeStoreAllocationPolicy; |
239 template <typename T, class P = FreeStoreAllocationPolicy> class List; | 239 template <typename T, class P = FreeStoreAllocationPolicy> class List; |
240 | 240 |
241 // ----------------------------------------------------------------------------- | 241 // ----------------------------------------------------------------------------- |
242 // Declarations for use in both the preparser and the rest of V8. | 242 // Declarations for use in both the preparser and the rest of V8. |
243 | 243 |
244 // The Strict Mode (ECMA-262 5th edition, 4.2.2). | 244 // The Strict Mode (ECMA-262 5th edition, 4.2.2). |
245 | 245 |
246 enum LanguageMode { | 246 enum LanguageMode { SLOPPY, STRICT, LANGUAGE_END = 3 }; |
247 // LanguageMode is expressed as a bitmask. Descriptions of the bits: | |
248 STRICT_BIT = 1 << 0, | |
249 STRONG_BIT = 1 << 1, | |
250 LANGUAGE_END, | |
251 | |
252 // Shorthands for some common language modes. | |
253 SLOPPY = 0, | |
254 STRICT = STRICT_BIT, | |
255 STRONG = STRICT_BIT | STRONG_BIT | |
256 }; | |
257 | 247 |
258 | 248 |
259 inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) { | 249 inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) { |
260 switch (mode) { | 250 switch (mode) { |
261 case SLOPPY: | 251 case SLOPPY: return os << "sloppy"; |
262 return os << "sloppy"; | 252 case STRICT: return os << "strict"; |
263 case STRICT: | 253 default: UNREACHABLE(); |
264 return os << "strict"; | |
265 case STRONG: | |
266 return os << "strong"; | |
267 default: | |
268 return os << "unknown"; | |
269 } | 254 } |
| 255 return os; |
270 } | 256 } |
271 | 257 |
272 | 258 |
273 inline bool is_sloppy(LanguageMode language_mode) { | 259 inline bool is_sloppy(LanguageMode language_mode) { |
274 return (language_mode & STRICT_BIT) == 0; | 260 return language_mode == SLOPPY; |
275 } | 261 } |
276 | 262 |
277 | 263 |
278 inline bool is_strict(LanguageMode language_mode) { | 264 inline bool is_strict(LanguageMode language_mode) { |
279 return language_mode & STRICT_BIT; | 265 return language_mode != SLOPPY; |
280 } | |
281 | |
282 | |
283 inline bool is_strong(LanguageMode language_mode) { | |
284 return language_mode & STRONG_BIT; | |
285 } | 266 } |
286 | 267 |
287 | 268 |
288 inline bool is_valid_language_mode(int language_mode) { | 269 inline bool is_valid_language_mode(int language_mode) { |
289 return language_mode == SLOPPY || language_mode == STRICT || | 270 return language_mode == SLOPPY || language_mode == STRICT; |
290 language_mode == STRONG; | |
291 } | 271 } |
292 | 272 |
293 | 273 |
294 inline LanguageMode construct_language_mode(bool strict_bit, bool strong_bit) { | 274 inline LanguageMode construct_language_mode(bool strict_bit) { |
295 int language_mode = 0; | 275 return static_cast<LanguageMode>(strict_bit); |
296 if (strict_bit) language_mode |= STRICT_BIT; | |
297 if (strong_bit) language_mode |= STRONG_BIT; | |
298 DCHECK(is_valid_language_mode(language_mode)); | |
299 return static_cast<LanguageMode>(language_mode); | |
300 } | 276 } |
301 | 277 |
302 | 278 |
303 // Mask for the sign bit in a smi. | 279 // Mask for the sign bit in a smi. |
304 const intptr_t kSmiSignMask = kIntptrSignBit; | 280 const intptr_t kSmiSignMask = kIntptrSignBit; |
305 | 281 |
306 const int kObjectAlignmentBits = kPointerSizeLog2; | 282 const int kObjectAlignmentBits = kPointerSizeLog2; |
307 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; | 283 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; |
308 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1; | 284 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1; |
309 | 285 |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 DCHECK(IsValidFunctionKind(kind)); | 1003 DCHECK(IsValidFunctionKind(kind)); |
1028 return kind & FunctionKind::kClassConstructor; | 1004 return kind & FunctionKind::kClassConstructor; |
1029 } | 1005 } |
1030 | 1006 |
1031 | 1007 |
1032 inline bool IsConstructable(FunctionKind kind, LanguageMode mode) { | 1008 inline bool IsConstructable(FunctionKind kind, LanguageMode mode) { |
1033 if (IsAccessorFunction(kind)) return false; | 1009 if (IsAccessorFunction(kind)) return false; |
1034 if (IsConciseMethod(kind)) return false; | 1010 if (IsConciseMethod(kind)) return false; |
1035 if (IsArrowFunction(kind)) return false; | 1011 if (IsArrowFunction(kind)) return false; |
1036 if (IsGeneratorFunction(kind)) return false; | 1012 if (IsGeneratorFunction(kind)) return false; |
1037 if (is_strong(mode)) return IsClassConstructor(kind); | |
1038 return true; | 1013 return true; |
1039 } | 1014 } |
1040 | 1015 |
1041 | 1016 |
1042 inline uint32_t ObjectHash(Address address) { | 1017 inline uint32_t ObjectHash(Address address) { |
1043 // All objects are at least pointer aligned, so we can remove the trailing | 1018 // All objects are at least pointer aligned, so we can remove the trailing |
1044 // zeros. | 1019 // zeros. |
1045 return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >> | 1020 return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >> |
1046 kPointerSizeLog2); | 1021 kPointerSizeLog2); |
1047 } | 1022 } |
1048 | 1023 |
1049 } // namespace internal | 1024 } // namespace internal |
1050 } // namespace v8 | 1025 } // namespace v8 |
1051 | 1026 |
1052 namespace i = v8::internal; | 1027 namespace i = v8::internal; |
1053 | 1028 |
1054 #endif // V8_GLOBALS_H_ | 1029 #endif // V8_GLOBALS_H_ |
OLD | NEW |