RuntimeCommon.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. // Runtime.h has both definitions and #include other runtime files.
  7. // Definitions here are extracted definitions (not #include's) from Runtime.h that core Runtime .h's can be used without #including full Runtime.h
  8. const extern int TotalNumberOfBuiltInProperties;
  9. namespace Js
  10. {
  11. // Forwards
  12. class RecyclableObject;
  13. struct CallInfo;
  14. class PropertyRecord;
  15. class JavascriptString;
  16. struct FrameDisplay;
  17. class TypedArrayBase;
  18. #if _M_IX86
  19. #define unaligned
  20. #elif _M_X64 || _M_ARM || _M_ARM64
  21. #define unaligned __unaligned
  22. #else
  23. #error Must define alignment capabilities for processor
  24. #endif
  25. typedef uint32 RegSlot;
  26. typedef uint16 ArgSlot;
  27. typedef uint16 PropertyIndex;
  28. typedef int32 BigPropertyIndex;
  29. typedef unsigned char PropertyAttributes;
  30. typedef uint32 SourceId;
  31. typedef uint16 ProfileId;
  32. typedef uint32 InlineCacheIndex;
  33. // Inline cache flags when property of the object is not writable
  34. enum InlineCacheFlags : char {
  35. InlineCacheNoFlags = 0x0,
  36. InlineCacheGetterFlag = 0x1,
  37. InlineCacheSetterFlag = 0x2,
  38. };
  39. #define PropertyNone 0x00
  40. #define PropertyEnumerable 0x01
  41. #define PropertyConfigurable 0x02
  42. #define PropertyWritable 0x04
  43. #define PropertyDeleted 0x08
  44. #define PropertyLetConstGlobal 0x10
  45. #define PropertyDeclaredGlobal 0x20
  46. #define PropertyLet 0x40
  47. #define PropertyConst 0x80
  48. // No more flags will fit unless PropertyAttributes is bumped up to a short instead of char
  49. #define PropertyBuiltInMethodDefaults (PropertyConfigurable|PropertyWritable)
  50. #define PropertyDynamicTypeDefaults (PropertyConfigurable|PropertyWritable|PropertyEnumerable)
  51. #define PropertyLetDefaults (PropertyEnumerable|PropertyConfigurable|PropertyWritable|PropertyLet)
  52. #define PropertyConstDefaults (PropertyEnumerable|PropertyConfigurable|PropertyConst)
  53. #define PropertyDeletedDefaults (PropertyDeleted | PropertyWritable | PropertyConfigurable)
  54. #define PropertyNoRedecl (PropertyLet | PropertyConst)
  55. #define PropertyClassMemberDefaults (PropertyConfigurable|PropertyWritable)
  56. #define PropertyModuleNamespaceDefault (PropertyEnumerable|PropertyWritable)
  57. BEGIN_ENUM_UINT(InternalPropertyIds)
  58. #define INTERNALPROPERTY(n) n,
  59. #include "InternalPropertyList.h"
  60. Count,
  61. END_ENUM_UINT()
  62. inline BOOL IsInternalPropertyId(PropertyId propertyId)
  63. {
  64. return propertyId < InternalPropertyIds::Count;
  65. }
  66. BEGIN_ENUM_UINT(PropertyIds)
  67. _none = InternalPropertyIds::Count,
  68. #define ENTRY_INTERNAL_SYMBOL(n) n,
  69. #define ENTRY_SYMBOL(n, d) n,
  70. #define ENTRY(n) n,
  71. #define ENTRY2(n, s) n,
  72. #include "Base/JnDirectFields.h"
  73. _countJSOnlyProperty,
  74. END_ENUM_UINT()
  75. inline BOOL IsBuiltInPropertyId(PropertyId propertyId)
  76. {
  77. return propertyId < TotalNumberOfBuiltInProperties;
  78. }
  79. #define PropertyTypesNone 0x00
  80. #define PropertyTypesReserved 0x01 // This bit is always to prevent the DWORD in DynamicTypeHandler looking like a pointer.
  81. #define PropertyTypesWritableDataOnly 0x10 // Indicates that a type handler has only writable data properties
  82. // (no accessors or non-writable properties)
  83. #define PropertyTypesWritableDataOnlyDetection 0x20 // Set on each call to DynamicTypeHandler::SetHasOnlyWritableDataProperties.
  84. #define PropertyTypesInlineSlotCapacityLocked 0x40 // Indicates that the inline slot capacity has been shrunk already and shouldn't be touched again.
  85. #define PropertyTypesAll 0x70
  86. typedef unsigned char PropertyTypes; // Holds flags that represent general information about the types of properties
  87. // handled by a type handler.
  88. BEGIN_ENUM_UINT(JavascriptHint)
  89. None, // no hint. use the default for that object
  90. HintString = 0x00000001, // 'string' hint in ToPrimitiveValue()
  91. HintNumber = 0x00000002, // 'number' hint
  92. END_ENUM_UINT()
  93. enum DescriptorFlags
  94. {
  95. None = 0x0, // No data/accessor descriptor
  96. Accessor = 0x1, // An accessor descriptor is present
  97. Data = 0x2, // A data descriptor is present
  98. Writable = 0x4, // Data descriptor is writable
  99. Const = 0x8, // Data is const, meaning we throw on attempt to write to it
  100. Proxy = 0x10, // data returned from proxy.
  101. WritableData = Data | Writable // Data descriptor is writable
  102. };
  103. BEGIN_ENUM_BYTE(BuiltinFunction)
  104. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) obj##_##name,
  105. #include "LibraryFunction.h"
  106. #undef LIBRARY_FUNCTION
  107. Count,
  108. None,
  109. END_ENUM_BYTE()
  110. typedef void * Var;
  111. typedef WriteBarrierPtr<void> WriteBarrierVar;
  112. typedef Var(__cdecl *JavascriptMethod)(RecyclableObject*, CallInfo, ...);
  113. typedef Var(*ExternalMethod)(RecyclableObject*, CallInfo, Var*);
  114. const uintptr_t AtomTag_Object = 0x0;
  115. #if INT32VAR
  116. // The 49th bit is set in this representation
  117. const int32 VarTag_Shift = 48;
  118. const uintptr_t AtomTag_IntPtr = (((uintptr_t)0x1i64) << VarTag_Shift);
  119. const int32 AtomTag_Int32 = 0x0; // lower 32-bits of a tagged integer
  120. const uintptr_t AtomTag = 0x1;
  121. const int32 AtomTag_Multiply = 1;
  122. const int32 AtomTag_Pair = 0x00010001; // Pair of tags
  123. #else
  124. const uintptr_t AtomTag_IntPtr = 0x1;
  125. const int32 AtomTag_Int32 = 0x1; // lower 32-bits of a tagged integer
  126. const uintptr_t AtomTag = 0x1;
  127. const int32 VarTag_Shift = 1;
  128. const int32 AtomTag_Multiply = 1 << VarTag_Shift;
  129. #endif
  130. #if FLOATVAR
  131. const uint64 FloatTag_Value = 0xFFFCull << 48;
  132. #endif
  133. template <bool IsPrototypeTemplate> class NullTypeHandler;
  134. template <typename TPropertyIndex, typename TMapKey, bool IsNotExtensibleSupported> class SimpleDictionaryTypeHandlerBase;
  135. template <typename TPropertyIndex, typename TMapKey, bool IsNotExtensibleSupported> class SimpleDictionaryUnorderedTypeHandler;
  136. template <typename TPropertyIndex> class DictionaryTypeHandlerBase;
  137. template <typename TPropertyIndex> class ES5ArrayTypeHandlerBase;
  138. typedef NullTypeHandler<false> NonProtoNullTypeHandler;
  139. typedef NullTypeHandler<true> ProtoNullTypeHandler;
  140. typedef SimpleDictionaryTypeHandlerBase<PropertyIndex, const PropertyRecord*, false> SimpleDictionaryTypeHandler;
  141. typedef SimpleDictionaryTypeHandlerBase<PropertyIndex, const PropertyRecord*, true> SimpleDictionaryTypeHandlerNotExtensible;
  142. typedef SimpleDictionaryTypeHandlerBase<BigPropertyIndex, const PropertyRecord*, false> BigSimpleDictionaryTypeHandler;
  143. typedef SimpleDictionaryTypeHandlerBase<BigPropertyIndex, const PropertyRecord*, true> BigSimpleDictionaryTypeHandlerNotExtensible;
  144. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, const PropertyRecord*, false> SimpleDictionaryUnorderedPropertyRecordKeyedTypeHandler;
  145. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, const PropertyRecord*, true> SimpleDictionaryUnorderedPropertyRecordKeyedTypeHandlerNotExtensible;
  146. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, const PropertyRecord*, false> BigSimpleDictionaryUnorderedPropertyRecordKeyedTypeHandler;
  147. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, const PropertyRecord*, true> BigSimpleDictionaryUnorderedPropertyRecordKeyedTypeHandlerNotExtensible;
  148. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, JavascriptString*, false> SimpleDictionaryUnorderedStringKeyedTypeHandler;
  149. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, JavascriptString*, true> SimpleDictionaryUnorderedStringKeyedTypeHandlerNotExtensible;
  150. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, JavascriptString*, false> BigSimpleDictionaryUnorderedStringKeyedTypeHandler;
  151. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, JavascriptString*, true> BigSimpleDictionaryUnorderedStringKeyedTypeHandlerNotExtensible;
  152. typedef DictionaryTypeHandlerBase<PropertyIndex> DictionaryTypeHandler;
  153. typedef DictionaryTypeHandlerBase<BigPropertyIndex> BigDictionaryTypeHandler;
  154. typedef ES5ArrayTypeHandlerBase<PropertyIndex> ES5ArrayTypeHandler;
  155. typedef ES5ArrayTypeHandlerBase<BigPropertyIndex> BigES5ArrayTypeHandler;
  156. template <int N> class ConcatStringN;
  157. typedef ConcatStringN<2> ConcatStringN2;
  158. typedef ConcatStringN<4> ConcatStringN4;
  159. typedef ConcatStringN<6> ConcatStringN6;
  160. typedef ConcatStringN<7> ConcatStringN7;
  161. template <char16 L, char16 R> class ConcatStringWrapping;
  162. typedef ConcatStringWrapping<_u('['), _u(']')> ConcatStringWrappingSB;
  163. typedef ConcatStringWrapping<_u('{'), _u('}')> ConcatStringWrappingB;
  164. typedef ConcatStringWrapping<_u('"'), _u('"')> ConcatStringWrappingQ;
  165. } // namespace Js.
  166. namespace JSON
  167. {
  168. class JSONParser;
  169. }
  170. //
  171. // Below was moved from ByteCodeGenerator.h to share with jscript9diag.
  172. //
  173. #define REGSLOT_TO_VARREG(r) (r)
  174. // To map between real reg number and const reg number, add 2 and negate.
  175. // This way, 0xFFFF (no register) maps to itself, and 0xFFFF is never a valid number.
  176. #define REGSLOT_TO_CONSTREG(r) ((Js::RegSlot)(0 - (r + 2)))
  177. #define CONSTREG_TO_REGSLOT(r) ((Js::RegSlot)(0 - (r + 2)))
  178. //
  179. // Shared string literals
  180. //
  181. #define JS_DISPLAY_STRING_NAN _u("NaN")
  182. #define JS_DISPLAY_STRING_DATE _u("Date")
  183. #define JS_DISPLAY_STRING_INVALID_DATE _u("Invalid Date")
  184. #define JS_DISPLAY_STRING_FUNCTION_ANONYMOUS _u("function() {\n [native code]\n}")
  185. #define JS_DISPLAY_STRING_FUNCTION_HEADER _u("function ")
  186. #define JS_DISPLAY_STRING_FUNCTION_BODY _u("() { [native code] }")
  187. #define JS_DIAG_TYPE_JavascriptRegExp _u("Object, (Regular Expression)")
  188. #define JS_DIAG_VALUE_JavascriptRegExpConstructor _u("{...}")
  189. #define JS_DIAG_TYPE_JavascriptRegExpConstructor _u("Object, (RegExp constructor)")
  190. #include "Language/SimdUtils.h"