| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
| 6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "src/assert-scope.h" | 11 #include "src/assert-scope.h" |
| 12 #include "src/bailout-reason.h" | 12 #include "src/bailout-reason.h" |
| 13 #include "src/base/bits.h" | 13 #include "src/base/bits.h" |
| 14 #include "src/base/flags.h" | 14 #include "src/base/flags.h" |
| 15 #include "src/builtins/builtins.h" | 15 #include "src/builtins/builtins.h" |
| 16 #include "src/checks.h" | 16 #include "src/checks.h" |
| 17 #include "src/elements-kind.h" | 17 #include "src/elements-kind.h" |
| 18 #include "src/field-index.h" | 18 #include "src/field-index.h" |
| 19 #include "src/flags.h" | 19 #include "src/flags.h" |
| 20 #include "src/list.h" | 20 #include "src/list.h" |
| 21 #include "src/messages.h" | 21 #include "src/messages.h" |
| 22 #include "src/objects/object-macros.h" |
| 22 #include "src/property-details.h" | 23 #include "src/property-details.h" |
| 23 #include "src/unicode-decoder.h" | 24 #include "src/unicode-decoder.h" |
| 24 #include "src/unicode.h" | 25 #include "src/unicode.h" |
| 25 #include "src/zone/zone.h" | 26 #include "src/zone/zone.h" |
| 26 | 27 |
| 27 #if V8_TARGET_ARCH_ARM | 28 #if V8_TARGET_ARCH_ARM |
| 28 #include "src/arm/constants-arm.h" // NOLINT | 29 #include "src/arm/constants-arm.h" // NOLINT |
| 29 #elif V8_TARGET_ARCH_ARM64 | 30 #elif V8_TARGET_ARCH_ARM64 |
| 30 #include "src/arm64/constants-arm64.h" // NOLINT | 31 #include "src/arm64/constants-arm64.h" // NOLINT |
| 31 #elif V8_TARGET_ARCH_MIPS | 32 #elif V8_TARGET_ARCH_MIPS |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 // Result of an abstract relational comparison of x and y, implemented according | 937 // Result of an abstract relational comparison of x and y, implemented according |
| 937 // to ES6 section 7.2.11 Abstract Relational Comparison. | 938 // to ES6 section 7.2.11 Abstract Relational Comparison. |
| 938 enum class ComparisonResult { | 939 enum class ComparisonResult { |
| 939 kLessThan, // x < y | 940 kLessThan, // x < y |
| 940 kEqual, // x = y | 941 kEqual, // x = y |
| 941 kGreaterThan, // x > y | 942 kGreaterThan, // x > y |
| 942 kUndefined // at least one of x or y was undefined or NaN | 943 kUndefined // at least one of x or y was undefined or NaN |
| 943 }; | 944 }; |
| 944 | 945 |
| 945 | 946 |
| 946 #define DECL_BOOLEAN_ACCESSORS(name) \ | |
| 947 inline bool name() const; \ | |
| 948 inline void set_##name(bool value); | |
| 949 | |
| 950 #define DECL_INT_ACCESSORS(name) \ | |
| 951 inline int name() const; \ | |
| 952 inline void set_##name(int value); | |
| 953 | |
| 954 | |
| 955 #define DECL_ACCESSORS(name, type) \ | |
| 956 inline type* name() const; \ | |
| 957 inline void set_##name(type* value, \ | |
| 958 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ | |
| 959 | |
| 960 | |
| 961 #define DECLARE_CAST(type) \ | |
| 962 INLINE(static type* cast(Object* object)); \ | |
| 963 INLINE(static const type* cast(const Object* object)); | |
| 964 | |
| 965 class AbstractCode; | 947 class AbstractCode; |
| 966 class AccessorPair; | 948 class AccessorPair; |
| 967 class AllocationSite; | 949 class AllocationSite; |
| 968 class AllocationSiteCreationContext; | 950 class AllocationSiteCreationContext; |
| 969 class AllocationSiteUsageContext; | 951 class AllocationSiteUsageContext; |
| 970 class Cell; | 952 class Cell; |
| 971 class ConsString; | 953 class ConsString; |
| 972 class ElementsAccessor; | 954 class ElementsAccessor; |
| 973 class FixedArrayBase; | 955 class FixedArrayBase; |
| 974 class FunctionLiteral; | 956 class FunctionLiteral; |
| (...skipping 3448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4423 | 4405 |
| 4424 void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value); | 4406 void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value); |
| 4425 | 4407 |
| 4426 // Returns the index to the value of an entry. | 4408 // Returns the index to the value of an entry. |
| 4427 static inline int EntryToValueIndex(int entry) { | 4409 static inline int EntryToValueIndex(int entry) { |
| 4428 return EntryToIndex(entry) + 1; | 4410 return EntryToIndex(entry) + 1; |
| 4429 } | 4411 } |
| 4430 }; | 4412 }; |
| 4431 | 4413 |
| 4432 | 4414 |
| 4433 // ScopeInfo represents information about different scopes of a source | |
| 4434 // program and the allocation of the scope's variables. Scope information | |
| 4435 // is stored in a compressed form in ScopeInfo objects and is used | |
| 4436 // at runtime (stack dumps, deoptimization, etc.). | |
| 4437 | |
| 4438 // This object provides quick access to scope info details for runtime | |
| 4439 // routines. | |
| 4440 class ScopeInfo : public FixedArray { | |
| 4441 public: | |
| 4442 DECLARE_CAST(ScopeInfo) | |
| 4443 | |
| 4444 // Return the type of this scope. | |
| 4445 ScopeType scope_type(); | |
| 4446 | |
| 4447 // Does this scope call eval? | |
| 4448 bool CallsEval(); | |
| 4449 | |
| 4450 // Return the language mode of this scope. | |
| 4451 LanguageMode language_mode(); | |
| 4452 | |
| 4453 // True if this scope is a (var) declaration scope. | |
| 4454 bool is_declaration_scope(); | |
| 4455 | |
| 4456 // Does this scope make a sloppy eval call? | |
| 4457 bool CallsSloppyEval() { return CallsEval() && is_sloppy(language_mode()); } | |
| 4458 | |
| 4459 // Return the total number of locals allocated on the stack and in the | |
| 4460 // context. This includes the parameters that are allocated in the context. | |
| 4461 int LocalCount(); | |
| 4462 | |
| 4463 // Return the number of stack slots for code. This number consists of two | |
| 4464 // parts: | |
| 4465 // 1. One stack slot per stack allocated local. | |
| 4466 // 2. One stack slot for the function name if it is stack allocated. | |
| 4467 int StackSlotCount(); | |
| 4468 | |
| 4469 // Return the number of context slots for code if a context is allocated. This | |
| 4470 // number consists of three parts: | |
| 4471 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS | |
| 4472 // 2. One context slot per context allocated local. | |
| 4473 // 3. One context slot for the function name if it is context allocated. | |
| 4474 // Parameters allocated in the context count as context allocated locals. If | |
| 4475 // no contexts are allocated for this scope ContextLength returns 0. | |
| 4476 int ContextLength(); | |
| 4477 | |
| 4478 // Does this scope declare a "this" binding? | |
| 4479 bool HasReceiver(); | |
| 4480 | |
| 4481 // Does this scope declare a "this" binding, and the "this" binding is stack- | |
| 4482 // or context-allocated? | |
| 4483 bool HasAllocatedReceiver(); | |
| 4484 | |
| 4485 // Does this scope declare a "new.target" binding? | |
| 4486 bool HasNewTarget(); | |
| 4487 | |
| 4488 // Is this scope the scope of a named function expression? | |
| 4489 bool HasFunctionName(); | |
| 4490 | |
| 4491 // Return if this has context allocated locals. | |
| 4492 bool HasHeapAllocatedLocals(); | |
| 4493 | |
| 4494 // Return if contexts are allocated for this scope. | |
| 4495 bool HasContext(); | |
| 4496 | |
| 4497 // Return if this is a function scope with "use asm". | |
| 4498 inline bool IsAsmModule(); | |
| 4499 | |
| 4500 // Return if this is a nested function within an asm module scope. | |
| 4501 inline bool IsAsmFunction(); | |
| 4502 | |
| 4503 inline bool HasSimpleParameters(); | |
| 4504 | |
| 4505 // Return the function_name if present. | |
| 4506 String* FunctionName(); | |
| 4507 | |
| 4508 ModuleInfo* ModuleDescriptorInfo(); | |
| 4509 | |
| 4510 // Return the name of the given parameter. | |
| 4511 String* ParameterName(int var); | |
| 4512 | |
| 4513 // Return the name of the given local. | |
| 4514 String* LocalName(int var); | |
| 4515 | |
| 4516 // Return the name of the given stack local. | |
| 4517 String* StackLocalName(int var); | |
| 4518 | |
| 4519 // Return the name of the given stack local. | |
| 4520 int StackLocalIndex(int var); | |
| 4521 | |
| 4522 // Return the name of the given context local. | |
| 4523 String* ContextLocalName(int var); | |
| 4524 | |
| 4525 // Return the mode of the given context local. | |
| 4526 VariableMode ContextLocalMode(int var); | |
| 4527 | |
| 4528 // Return the initialization flag of the given context local. | |
| 4529 InitializationFlag ContextLocalInitFlag(int var); | |
| 4530 | |
| 4531 // Return the initialization flag of the given context local. | |
| 4532 MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var); | |
| 4533 | |
| 4534 // Return true if this local was introduced by the compiler, and should not be | |
| 4535 // exposed to the user in a debugger. | |
| 4536 static bool VariableIsSynthetic(String* name); | |
| 4537 | |
| 4538 // Lookup support for serialized scope info. Returns the | |
| 4539 // the stack slot index for a given slot name if the slot is | |
| 4540 // present; otherwise returns a value < 0. The name must be an internalized | |
| 4541 // string. | |
| 4542 int StackSlotIndex(String* name); | |
| 4543 | |
| 4544 // Lookup support for serialized scope info. Returns the local context slot | |
| 4545 // index for a given slot name if the slot is present; otherwise | |
| 4546 // returns a value < 0. The name must be an internalized string. | |
| 4547 // If the slot is present and mode != NULL, sets *mode to the corresponding | |
| 4548 // mode for that variable. | |
| 4549 static int ContextSlotIndex(Handle<ScopeInfo> scope_info, Handle<String> name, | |
| 4550 VariableMode* mode, InitializationFlag* init_flag, | |
| 4551 MaybeAssignedFlag* maybe_assigned_flag); | |
| 4552 | |
| 4553 // Lookup metadata of a MODULE-allocated variable. Return 0 if there is no | |
| 4554 // module variable with the given name (the index value of a MODULE variable | |
| 4555 // is never 0). | |
| 4556 int ModuleIndex(Handle<String> name, VariableMode* mode, | |
| 4557 InitializationFlag* init_flag, | |
| 4558 MaybeAssignedFlag* maybe_assigned_flag); | |
| 4559 | |
| 4560 // Lookup the name of a certain context slot by its index. | |
| 4561 String* ContextSlotName(int slot_index); | |
| 4562 | |
| 4563 // Lookup support for serialized scope info. Returns the | |
| 4564 // parameter index for a given parameter name if the parameter is present; | |
| 4565 // otherwise returns a value < 0. The name must be an internalized string. | |
| 4566 int ParameterIndex(String* name); | |
| 4567 | |
| 4568 // Lookup support for serialized scope info. Returns the function context | |
| 4569 // slot index if the function name is present and context-allocated (named | |
| 4570 // function expressions, only), otherwise returns a value < 0. The name | |
| 4571 // must be an internalized string. | |
| 4572 int FunctionContextSlotIndex(String* name); | |
| 4573 | |
| 4574 // Lookup support for serialized scope info. Returns the receiver context | |
| 4575 // slot index if scope has a "this" binding, and the binding is | |
| 4576 // context-allocated. Otherwise returns a value < 0. | |
| 4577 int ReceiverContextSlotIndex(); | |
| 4578 | |
| 4579 FunctionKind function_kind(); | |
| 4580 | |
| 4581 // Returns true if this ScopeInfo is linked to a outer ScopeInfo. | |
| 4582 bool HasOuterScopeInfo(); | |
| 4583 | |
| 4584 // Returns true if this ScopeInfo was created for a debug-evaluate scope. | |
| 4585 bool IsDebugEvaluateScope(); | |
| 4586 | |
| 4587 // Can be used to mark a ScopeInfo that looks like a with-scope as actually | |
| 4588 // being a debug-evaluate scope. | |
| 4589 void SetIsDebugEvaluateScope(); | |
| 4590 | |
| 4591 // Return the outer ScopeInfo if present. | |
| 4592 ScopeInfo* OuterScopeInfo(); | |
| 4593 | |
| 4594 #ifdef DEBUG | |
| 4595 bool Equals(ScopeInfo* other) const; | |
| 4596 #endif | |
| 4597 | |
| 4598 static Handle<ScopeInfo> Create(Isolate* isolate, Zone* zone, Scope* scope, | |
| 4599 MaybeHandle<ScopeInfo> outer_scope); | |
| 4600 static Handle<ScopeInfo> CreateForWithScope( | |
| 4601 Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope); | |
| 4602 static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate); | |
| 4603 | |
| 4604 // Serializes empty scope info. | |
| 4605 V8_EXPORT_PRIVATE static ScopeInfo* Empty(Isolate* isolate); | |
| 4606 | |
| 4607 #ifdef DEBUG | |
| 4608 void Print(); | |
| 4609 #endif | |
| 4610 | |
| 4611 // The layout of the static part of a ScopeInfo is as follows. Each entry is | |
| 4612 // numeric and occupies one array slot. | |
| 4613 // 1. A set of properties of the scope. | |
| 4614 // 2. The number of parameters. For non-function scopes this is 0. | |
| 4615 // 3. The number of non-parameter variables allocated on the stack. | |
| 4616 // 4. The number of non-parameter and parameter variables allocated in the | |
| 4617 // context. | |
| 4618 #define FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(V) \ | |
| 4619 V(Flags) \ | |
| 4620 V(ParameterCount) \ | |
| 4621 V(StackLocalCount) \ | |
| 4622 V(ContextLocalCount) | |
| 4623 | |
| 4624 #define FIELD_ACCESSORS(name) \ | |
| 4625 inline void Set##name(int value); \ | |
| 4626 inline int name(); | |
| 4627 FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS) | |
| 4628 #undef FIELD_ACCESSORS | |
| 4629 | |
| 4630 enum { | |
| 4631 #define DECL_INDEX(name) k##name, | |
| 4632 FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(DECL_INDEX) | |
| 4633 #undef DECL_INDEX | |
| 4634 kVariablePartIndex | |
| 4635 }; | |
| 4636 | |
| 4637 private: | |
| 4638 // The layout of the variable part of a ScopeInfo is as follows: | |
| 4639 // 1. ParameterNames: | |
| 4640 // This part stores the names of the parameters for function scopes. One | |
| 4641 // slot is used per parameter, so in total this part occupies | |
| 4642 // ParameterCount() slots in the array. For other scopes than function | |
| 4643 // scopes ParameterCount() is 0. | |
| 4644 // 2. StackLocalFirstSlot: | |
| 4645 // Index of a first stack slot for stack local. Stack locals belonging to | |
| 4646 // this scope are located on a stack at slots starting from this index. | |
| 4647 // 3. StackLocalNames: | |
| 4648 // Contains the names of local variables that are allocated on the stack, | |
| 4649 // in increasing order of the stack slot index. First local variable has a | |
| 4650 // stack slot index defined in StackLocalFirstSlot (point 2 above). | |
| 4651 // One slot is used per stack local, so in total this part occupies | |
| 4652 // StackLocalCount() slots in the array. | |
| 4653 // 4. ContextLocalNames: | |
| 4654 // Contains the names of local variables and parameters that are allocated | |
| 4655 // in the context. They are stored in increasing order of the context slot | |
| 4656 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per | |
| 4657 // context local, so in total this part occupies ContextLocalCount() slots | |
| 4658 // in the array. | |
| 4659 // 5. ContextLocalInfos: | |
| 4660 // Contains the variable modes and initialization flags corresponding to | |
| 4661 // the context locals in ContextLocalNames. One slot is used per | |
| 4662 // context local, so in total this part occupies ContextLocalCount() | |
| 4663 // slots in the array. | |
| 4664 // 6. ReceiverInfo: | |
| 4665 // If the scope binds a "this" value, one slot is reserved to hold the | |
| 4666 // context or stack slot index for the variable. | |
| 4667 // 7. FunctionNameInfo: | |
| 4668 // If the scope belongs to a named function expression this part contains | |
| 4669 // information about the function variable. It always occupies two array | |
| 4670 // slots: a. The name of the function variable. | |
| 4671 // b. The context or stack slot index for the variable. | |
| 4672 // 8. OuterScopeInfoIndex: | |
| 4673 // The outer scope's ScopeInfo or the hole if there's none. | |
| 4674 // 9. ModuleInfo, ModuleVariableCount, and ModuleVariables: | |
| 4675 // For a module scope, this part contains the ModuleInfo, the number of | |
| 4676 // MODULE-allocated variables, and the metadata of those variables. For | |
| 4677 // non-module scopes it is empty. | |
| 4678 int ParameterNamesIndex(); | |
| 4679 int StackLocalFirstSlotIndex(); | |
| 4680 int StackLocalNamesIndex(); | |
| 4681 int ContextLocalNamesIndex(); | |
| 4682 int ContextLocalInfosIndex(); | |
| 4683 int ReceiverInfoIndex(); | |
| 4684 int FunctionNameInfoIndex(); | |
| 4685 int OuterScopeInfoIndex(); | |
| 4686 int ModuleInfoIndex(); | |
| 4687 int ModuleVariableCountIndex(); | |
| 4688 int ModuleVariablesIndex(); | |
| 4689 | |
| 4690 int Lookup(Handle<String> name, int start, int end, VariableMode* mode, | |
| 4691 VariableLocation* location, InitializationFlag* init_flag, | |
| 4692 MaybeAssignedFlag* maybe_assigned_flag); | |
| 4693 | |
| 4694 // Get metadata of i-th MODULE-allocated variable, where 0 <= i < | |
| 4695 // ModuleVariableCount. The metadata is returned via out-arguments, which may | |
| 4696 // be nullptr if the corresponding information is not requested | |
| 4697 void ModuleVariable(int i, String** name, int* index, | |
| 4698 VariableMode* mode = nullptr, | |
| 4699 InitializationFlag* init_flag = nullptr, | |
| 4700 MaybeAssignedFlag* maybe_assigned_flag = nullptr); | |
| 4701 | |
| 4702 // Used for the function name variable for named function expressions, and for | |
| 4703 // the receiver. | |
| 4704 enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED }; | |
| 4705 | |
| 4706 // Properties of scopes. | |
| 4707 class ScopeTypeField : public BitField<ScopeType, 0, 4> {}; | |
| 4708 class CallsEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {}; | |
| 4709 STATIC_ASSERT(LANGUAGE_END == 2); | |
| 4710 class LanguageModeField | |
| 4711 : public BitField<LanguageMode, CallsEvalField::kNext, 1> {}; | |
| 4712 class DeclarationScopeField | |
| 4713 : public BitField<bool, LanguageModeField::kNext, 1> {}; | |
| 4714 class ReceiverVariableField | |
| 4715 : public BitField<VariableAllocationInfo, DeclarationScopeField::kNext, | |
| 4716 2> {}; | |
| 4717 class HasNewTargetField | |
| 4718 : public BitField<bool, ReceiverVariableField::kNext, 1> {}; | |
| 4719 class FunctionVariableField | |
| 4720 : public BitField<VariableAllocationInfo, HasNewTargetField::kNext, 2> {}; | |
| 4721 class AsmModuleField | |
| 4722 : public BitField<bool, FunctionVariableField::kNext, 1> {}; | |
| 4723 class AsmFunctionField : public BitField<bool, AsmModuleField::kNext, 1> {}; | |
| 4724 class HasSimpleParametersField | |
| 4725 : public BitField<bool, AsmFunctionField::kNext, 1> {}; | |
| 4726 class FunctionKindField | |
| 4727 : public BitField<FunctionKind, HasSimpleParametersField::kNext, 10> {}; | |
| 4728 class HasOuterScopeInfoField | |
| 4729 : public BitField<bool, FunctionKindField::kNext, 1> {}; | |
| 4730 class IsDebugEvaluateScopeField | |
| 4731 : public BitField<bool, HasOuterScopeInfoField::kNext, 1> {}; | |
| 4732 | |
| 4733 // Properties of variables. | |
| 4734 class VariableModeField : public BitField<VariableMode, 0, 3> {}; | |
| 4735 class InitFlagField : public BitField<InitializationFlag, 3, 1> {}; | |
| 4736 class MaybeAssignedFlagField : public BitField<MaybeAssignedFlag, 4, 1> {}; | |
| 4737 | |
| 4738 friend class ScopeIterator; | |
| 4739 }; | |
| 4740 | |
| 4741 // The cache for maps used by normalized (dictionary mode) objects. | 4415 // The cache for maps used by normalized (dictionary mode) objects. |
| 4742 // Such maps do not have property descriptors, so a typical program | 4416 // Such maps do not have property descriptors, so a typical program |
| 4743 // needs very limited number of distinct normalized maps. | 4417 // needs very limited number of distinct normalized maps. |
| 4744 class NormalizedMapCache: public FixedArray { | 4418 class NormalizedMapCache: public FixedArray { |
| 4745 public: | 4419 public: |
| 4746 static Handle<NormalizedMapCache> New(Isolate* isolate); | 4420 static Handle<NormalizedMapCache> New(Isolate* isolate); |
| 4747 | 4421 |
| 4748 MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, | 4422 MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, |
| 4749 PropertyNormalizationMode mode); | 4423 PropertyNormalizationMode mode); |
| 4750 void Set(Handle<Map> fast_map, Handle<Map> normalized_map); | 4424 void Set(Handle<Map> fast_map, Handle<Map> normalized_map); |
| (...skipping 7270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12021 value &= ~(1 << bit_position); | 11695 value &= ~(1 << bit_position); |
| 12022 } | 11696 } |
| 12023 return value; | 11697 return value; |
| 12024 } | 11698 } |
| 12025 }; | 11699 }; |
| 12026 | 11700 |
| 12027 | 11701 |
| 12028 } // NOLINT, false-positive due to second-order macros. | 11702 } // NOLINT, false-positive due to second-order macros. |
| 12029 } // NOLINT, false-positive due to second-order macros. | 11703 } // NOLINT, false-positive due to second-order macros. |
| 12030 | 11704 |
| 11705 #include "src/objects/object-macros-undef.h" |
| 11706 |
| 12031 #endif // V8_OBJECTS_H_ | 11707 #endif // V8_OBJECTS_H_ |
| OLD | NEW |