react-native-windows 0.78.4 → 0.78.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/Directory.Build.props +6 -4
  2. package/Folly/Folly.vcxproj +46 -6
  3. package/Folly/Folly.vcxproj.filters +16 -4
  4. package/Folly/TEMP_UntilFollyUpdate/ConstexprMath.h +26 -18
  5. package/Folly/TEMP_UntilFollyUpdate/Conv.cpp +1205 -0
  6. package/Folly/TEMP_UntilFollyUpdate/chrono/Hardware.h +155 -0
  7. package/Folly/TEMP_UntilFollyUpdate/concurrency/CacheLocality.cpp +633 -0
  8. package/Folly/TEMP_UntilFollyUpdate/{dynamic-inl.h → json/dynamic-inl.h} +3 -4
  9. package/Folly/TEMP_UntilFollyUpdate/{json.cpp → json/json.cpp} +14 -10
  10. package/Folly/TEMP_UntilFollyUpdate/lang/SafeAssert.h +7 -14
  11. package/Folly/TEMP_UntilFollyUpdate/lang/ToAscii.h +6 -6
  12. package/Folly/ThreadNameStub.cpp +10 -0
  13. package/Folly/cgmanifest.json +11 -1
  14. package/Libraries/Components/View/View.windows.js +107 -56
  15. package/Libraries/Components/View/ViewAccessibility.d.ts +60 -1
  16. package/Libraries/Image/Image.windows.js +42 -21
  17. package/Libraries/Modal/Modal.d.ts +7 -0
  18. package/Libraries/Modal/Modal.windows.js +7 -1
  19. package/Libraries/NativeComponent/BaseViewConfig.windows.js +3 -0
  20. package/Libraries/Text/Text.d.ts +18 -0
  21. package/Microsoft.ReactNative/AsynchronousEventBeat.cpp +4 -25
  22. package/Microsoft.ReactNative/AsynchronousEventBeat.h +0 -3
  23. package/Microsoft.ReactNative/Base/FollyIncludes.h +1 -0
  24. package/Microsoft.ReactNative/CallInvoker.cpp +42 -0
  25. package/Microsoft.ReactNative/CallInvoker.h +34 -0
  26. package/Microsoft.ReactNative/{JSDispatcherWriter.cpp → CallInvokerWriter.cpp} +35 -47
  27. package/Microsoft.ReactNative/CallInvokerWriter.h +74 -0
  28. package/Microsoft.ReactNative/CompositionComponentView.idl +0 -5
  29. package/Microsoft.ReactNative/CompositionSwitcher.idl +7 -0
  30. package/Microsoft.ReactNative/Fabric/AbiViewProps.cpp +8 -10
  31. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +4 -1
  32. package/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.cpp +12 -2
  33. package/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.h +2 -0
  34. package/Microsoft.ReactNative/Fabric/Composition/CompositionAnnotationProvider.cpp +100 -0
  35. package/Microsoft.ReactNative/Fabric/Composition/CompositionAnnotationProvider.h +31 -0
  36. package/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp +77 -11
  37. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +43 -1
  38. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +7 -0
  39. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +86 -56
  40. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +5 -1
  41. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +0 -4
  42. package/Microsoft.ReactNative/Fabric/Composition/CompositionUIService.cpp +0 -2
  43. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +118 -63
  44. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +2 -0
  45. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +133 -8
  46. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +16 -2
  47. package/Microsoft.ReactNative/Fabric/Composition/FocusManager.cpp +4 -2
  48. package/Microsoft.ReactNative/Fabric/Composition/FocusManager.h +9 -1
  49. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +34 -11
  50. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.h +3 -0
  51. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +133 -135
  52. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp +9 -6
  53. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +46 -49
  54. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +6 -1
  55. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +13 -8
  56. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +5 -2
  57. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +146 -25
  58. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +14 -0
  59. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +160 -12
  60. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +6 -0
  61. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputEventEmitter.cpp +47 -0
  62. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputEventEmitter.h +15 -1
  63. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputProps.cpp +6 -2
  64. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputProps.h +4 -1
  65. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +7 -9
  66. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.h +4 -1
  67. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +5 -0
  68. package/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp +40 -36
  69. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +68 -0
  70. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +11 -0
  71. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +70 -13
  72. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +10 -2
  73. package/Microsoft.ReactNative/Fabric/ImageManager.cpp +5 -5
  74. package/Microsoft.ReactNative/Fabric/ImageRequestParams.cpp +26 -0
  75. package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +47 -8
  76. package/Microsoft.ReactNative/Fabric/WindowsImageManager.h +10 -1
  77. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/CompositionAccessibilityProps.h +67 -0
  78. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.cpp +22 -4
  79. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.h +15 -2
  80. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.cpp +20 -0
  81. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.h +5 -0
  82. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/MouseEvent.h +20 -0
  83. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/HostPlatformColor.h +5 -8
  84. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/PlatformColorParser.h +1 -2
  85. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.cpp +247 -45
  86. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.h +15 -0
  87. package/Microsoft.ReactNative/Fabric/platform/react/threading/MessageQueueThreadImpl.cpp +39 -0
  88. package/Microsoft.ReactNative/Fabric/platform/react/threading/MessageQueueThreadImpl.h +54 -0
  89. package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.cpp +126 -0
  90. package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.h +73 -0
  91. package/Microsoft.ReactNative/IReactContext.cpp +17 -0
  92. package/Microsoft.ReactNative/IReactContext.h +1 -0
  93. package/Microsoft.ReactNative/IReactContext.idl +18 -1
  94. package/Microsoft.ReactNative/IReactDispatcher.idl +1 -0
  95. package/Microsoft.ReactNative/IReactModuleBuilder.cpp +12 -0
  96. package/Microsoft.ReactNative/IReactModuleBuilder.h +2 -0
  97. package/Microsoft.ReactNative/IReactModuleBuilder.idl +8 -0
  98. package/Microsoft.ReactNative/JsiApi.cpp +10 -2
  99. package/Microsoft.ReactNative/JsiApi.h +1 -0
  100. package/Microsoft.ReactNative/JsiApi.idl +1 -0
  101. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +0 -3
  102. package/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +2 -3
  103. package/Microsoft.ReactNative/Modules/AlertModule.cpp +7 -12
  104. package/Microsoft.ReactNative/Modules/Animated/AnimationDriver.cpp +2 -1
  105. package/Microsoft.ReactNative/Modules/Animated/NativeAnimatedModule.cpp +4 -8
  106. package/Microsoft.ReactNative/Modules/AppStateModule.cpp +2 -2
  107. package/Microsoft.ReactNative/Modules/ClipboardModule.cpp +6 -8
  108. package/Microsoft.ReactNative/Modules/ClipboardModule.h +1 -1
  109. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +6 -15
  110. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +13 -24
  111. package/Microsoft.ReactNative/QuirkSettings.cpp +0 -16
  112. package/Microsoft.ReactNative/QuirkSettings.h +0 -3
  113. package/Microsoft.ReactNative/ReactHost/ReactHost.cpp +11 -1
  114. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +78 -68
  115. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -2
  116. package/Microsoft.ReactNative/ReactInstanceSettings.cpp +12 -0
  117. package/Microsoft.ReactNative/ReactInstanceSettings.h +2 -0
  118. package/Microsoft.ReactNative/ReactInstanceSettings.idl +6 -0
  119. package/Microsoft.ReactNative/ReactNativeIsland.idl +3 -0
  120. package/Microsoft.ReactNative/ReactSupport.cpp +44 -11
  121. package/Microsoft.ReactNative/RedBox.cpp +30 -1
  122. package/Microsoft.ReactNative/SchedulerSettings.cpp +4 -4
  123. package/Microsoft.ReactNative/SchedulerSettings.h +1 -1
  124. package/Microsoft.ReactNative/TurboModulesProvider.cpp +30 -12
  125. package/Microsoft.ReactNative/Utils/ImageUtils.h +1 -0
  126. package/Microsoft.ReactNative/Utils/LocalBundleReader.cpp +37 -31
  127. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.cpp +1 -0
  128. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.inc +2 -0
  129. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi_posix.cpp +1 -1
  130. package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.cpp +94 -27
  131. package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.h +27 -6
  132. package/Microsoft.ReactNative.Cxx/JSI/JsiApiContext.cpp +45 -11
  133. package/Microsoft.ReactNative.Cxx/JSI/JsiApiContext.h +6 -0
  134. package/Microsoft.ReactNative.Cxx/JSI/decorator.h +220 -0
  135. package/Microsoft.ReactNative.Cxx/JSI/instrumentation.h +28 -0
  136. package/Microsoft.ReactNative.Cxx/JSI/jsi-inl.h +6 -0
  137. package/Microsoft.ReactNative.Cxx/JSI/jsi.cpp +241 -4
  138. package/Microsoft.ReactNative.Cxx/JSI/jsi.h +207 -19
  139. package/Microsoft.ReactNative.Cxx/JSValue.cpp +19 -3
  140. package/Microsoft.ReactNative.Cxx/JSValue.h +15 -7
  141. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +2 -2
  142. package/Microsoft.ReactNative.Cxx/NativeModules.h +60 -2
  143. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.cpp +1267 -614
  144. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.h +4 -2
  145. package/Microsoft.ReactNative.Cxx/ReactContext.h +7 -0
  146. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.cpp +11 -13
  147. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.h +2 -3
  148. package/Microsoft.ReactNative.Cxx/node-api/js_native_api.h +81 -20
  149. package/Microsoft.ReactNative.Cxx/node-api/js_native_api_types.h +47 -2
  150. package/Microsoft.ReactNative.Cxx/node-api/js_runtime_api.h +13 -0
  151. package/Microsoft.ReactNative.Cxx/stubs/glog/logging.h +1 -1
  152. package/Microsoft.ReactNative.Managed/ReactContext.cs +3 -1
  153. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  154. package/PropertySheets/JSEngine.props +1 -1
  155. package/PropertySheets/React.Cpp.props +2 -1
  156. package/PropertySheets/WebView2.props +1 -1
  157. package/PropertySheets/WinUI.props +2 -2
  158. package/ReactCommon/TEMP_UntilReactCommonUpdate/jserrorhandler/JsErrorHandler.cpp +429 -0
  159. package/ReactCommon/cgmanifest.json +1 -1
  160. package/Shared/HermesRuntimeHolder.cpp +6 -0
  161. package/Shared/JSI/ChakraRuntime.cpp +4 -0
  162. package/Shared/JSI/ChakraRuntime.h +2 -0
  163. package/Shared/Modules/BlobModule.cpp +14 -16
  164. package/Shared/Modules/BlobModule.h +3 -1
  165. package/Shared/Networking/WinRTWebSocketResource.cpp +82 -101
  166. package/Shared/Networking/WinRTWebSocketResource.h +91 -7
  167. package/Shared/Shared.vcxitems +11 -7
  168. package/Shared/Shared.vcxitems.filters +6 -1
  169. package/Shared/TurboModuleManager.cpp +0 -15
  170. package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +6 -6
  171. package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +6 -6
  172. package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +6 -6
  173. package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +6 -6
  174. package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +6 -6
  175. package/codegen/react/components/rnwcore/AndroidSwitch.g.h +6 -6
  176. package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +6 -6
  177. package/codegen/react/components/rnwcore/InputAccessory.g.h +6 -6
  178. package/codegen/react/components/rnwcore/ModalHostView.g.h +11 -7
  179. package/codegen/react/components/rnwcore/Props.cpp +2 -1
  180. package/codegen/react/components/rnwcore/Props.h +1 -0
  181. package/codegen/react/components/rnwcore/PullToRefreshView.g.h +6 -6
  182. package/codegen/react/components/rnwcore/SafeAreaView.g.h +6 -6
  183. package/codegen/react/components/rnwcore/Switch.g.h +6 -6
  184. package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +6 -6
  185. package/index.windows.js +4 -2
  186. package/package.json +3 -4
  187. package/src/private/specs/components/RCTModalHostViewNativeComponent.js +8 -0
  188. package/stubs/glog/logging.h +1 -1
  189. package/Microsoft.ReactNative/JSDispatcherWriter.h +0 -47
  190. package/Microsoft.ReactNative/SynchronousEventBeat.cpp +0 -51
  191. package/Microsoft.ReactNative/SynchronousEventBeat.h +0 -31
