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
43 // Determine whether we are running in a simulated environment.
44 // Setting USE_SIMULATOR explicitly from the build script will force
45 // the use of a simulated environment.
46 #if !defined(USE_SIMULATOR)
47 #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
48 #define USE_SIMULATOR 1
50 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
51 #define USE_SIMULATOR 1
53 #if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC)
54 #define USE_SIMULATOR 1
56 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
57 #define USE_SIMULATOR 1
59 #if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
60 #define USE_SIMULATOR 1
64 // Determine whether the architecture uses an embedded constant pool
65 // (contiguous constant pool embedded in code object).
66 #if V8_TARGET_ARCH_PPC
67 #define V8_EMBEDDED_CONSTANT_POOL 1
69 #define V8_EMBEDDED_CONSTANT_POOL 0
72 #ifdef V8_TARGET_ARCH_ARM
73 // Set stack limit lower for ARM than for other architectures because
74 // stack allocating MacroAssembler takes 120K bytes.
75 // See issue crbug.com/405338
76 #define V8_DEFAULT_STACK_SIZE_KB 864
78 // Slightly less than 1MB, since Windows' default stack size for
79 // the main execution thread is 1MB for both 32 and 64-bit.
80 #define V8_DEFAULT_STACK_SIZE_KB 984
84 // Determine whether double field unboxing feature is enabled.
85 #if V8_TARGET_ARCH_64_BIT
86 #define V8_DOUBLE_FIELDS_UNBOXING 1
88 #define V8_DOUBLE_FIELDS_UNBOXING 0
93 typedef byte* Address;
95 // -----------------------------------------------------------------------------
99 const int MB = KB * KB;
100 const int GB = KB * KB * KB;
101 const int kMaxInt = 0x7FFFFFFF;
102 const int kMinInt = -kMaxInt - 1;
103 const int kMaxInt8 = (1 << 7) - 1;
104 const int kMinInt8 = -(1 << 7);
105 const int kMaxUInt8 = (1 << 8) - 1;
106 const int kMinUInt8 = 0;
107 const int kMaxInt16 = (1 << 15) - 1;
108 const int kMinInt16 = -(1 << 15);
109 const int kMaxUInt16 = (1 << 16) - 1;
110 const int kMinUInt16 = 0;
112 const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
114 const int kCharSize = sizeof(char); // NOLINT
115 const int kShortSize = sizeof(short); // NOLINT
116 const int kIntSize = sizeof(int); // NOLINT
117 const int kInt32Size = sizeof(int32_t); // NOLINT
118 const int kInt64Size = sizeof(int64_t); // NOLINT
119 const int kFloatSize = sizeof(float); // NOLINT
120 const int kDoubleSize = sizeof(double); // NOLINT
121 const int kIntptrSize = sizeof(intptr_t); // NOLINT
122 const int kPointerSize = sizeof(void*); // NOLINT
123 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
124 const int kRegisterSize = kPointerSize + kPointerSize;
126 const int kRegisterSize = kPointerSize;
128 const int kPCOnStackSize = kRegisterSize;
129 const int kFPOnStackSize = kRegisterSize;
131 const int kDoubleSizeLog2 = 3;
133 #if V8_HOST_ARCH_64_BIT
134 const int kPointerSizeLog2 = 3;
135 const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
136 const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
137 const bool kRequiresCodeRange = true;
138 #if V8_TARGET_ARCH_MIPS64
139 // To use pseudo-relative jumps such as j/jal instructions which have 28-bit
140 // encoded immediate, the addresses have to be in range of 256MB aligned
141 // region. Used only for large object space.
142 const size_t kMaximalCodeRangeSize = 256 * MB;
144 const size_t kMaximalCodeRangeSize = 512 * MB;
147 const size_t kMinimumCodeRangeSize = 4 * MB;
148 const size_t kReservedCodeRangePages = 1;
150 const size_t kMinimumCodeRangeSize = 3 * MB;
151 const size_t kReservedCodeRangePages = 0;
154 const int kPointerSizeLog2 = 2;
155 const intptr_t kIntptrSignBit = 0x80000000;
156 const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
157 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
158 // x32 port also requires code range.
159 const bool kRequiresCodeRange = true;
160 const size_t kMaximalCodeRangeSize = 256 * MB;
161 const size_t kMinimumCodeRangeSize = 3 * MB;
162 const size_t kReservedCodeRangePages = 0;
164 const bool kRequiresCodeRange = false;
165 const size_t kMaximalCodeRangeSize = 0 * MB;
166 const size_t kMinimumCodeRangeSize = 0 * MB;
167 const size_t kReservedCodeRangePages = 0;
171 STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
173 const int kBitsPerByte = 8;
174 const int kBitsPerByteLog2 = 3;
175 const int kBitsPerPointer = kPointerSize * kBitsPerByte;
176 const int kBitsPerInt = kIntSize * kBitsPerByte;
178 // IEEE 754 single precision floating point number bit layout.
179 const uint32_t kBinary32SignMask = 0x80000000u;
180 const uint32_t kBinary32ExponentMask = 0x7f800000u;
181 const uint32_t kBinary32MantissaMask = 0x007fffffu;
182 const int kBinary32ExponentBias = 127;
183 const int kBinary32MaxExponent = 0xFE;
184 const int kBinary32MinExponent = 0x01;
185 const int kBinary32MantissaBits = 23;
186 const int kBinary32ExponentShift = 23;
188 // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
190 const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
192 // Latin1/UTF-16 constants
193 // Code-point values in Unicode 4.0 are 21 bits wide.
194 // Code units in UTF-16 are 16 bits wide.
195 typedef uint16_t uc16;
196 typedef int32_t uc32;
197 const int kOneByteSize = kCharSize;
198 const int kUC16Size = sizeof(uc16); // NOLINT
200 // 128 bit SIMD value size.
201 const int kSimd128Size = 16;
203 // Round up n to be a multiple of sz, where sz is a power of 2.
204 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
207 // FUNCTION_ADDR(f) gets the address of a C function f.
208 #define FUNCTION_ADDR(f) \
209 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
212 // FUNCTION_CAST<F>(addr) casts an address into a function
213 // of type F. Used to invoke generated code from within C.
214 template <typename F>
215 F FUNCTION_CAST(Address addr) {
216 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
220 // -----------------------------------------------------------------------------
221 // Forward declarations for frequently used classes
222 // (sorted alphabetically)
224 class FreeStoreAllocationPolicy;
225 template <typename T, class P = FreeStoreAllocationPolicy> class List;
227 // -----------------------------------------------------------------------------
228 // Declarations for use in both the preparser and the rest of V8.
230 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
233 // LanguageMode is expressed as a bitmask. Descriptions of the bits:
238 // Shorthands for some common language modes.
241 STRONG = STRICT_BIT | STRONG_BIT
245 inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
248 return os << "sloppy";
250 return os << "strict";
252 return os << "strong";
254 return os << "unknown";
259 inline bool is_sloppy(LanguageMode language_mode) {
260 return (language_mode & STRICT_BIT) == 0;
264 inline bool is_strict(LanguageMode language_mode) {
265 return language_mode & STRICT_BIT;
269 inline bool is_strong(LanguageMode language_mode) {
270 return language_mode & STRONG_BIT;
274 inline bool is_valid_language_mode(int language_mode) {
275 return language_mode == SLOPPY || language_mode == STRICT ||
276 language_mode == STRONG;
280 inline LanguageMode construct_language_mode(bool strict_bit, bool strong_bit) {
281 int language_mode = 0;
282 if (strict_bit) language_mode |= STRICT_BIT;
283 if (strong_bit) language_mode |= STRONG_BIT;
284 DCHECK(is_valid_language_mode(language_mode));
285 return static_cast<LanguageMode>(language_mode);
289 // Strong mode behaviour must sometimes be signalled by a two valued enum where
290 // caching is involved, to prevent sloppy and strict mode from being incorrectly
292 enum class Strength : bool {
293 WEAK, // sloppy, strict behaviour
294 STRONG // strong behaviour
298 inline bool is_strong(Strength strength) {
299 return strength == Strength::STRONG;
303 inline std::ostream& operator<<(std::ostream& os, const Strength& strength) {
304 return os << (is_strong(strength) ? "strong" : "weak");
308 inline Strength strength(LanguageMode language_mode) {
309 return is_strong(language_mode) ? Strength::STRONG : Strength::WEAK;
313 inline size_t hash_value(Strength strength) {
314 return static_cast<size_t>(strength);
318 // Mask for the sign bit in a smi.
319 const intptr_t kSmiSignMask = kIntptrSignBit;
321 const int kObjectAlignmentBits = kPointerSizeLog2;
322 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
323 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
325 // Desired alignment for pointers.
326 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
327 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
329 // Desired alignment for double values.
330 const intptr_t kDoubleAlignment = 8;
331 const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
333 // Desired alignment for 128 bit SIMD values.
334 const intptr_t kSimd128Alignment = 16;
335 const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1;
337 // Desired alignment for generated code is 32 bytes (to improve cache line
339 const int kCodeAlignmentBits = 5;
340 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
341 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
343 // The owner field of a page is tagged with the page header tag. We need that
344 // to find out if a slot is part of a large object. If we mask out the lower
345 // 0xfffff bits (1M pages), go to the owner offset, and see that this field
346 // is tagged with the page header tag, we can just look up the owner.
347 // Otherwise, we know that we are somewhere (not within the first 1M) in a
349 const int kPageHeaderTag = 3;
350 const int kPageHeaderTagSize = 2;
351 const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
354 // Zap-value: The value used for zapping dead objects.
355 // Should be a recognizable hex value tagged as a failure.
356 #ifdef V8_HOST_ARCH_64_BIT
357 const Address kZapValue =
358 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
359 const Address kHandleZapValue =
360 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
361 const Address kGlobalHandleZapValue =
362 reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
363 const Address kFromSpaceZapValue =
364 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
365 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
366 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
367 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
369 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
370 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
371 const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
372 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
373 const uint32_t kSlotsZapValue = 0xbeefdeef;
374 const uint32_t kDebugZapValue = 0xbadbaddb;
375 const uint32_t kFreeListZapValue = 0xfeed1eaf;
378 const int kCodeZapValue = 0xbadc0de;
379 const uint32_t kPhantomReferenceZap = 0xca11bac;
381 // On Intel architecture, cache line size is 64 bytes.
382 // On ARM it may be less (32 bytes), but as far this constant is
383 // used for aligning data, it doesn't hurt to align on a greater value.
384 #define PROCESSOR_CACHE_LINE_SIZE 64
386 // Constants relevant to double precision floating point numbers.
387 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
388 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
391 // -----------------------------------------------------------------------------
392 // Forward declarations for frequently used classes
405 class DescriptorArray;
406 class TransitionArray;
407 class ExternalReference;
409 class FunctionTemplateInfo;
411 class SeededNumberDictionary;
412 class UnseededNumberDictionary;
413 class NameDictionary;
414 class GlobalDictionary;
415 template <typename T> class MaybeHandle;
416 template <typename T> class Handle;
420 class InterceptorInfo;
426 class LargeObjectSpace;
427 class MacroAssembler;
430 class MarkCompactCollector;
434 class ParameterCount;
440 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
449 class MessageLocation;
451 typedef bool (*WeakSlotCallback)(Object** pointer);
453 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
455 // -----------------------------------------------------------------------------
458 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
460 // Keep this enum in sync with the ObjectSpace enum in v8.h
461 enum AllocationSpace {
462 NEW_SPACE, // Semispaces collected with copying collector.
463 OLD_SPACE, // May contain pointers to new space.
464 CODE_SPACE, // No pointers to new space, marked executable.
465 MAP_SPACE, // Only and all map objects.
466 LO_SPACE, // Promoted large objects.
468 FIRST_SPACE = NEW_SPACE,
469 LAST_SPACE = LO_SPACE,
470 FIRST_PAGED_SPACE = OLD_SPACE,
471 LAST_PAGED_SPACE = MAP_SPACE
473 const int kSpaceTagSize = 3;
474 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
476 enum AllocationAlignment {
483 // A flag that indicates whether objects should be pretenured when
484 // allocated (allocated directly into the old generation) or not
485 // (allocated in the young generation if the object size and type
487 enum PretenureFlag { NOT_TENURED, TENURED };
489 inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
492 return os << "NotTenured";
494 return os << "Tenured";
500 enum MinimumCapacity {
501 USE_DEFAULT_MINIMUM_CAPACITY,
502 USE_CUSTOM_MINIMUM_CAPACITY
505 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
507 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
511 VISIT_ALL_IN_SCAVENGE,
512 VISIT_ALL_IN_SWEEP_NEWSPACE,
516 // Flag indicating whether code is built into the VM (one of the natives files).
517 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
519 // JavaScript defines two kinds of 'nil'.
520 enum NilValue { kNullValue, kUndefinedValue };
522 // ParseRestriction is used to restrict the set of valid statements in a
523 // unit of compilation. Restriction violations cause a syntax error.
524 enum ParseRestriction {
525 NO_PARSE_RESTRICTION, // All expressions are allowed.
526 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression.
529 // A CodeDesc describes a buffer holding instructions and relocation
530 // information. The instructions start at the beginning of the buffer
531 // and grow forward, the relocation information starts at the end of
532 // the buffer and grows backward. A constant pool may exist at the
533 // end of the instructions.
535 // |<--------------- buffer_size ----------------------------------->|
536 // |<------------- instr_size ---------->| |<-- reloc_size -->|
537 // | |<- const_pool_size ->| |
538 // +=====================================+========+==================+
539 // | instructions | data | free | reloc info |
540 // +=====================================+========+==================+
550 int constant_pool_size;
555 // Callback function used for checking constraints when copying/relocating
556 // objects. Returns true if an object can be copied/relocated from its
557 // old_addr to a new_addr.
558 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
561 // Callback function on inline caches, used for iterating over inline caches
563 typedef void (*InlineCacheCallback)(Code* code, Address ic);
566 // State for inline cache call sites. Aliased as IC::State.
567 enum InlineCacheState {
568 // Has never been executed.
570 // Has been executed but monomorhic state has been delayed.
572 // Has been executed and only one receiver type has been seen.
574 // Check failed due to prototype (or map deprecation).
576 // Multiple receiver types have been seen.
578 // Many receiver types have been seen.
580 // A generic handler is installed and no extra typefeedback is recorded.
582 // Special state for debug break or step in prepare stubs.
584 // Type-vector-based ICs have a default state, with the full calculation
585 // of IC state only determined by a look at the IC and the typevector
591 enum CallFunctionFlags {
592 NO_CALL_FUNCTION_FLAGS,
594 // Always wrap the receiver and call to the JSFunction. Only use this flag
595 // both the receiver type and the target method are statically known.
600 enum CallConstructorFlags {
601 NO_CALL_CONSTRUCTOR_FLAGS = 0,
602 // The call target is cached in the instruction stream.
603 RECORD_CONSTRUCTOR_TARGET = 1,
604 SUPER_CONSTRUCTOR_CALL = 1 << 1,
605 SUPER_CALL_RECORD_TARGET = SUPER_CONSTRUCTOR_CALL | RECORD_CONSTRUCTOR_TARGET
609 enum CacheHolderFlag {
611 kCacheOnPrototypeReceiverIsDictionary,
612 kCacheOnPrototypeReceiverIsPrimitive,
617 // The Store Buffer (GC).
619 kStoreBufferFullEvent,
620 kStoreBufferStartScanningPagesEvent,
621 kStoreBufferScanningPageEvent
625 typedef void (*StoreBufferCallback)(Heap* heap,
627 StoreBufferEvent event);
630 // Union used for fast testing of specific double values.
631 union DoubleRepresentation {
634 DoubleRepresentation(double x) { value = x; }
635 bool operator==(const DoubleRepresentation& other) const {
636 return bits == other.bits;
641 // Union used for customized checking of the IEEE double types
642 // inlined within v8 runtime, rather than going to the underlying
643 // platform headers and libraries
644 union IeeeDoubleLittleEndianArchType {
647 unsigned int man_low :32;
648 unsigned int man_high :20;
649 unsigned int exp :11;
650 unsigned int sign :1;
655 union IeeeDoubleBigEndianArchType {
658 unsigned int sign :1;
659 unsigned int exp :11;
660 unsigned int man_high :20;
661 unsigned int man_low :32;
667 struct AccessorDescriptor {
668 Object* (*getter)(Isolate* isolate, Object* object, void* data);
670 Isolate* isolate, JSObject* object, Object* value, void* data);
675 // -----------------------------------------------------------------------------
680 #define HAS_SMI_TAG(value) \
681 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
683 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
684 #define OBJECT_POINTER_ALIGN(value) \
685 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
687 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
688 #define POINTER_SIZE_ALIGN(value) \
689 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
691 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
692 #define CODE_POINTER_ALIGN(value) \
693 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
695 // DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
696 #define DOUBLE_POINTER_ALIGN(value) \
697 (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
700 // CPU feature flags.
720 MOVW_MOVT_IMMEDIATE_LOADS,
736 NUMBER_OF_CPU_FEATURES
740 // Used to specify if a macro instruction must perform a smi check on tagged
749 EVAL_SCOPE, // The top-level scope for an eval source.
750 FUNCTION_SCOPE, // The top-level scope for a function.
751 MODULE_SCOPE, // The scope introduced by a module literal
752 SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval.
753 CATCH_SCOPE, // The scope introduced by catch.
754 BLOCK_SCOPE, // The scope introduced by a new block.
755 WITH_SCOPE, // The scope introduced by with.
756 ARROW_SCOPE // The top-level scope for an arrow function literal.
759 // The mips architecture prior to revision 5 has inverted encoding for sNaN.
760 #if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6)) || \
761 (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6))
762 const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
763 const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
765 const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
766 const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
769 const uint64_t kHoleNanInt64 =
770 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
773 // The order of this enum has to be kept in sync with the predicates below.
775 // User declared variables:
776 VAR, // declared via 'var', and 'function' declarations
778 CONST_LEGACY, // declared via legacy 'const' declarations
780 LET, // declared via 'let' declarations (first lexical)
782 CONST, // declared via 'const' declarations
784 IMPORT, // declared via 'import' declarations (last lexical)
786 // Variables introduced by the compiler:
787 TEMPORARY, // temporary variables (not user-visible), stack-allocated
788 // unless the scope as a whole has forced context allocation
790 DYNAMIC, // always require dynamic lookup (we don't know
793 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
794 // variable is global unless it has been shadowed
795 // by an eval-introduced variable
797 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the
798 // variable is local and where it is unless it
799 // has been shadowed by an eval-introduced
804 inline bool IsDynamicVariableMode(VariableMode mode) {
805 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
809 inline bool IsDeclaredVariableMode(VariableMode mode) {
810 return mode >= VAR && mode <= IMPORT;
814 inline bool IsLexicalVariableMode(VariableMode mode) {
815 return mode >= LET && mode <= IMPORT;
819 inline bool IsImmutableVariableMode(VariableMode mode) {
820 return mode == CONST || mode == CONST_LEGACY || mode == IMPORT;
824 enum class VariableLocation {
825 // Before and during variable allocation, a variable whose location is
826 // not yet determined. After allocation, a variable looked up as a
827 // property on the global object (and possibly absent). name() is the
828 // variable name, index() is invalid.
831 // A slot in the parameter section on the stack. index() is the
832 // parameter index, counting left-to-right. The receiver is index -1;
833 // the first parameter is index 0.
836 // A slot in the local section on the stack. index() is the variable
837 // index in the stack frame, starting at 0.
840 // An indexed slot in a heap context. index() is the variable index in
841 // the context object on the heap, starting at 0. scope() is the
842 // corresponding scope.
845 // An indexed slot in a script context that contains a respective global
846 // property cell. name() is the variable name, index() is the variable
847 // index in the context object on the heap, starting at 0. scope() is the
848 // corresponding script scope.
851 // A named slot in a heap context. name() is the variable name in the
852 // context object on the heap, with lookup starting at the current
853 // context. index() is invalid.
858 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
859 // and immutable bindings that can be in two states: initialized and
860 // uninitialized. In ES5 only immutable bindings have these two states. When
861 // accessing a binding, it needs to be checked for initialization. However in
862 // the following cases the binding is initialized immediately after creation
863 // so the initialization check can always be skipped:
864 // 1. Var declared local variables.
866 // 2. A local variable introduced by a function declaration.
869 // function x(foo) {}
870 // 4. Catch bound variables.
871 // try {} catch (foo) {}
872 // 6. Function variables of named function expressions.
873 // var x = function foo() {}
874 // 7. Implicit binding of 'this'.
875 // 8. Implicit binding of 'arguments' in functions.
877 // ES5 specified object environment records which are introduced by ES elements
878 // such as Program and WithStatement that associate identifier bindings with the
879 // properties of some object. In the specification only mutable bindings exist
880 // (which may be non-writable) and have no distinct initialization step. However
881 // V8 allows const declarations in global code with distinct creation and
882 // initialization steps which are represented by non-writable properties in the
883 // global object. As a result also these bindings need to be checked for
886 // The following enum specifies a flag that indicates if the binding needs a
887 // distinct initialization step (kNeedsInitialization) or if the binding is
888 // immediately initialized upon creation (kCreatedInitialized).
889 enum InitializationFlag {
890 kNeedsInitialization,
895 enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
898 // Serialized in PreparseData, so numeric values should not be changed.
899 enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
902 enum ClearExceptionFlag {
909 TREAT_MINUS_ZERO_AS_ZERO,
914 enum Signedness { kSigned, kUnsigned };
919 kArrowFunction = 1 << 0,
920 kGeneratorFunction = 1 << 1,
921 kConciseMethod = 1 << 2,
922 kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
923 kAccessorFunction = 1 << 3,
924 kDefaultConstructor = 1 << 4,
925 kSubclassConstructor = 1 << 5,
926 kBaseConstructor = 1 << 6,
927 kInObjectLiteral = 1 << 7,
928 kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
929 kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor,
930 kConciseMethodInObjectLiteral = kConciseMethod | kInObjectLiteral,
931 kConciseGeneratorMethodInObjectLiteral =
932 kConciseGeneratorMethod | kInObjectLiteral,
933 kAccessorFunctionInObjectLiteral = kAccessorFunction | kInObjectLiteral,
937 inline bool IsValidFunctionKind(FunctionKind kind) {
938 return kind == FunctionKind::kNormalFunction ||
939 kind == FunctionKind::kArrowFunction ||
940 kind == FunctionKind::kGeneratorFunction ||
941 kind == FunctionKind::kConciseMethod ||
942 kind == FunctionKind::kConciseGeneratorMethod ||
943 kind == FunctionKind::kAccessorFunction ||
944 kind == FunctionKind::kDefaultBaseConstructor ||
945 kind == FunctionKind::kDefaultSubclassConstructor ||
946 kind == FunctionKind::kBaseConstructor ||
947 kind == FunctionKind::kSubclassConstructor ||
948 kind == FunctionKind::kConciseMethodInObjectLiteral ||
949 kind == FunctionKind::kConciseGeneratorMethodInObjectLiteral ||
950 kind == FunctionKind::kAccessorFunctionInObjectLiteral;
954 inline bool IsArrowFunction(FunctionKind kind) {
955 DCHECK(IsValidFunctionKind(kind));
956 return kind & FunctionKind::kArrowFunction;
960 inline bool IsGeneratorFunction(FunctionKind kind) {
961 DCHECK(IsValidFunctionKind(kind));
962 return kind & FunctionKind::kGeneratorFunction;
966 inline bool IsConciseMethod(FunctionKind kind) {
967 DCHECK(IsValidFunctionKind(kind));
968 return kind & FunctionKind::kConciseMethod;
972 inline bool IsAccessorFunction(FunctionKind kind) {
973 DCHECK(IsValidFunctionKind(kind));
974 return kind & FunctionKind::kAccessorFunction;
978 inline bool IsDefaultConstructor(FunctionKind kind) {
979 DCHECK(IsValidFunctionKind(kind));
980 return kind & FunctionKind::kDefaultConstructor;
984 inline bool IsBaseConstructor(FunctionKind kind) {
985 DCHECK(IsValidFunctionKind(kind));
986 return kind & FunctionKind::kBaseConstructor;
990 inline bool IsSubclassConstructor(FunctionKind kind) {
991 DCHECK(IsValidFunctionKind(kind));
992 return kind & FunctionKind::kSubclassConstructor;
996 inline bool IsConstructor(FunctionKind kind) {
997 DCHECK(IsValidFunctionKind(kind));
999 (FunctionKind::kBaseConstructor | FunctionKind::kSubclassConstructor |
1000 FunctionKind::kDefaultConstructor);
1004 inline bool IsInObjectLiteral(FunctionKind kind) {
1005 DCHECK(IsValidFunctionKind(kind));
1006 return kind & FunctionKind::kInObjectLiteral;
1010 inline FunctionKind WithObjectLiteralBit(FunctionKind kind) {
1011 kind = static_cast<FunctionKind>(kind | FunctionKind::kInObjectLiteral);
1012 DCHECK(IsValidFunctionKind(kind));
1015 } } // namespace v8::internal
1017 namespace i = v8::internal;
1019 #endif // V8_GLOBALS_H_