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
3 // found in the LICENSE file.
13 #include "src/base/build_config.h"
14 #include "src/base/logging.h"
15 #include "src/base/macros.h"
17 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
18 // warning flag and certain versions of GCC due to a bug:
19 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
20 // For now, we use the more involved template-based version from <limits>, but
21 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
22 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
23 # include <limits> // NOLINT
24 # define V8_INFINITY std::numeric_limits<double>::infinity()
26 # define V8_INFINITY HUGE_VAL
28 #define V8_INFINITY (__builtin_inff())
30 # define V8_INFINITY INFINITY
33 #if V8_TARGET_ARCH_IA32 || (V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_32_BIT) || \
34 V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS || \
35 V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC
36 #define V8_TURBOFAN_BACKEND 1
38 #define V8_TURBOFAN_BACKEND 0
40 #if V8_TURBOFAN_BACKEND
41 #define V8_TURBOFAN_TARGET 1
43 #define V8_TURBOFAN_TARGET 0
56 // Determine whether we are running in a simulated environment.
57 // Setting USE_SIMULATOR explicitly from the build script will force
58 // the use of a simulated environment.
59 #if !defined(USE_SIMULATOR)
60 #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
61 #define USE_SIMULATOR 1
63 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
64 #define USE_SIMULATOR 1
66 #if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC)
67 #define USE_SIMULATOR 1
69 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
70 #define USE_SIMULATOR 1
72 #if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
73 #define USE_SIMULATOR 1
77 // Determine whether the architecture uses an embedded constant pool
78 // (contiguous constant pool embedded in code object).
79 #if V8_TARGET_ARCH_PPC
80 #define V8_EMBEDDED_CONSTANT_POOL 1
82 #define V8_EMBEDDED_CONSTANT_POOL 0
85 #ifdef V8_TARGET_ARCH_ARM
86 // Set stack limit lower for ARM than for other architectures because
87 // stack allocating MacroAssembler takes 120K bytes.
88 // See issue crbug.com/405338
89 #define V8_DEFAULT_STACK_SIZE_KB 864
91 // Slightly less than 1MB, since Windows' default stack size for
92 // the main execution thread is 1MB for both 32 and 64-bit.
93 #define V8_DEFAULT_STACK_SIZE_KB 984
97 // Determine whether double field unboxing feature is enabled.
98 #if V8_TARGET_ARCH_64_BIT
99 #define V8_DOUBLE_FIELDS_UNBOXING 1
101 #define V8_DOUBLE_FIELDS_UNBOXING 0
105 typedef uint8_t byte;
106 typedef byte* Address;
108 // -----------------------------------------------------------------------------
112 const int MB = KB * KB;
113 const int GB = KB * KB * KB;
114 const int kMaxInt = 0x7FFFFFFF;
115 const int kMinInt = -kMaxInt - 1;
116 const int kMaxInt8 = (1 << 7) - 1;
117 const int kMinInt8 = -(1 << 7);
118 const int kMaxUInt8 = (1 << 8) - 1;
119 const int kMinUInt8 = 0;
120 const int kMaxInt16 = (1 << 15) - 1;
121 const int kMinInt16 = -(1 << 15);
122 const int kMaxUInt16 = (1 << 16) - 1;
123 const int kMinUInt16 = 0;
125 const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
127 const int kCharSize = sizeof(char); // NOLINT
128 const int kShortSize = sizeof(short); // NOLINT
129 const int kIntSize = sizeof(int); // NOLINT
130 const int kInt32Size = sizeof(int32_t); // NOLINT
131 const int kInt64Size = sizeof(int64_t); // NOLINT
132 const int kFloatSize = sizeof(float); // NOLINT
133 const int kDoubleSize = sizeof(double); // NOLINT
134 const int kIntptrSize = sizeof(intptr_t); // NOLINT
135 const int kPointerSize = sizeof(void*); // NOLINT
136 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
137 const int kRegisterSize = kPointerSize + kPointerSize;
139 const int kRegisterSize = kPointerSize;
141 const int kPCOnStackSize = kRegisterSize;
142 const int kFPOnStackSize = kRegisterSize;
144 const int kDoubleSizeLog2 = 3;
146 #if V8_HOST_ARCH_64_BIT
147 const int kPointerSizeLog2 = 3;
148 const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
149 const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
150 const bool kRequiresCodeRange = true;
151 const size_t kMaximalCodeRangeSize = 512 * MB;
153 const size_t kMinimumCodeRangeSize = 4 * MB;
154 const size_t kReservedCodeRangePages = 1;
156 const size_t kMinimumCodeRangeSize = 3 * MB;
157 const size_t kReservedCodeRangePages = 0;
160 const int kPointerSizeLog2 = 2;
161 const intptr_t kIntptrSignBit = 0x80000000;
162 const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
163 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
164 // x32 port also requires code range.
165 const bool kRequiresCodeRange = true;
166 const size_t kMaximalCodeRangeSize = 256 * MB;
167 const size_t kMinimumCodeRangeSize = 3 * MB;
168 const size_t kReservedCodeRangePages = 0;
170 const bool kRequiresCodeRange = false;
171 const size_t kMaximalCodeRangeSize = 0 * MB;
172 const size_t kMinimumCodeRangeSize = 0 * MB;
173 const size_t kReservedCodeRangePages = 0;
177 STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
179 const int kBitsPerByte = 8;
180 const int kBitsPerByteLog2 = 3;
181 const int kBitsPerPointer = kPointerSize * kBitsPerByte;
182 const int kBitsPerInt = kIntSize * kBitsPerByte;
184 // IEEE 754 single precision floating point number bit layout.
185 const uint32_t kBinary32SignMask = 0x80000000u;
186 const uint32_t kBinary32ExponentMask = 0x7f800000u;
187 const uint32_t kBinary32MantissaMask = 0x007fffffu;
188 const int kBinary32ExponentBias = 127;
189 const int kBinary32MaxExponent = 0xFE;
190 const int kBinary32MinExponent = 0x01;
191 const int kBinary32MantissaBits = 23;
192 const int kBinary32ExponentShift = 23;
194 // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
196 const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
198 // Latin1/UTF-16 constants
199 // Code-point values in Unicode 4.0 are 21 bits wide.
200 // Code units in UTF-16 are 16 bits wide.
201 typedef uint16_t uc16;
202 typedef int32_t uc32;
203 const int kOneByteSize = kCharSize;
204 const int kUC16Size = sizeof(uc16); // NOLINT
206 // 128 bit SIMD value size.
207 const int kSimd128Size = 16;
209 // Round up n to be a multiple of sz, where sz is a power of 2.
210 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
213 // FUNCTION_ADDR(f) gets the address of a C function f.
214 #define FUNCTION_ADDR(f) \
215 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
218 // FUNCTION_CAST<F>(addr) casts an address into a function
219 // of type F. Used to invoke generated code from within C.
220 template <typename F>
221 F FUNCTION_CAST(Address addr) {
222 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
226 // -----------------------------------------------------------------------------
227 // Forward declarations for frequently used classes
228 // (sorted alphabetically)
230 class FreeStoreAllocationPolicy;
231 template <typename T, class P = FreeStoreAllocationPolicy> class List;
233 // -----------------------------------------------------------------------------
234 // Declarations for use in both the preparser and the rest of V8.
236 enum ObjectStrength {
238 FIRM // strong object
241 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
244 // LanguageMode is expressed as a bitmask. Descriptions of the bits:
249 // Shorthands for some common language modes.
252 STRONG = STRICT_BIT | STRONG_BIT
256 inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
259 return os << "sloppy";
261 return os << "strict";
263 return os << "strong";
265 return os << "unknown";
270 inline bool is_sloppy(LanguageMode language_mode) {
271 return (language_mode & STRICT_BIT) == 0;
275 inline bool is_strict(LanguageMode language_mode) {
276 return language_mode & STRICT_BIT;
280 inline bool is_strong(LanguageMode language_mode) {
281 return language_mode & STRONG_BIT;
285 inline bool is_valid_language_mode(int language_mode) {
286 return language_mode == SLOPPY || language_mode == STRICT ||
287 language_mode == STRONG;
291 inline LanguageMode construct_language_mode(bool strict_bit, bool strong_bit) {
292 int language_mode = 0;
293 if (strict_bit) language_mode |= STRICT_BIT;
294 if (strong_bit) language_mode |= STRONG_BIT;
295 DCHECK(is_valid_language_mode(language_mode));
296 return static_cast<LanguageMode>(language_mode);
300 inline ObjectStrength strength(LanguageMode language_mode) {
301 return is_strong(language_mode) ? FIRM : WEAK;
305 // Mask for the sign bit in a smi.
306 const intptr_t kSmiSignMask = kIntptrSignBit;
308 const int kObjectAlignmentBits = kPointerSizeLog2;
309 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
310 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
312 // Desired alignment for pointers.
313 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
314 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
316 // Desired alignment for double values.
317 const intptr_t kDoubleAlignment = 8;
318 const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
320 // Desired alignment for 128 bit SIMD values.
321 const intptr_t kSimd128Alignment = 16;
322 const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1;
324 // Desired alignment for generated code is 32 bytes (to improve cache line
326 const int kCodeAlignmentBits = 5;
327 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
328 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
330 // The owner field of a page is tagged with the page header tag. We need that
331 // to find out if a slot is part of a large object. If we mask out the lower
332 // 0xfffff bits (1M pages), go to the owner offset, and see that this field
333 // is tagged with the page header tag, we can just look up the owner.
334 // Otherwise, we know that we are somewhere (not within the first 1M) in a
336 const int kPageHeaderTag = 3;
337 const int kPageHeaderTagSize = 2;
338 const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
341 // Zap-value: The value used for zapping dead objects.
342 // Should be a recognizable hex value tagged as a failure.
343 #ifdef V8_HOST_ARCH_64_BIT
344 const Address kZapValue =
345 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
346 const Address kHandleZapValue =
347 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
348 const Address kGlobalHandleZapValue =
349 reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
350 const Address kFromSpaceZapValue =
351 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
352 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
353 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
354 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
356 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
357 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
358 const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
359 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
360 const uint32_t kSlotsZapValue = 0xbeefdeef;
361 const uint32_t kDebugZapValue = 0xbadbaddb;
362 const uint32_t kFreeListZapValue = 0xfeed1eaf;
365 const int kCodeZapValue = 0xbadc0de;
366 const uint32_t kPhantomReferenceZap = 0xca11bac;
368 // On Intel architecture, cache line size is 64 bytes.
369 // On ARM it may be less (32 bytes), but as far this constant is
370 // used for aligning data, it doesn't hurt to align on a greater value.
371 #define PROCESSOR_CACHE_LINE_SIZE 64
373 // Constants relevant to double precision floating point numbers.
374 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
375 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
378 // -----------------------------------------------------------------------------
379 // Forward declarations for frequently used classes
393 class DescriptorArray;
394 class TransitionArray;
395 class ExternalReference;
397 class FunctionTemplateInfo;
399 class SeededNumberDictionary;
400 class UnseededNumberDictionary;
401 class NameDictionary;
402 class GlobalDictionary;
403 template <typename T> class MaybeHandle;
404 template <typename T> class Handle;
408 class InterceptorInfo;
414 class LargeObjectSpace;
415 class MacroAssembler;
418 class MarkCompactCollector;
427 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
437 class MessageLocation;
439 typedef bool (*WeakSlotCallback)(Object** pointer);
441 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
443 // -----------------------------------------------------------------------------
446 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
448 // Keep this enum in sync with the ObjectSpace enum in v8.h
449 enum AllocationSpace {
450 NEW_SPACE, // Semispaces collected with copying collector.
451 OLD_SPACE, // May contain pointers to new space.
452 CODE_SPACE, // No pointers to new space, marked executable.
453 MAP_SPACE, // Only and all map objects.
454 LO_SPACE, // Promoted large objects.
456 FIRST_SPACE = NEW_SPACE,
457 LAST_SPACE = LO_SPACE,
458 FIRST_PAGED_SPACE = OLD_SPACE,
459 LAST_PAGED_SPACE = MAP_SPACE
461 const int kSpaceTagSize = 3;
462 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
464 enum AllocationAlignment {
471 // A flag that indicates whether objects should be pretenured when
472 // allocated (allocated directly into the old generation) or not
473 // (allocated in the young generation if the object size and type
475 enum PretenureFlag { NOT_TENURED, TENURED };
477 inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
480 return os << "NotTenured";
482 return os << "Tenured";
488 enum MinimumCapacity {
489 USE_DEFAULT_MINIMUM_CAPACITY,
490 USE_CUSTOM_MINIMUM_CAPACITY
493 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
495 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
499 VISIT_ALL_IN_SCAVENGE,
500 VISIT_ALL_IN_SWEEP_NEWSPACE,
504 // Flag indicating whether code is built into the VM (one of the natives files).
505 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
508 // ParseRestriction is used to restrict the set of valid statements in a
509 // unit of compilation. Restriction violations cause a syntax error.
510 enum ParseRestriction {
511 NO_PARSE_RESTRICTION, // All expressions are allowed.
512 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression.
515 // A CodeDesc describes a buffer holding instructions and relocation
516 // information. The instructions start at the beginning of the buffer
517 // and grow forward, the relocation information starts at the end of
518 // the buffer and grows backward. A constant pool may exist at the
519 // end of the instructions.
521 // |<--------------- buffer_size ----------------------------------->|
522 // |<------------- instr_size ---------->| |<-- reloc_size -->|
523 // | |<- const_pool_size ->| |
524 // +=====================================+========+==================+
525 // | instructions | data | free | reloc info |
526 // +=====================================+========+==================+
536 int constant_pool_size;
541 // Callback function used for iterating objects in heap spaces,
542 // for example, scanning heap objects.
543 typedef int (*HeapObjectCallback)(HeapObject* obj);
546 // Callback function used for checking constraints when copying/relocating
547 // objects. Returns true if an object can be copied/relocated from its
548 // old_addr to a new_addr.
549 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
552 // Callback function on inline caches, used for iterating over inline caches
554 typedef void (*InlineCacheCallback)(Code* code, Address ic);
557 // State for inline cache call sites. Aliased as IC::State.
558 enum InlineCacheState {
559 // Has never been executed.
561 // Has been executed but monomorhic state has been delayed.
563 // Has been executed and only one receiver type has been seen.
565 // Check failed due to prototype (or map deprecation).
567 // Multiple receiver types have been seen.
569 // Many receiver types have been seen.
571 // A generic handler is installed and no extra typefeedback is recorded.
573 // Special state for debug break or step in prepare stubs.
575 // Type-vector-based ICs have a default state, with the full calculation
576 // of IC state only determined by a look at the IC and the typevector
582 enum CallFunctionFlags {
583 NO_CALL_FUNCTION_FLAGS,
585 // Always wrap the receiver and call to the JSFunction. Only use this flag
586 // both the receiver type and the target method are statically known.
591 enum CallConstructorFlags {
592 NO_CALL_CONSTRUCTOR_FLAGS = 0,
593 // The call target is cached in the instruction stream.
594 RECORD_CONSTRUCTOR_TARGET = 1,
595 SUPER_CONSTRUCTOR_CALL = 1 << 1,
596 SUPER_CALL_RECORD_TARGET = SUPER_CONSTRUCTOR_CALL | RECORD_CONSTRUCTOR_TARGET
600 enum CacheHolderFlag {
602 kCacheOnPrototypeReceiverIsDictionary,
603 kCacheOnPrototypeReceiverIsPrimitive,
608 // The Store Buffer (GC).
610 kStoreBufferFullEvent,
611 kStoreBufferStartScanningPagesEvent,
612 kStoreBufferScanningPageEvent
616 typedef void (*StoreBufferCallback)(Heap* heap,
618 StoreBufferEvent event);
621 // Union used for fast testing of specific double values.
622 union DoubleRepresentation {
625 DoubleRepresentation(double x) { value = x; }
626 bool operator==(const DoubleRepresentation& other) const {
627 return bits == other.bits;
632 // Union used for customized checking of the IEEE double types
633 // inlined within v8 runtime, rather than going to the underlying
634 // platform headers and libraries
635 union IeeeDoubleLittleEndianArchType {
638 unsigned int man_low :32;
639 unsigned int man_high :20;
640 unsigned int exp :11;
641 unsigned int sign :1;
646 union IeeeDoubleBigEndianArchType {
649 unsigned int sign :1;
650 unsigned int exp :11;
651 unsigned int man_high :20;
652 unsigned int man_low :32;
658 struct AccessorDescriptor {
659 Object* (*getter)(Isolate* isolate, Object* object, void* data);
661 Isolate* isolate, JSObject* object, Object* value, void* data);
666 // -----------------------------------------------------------------------------
671 #define HAS_SMI_TAG(value) \
672 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
674 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
675 #define OBJECT_POINTER_ALIGN(value) \
676 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
678 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
679 #define POINTER_SIZE_ALIGN(value) \
680 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
682 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
683 #define CODE_POINTER_ALIGN(value) \
684 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
686 // DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
687 #define DOUBLE_POINTER_ALIGN(value) \
688 (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
691 // CPU feature flags.
711 MOVW_MOVT_IMMEDIATE_LOADS,
727 NUMBER_OF_CPU_FEATURES
731 // Used to specify if a macro instruction must perform a smi check on tagged
740 EVAL_SCOPE, // The top-level scope for an eval source.
741 FUNCTION_SCOPE, // The top-level scope for a function.
742 MODULE_SCOPE, // The scope introduced by a module literal
743 SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval.
744 CATCH_SCOPE, // The scope introduced by catch.
745 BLOCK_SCOPE, // The scope introduced by a new block.
746 WITH_SCOPE, // The scope introduced by with.
747 ARROW_SCOPE // The top-level scope for an arrow function literal.
750 // The mips architecture prior to revision 5 has inverted encoding for sNaN.
751 #if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6)) || \
752 (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6))
753 const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
754 const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
756 const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
757 const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
760 const uint64_t kHoleNanInt64 =
761 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
764 // The order of this enum has to be kept in sync with the predicates below.
766 // User declared variables:
767 VAR, // declared via 'var', and 'function' declarations
769 CONST_LEGACY, // declared via legacy 'const' declarations
771 LET, // declared via 'let' declarations (first lexical)
773 CONST, // declared via 'const' declarations
775 IMPORT, // declared via 'import' declarations (last lexical)
777 // Variables introduced by the compiler:
778 INTERNAL, // like VAR, but not user-visible (may or may not
781 TEMPORARY, // temporary variables (not user-visible), stack-allocated
782 // unless the scope as a whole has forced context allocation
784 DYNAMIC, // always require dynamic lookup (we don't know
787 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
788 // variable is global unless it has been shadowed
789 // by an eval-introduced variable
791 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the
792 // variable is local and where it is unless it
793 // has been shadowed by an eval-introduced
798 inline bool IsDynamicVariableMode(VariableMode mode) {
799 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
803 inline bool IsDeclaredVariableMode(VariableMode mode) {
804 return mode >= VAR && mode <= IMPORT;
808 inline bool IsLexicalVariableMode(VariableMode mode) {
809 return mode >= LET && mode <= IMPORT;
813 inline bool IsImmutableVariableMode(VariableMode mode) {
814 return mode == CONST || mode == CONST_LEGACY || mode == IMPORT;
818 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
819 // and immutable bindings that can be in two states: initialized and
820 // uninitialized. In ES5 only immutable bindings have these two states. When
821 // accessing a binding, it needs to be checked for initialization. However in
822 // the following cases the binding is initialized immediately after creation
823 // so the initialization check can always be skipped:
824 // 1. Var declared local variables.
826 // 2. A local variable introduced by a function declaration.
829 // function x(foo) {}
830 // 4. Catch bound variables.
831 // try {} catch (foo) {}
832 // 6. Function variables of named function expressions.
833 // var x = function foo() {}
834 // 7. Implicit binding of 'this'.
835 // 8. Implicit binding of 'arguments' in functions.
837 // ES5 specified object environment records which are introduced by ES elements
838 // such as Program and WithStatement that associate identifier bindings with the
839 // properties of some object. In the specification only mutable bindings exist
840 // (which may be non-writable) and have no distinct initialization step. However
841 // V8 allows const declarations in global code with distinct creation and
842 // initialization steps which are represented by non-writable properties in the
843 // global object. As a result also these bindings need to be checked for
846 // The following enum specifies a flag that indicates if the binding needs a
847 // distinct initialization step (kNeedsInitialization) or if the binding is
848 // immediately initialized upon creation (kCreatedInitialized).
849 enum InitializationFlag {
850 kNeedsInitialization,
855 enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
858 // Serialized in PreparseData, so numeric values should not be changed.
859 enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
862 enum ClearExceptionFlag {
869 TREAT_MINUS_ZERO_AS_ZERO,
874 enum Signedness { kSigned, kUnsigned };
879 kArrowFunction = 1 << 0,
880 kGeneratorFunction = 1 << 1,
881 kConciseMethod = 1 << 2,
882 kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
883 kAccessorFunction = 1 << 3,
884 kDefaultConstructor = 1 << 4,
885 kSubclassConstructor = 1 << 5,
886 kBaseConstructor = 1 << 6,
887 kInObjectLiteral = 1 << 7,
888 kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
889 kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor,
890 kConciseMethodInObjectLiteral = kConciseMethod | kInObjectLiteral,
891 kConciseGeneratorMethodInObjectLiteral =
892 kConciseGeneratorMethod | kInObjectLiteral,
893 kAccessorFunctionInObjectLiteral = kAccessorFunction | kInObjectLiteral,
897 inline bool IsValidFunctionKind(FunctionKind kind) {
898 return kind == FunctionKind::kNormalFunction ||
899 kind == FunctionKind::kArrowFunction ||
900 kind == FunctionKind::kGeneratorFunction ||
901 kind == FunctionKind::kConciseMethod ||
902 kind == FunctionKind::kConciseGeneratorMethod ||
903 kind == FunctionKind::kAccessorFunction ||
904 kind == FunctionKind::kDefaultBaseConstructor ||
905 kind == FunctionKind::kDefaultSubclassConstructor ||
906 kind == FunctionKind::kBaseConstructor ||
907 kind == FunctionKind::kSubclassConstructor ||
908 kind == FunctionKind::kConciseMethodInObjectLiteral ||
909 kind == FunctionKind::kConciseGeneratorMethodInObjectLiteral ||
910 kind == FunctionKind::kAccessorFunctionInObjectLiteral;
914 inline bool IsArrowFunction(FunctionKind kind) {
915 DCHECK(IsValidFunctionKind(kind));
916 return kind & FunctionKind::kArrowFunction;
920 inline bool IsGeneratorFunction(FunctionKind kind) {
921 DCHECK(IsValidFunctionKind(kind));
922 return kind & FunctionKind::kGeneratorFunction;
926 inline bool IsConciseMethod(FunctionKind kind) {
927 DCHECK(IsValidFunctionKind(kind));
928 return kind & FunctionKind::kConciseMethod;
932 inline bool IsAccessorFunction(FunctionKind kind) {
933 DCHECK(IsValidFunctionKind(kind));
934 return kind & FunctionKind::kAccessorFunction;
938 inline bool IsDefaultConstructor(FunctionKind kind) {
939 DCHECK(IsValidFunctionKind(kind));
940 return kind & FunctionKind::kDefaultConstructor;
944 inline bool IsBaseConstructor(FunctionKind kind) {
945 DCHECK(IsValidFunctionKind(kind));
946 return kind & FunctionKind::kBaseConstructor;
950 inline bool IsSubclassConstructor(FunctionKind kind) {
951 DCHECK(IsValidFunctionKind(kind));
952 return kind & FunctionKind::kSubclassConstructor;
956 inline bool IsConstructor(FunctionKind kind) {
957 DCHECK(IsValidFunctionKind(kind));
959 (FunctionKind::kBaseConstructor | FunctionKind::kSubclassConstructor |
960 FunctionKind::kDefaultConstructor);
964 inline bool IsInObjectLiteral(FunctionKind kind) {
965 DCHECK(IsValidFunctionKind(kind));
966 return kind & FunctionKind::kInObjectLiteral;
970 inline FunctionKind WithObjectLiteralBit(FunctionKind kind) {
971 kind = static_cast<FunctionKind>(kind | FunctionKind::kInObjectLiteral);
972 DCHECK(IsValidFunctionKind(kind));
975 } } // namespace v8::internal
977 namespace i = v8::internal;
979 #endif // V8_GLOBALS_H_