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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // ----------------------------------------------------------------------------- | 226 // ----------------------------------------------------------------------------- |
227 // Forward declarations for frequently used classes | 227 // Forward declarations for frequently used classes |
228 // (sorted alphabetically) | 228 // (sorted alphabetically) |
229 | 229 |
230 class FreeStoreAllocationPolicy; | 230 class FreeStoreAllocationPolicy; |
231 template <typename T, class P = FreeStoreAllocationPolicy> class List; | 231 template <typename T, class P = FreeStoreAllocationPolicy> class List; |
232 | 232 |
233 // ----------------------------------------------------------------------------- | 233 // ----------------------------------------------------------------------------- |
234 // Declarations for use in both the preparser and the rest of V8. | 234 // Declarations for use in both the preparser and the rest of V8. |
235 | 235 |
236 enum ObjectStrength { | |
237 WEAK, | |
238 FIRM // strong object | |
239 }; | |
240 | |
241 // The Strict Mode (ECMA-262 5th edition, 4.2.2). | 236 // The Strict Mode (ECMA-262 5th edition, 4.2.2). |
242 | 237 |
243 enum LanguageMode { | 238 enum LanguageMode { |
244 // LanguageMode is expressed as a bitmask. Descriptions of the bits: | 239 // LanguageMode is expressed as a bitmask. Descriptions of the bits: |
245 STRICT_BIT = 1 << 0, | 240 STRICT_BIT = 1 << 0, |
246 STRONG_BIT = 1 << 1, | 241 STRONG_BIT = 1 << 1, |
247 LANGUAGE_END, | 242 LANGUAGE_END, |
248 | 243 |
249 // Shorthands for some common language modes. | 244 // Shorthands for some common language modes. |
250 SLOPPY = 0, | 245 SLOPPY = 0, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 285 |
291 inline LanguageMode construct_language_mode(bool strict_bit, bool strong_bit) { | 286 inline LanguageMode construct_language_mode(bool strict_bit, bool strong_bit) { |
292 int language_mode = 0; | 287 int language_mode = 0; |
293 if (strict_bit) language_mode |= STRICT_BIT; | 288 if (strict_bit) language_mode |= STRICT_BIT; |
294 if (strong_bit) language_mode |= STRONG_BIT; | 289 if (strong_bit) language_mode |= STRONG_BIT; |
295 DCHECK(is_valid_language_mode(language_mode)); | 290 DCHECK(is_valid_language_mode(language_mode)); |
296 return static_cast<LanguageMode>(language_mode); | 291 return static_cast<LanguageMode>(language_mode); |
297 } | 292 } |
298 | 293 |
299 | 294 |
300 inline ObjectStrength strength(LanguageMode language_mode) { | 295 // Strong mode behaviour must sometimes be signalled by a two valued enum where |
301 return is_strong(language_mode) ? FIRM : WEAK; | 296 // caching is involved, to prevent sloppy and strict mode from being incorrectly |
| 297 // differentiated. |
| 298 enum class Strength : bool { |
| 299 WEAK, // sloppy, strict behaviour |
| 300 STRONG // strong behaviour |
| 301 }; |
| 302 |
| 303 |
| 304 inline bool is_strong(Strength strength) { |
| 305 return strength == Strength::STRONG; |
302 } | 306 } |
303 | 307 |
304 | 308 |
| 309 inline std::ostream& operator<<(std::ostream& os, const Strength& strength) { |
| 310 return os << (is_strong(strength) ? "strong" : "weak"); |
| 311 } |
| 312 |
| 313 |
| 314 inline Strength strength(LanguageMode language_mode) { |
| 315 return is_strong(language_mode) ? Strength::STRONG : Strength::WEAK; |
| 316 } |
| 317 |
| 318 |
| 319 inline size_t hash_value(Strength strength) { |
| 320 return static_cast<size_t>(strength); |
| 321 } |
| 322 |
| 323 |
305 // Mask for the sign bit in a smi. | 324 // Mask for the sign bit in a smi. |
306 const intptr_t kSmiSignMask = kIntptrSignBit; | 325 const intptr_t kSmiSignMask = kIntptrSignBit; |
307 | 326 |
308 const int kObjectAlignmentBits = kPointerSizeLog2; | 327 const int kObjectAlignmentBits = kPointerSizeLog2; |
309 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; | 328 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; |
310 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1; | 329 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1; |
311 | 330 |
312 // Desired alignment for pointers. | 331 // Desired alignment for pointers. |
313 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2); | 332 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2); |
314 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1; | 333 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1; |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 inline FunctionKind WithObjectLiteralBit(FunctionKind kind) { | 989 inline FunctionKind WithObjectLiteralBit(FunctionKind kind) { |
971 kind = static_cast<FunctionKind>(kind | FunctionKind::kInObjectLiteral); | 990 kind = static_cast<FunctionKind>(kind | FunctionKind::kInObjectLiteral); |
972 DCHECK(IsValidFunctionKind(kind)); | 991 DCHECK(IsValidFunctionKind(kind)); |
973 return kind; | 992 return kind; |
974 } | 993 } |
975 } } // namespace v8::internal | 994 } } // namespace v8::internal |
976 | 995 |
977 namespace i = v8::internal; | 996 namespace i = v8::internal; |
978 | 997 |
979 #endif // V8_GLOBALS_H_ | 998 #endif // V8_GLOBALS_H_ |
OLD | NEW |