RuntimeCommon.h 12 KB

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