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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 | 871 |
872 const uint64_t kHoleNanInt64 = | 872 const uint64_t kHoleNanInt64 = |
873 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32; | 873 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32; |
874 | 874 |
875 | 875 |
876 // ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER | 876 // ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER |
877 const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1 | 877 const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1 |
878 | 878 |
879 | 879 |
880 // The order of this enum has to be kept in sync with the predicates below. | 880 // The order of this enum has to be kept in sync with the predicates below. |
881 enum VariableMode { | 881 enum VariableMode : uint8_t { |
882 // User declared variables: | 882 // User declared variables: |
883 VAR, // declared via 'var', and 'function' declarations | 883 VAR, // declared via 'var', and 'function' declarations |
884 | 884 |
885 CONST_LEGACY, // declared via legacy 'const' declarations | 885 CONST_LEGACY, // declared via legacy 'const' declarations |
886 | 886 |
887 LET, // declared via 'let' declarations (first lexical) | 887 LET, // declared via 'let' declarations (first lexical) |
888 | 888 |
889 CONST, // declared via 'const' declarations (last lexical) | 889 CONST, // declared via 'const' declarations (last lexical) |
890 | 890 |
891 // Variables introduced by the compiler: | 891 // Variables introduced by the compiler: |
892 TEMPORARY, // temporary variables (not user-visible), stack-allocated | 892 TEMPORARY, // temporary variables (not user-visible), stack-allocated |
893 // unless the scope as a whole has forced context allocation | 893 // unless the scope as a whole has forced context allocation |
894 | 894 |
895 DYNAMIC, // always require dynamic lookup (we don't know | 895 DYNAMIC, // always require dynamic lookup (we don't know |
896 // the declaration) | 896 // the declaration) |
897 | 897 |
898 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the | 898 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the |
899 // variable is global unless it has been shadowed | 899 // variable is global unless it has been shadowed |
900 // by an eval-introduced variable | 900 // by an eval-introduced variable |
901 | 901 |
902 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the | 902 DYNAMIC_LOCAL, // requires dynamic lookup, but we know that the |
903 // variable is local and where it is unless it | 903 // variable is local and where it is unless it |
904 // has been shadowed by an eval-introduced | 904 // has been shadowed by an eval-introduced |
905 // variable | 905 // variable |
| 906 |
| 907 kLastVariableMode = DYNAMIC_LOCAL |
906 }; | 908 }; |
907 | 909 |
908 inline bool IsDynamicVariableMode(VariableMode mode) { | 910 inline bool IsDynamicVariableMode(VariableMode mode) { |
909 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL; | 911 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL; |
910 } | 912 } |
911 | 913 |
912 | 914 |
913 inline bool IsDeclaredVariableMode(VariableMode mode) { | 915 inline bool IsDeclaredVariableMode(VariableMode mode) { |
914 return mode >= VAR && mode <= CONST; | 916 return mode >= VAR && mode <= CONST; |
915 } | 917 } |
916 | 918 |
917 | 919 |
918 inline bool IsLexicalVariableMode(VariableMode mode) { | 920 inline bool IsLexicalVariableMode(VariableMode mode) { |
919 return mode >= LET && mode <= CONST; | 921 return mode >= LET && mode <= CONST; |
920 } | 922 } |
921 | 923 |
922 | 924 |
923 inline bool IsImmutableVariableMode(VariableMode mode) { | 925 inline bool IsImmutableVariableMode(VariableMode mode) { |
924 return mode == CONST || mode == CONST_LEGACY; | 926 return mode == CONST || mode == CONST_LEGACY; |
925 } | 927 } |
926 | 928 |
927 enum class VariableLocation { | 929 enum class VariableLocation : uint8_t { |
928 // Before and during variable allocation, a variable whose location is | 930 // Before and during variable allocation, a variable whose location is |
929 // not yet determined. After allocation, a variable looked up as a | 931 // not yet determined. After allocation, a variable looked up as a |
930 // property on the global object (and possibly absent). name() is the | 932 // property on the global object (and possibly absent). name() is the |
931 // variable name, index() is invalid. | 933 // variable name, index() is invalid. |
932 UNALLOCATED, | 934 UNALLOCATED, |
933 | 935 |
934 // A slot in the parameter section on the stack. index() is the | 936 // A slot in the parameter section on the stack. index() is the |
935 // parameter index, counting left-to-right. The receiver is index -1; | 937 // parameter index, counting left-to-right. The receiver is index -1; |
936 // the first parameter is index 0. | 938 // the first parameter is index 0. |
937 PARAMETER, | 939 PARAMETER, |
(...skipping 12 matching lines...) Expand all Loading... |
950 // index in the context object on the heap, starting at 0. scope() is the | 952 // index in the context object on the heap, starting at 0. scope() is the |
951 // corresponding script scope. | 953 // corresponding script scope. |
952 GLOBAL, | 954 GLOBAL, |
953 | 955 |
954 // A named slot in a heap context. name() is the variable name in the | 956 // A named slot in a heap context. name() is the variable name in the |
955 // context object on the heap, with lookup starting at the current | 957 // context object on the heap, with lookup starting at the current |
956 // context. index() is invalid. | 958 // context. index() is invalid. |
957 LOOKUP, | 959 LOOKUP, |
958 | 960 |
959 // A named slot in a module's export table. | 961 // A named slot in a module's export table. |
960 MODULE | 962 MODULE, |
| 963 |
| 964 kLastVariableLocation = MODULE |
961 }; | 965 }; |
962 | 966 |
963 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable | 967 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable |
964 // and immutable bindings that can be in two states: initialized and | 968 // and immutable bindings that can be in two states: initialized and |
965 // uninitialized. In ES5 only immutable bindings have these two states. When | 969 // uninitialized. In ES5 only immutable bindings have these two states. When |
966 // accessing a binding, it needs to be checked for initialization. However in | 970 // accessing a binding, it needs to be checked for initialization. However in |
967 // the following cases the binding is initialized immediately after creation | 971 // the following cases the binding is initialized immediately after creation |
968 // so the initialization check can always be skipped: | 972 // so the initialization check can always be skipped: |
969 // 1. Var declared local variables. | 973 // 1. Var declared local variables. |
970 // var foo; | 974 // var foo; |
(...skipping 13 matching lines...) Expand all Loading... |
984 // properties of some object. In the specification only mutable bindings exist | 988 // properties of some object. In the specification only mutable bindings exist |
985 // (which may be non-writable) and have no distinct initialization step. However | 989 // (which may be non-writable) and have no distinct initialization step. However |
986 // V8 allows const declarations in global code with distinct creation and | 990 // V8 allows const declarations in global code with distinct creation and |
987 // initialization steps which are represented by non-writable properties in the | 991 // initialization steps which are represented by non-writable properties in the |
988 // global object. As a result also these bindings need to be checked for | 992 // global object. As a result also these bindings need to be checked for |
989 // initialization. | 993 // initialization. |
990 // | 994 // |
991 // The following enum specifies a flag that indicates if the binding needs a | 995 // The following enum specifies a flag that indicates if the binding needs a |
992 // distinct initialization step (kNeedsInitialization) or if the binding is | 996 // distinct initialization step (kNeedsInitialization) or if the binding is |
993 // immediately initialized upon creation (kCreatedInitialized). | 997 // immediately initialized upon creation (kCreatedInitialized). |
994 enum InitializationFlag { | 998 enum InitializationFlag : uint8_t { kNeedsInitialization, kCreatedInitialized }; |
995 kNeedsInitialization, | |
996 kCreatedInitialized | |
997 }; | |
998 | 999 |
999 | 1000 enum MaybeAssignedFlag : uint8_t { kNotAssigned, kMaybeAssigned }; |
1000 enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned }; | |
1001 | |
1002 | 1001 |
1003 // Serialized in PreparseData, so numeric values should not be changed. | 1002 // Serialized in PreparseData, so numeric values should not be changed. |
1004 enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 }; | 1003 enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 }; |
1005 | 1004 |
1006 | 1005 |
1007 enum MinusZeroMode { | 1006 enum MinusZeroMode { |
1008 TREAT_MINUS_ZERO_AS_ZERO, | 1007 TREAT_MINUS_ZERO_AS_ZERO, |
1009 FAIL_ON_MINUS_ZERO | 1008 FAIL_ON_MINUS_ZERO |
1010 }; | 1009 }; |
1011 | 1010 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 public: | 1155 public: |
1157 enum { kNone = 0x00, kSignedSmall = 0x01, kNumber = 0x3, kAny = 0x7 }; | 1156 enum { kNone = 0x00, kSignedSmall = 0x01, kNumber = 0x3, kAny = 0x7 }; |
1158 }; | 1157 }; |
1159 | 1158 |
1160 } // namespace internal | 1159 } // namespace internal |
1161 } // namespace v8 | 1160 } // namespace v8 |
1162 | 1161 |
1163 namespace i = v8::internal; | 1162 namespace i = v8::internal; |
1164 | 1163 |
1165 #endif // V8_GLOBALS_H_ | 1164 #endif // V8_GLOBALS_H_ |
OLD | NEW |