@@ -64,6 +64,150 @@ Value callGlobalFunction(Runtime& runtime, const char* name, const Value& arg) {
64
64
  return f.call(runtime, arg);
65
65
  }
66
66
 
67
+ #if JSI_VERSION >= 14
68
+ // Given a sequence of UTF8 encoded bytes, advance the input to past where a
69
+ // 32-bit unicode codepoint as been decoded and return the codepoint. If the
70
+ // UTF8 encoding is invalid, then return the value with the unicode replacement
71
+ // character (U+FFFD). This decoder also relies on zero termination at end of
72
+ // the input for bound checks.
73
+ // \param input char pointer pointing to the current character
74
+ // \return Unicode codepoint
75
+ uint32_t decodeUTF8(const char*& input) {
76
+ uint32_t ch = (unsigned char)input[0];
77
+ if (ch <= 0x7f) {
78
+ input += 1;
79
+ return ch;
80
+ }
81
+ uint32_t ret;
82
+ constexpr uint32_t replacementCharacter = 0xFFFD;
83
+ if ((ch & 0xE0) == 0xC0) {
84
+ uint32_t ch1 = (unsigned char)input[1];
85
+ if ((ch1 & 0xC0) != 0x80) {
86
+ input += 1;
87
+ return replacementCharacter;
88
+ }
89
+ ret = ((ch & 0x1F) << 6) | (ch1 & 0x3F);
90
+ input += 2;
91
+ if (ret <= 0x7F) {
92
+ return replacementCharacter;
93
+ }
94
+ } else if ((ch & 0xF0) == 0xE0) {
95
+ uint32_t ch1 = (unsigned char)input[1];
96
+ if ((ch1 & 0x40) != 0 || (ch1 & 0x80) == 0) {
97
+ input += 1;
98
+ return replacementCharacter;
99
+ }
100
+ uint32_t ch2 = (unsigned char)input[2];
101
+ if ((ch2 & 0x40) != 0 || (ch2 & 0x80) == 0) {
102
+ input += 2;
103
+ return replacementCharacter;
104
+ }
105
+ ret = ((ch & 0x0F) << 12) | ((ch1 & 0x3F) << 6) | (ch2 & 0x3F);
106
+ input += 3;
107
+ if (ret <= 0x7FF) {
108
+ return replacementCharacter;
109
+ }
110
+ } else if ((ch & 0xF8) == 0xF0) {
111
+ uint32_t ch1 = (unsigned char)input[1];
112
+ if ((ch1 & 0x40) != 0 || (ch1 & 0x80) == 0) {
113
+ input += 1;
114
+ return replacementCharacter;
115
+ }
116
+ uint32_t ch2 = (unsigned char)input[2];
117
+ if ((ch2 & 0x40) != 0 || (ch2 & 0x80) == 0) {
118
+ input += 2;
119
+ return replacementCharacter;
120
+ }
121
+ uint32_t ch3 = (unsigned char)input[3];
122
+ if ((ch3 & 0x40) != 0 || (ch3 & 0x80) == 0) {
123
+ input += 3;
124
+ return replacementCharacter;
125
+ }
126
+ ret = ((ch & 0x07) << 18) | ((ch1 & 0x3F) << 12) | ((ch2 & 0x3F) << 6) |
127
+ (ch3 & 0x3F);
128
+ input += 4;
129
+ if (ret <= 0xFFFF) {
130
+ return replacementCharacter;
131
+ }
132
+ if (ret > 0x10FFFF) {
133
+ return replacementCharacter;
134
+ }
135
+ } else {
136
+ input += 1;
137
+ return replacementCharacter;
138
+ }
139
+ return ret;
140
+ }
141
+
142
+ // Given a valid 32-bit unicode codepoint, encode it as UTF-16 into the output.
143
+ void encodeUTF16(std::u16string& out, uint32_t cp) {
144
+ if (cp < 0x10000) {
145
+ out.push_back((uint16_t)cp);
146
+ return;
147
+ }
148
+ cp -= 0x10000;
149
+ uint16_t highSurrogate = 0xD800 + ((cp >> 10) & 0x3FF);
150
+ out.push_back(highSurrogate);
151
+ uint16_t lowSurrogate = 0xDC00 + (cp & 0x3FF);
152
+ out.push_back(lowSurrogate);
153
+ }
154
+
155
+ // Convert the UTF8 encoded string into a UTF16 encoded string. If the
156
+ // input is not valid UTF8, the replacement character (U+FFFD) is used to
157
+ // represent the invalid sequence.
158
+ std::u16string convertUTF8ToUTF16(const std::string& utf8) {
159
+ std::u16string ret;
160
+ const char* curr = utf8.data();
161
+ const char* end = curr + utf8.length();
162
+ while (curr < end) {
163
+ auto cp = decodeUTF8(curr);
164
+ encodeUTF16(ret, cp);
165
+ }
166
+ return ret;
167
+ }
168
+ #endif
169
+
170
+ #if JSI_VERSION >= 19
171
+ // Given a unsigned number, which is less than 16, return the hex character.
172
+ inline char hexDigit(unsigned x) {
173
+ return static_cast<char>(x < 10 ? '0' + x : 'A' + (x - 10));
174
+ }
175
+
176
+ // Given a sequence of UTF 16 code units, return true if all code units are
177
+ // ASCII characters
178
+ bool isAllASCII(const char16_t* utf16, size_t length) {
179
+ for (const char16_t* e = utf16 + length; utf16 != e; ++utf16) {
180
+ if (*utf16 > 0x7F)
181
+ return false;
182
+ }
183
+ return true;
184
+ }
185
+
186
+ // Given a sequences of UTF 16 code units, return a string that explicitly
187
+ // expresses the code units
188
+ std::string getUtf16CodeUnitString(const char16_t* utf16, size_t length) {
189
+ // Every character will need 4 hex digits + the character escape "\u".
190
+ // Plus 2 character for the opening and closing single quote.
191
+ std::string s = std::string(6 * length + 2, 0);
192
+ s.front() = '\'';
193
+
194
+ for (size_t i = 0; i != length; ++i) {
195
+ char16_t ch = utf16[i];
196
+ size_t start = (6 * i) + 1;
197
+
198
+ s[start] = '\\';
199
+ s[start + 1] = 'u';
200
+
201
+ s[start + 2] = hexDigit((ch >> 12) & 0x000f);
202
+ s[start + 3] = hexDigit((ch >> 8) & 0x000f);
203
+ s[start + 4] = hexDigit((ch >> 4) & 0x000f);
204
+ s[start + 5] = hexDigit(ch & 0x000f);
205
+ }
206
+ s.back() = '\'';
207
+ return s;
208
+ }
209
+ #endif
210
+
67
211
  } // namespace
