RuntimeCommon.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. 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. BEGIN_ENUM_UINT(InternalPropertyIds)
  57. #define INTERNALPROPERTY(n) n,
  58. #include "InternalPropertyList.h"
  59. Count,
  60. END_ENUM_UINT()
  61. inline BOOL IsInternalPropertyId(PropertyId propertyId)
  62. {
  63. return propertyId < InternalPropertyIds::Count;
  64. }
  65. BEGIN_ENUM_UINT(PropertyIds)
  66. _none = InternalPropertyIds::Count,
  67. #define ENTRY_INTERNAL_SYMBOL(n) n,
  68. #define ENTRY_SYMBOL(n, d) n,
  69. #define ENTRY(n) n,
  70. #define ENTRY2(n, s) n,
  71. #include "Base\JnDirectFields.h"
  72. _countJSOnlyProperty,
  73. END_ENUM_UINT()
  74. inline BOOL IsBuiltInPropertyId(PropertyId propertyId)
  75. {
  76. return propertyId < TotalNumberOfBuiltInProperties;
  77. }
  78. #define PropertyTypesNone 0x00
  79. #define PropertyTypesReserved 0x01 // This bit is always to prevent the DWORD in DynamicTypeHandler looking like a pointer.
  80. #define PropertyTypesWritableDataOnly 0x10 // Indicates that a type handler has only writable data properties
  81. // (no accessors or non-writable properties)
  82. #define PropertyTypesWritableDataOnlyDetection 0x20 // Set on each call to DynamicTypeHandler::SetHasOnlyWritableDataProperties.
  83. #define PropertyTypesInlineSlotCapacityLocked 0x40 // Indicates that the inline slot capacity has been shrunk already and shouldn't be touched again.
  84. #define PropertyTypesAll 0x70
  85. typedef unsigned char PropertyTypes; // Holds flags that represent general information about the types of properties
  86. // handled by a type handler.
  87. BEGIN_ENUM_UINT(JavascriptHint)
  88. None, // no hint. use the default for that object
  89. HintString = 0x00000001, // 'string' hint in ToPrimitiveValue()
  90. HintNumber = 0x00000002, // 'number' hint
  91. END_ENUM_UINT()
  92. enum DescriptorFlags
  93. {
  94. None = 0x0, // No data/accessor descriptor
  95. Accessor = 0x1, // An accessor descriptor is present
  96. Data = 0x2, // A data descriptor is present
  97. Writable = 0x4, // Data descriptor is writable
  98. Const = 0x8, // Data is const, meaning we throw on attempt to write to it
  99. Proxy = 0x10, // data returned from proxy.
  100. WritableData = Data | Writable // Data descriptor is writable
  101. };
  102. BEGIN_ENUM_BYTE(BuiltinFunction)
  103. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) obj##_##name,
  104. #include "LibraryFunction.h"
  105. #undef LIBRARY_FUNCTION
  106. Count,
  107. None,
  108. END_ENUM_BYTE()
  109. typedef void * Var;
  110. typedef WriteBarrierPtr<void> WriteBarrierVar;
  111. typedef Var(__cdecl *JavascriptMethod)(RecyclableObject*, CallInfo, ...);
  112. typedef Var(*ExternalMethod)(RecyclableObject*, CallInfo, Var*);
  113. const uintptr AtomTag_Object = 0x0;
  114. #if INT32VAR
  115. // The 49th bit is set in this representation
  116. const int32 VarTag_Shift = 48;
  117. const uintptr AtomTag_IntPtr = (((uintptr)0x1i64) << VarTag_Shift);
  118. const int32 AtomTag_Int32 = 0x0; // lower 32-bits of a tagged integer
  119. const uintptr AtomTag = 0x1;
  120. const int32 AtomTag_Multiply = 1;
  121. const int32 AtomTag_Pair = 0x00010001; // Pair of tags
  122. #else
  123. const uintptr AtomTag_IntPtr = 0x1;
  124. const int32 AtomTag_Int32 = 0x1; // lower 32-bits of a tagged integer
  125. const uintptr AtomTag = 0x1;
  126. const int32 VarTag_Shift = 1;
  127. const int32 AtomTag_Multiply = 1 << VarTag_Shift;
  128. #endif
  129. #if FLOATVAR
  130. const uint64 FloatTag_Value = 0xFFFCull << 48;
  131. #endif
  132. template <bool IsPrototypeTemplate> class NullTypeHandler;
  133. template <typename TPropertyIndex, typename TMapKey, bool IsNotExtensibleSupported> class SimpleDictionaryTypeHandlerBase;
  134. template <typename TPropertyIndex, typename TMapKey, bool IsNotExtensibleSupported> class SimpleDictionaryUnorderedTypeHandler;
  135. template <typename TPropertyIndex> class DictionaryTypeHandlerBase;
  136. template <typename TPropertyIndex> class ES5ArrayTypeHandlerBase;
  137. typedef NullTypeHandler<false> NonProtoNullTypeHandler;
  138. typedef NullTypeHandler<true> ProtoNullTypeHandler;
  139. typedef SimpleDictionaryTypeHandlerBase<PropertyIndex, const PropertyRecord*, false> SimpleDictionaryTypeHandler;
  140. typedef SimpleDictionaryTypeHandlerBase<PropertyIndex, const PropertyRecord*, true> SimpleDictionaryTypeHandlerNotExtensible;
  141. typedef SimpleDictionaryTypeHandlerBase<BigPropertyIndex, const PropertyRecord*, false> BigSimpleDictionaryTypeHandler;
  142. typedef SimpleDictionaryTypeHandlerBase<BigPropertyIndex, const PropertyRecord*, true> BigSimpleDictionaryTypeHandlerNotExtensible;
  143. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, const PropertyRecord*, false> SimpleDictionaryUnorderedPropertyRecordKeyedTypeHandler;
  144. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, const PropertyRecord*, true> SimpleDictionaryUnorderedPropertyRecordKeyedTypeHandlerNotExtensible;
  145. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, const PropertyRecord*, false> BigSimpleDictionaryUnorderedPropertyRecordKeyedTypeHandler;
  146. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, const PropertyRecord*, true> BigSimpleDictionaryUnorderedPropertyRecordKeyedTypeHandlerNotExtensible;
  147. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, JavascriptString*, false> SimpleDictionaryUnorderedStringKeyedTypeHandler;
  148. typedef SimpleDictionaryUnorderedTypeHandler<PropertyIndex, JavascriptString*, true> SimpleDictionaryUnorderedStringKeyedTypeHandlerNotExtensible;
  149. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, JavascriptString*, false> BigSimpleDictionaryUnorderedStringKeyedTypeHandler;
  150. typedef SimpleDictionaryUnorderedTypeHandler<BigPropertyIndex, JavascriptString*, true> BigSimpleDictionaryUnorderedStringKeyedTypeHandlerNotExtensible;
  151. typedef DictionaryTypeHandlerBase<PropertyIndex> DictionaryTypeHandler;
  152. typedef DictionaryTypeHandlerBase<BigPropertyIndex> BigDictionaryTypeHandler;
  153. typedef ES5ArrayTypeHandlerBase<PropertyIndex> ES5ArrayTypeHandler;
  154. typedef ES5ArrayTypeHandlerBase<BigPropertyIndex> BigES5ArrayTypeHandler;
  155. template <int N> class ConcatStringN;
  156. typedef ConcatStringN<2> ConcatStringN2;
  157. typedef ConcatStringN<4> ConcatStringN4;
  158. typedef ConcatStringN<6> ConcatStringN6;
  159. typedef ConcatStringN<7> ConcatStringN7;
  160. template <wchar_t L, wchar_t R> class ConcatStringWrapping;
  161. typedef ConcatStringWrapping<L'[', L']'> ConcatStringWrappingSB;
  162. typedef ConcatStringWrapping<L'{', L'}'> ConcatStringWrappingB;
  163. typedef ConcatStringWrapping<L'"', L'"'> ConcatStringWrappingQ;
  164. } // namespace Js.
  165. namespace JSON
  166. {
  167. class JSONParser;
  168. }
  169. //
  170. // Below was moved from ByteCodeGenerator.h to share with jscript9diag.
  171. //
  172. #define REGSLOT_TO_VARREG(r) (r)
  173. // To map between real reg number and const reg number, add 2 and negate.
  174. // This way, 0xFFFF (no register) maps to itself, and 0xFFFF is never a valid number.
  175. #define REGSLOT_TO_CONSTREG(r) ((Js::RegSlot)(0 - (r + 2)))
  176. #define CONSTREG_TO_REGSLOT(r) ((Js::RegSlot)(0 - (r + 2)))
  177. //
  178. // Shared string literals
  179. //
  180. #define JS_DISPLAY_STRING_NAN L"NaN"
  181. #define JS_DISPLAY_STRING_DATE L"Date"
  182. #define JS_DISPLAY_STRING_INVALID_DATE L"Invalid Date"
  183. #define JS_DISPLAY_STRING_FUNCTION_ANONYMOUS L"\012function() {\012 [native code]\012}\012"
  184. #define JS_DISPLAY_STRING_FUNCTION_HEADER L"function "
  185. #define JS_DISPLAY_STRING_FUNCTION_BODY L"() { [native code] }"
  186. #define JS_DIAG_TYPE_JavascriptRegExp L"Object, (Regular Expression)"
  187. #define JS_DIAG_VALUE_JavascriptRegExpConstructor L"{...}"
  188. #define JS_DIAG_TYPE_JavascriptRegExpConstructor L"Object, (RegExp constructor)"
  189. #define JS_DEFAULT_CTOR_DISPLAY_STRING L"constructor() {}"
  190. #define JS_DEFAULT_EXTENDS_CTOR_DISPLAY_STRING L"constructor(...args) { super(...args); }"
  191. #include "Language\SIMDUtils.h"