68
212
 
69
213
  Buffer::~Buffer() = default;
@@ -115,12 +259,26 @@ Instrumentation& Runtime::instrumentation() {
115
259
  void startHeapSampling(size_t) override {}
116
260
  void stopHeapSampling(std::ostream&) override {}
117
261
 
118
- void createSnapshotToFile(const std::string&) override {
262
+ #if JSI_VERSION >= 13
263
+ void createSnapshotToFile(
264
+ const std::string& /*path*/,
265
+ const HeapSnapshotOptions& /*options*/) override
266
+ #else
267
+ void createSnapshotToFile(const std::string&) override
268
+ #endif
269
+ {
119
270
  throw JSINativeException(
120
271
  "Default instrumentation cannot create a heap snapshot");
121
272
  }
122
273
 
123
- void createSnapshotToStream(std::ostream&) override {
274
+ #if JSI_VERSION >= 13
275
+ void createSnapshotToStream(
276
+ std::ostream& /*os*/,
277
+ const HeapSnapshotOptions& /*options*/) override
278
+ #else
279
+ void createSnapshotToStream(std::ostream&) override
280
+ #endif
281
+ {
124
282
  throw JSINativeException(
125
283
  "Default instrumentation cannot create a heap snapshot");
126
284
  }
@@ -161,7 +319,86 @@ Value Value::createFromJsonUtf8(
161
319
  }
162
320
  #endif
163
321
 
164
- Pointer& Pointer::operator=(Pointer&& other) {
322
+ #if JSI_VERSION >= 19
323
+ String Runtime::createStringFromUtf16(const char16_t* utf16, size_t length) {
324
+ if (isAllASCII(utf16, length)) {
325
+ std::string buffer(length, '\0');
326
+ for (size_t i = 0; i < length; ++i) {
327
+ buffer[i] = static_cast<char>(utf16[i]);
328
+ }
329
+ return createStringFromAscii(buffer.data(), length);
330
+ }
331
+ auto s = getUtf16CodeUnitString(utf16, length);
332
+ return global()
333
+ .getPropertyAsFunction(*this, "eval")
334
+ .call(*this, s)
335
+ .getString(*this);
336
+ }
337
+
338
+ PropNameID Runtime::createPropNameIDFromUtf16(
339
+ const char16_t* utf16,
340
+ size_t length) {
341
+ auto jsString = createStringFromUtf16(utf16, length);
342
+ return createPropNameIDFromString(jsString);
343
+ }
344
+ #endif
345
+
346
+ #if JSI_VERSION >= 14
347
+ std::u16string Runtime::utf16(const PropNameID& sym) {
348
+ auto utf8Str = utf8(sym);
349
+ return convertUTF8ToUTF16(utf8Str);
350
+ }
351
+
352
+ std::u16string Runtime::utf16(const String& str) {
353
+ auto utf8Str = utf8(str);
354
+ return convertUTF8ToUTF16(utf8Str);
355
+ }
356
+ #endif
357
+
358
+ #if JSI_VERSION >= 16
359
+ void Runtime::getStringData(
360
+ const jsi::String& str,
361
+ void* ctx,
362
+ void (*cb)(void* ctx, bool ascii, const void* data, size_t num)) {
363
+ auto utf16Str = utf16(str);
364
+ cb(ctx, false, utf16Str.data(), utf16Str.size());
365
+ }
366
+
367
+ void Runtime::getPropNameIdData(
368
+ const jsi::PropNameID& sym,
369
+ void* ctx,
370
+ void (*cb)(void* ctx, bool ascii, const void* data, size_t num)) {
371
+ auto utf16Str = utf16(sym);
372
+ cb(ctx, false, utf16Str.data(), utf16Str.size());
373
+ }
374
+ #endif
375
+
376
+ #if JSI_VERSION >= 17
377
+ void Runtime::setPrototypeOf(const Object& object, const Value& prototype) {
378
+ auto setPrototypeOfFn = global()
379
+ .getPropertyAsObject(*this, "Object")
380
+ .getPropertyAsFunction(*this, "setPrototypeOf");
381
+ setPrototypeOfFn.call(*this, object, prototype).asObject(*this);
382
+ }
383
+
384
+ Value Runtime::getPrototypeOf(const Object& object) {
385
+ auto setPrototypeOfFn = global()
386
+ .getPropertyAsObject(*this, "Object")
387
+ .getPropertyAsFunction(*this, "getPrototypeOf");
388
+ return setPrototypeOfFn.call(*this, object);
389
+ }
390
+ #endif
391
+
392
+ #if JSI_VERSION >= 18
393
+ Object Runtime::createObjectWithPrototype(const Value& prototype) {
394
+ auto createFn = global()
395
+ .getPropertyAsObject(*this, "Object")
396
+ .getPropertyAsFunction(*this, "create");
397
+ return createFn.call(*this, prototype).asObject(*this);
398
+ }
399
+ #endif
400
+
401
+ Pointer& Pointer::operator=(Pointer&& other) JSI_NOEXCEPT_15 {
165
402
  if (ptr_) {
166
403
  ptr_->invalidate();
167
404
  }
@@ -236,7 +473,7 @@ Function Object::asFunction(Runtime& runtime) && {
236
473
  return std::move(*this).getFunction(runtime);
237
474
  }
238
475
 
239
- Value::Value(Value&& other) : Value(other.kind_) {
476
+ Value::Value(Value&& other) JSI_NOEXCEPT_15 : Value(other.kind_) {
240
477
  if (kind_ == BooleanKind) {
241
478
  data_.boolean = other.data_.boolean;
242
479
  } else if (kind_ == NumberKind) {
@@ -15,22 +15,20 @@
15
15
  #include <string>
16
16
  #include <vector>
17
17
 
18
- #ifndef JSI_EXPORT
19
- #ifdef _MSC_VER
20
- #ifdef CREATE_SHARED_LIBRARY
21
- #define JSI_EXPORT __declspec(dllexport)
22
- #else
23
- #define JSI_EXPORT
24
- #endif // CREATE_SHARED_LIBRARY
25
- #else // _MSC_VER
26
- #define JSI_EXPORT __attribute__((visibility("default")))
27
- #endif // _MSC_VER
28
- #endif // !defined(JSI_EXPORT)
29
-
30
18
  // JSI version defines set of features available in the API.
31
19
  // Each significant API change must be under a new version.
20
+ // The JSI_VERSION can be provided as a parameter to compiler
21
+ // or in the optional "jsi_version.h" file.
22
+
32
23
  #ifndef JSI_VERSION
33
- #define JSI_VERSION 11
24
+ #if defined(__has_include) && __has_include(<jsi/jsi-version.h>)
25
+ #include <jsi/jsi-version.h>
26
+ #endif
27
+ #endif
28
+
29
+ #ifndef JSI_VERSION
30
+ // Use the latest version by default
31
+ #define JSI_VERSION 19
34
32
  #endif
35
33
 
36
34
  #if JSI_VERSION >= 3
@@ -45,6 +43,24 @@
45
43
  #define JSI_CONST_10
46
44
  #endif
47
45
 
46
+ #if JSI_VERSION >= 15
47
+ #define JSI_NOEXCEPT_15 noexcept
48
+ #else
49
+ #define JSI_NOEXCEPT_15
50
+ #endif
51
+
52
+ #ifndef JSI_EXPORT
53
+ #ifdef _MSC_VER
54
+ #ifdef CREATE_SHARED_LIBRARY
55
+ #define JSI_EXPORT __declspec(dllexport)
56
+ #else
57
+ #define JSI_EXPORT
58
+ #endif // CREATE_SHARED_LIBRARY
59
+ #else // _MSC_VER
60
+ #define JSI_EXPORT __attribute__((visibility("default")))
61
+ #endif // _MSC_VER
62
+ #endif // !defined(JSI_EXPORT)
63
+
48
64
  class FBJSRuntime;
49
65
  namespace facebook {
50
66
  namespace jsi {
@@ -233,6 +249,15 @@ class JSI_EXPORT Runtime {
233
249
  virtual Value evaluatePreparedJavaScript(
234
250
  const std::shared_ptr<const PreparedJavaScript>& js) = 0;
235
251
 
252
+ #if JSI_VERSION >= 12
253
+ /// Queues a microtask in the JavaScript VM internal Microtask (a.k.a. Job in
254
+ /// ECMA262) queue, to be executed when the host drains microtasks in
255
+ /// its event loop implementation.
256
+ ///
257
+ /// \param callback a function to be executed as a microtask.
258
+ virtual void queueMicrotask(const jsi::Function& callback) = 0;
259
+ #endif
260
+
236
261
  #if JSI_VERSION >= 4
237
262
  /// Drain the JavaScript VM internal Microtask (a.k.a. Job in ECMA262) queue.
238
263
  ///
@@ -309,7 +334,7 @@ class JSI_EXPORT Runtime {
309
334
  // rvalue arguments/methods would also reduce the number of clones.
310
335
 
311
336
  struct PointerValue {
312
- virtual void invalidate() = 0;
337
+ virtual void invalidate() JSI_NOEXCEPT_15 = 0;
313
338
 
314
339
  protected:
315
340
  virtual ~PointerValue() = default;
@@ -329,6 +354,11 @@ class JSI_EXPORT Runtime {
329
354
  virtual PropNameID createPropNameIDFromUtf8(
330
355
  const uint8_t* utf8,
331
356
  size_t length) = 0;
357
+ #if JSI_VERSION >= 19
358
+ virtual PropNameID createPropNameIDFromUtf16(
359
+ const char16_t* utf16,
360
+ size_t length);
361
+ #endif
332
362
  virtual PropNameID createPropNameIDFromString(const String& str) = 0;
333
363
  #if JSI_VERSION >= 5
334
364
  virtual PropNameID createPropNameIDFromSymbol(const Symbol& sym) = 0;
@@ -349,6 +379,9 @@ class JSI_EXPORT Runtime {
349
379
 
350
380
  virtual String createStringFromAscii(const char* str, size_t length) = 0;
351
381
  virtual String createStringFromUtf8(const uint8_t* utf8, size_t length) = 0;
382
+ #if JSI_VERSION >= 19
383
+ virtual String createStringFromUtf16(const char16_t* utf16, size_t length);
384
+ #endif
352
385
  virtual std::string utf8(const String&) = 0;
353
386
 
354
387
  // \return a \c Value created from a utf8-encoded JSON string. The default
@@ -362,6 +395,11 @@ class JSI_EXPORT Runtime {
362
395
  virtual std::shared_ptr<HostObject> getHostObject(const jsi::Object&) = 0;
363
396
  virtual HostFunctionType& getHostFunction(const jsi::Function&) = 0;
364
397
 
398
+ #if JSI_VERSION >= 18
399
+ // Creates a new Object with the custom prototype
400
+ virtual Object createObjectWithPrototype(const Value& prototype);
401
+ #endif
402
+
365
403
  #if JSI_VERSION >= 7
366
404
  virtual bool hasNativeState(const jsi::Object&) = 0;
367
405
  virtual std::shared_ptr<NativeState> getNativeState(const jsi::Object&) = 0;
@@ -370,6 +408,11 @@ class JSI_EXPORT Runtime {
370
408
  std::shared_ptr<NativeState> state) = 0;
371
409
  #endif
372
410
 
411
+ #if JSI_VERSION >= 17
412
+ virtual void setPrototypeOf(const Object& object, const Value& prototype);
413
+ virtual Value getPrototypeOf(const Object& object);
414
+ #endif
415
+
373
416
  virtual Value getProperty(const Object&, const PropNameID& name) = 0;
374
417
  virtual Value getProperty(const Object&, const String& name) = 0;
375
418
  virtual bool hasProperty(const Object&, const PropNameID& name) = 0;
@@ -438,6 +481,41 @@ class JSI_EXPORT Runtime {
438
481
  size_t amount) = 0;
439
482
  #endif
440
483
 
484
+ #if JSI_VERSION >= 14
485
+ virtual std::u16string utf16(const String& str);
486
+ virtual std::u16string utf16(const PropNameID& sym);
487
+ #endif
488
+
489
+ #if JSI_VERSION >= 16
490
+ /// Invokes the provided callback \p cb with the String content in \p str.
491
+ /// The callback must take in three arguments: bool ascii, const void* data,
492
+ /// and size_t num, respectively. \p ascii indicates whether the \p data
493
+ /// passed to the callback should be interpreted as a pointer to a sequence of
494
+ /// \p num ASCII characters or UTF16 characters. Depending on the internal
495
+ /// representation of the string, the function may invoke the callback
496
+ /// multiple times, with a different format on each invocation. The callback
497
+ /// must not access runtime functionality, as any operation on the runtime may
498
+ /// invalidate the data pointers.
499
+ virtual void getStringData(
500
+ const jsi::String& str,
501
+ void* ctx,
502
+ void (*cb)(void* ctx, bool ascii, const void* data, size_t num));
503
+
504
+ /// Invokes the provided callback \p cb with the PropNameID content in \p sym.
505
+ /// The callback must take in three arguments: bool ascii, const void* data,
506
+ /// and size_t num, respectively. \p ascii indicates whether the \p data
507
+ /// passed to the callback should be interpreted as a pointer to a sequence of
508
+ /// \p num ASCII characters or UTF16 characters. Depending on the internal
509
+ /// representation of the string, the function may invoke the callback
510
+ /// multiple times, with a different format on each invocation. The callback
511
+ /// must not access runtime functionality, as any operation on the runtime may
512
+ /// invalidate the data pointers.
513
+ virtual void getPropNameIdData(
514
+ const jsi::PropNameID& sym,
515
+ void* ctx,
516
+ void (*cb)(void* ctx, bool ascii, const void* data, size_t num));
517
+ #endif
518
+
441
519
  // These exist so derived classes can access the private parts of
442
520
  // Value, Symbol, String, and Object, which are all friends of Runtime.
443
521
  template <typename T>
@@ -456,7 +534,7 @@ class JSI_EXPORT Runtime {
456
534
  // Base class for pointer-storing types.
457
535
  class JSI_EXPORT Pointer {
458
536
  protected:
459
- explicit Pointer(Pointer&& other) : ptr_(other.ptr_) {
537
+ explicit Pointer(Pointer&& other) JSI_NOEXCEPT_15 : ptr_(other.ptr_) {
460
538
  other.ptr_ = nullptr;
461
539
  }
462
540
 
@@ -466,7 +544,7 @@ class JSI_EXPORT Pointer {
466
544
  }
467
545
  }
468
546
 
469
- Pointer& operator=(Pointer&& other);
547
+ Pointer& operator=(Pointer&& other) JSI_NOEXCEPT_15;
470
548
 
471
549
  friend class Runtime;
472
550
  friend class Value;
@@ -519,6 +597,23 @@ class JSI_EXPORT PropNameID : public Pointer {
519
597
  reinterpret_cast<const uint8_t*>(utf8.data()), utf8.size());
520
598
  }
521
599
 
600
+ #if JSI_VERSION >= 19
601
+ /// Given a series of UTF-16 encoded code units, create a PropNameId. The
602
+ /// input may contain unpaired surrogates, which will be interpreted as a code
603
+ /// point of the same value.
604
+ static PropNameID
605
+ forUtf16(Runtime& runtime, const char16_t* utf16, size_t length) {
606
+ return runtime.createPropNameIDFromUtf16(utf16, length);
607
+ }
608
+
609
+ /// Given a series of UTF-16 encoded code units stored inside std::u16string,
610
+ /// create a PropNameId. The input may contain unpaired surrogates, which
611
+ /// will be interpreted as a code point of the same value.
612
+ static PropNameID forUtf16(Runtime& runtime, const std::u16string& str) {
613
+ return runtime.createPropNameIDFromUtf16(str.data(), str.size());
614
+ }
615
+ #endif
616
+
522
617
  /// Create a PropNameID from a JS string.
523
618
  static PropNameID forString(Runtime& runtime, const jsi::String& str) {
524
619
  return runtime.createPropNameIDFromString(str);
@@ -544,6 +639,31 @@ class JSI_EXPORT PropNameID : public Pointer {
544
639
  return runtime.utf8(*this);
545
640
  }
546
641
 
642
+ #if JSI_VERSION >= 14
643
+ /// Copies the data in a PropNameID as utf16 into a C++ string.
644
+ std::u16string utf16(Runtime& runtime) const {
645
+ return runtime.utf16(*this);
646
+ }
647
+ #endif
648
+
649
+ #if JSI_VERSION >= 16
650
+ /// Invokes the user provided callback to process the content in PropNameId.
651
+ /// The callback must take in three arguments: bool ascii, const void* data,
652
+ /// and size_t num, respectively. \p ascii indicates whether the \p data
653
+ /// passed to the callback should be interpreted as a pointer to a sequence of
654
+ /// \p num ASCII characters or UTF16 characters. The function may invoke the
655
+ /// callback multiple times, with a different format on each invocation. The
656
+ /// callback must not access runtime functionality, as any operation on the
657
+ /// runtime may invalidate the data pointers.
658
+ template <typename CB>
659
+ void getPropNameIdData(Runtime& runtime, CB& cb) const {
660
+ runtime.getPropNameIdData(
661
+ *this, &cb, [](void* ctx, bool ascii, const void* data, size_t num) {
662
+ (*((CB*)ctx))(ascii, data, num);
663
+ });
664
+ }
665
+ #endif
666
+
547
667
  static bool compare(
548
668
  Runtime& runtime,
549
669
  const jsi::PropNameID& a,
@@ -688,6 +808,23 @@ class JSI_EXPORT String : public Pointer {
688
808
  reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());
689
809
  }
690
810
 
811
+ #if JSI_VERSION >= 19
812
+ /// Given a series of UTF-16 encoded code units, create a JS String. The input
813
+ /// may contain unpaired surrogates, which will be interpreted as a code point
814
+ /// of the same value.
815
+ static String
816
+ createFromUtf16(Runtime& runtime, const char16_t* utf16, size_t length) {
817
+ return runtime.createStringFromUtf16(utf16, length);
818
+ }
819
+
820
+ /// Given a series of UTF-16 encoded code units stored inside std::u16string,
821
+ /// create a JS String. The input may contain unpaired surrogates, which will
822
+ /// be interpreted as a code point of the same value.
823
+ static String createFromUtf16(Runtime& runtime, const std::u16string& utf16) {
824
+ return runtime.createStringFromUtf16(utf16.data(), utf16.length());
825
+ }
826
+ #endif
827
+
691
828
  /// \return whether a and b contain the same characters.
692
829
  static bool strictEquals(Runtime& runtime, const String& a, const String& b) {
693
830
  return runtime.strictEquals(a, b);
@@ -698,6 +835,31 @@ class JSI_EXPORT String : public Pointer {
698
835
  return runtime.utf8(*this);
699
836
  }
700
837
 
838
+ #if JSI_VERSION >= 14
839
+ /// Copies the data in a JS string as utf16 into a C++ string.
840
+ std::u16string utf16(Runtime& runtime) const {
841
+ return runtime.utf16(*this);
842
+ }
843
+ #endif
844
+
845
+ #if JSI_VERSION >= 16
846
+ /// Invokes the user provided callback to process content in String. The
847
+ /// callback must take in three arguments: bool ascii, const void* data, and
848
+ /// size_t num, respectively. \p ascii indicates whether the \p data passed to
849
+ /// the callback should be interpreted as a pointer to a sequence of \p num
850
+ /// ASCII characters or UTF16 characters. The function may invoke the callback
851
+ /// multiple times, with a different format on each invocation. The callback
852
+ /// must not access runtime functionality, as any operation on the runtime may
853
+ /// invalidate the data pointers.
854
+ template <typename CB>
855
+ void getStringData(Runtime& runtime, CB& cb) const {
856
+ runtime.getStringData(
857
+ *this, &cb, [](void* ctx, bool ascii, const void* data, size_t num) {
858
+ (*((CB*)ctx))(ascii, data, num);
859
+ });
860
+ }
861
+ #endif
862
+
701
863
  friend class Runtime;
702
864
  friend class Value;
703
865
  };
@@ -722,6 +884,13 @@ class JSI_EXPORT Object : public Pointer {
722
884
  return runtime.createObject(ho);
723
885
  }
724
886
 
887
+ #if JSI_VERSION >= 18
888
+ /// Creates a new Object with the custom prototype
889
+ static Object create(Runtime& runtime, const Value& prototype) {
890
+ return runtime.createObjectWithPrototype(prototype);
891
+ }
892
+ #endif
893
+
725
894
  /// \return whether this and \c obj are the same JSObject or not.
726
895
  static bool strictEquals(Runtime& runtime, const Object& a, const Object& b) {
727
896
  return runtime.strictEquals(a, b);
@@ -732,6 +901,18 @@ class JSI_EXPORT Object : public Pointer {
732
901
  return rt.instanceOf(*this, ctor);
733
902
  }
734
903
 
904
+ #if JSI_VERSION >= 17
905
+ /// Sets \p prototype as the prototype of the object. The prototype must be
906
+ /// either an Object or null. If the prototype was not set successfully, this
907
+ /// method will throw.
908
+ void setPrototype(Runtime& runtime, const Value& prototype) const {
909
+ return runtime.setPrototypeOf(*this, prototype);
910
+ }
911
+
912
+ /// \return the prototype of the object
913
+ inline Value getPrototype(Runtime& runtime) const;
914
+ #endif
915
+
735
916
  /// \return the property of the object with the given ascii name.
736
917
  /// If the name isn't a property on the object, returns the
737
918
  /// undefined value.
@@ -1055,6 +1236,11 @@ class JSI_EXPORT Function : public Object {
1055
1236
  /// \param name the name property for the function.
1056
1237
  /// \param paramCount the length property for the function, which
1057
1238
  /// may not be the number of arguments the function is passed.
1239
+ /// \note The std::function's dtor will be called when the GC finalizes this
1240
+ /// function. As with HostObject, this may be as late as when the Runtime is
1241
+ /// shut down, and may occur on an arbitrary thread. If the function contains
1242
+ /// any captured values, you are responsible for ensuring that their
1243
+ /// destructors are safe to call on any thread.
1058
1244
  static Function createFromHostFunction(
1059
1245
  Runtime& runtime,
1060
1246
  const jsi::PropNameID& name,
@@ -1158,7 +1344,7 @@ class JSI_EXPORT Function : public Object {
1158
1344
  class JSI_EXPORT Value {
1159
1345
  public:
1160
1346
  /// Default ctor creates an \c undefined JS value.
1161
- Value() : Value(UndefinedKind) {}
1347
+ Value() JSI_NOEXCEPT_15 : Value(UndefinedKind) {}
1162
1348
 
1163
1349
  /// Creates a \c null JS value.
1164
1350
  /* implicit */ Value(std::nullptr_t) : kind_(NullKind) {}
@@ -1201,7 +1387,7 @@ class JSI_EXPORT Value {
1201
1387
  "Value cannot be constructed directly from const char*");
1202
1388
  }
1203
1389
 
1204
- Value(Value&& value);
1390
+ Value(Value&& other) JSI_NOEXCEPT_15;
1205
1391
 
1206
1392
  /// Copies a Symbol lvalue into a new JS value.
1207
1393
  Value(Runtime& runtime, const Symbol& sym) : Value(SymbolKind) {
@@ -1263,7 +1449,7 @@ class JSI_EXPORT Value {
1263
1449
  /// https://262.ecma-international.org/11.0/#sec-strict-equality-comparison
1264
1450
  static bool strictEquals(Runtime& runtime, const Value& a, const Value& b);
1265
1451
 
1266
- Value& operator=(Value&& other) {
1452
+ Value& operator=(Value&& other) JSI_NOEXCEPT_15 {
1267
1453
  this->~Value();
1268
1454
  new (this) Value(std::move(other));
1269
1455
  return *this;
@@ -1584,6 +1770,8 @@ class JSI_EXPORT JSError : public JSIException {
1584
1770
  return *value_;
1585
1771
  }
1586
1772
 
1773
+ // TODO: (vmoroz) Can we remove it considering that we have the new JSError
1774
+ // constructor?
1587
1775
  // In V8's case, creating an Error object in JS doesn't record the callstack.
1588
1776
  // To preserve it, we need a way to manually add the stack here and on the JS
1589
1777
  // side.
@@ -278,7 +278,7 @@ JSValue const &JSValueObject::operator[](std::string_view propertyName) const no
278
278
  return it->second;
279
279
  }
280
280
 
281
- return JSValue::Null;
281
+ return JSValue::NullRef();
282
282
  }
283
283
 
284
284
  bool JSValueObject::Equals(JSValueObject const &other) const noexcept {
@@ -434,6 +434,22 @@ void JSValueArray::WriteTo(IJSValueWriter const &writer) const noexcept {
434
434
  /*static*/ JSValue const JSValue::EmptyArray{JSValueArray{}};
435
435
  /*static*/ JSValue const JSValue::EmptyString{std::string{}};
436
436
 
437
+ const JSValue &JSValue::NullRef() noexcept {
438
+ return JSValue::Null;
439
+ }
440
+
441
+ const JSValue &JSValue::EmptyObjectRef() noexcept {
442
+ return JSValue::EmptyObject;
443
+ }
444
+
445
+ const JSValue &JSValue::EmptyArrayRef() noexcept {
446
+ return JSValue::EmptyArray;
447
+ }
448
+
449
+ const JSValue &JSValue::EmptyStringRef() noexcept {
450
+ return JSValue::EmptyString;
451
+ }
452
+
437
453
  #pragma warning(push)
438
454
  #pragma warning(disable : 26495) // False positive for union member not initialized
439
455
  JSValue::JSValue(JSValue &&other) noexcept : m_type{other.m_type} {
@@ -739,7 +755,7 @@ JSValue const *JSValue::TryGetObjectProperty(std::string_view propertyName) cons
739
755
 
740
756
  JSValue const &JSValue::GetObjectProperty(std::string_view propertyName) const noexcept {
741
757
  auto result = TryGetObjectProperty(propertyName);
742
- return result ? *result : Null;
758
+ return result ? *result : NullRef();
743
759
  }
744
760
 
745
761
  size_t JSValue::ItemCount() const noexcept {
@@ -752,7 +768,7 @@ JSValue const *JSValue::TryGetArrayItem(JSValueArray::size_type index) const noe
752
768
 
753
769
  JSValue const &JSValue::GetArrayItem(JSValueArray::size_type index) const noexcept {
754
770
  auto result = TryGetArrayItem(index);
755
- return result ? *result : Null;
771
+ return result ? *result : NullRef();
756
772
  }
757
773
 
758
774
  bool JSValue::Equals(JSValue const &other) const noexcept {