react-native-windows 0.80.0 → 0.80.5

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 (86) hide show
  1. package/Directory.Build.props +1 -1
  2. package/Microsoft.ReactNative/Fabric/Composition/DebuggerUIIsland.cpp +169 -0
  3. package/Microsoft.ReactNative/Fabric/Composition/DebuggerUIIsland.h +42 -0
  4. package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.cpp +1 -1
  5. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +60 -33
  6. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +68 -1
  7. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +9 -0
  8. package/Microsoft.ReactNative/Fabric/Composition/TextDrawing.cpp +5 -37
  9. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +5 -3
  10. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +6 -1
  11. package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +14 -1
  12. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/PlatformColorUtils.cpp +0 -17
  13. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/PlatformColorUtils.h +0 -3
  14. package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.cpp +75 -24
  15. package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.h +4 -25
  16. package/Microsoft.ReactNative/JsiApi.cpp +1 -1
  17. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -0
  18. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +3 -0
  19. package/Microsoft.ReactNative/ReactHost/DebuggerNotifications.h +54 -0
  20. package/Microsoft.ReactNative/ReactHost/React.h +11 -4
  21. package/Microsoft.ReactNative/ReactHost/ReactHost.cpp +195 -29
  22. package/Microsoft.ReactNative/ReactHost/ReactHost.h +22 -4
  23. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +24 -5
  24. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -1
  25. package/Microsoft.ReactNative/ReactRootView.cpp +108 -0
  26. package/Microsoft.ReactNative/ReactRootView.h +6 -0
  27. package/Microsoft.ReactNative/Views/DevMenu.cpp +1 -1
  28. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +1 -1
  29. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  30. package/PropertySheets/JSEngine.props +1 -1
  31. package/PropertySheets/React.Cpp.props +2 -2
  32. package/ReactCommon/ReactCommon.vcxproj +18 -1
  33. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +1 -1
  34. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +4 -4
  35. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.cpp +23 -9
  36. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.h +16 -0
  37. package/ReactCommon/cgmanifest.json +1 -1
  38. package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +2 -0
  39. package/Shared/DevServerHelper.h +13 -3
  40. package/Shared/DevSettings.h +7 -0
  41. package/Shared/DevSupportManager.cpp +79 -20
  42. package/Shared/DevSupportManager.h +7 -19
  43. package/Shared/Hermes/HermesRuntimeAgentDelegate.cpp +99 -0
  44. package/Shared/Hermes/HermesRuntimeAgentDelegate.h +81 -0
  45. package/Shared/Hermes/HermesRuntimeTargetDelegate.cpp +263 -0
  46. package/Shared/Hermes/HermesRuntimeTargetDelegate.h +77 -0
  47. package/Shared/HermesRuntimeHolder.cpp +29 -111
  48. package/Shared/HermesRuntimeHolder.h +214 -32
  49. package/Shared/IDevSupportManager.h +5 -2
  50. package/Shared/Inspector/ReactInspectorPackagerConnectionDelegate.cpp +108 -0
  51. package/Shared/Inspector/ReactInspectorPackagerConnectionDelegate.h +19 -0
  52. package/Shared/Inspector/ReactInspectorThread.h +18 -0
  53. package/Shared/JSI/RuntimeHolder.h +5 -2
  54. package/Shared/OInstance.cpp +44 -27
  55. package/Shared/Shared.vcxitems +27 -17
  56. package/Shared/Shared.vcxitems.filters +33 -15
  57. package/package.json +4 -4
  58. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.cpp +0 -79
  59. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.h +0 -51
  60. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.inc +0 -50
  61. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi.cpp +0 -41
  62. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi.h +0 -127
  63. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi.inc +0 -125
  64. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi_posix.cpp +0 -16
  65. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi_win.cpp +0 -23
  66. package/Microsoft.ReactNative.Cxx/JSI/decorator.h +0 -1054
  67. package/Microsoft.ReactNative.Cxx/JSI/instrumentation.h +0 -145
  68. package/Microsoft.ReactNative.Cxx/JSI/jsi-inl.h +0 -372
  69. package/Microsoft.ReactNative.Cxx/JSI/jsi.cpp +0 -797
  70. package/Microsoft.ReactNative.Cxx/JSI/jsi.h +0 -1799
  71. package/Microsoft.ReactNative.Cxx/JSI/threadsafe.h +0 -79
  72. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.cpp +0 -3531
  73. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.h +0 -38
  74. package/Microsoft.ReactNative.Cxx/node-api/js_native_api.h +0 -614
  75. package/Microsoft.ReactNative.Cxx/node-api/js_native_api_types.h +0 -212
  76. package/Microsoft.ReactNative.Cxx/node-api/js_runtime_api.h +0 -199
  77. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +0 -78
  78. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.h +0 -196
  79. package/ReactCommon/TEMP_UntilReactCommonUpdate/jserrorhandler/JsErrorHandler.cpp +0 -429
  80. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsitooling/react/runtime/JSRuntimeFactory.cpp +0 -45
  81. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsitooling/react/runtime/JSRuntimeFactory.h +0 -91
  82. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +0 -670
  83. package/Shared/InspectorPackagerConnection.cpp +0 -232
  84. package/Shared/InspectorPackagerConnection.h +0 -61
  85. /package/Shared/{HermesSamplingProfiler.cpp → Hermes/HermesSamplingProfiler.cpp} +0 -0
  86. /package/Shared/{HermesSamplingProfiler.h → Hermes/HermesSamplingProfiler.h} +0 -0
@@ -1,1054 +0,0 @@
1
- /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- #pragma once
9
-
10
- #include <tuple>
11
-
12
- #include <jsi/instrumentation.h>
13
- #include <jsi/jsi.h>
14
-
15
- // This file contains objects to help API users create their own
16
- // runtime adapters, i.e. if you want to compose runtimes to add your
17
- // own behavior.
18
-
19
- namespace facebook {
20
- namespace jsi {
21
-
22
- // Use this to wrap host functions. It will pass the member runtime as
23
- // the first arg to the callback. The first argument to the ctor
24
- // should be the decorated runtime, not the plain one.
25
- class DecoratedHostFunction {
26
- public:
27
- DecoratedHostFunction(Runtime& drt, HostFunctionType plainHF)
28
- : drt_(drt), plainHF_(std::move(plainHF)) {}
29
-
30
- Runtime& decoratedRuntime() {
31
- return drt_;
32
- }
33
-
34
- Value
35
- operator()(Runtime&, const Value& thisVal, const Value* args, size_t count) {
36
- return plainHF_(decoratedRuntime(), thisVal, args, count);
37
- }
38
-
39
- private:
40
- template <typename Plain, typename Base>
41
- friend class RuntimeDecorator;
42
-
43
- Runtime& drt_;
44
- HostFunctionType plainHF_;
45
- };
46
-
47
- // From the perspective of the caller, a plain HostObject is passed to
48
- // the decorated Runtime, and the HostObject methods expect to get
49
- // passed that Runtime. But the plain Runtime will pass itself to its
50
- // callback, so we need a helper here which curries the decorated
51
- // Runtime, and calls the plain HostObject with it.
52
- //
53
- // If the concrete RuntimeDecorator derives DecoratedHostObject, it
54
- // should call the base class get() and set() to invoke the plain
55
- // HostObject functionality. The Runtime& it passes does not matter,
56
- // as it is not used.
57
- class DecoratedHostObject : public HostObject {
58
- public:
59
- DecoratedHostObject(Runtime& drt, std::shared_ptr<HostObject> plainHO)
60
- : drt_(drt), plainHO_(plainHO) {}
61
-
62
- // The derived class methods can call this to get a reference to the
63
- // decorated runtime, since the rt passed to the callback will be
64
- // the plain runtime.
65
- Runtime& decoratedRuntime() {
66
- return drt_;
67
- }
68
-
69
- Value get(Runtime&, const PropNameID& name) override {
70
- return plainHO_->get(decoratedRuntime(), name);
71
- }
72
-
73
- void set(Runtime&, const PropNameID& name, const Value& value) override {
74
- plainHO_->set(decoratedRuntime(), name, value);
75
- }
76
-
77
- std::vector<PropNameID> getPropertyNames(Runtime&) override {
78
- return plainHO_->getPropertyNames(decoratedRuntime());
79
- }
80
-
81
- private:
82
- template <typename Plain, typename Base>
83
- friend class RuntimeDecorator;
84
-
85
- Runtime& drt_;
86
- std::shared_ptr<HostObject> plainHO_;
87
- };
88
-
89
- /// C++ variant on a standard Decorator pattern, using template
90
- /// parameters. The \c Plain template parameter type is the
91
- /// undecorated Runtime type. You can usually use \c Runtime here,
92
- /// but if you know the concrete type ahead of time and it's final,
93
- /// the compiler can devirtualize calls to the decorated
94
- /// implementation. The \c Base template parameter type will be used
95
- /// as the base class of the decorated type. Here, too, you can
96
- /// usually use \c Runtime, but if you want the decorated type to
97
- /// implement a derived class of Runtime, you can specify that here.
98
- /// For an example, see threadsafe.h.
99
- template <typename Plain = Runtime, typename Base = Runtime>
100
- class RuntimeDecorator : public Base, private jsi::Instrumentation {
101
- public:
102
- Plain& plain() {
103
- static_assert(
104
- std::is_base_of<Runtime, Plain>::value,
105
- "RuntimeDecorator's Plain type must derive from jsi::Runtime");
106
- static_assert(
107
- std::is_base_of<Runtime, Base>::value,
108
- "RuntimeDecorator's Base type must derive from jsi::Runtime");
109
- return plain_;
110
- }
111
- const Plain& plain() const {
112
- return plain_;
113
- }
114
-
115
- Value evaluateJavaScript(
116
- const std::shared_ptr<const Buffer>& buffer,
117
- const std::string& sourceURL) override {
118
- return plain().evaluateJavaScript(buffer, sourceURL);
119
- }
120
- std::shared_ptr<const PreparedJavaScript> prepareJavaScript(
121
- const std::shared_ptr<const Buffer>& buffer,
122
- std::string sourceURL) override {
123
- return plain().prepareJavaScript(buffer, std::move(sourceURL));
124
- }
125
- Value evaluatePreparedJavaScript(
126
- const std::shared_ptr<const PreparedJavaScript>& js) override {
127
- return plain().evaluatePreparedJavaScript(js);
128
- }
129
- #if JSI_VERSION >= 12
130
- void queueMicrotask(const jsi::Function& callback) override {
131
- return plain().queueMicrotask(callback);
132
- }
133
- #endif
134
- #if JSI_VERSION >= 4
135
- bool drainMicrotasks(int maxMicrotasksHint) override {
136
- return plain().drainMicrotasks(maxMicrotasksHint);
137
- }
138
- #endif
139
- Object global() override {
140
- return plain().global();
141
- }
142
- std::string description() override {
143
- return plain().description();
144
- };
145
- bool isInspectable() override {
146
- return plain().isInspectable();
147
- };
148
- Instrumentation& instrumentation() override {
149
- return *this;
150
- }
151
-
152
- protected:
153
- // plain is generally going to be a reference to an object managed
154
- // by a derived class. We cache it here so this class can be
155
- // concrete, and avoid making virtual calls to find the plain
156
- // Runtime. Note that the ctor and dtor do not access through the
157
- // reference, so passing a reference to an object before its
158
- // lifetime has started is ok.
159
- RuntimeDecorator(Plain& plain) : plain_(plain) {}
160
-
161
- Runtime::PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override {
162
- return plain_.cloneSymbol(pv);
163
- };
164
- #if JSI_VERSION >= 6
165
- Runtime::PointerValue* cloneBigInt(const Runtime::PointerValue* pv) override {
166
- return plain_.cloneBigInt(pv);
167
- };
168
- #endif
169
- Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override {
170
- return plain_.cloneString(pv);
171
- };
172
- Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override {
173
- return plain_.cloneObject(pv);
174
- };
175
- Runtime::PointerValue* clonePropNameID(
176
- const Runtime::PointerValue* pv) override {
177
- return plain_.clonePropNameID(pv);
178
- };
179
-
180
- PropNameID createPropNameIDFromAscii(const char* str, size_t length)
181
- override {
182
- return plain_.createPropNameIDFromAscii(str, length);
183
- };
184
- PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length)
185
- override {
186
- return plain_.createPropNameIDFromUtf8(utf8, length);
187
- };
188
- PropNameID createPropNameIDFromString(const String& str) override {
189
- return plain_.createPropNameIDFromString(str);
190
- };
191
- #if JSI_VERSION >= 19
192
- PropNameID createPropNameIDFromUtf16(const char16_t* utf16, size_t length)
193
- override {
194
- return plain_.createPropNameIDFromUtf16(utf16, length);
195
- }
196
- #endif
197
- #if JSI_VERSION >= 5
198
- PropNameID createPropNameIDFromSymbol(const Symbol& sym) override {
199
- return plain_.createPropNameIDFromSymbol(sym);
200
- };
201
- #endif
202
- std::string utf8(const PropNameID& id) override {
203
- return plain_.utf8(id);
204
- };
205
- bool compare(const PropNameID& a, const PropNameID& b) override {
206
- return plain_.compare(a, b);
207
- };
208
-
209
- std::string symbolToString(const Symbol& sym) override {
210
- return plain_.symbolToString(sym);
211
- }
212
-
213
- #if JSI_VERSION >= 8
214
- BigInt createBigIntFromInt64(int64_t value) override {
215
- return plain_.createBigIntFromInt64(value);
216
- }
217
- BigInt createBigIntFromUint64(uint64_t value) override {
218
- return plain_.createBigIntFromUint64(value);
219
- }
220
- bool bigintIsInt64(const BigInt& b) override {
221
- return plain_.bigintIsInt64(b);
222
- }
223
- bool bigintIsUint64(const BigInt& b) override {
224
- return plain_.bigintIsUint64(b);
225
- }
226
- uint64_t truncate(const BigInt& b) override {
227
- return plain_.truncate(b);
228
- }
229
- String bigintToString(const BigInt& bigint, int radix) override {
230
- return plain_.bigintToString(bigint, radix);
231
- }
232
- #endif
233
-
234
- String createStringFromAscii(const char* str, size_t length) override {
235
- return plain_.createStringFromAscii(str, length);
236
- };
237
- String createStringFromUtf8(const uint8_t* utf8, size_t length) override {
238
- return plain_.createStringFromUtf8(utf8, length);
239
- };
240
- #if JSI_VERSION >= 19
241
- String createStringFromUtf16(const char16_t* utf16, size_t length) override {
242
- return plain_.createStringFromUtf16(utf16, length);
243
- }
244
- #endif
245
- std::string utf8(const String& s) override {
246
- return plain_.utf8(s);
247
- }
248
-
249
- #if JSI_VERSION >= 14
250
- std::u16string utf16(const String& str) override {
251
- return plain_.utf16(str);
252
- }
253
- std::u16string utf16(const PropNameID& sym) override {
254
- return plain_.utf16(sym);
255
- }
256
- #endif
257
-
258
- #if JSI_VERSION >= 16
259
- void getStringData(
260
- const jsi::String& str,
261
- void* ctx,
262
- void (
263
- *cb)(void* ctx, bool ascii, const void* data, size_t num)) override {
264
- plain_.getStringData(str, ctx, cb);
265
- }
266
-
267
- void getPropNameIdData(
268
- const jsi::PropNameID& sym,
269
- void* ctx,
270
- void (
271
- *cb)(void* ctx, bool ascii, const void* data, size_t num)) override {
272
- plain_.getPropNameIdData(sym, ctx, cb);
273
- }
274
- #endif
275
-
276
- #if JSI_VERSION >= 18
277
- Object createObjectWithPrototype(const Value& prototype) override {
278
- return plain_.createObjectWithPrototype(prototype);
279
- }
280
- #endif
281
-
282
- Object createObject() override {
283
- return plain_.createObject();
284
- };
285
-
286
- Object createObject(std::shared_ptr<HostObject> ho) override {
287
- return plain_.createObject(
288
- std::make_shared<DecoratedHostObject>(*this, std::move(ho)));
289
- };
290
- std::shared_ptr<HostObject> getHostObject(const jsi::Object& o) override {
291
- std::shared_ptr<HostObject> dho = plain_.getHostObject(o);
292
- return static_cast<DecoratedHostObject&>(*dho).plainHO_;
293
- };
294
- HostFunctionType& getHostFunction(const jsi::Function& f) override {
295
- HostFunctionType& dhf = plain_.getHostFunction(f);
296
- // This will fail if a cpp file including this header is not compiled
297
- // with RTTI.
298
- return dhf.target<DecoratedHostFunction>()->plainHF_;
299
- };
300
-
301
- #if JSI_VERSION >= 7
302
- bool hasNativeState(const Object& o) override {
303
- return plain_.hasNativeState(o);
304
- }
305
- std::shared_ptr<NativeState> getNativeState(const Object& o) override {
306
- return plain_.getNativeState(o);
307
- }
308
- void setNativeState(const Object& o, std::shared_ptr<NativeState> state)
309
- override {
310
- plain_.setNativeState(o, state);
311
- }
312
- #endif
313
-
314
- #if JSI_VERSION >= 11
315
- void setExternalMemoryPressure(const Object& obj, size_t amt) override {
316
- plain_.setExternalMemoryPressure(obj, amt);
317
- }
318
- #endif
319
-
320
- #if JSI_VERSION >= 17
321
- void setPrototypeOf(const Object& object, const Value& prototype) override {
322
- plain_.setPrototypeOf(object, prototype);
323
- }
324
-
325
- Value getPrototypeOf(const Object& object) override {
326
- return plain_.getPrototypeOf(object);
327
- }
328
- #endif
329
-
330
- Value getProperty(const Object& o, const PropNameID& name) override {
331
- return plain_.getProperty(o, name);
332
- };
333
- Value getProperty(const Object& o, const String& name) override {
334
- return plain_.getProperty(o, name);
335
- };
336
- bool hasProperty(const Object& o, const PropNameID& name) override {
337
- return plain_.hasProperty(o, name);
338
- };
339
- bool hasProperty(const Object& o, const String& name) override {
340
- return plain_.hasProperty(o, name);
341
- };
342
- void setPropertyValue(
343
- JSI_CONST_10 Object& o,
344
- const PropNameID& name,
345
- const Value& value) override {
346
- plain_.setPropertyValue(o, name, value);
347
- };
348
- void setPropertyValue(
349
- JSI_CONST_10 Object& o,
350
- const String& name,
351
- const Value& value) override {
352
- plain_.setPropertyValue(o, name, value);
353
- };
354
-
355
- bool isArray(const Object& o) const override {
356
- return plain_.isArray(o);
357
- };
358
- bool isArrayBuffer(const Object& o) const override {
359
- return plain_.isArrayBuffer(o);
360
- };
361
- bool isFunction(const Object& o) const override {
362
- return plain_.isFunction(o);
363
- };
364
- bool isHostObject(const jsi::Object& o) const override {
365
- return plain_.isHostObject(o);
366
- };
367
- bool isHostFunction(const jsi::Function& f) const override {
368
- return plain_.isHostFunction(f);
369
- };
370
- Array getPropertyNames(const Object& o) override {
371
- return plain_.getPropertyNames(o);
372
- };
373
-
374
- WeakObject createWeakObject(const Object& o) override {
375
- return plain_.createWeakObject(o);
376
- };
377
- Value lockWeakObject(JSI_NO_CONST_3 JSI_CONST_10 WeakObject& wo) override {
378
- return plain_.lockWeakObject(wo);
379
- };
380
-
381
- Array createArray(size_t length) override {
382
- return plain_.createArray(length);
383
- };
384
- #if JSI_VERSION >= 9
385
- ArrayBuffer createArrayBuffer(
386
- std::shared_ptr<MutableBuffer> buffer) override {
387
- return plain_.createArrayBuffer(std::move(buffer));
388
- };
389
- #endif
390
- size_t size(const Array& a) override {
391
- return plain_.size(a);
392
- };
393
- size_t size(const ArrayBuffer& ab) override {
394
- return plain_.size(ab);
395
- };
396
- uint8_t* data(const ArrayBuffer& ab) override {
397
- return plain_.data(ab);
398
- };
399
- Value getValueAtIndex(const Array& a, size_t i) override {
400
- return plain_.getValueAtIndex(a, i);
401
- };
402
- void setValueAtIndexImpl(JSI_CONST_10 Array& a, size_t i, const Value& value)
403
- override {
404
- plain_.setValueAtIndexImpl(a, i, value);
405
- };
406
-
407
- Function createFunctionFromHostFunction(
408
- const PropNameID& name,
409
- unsigned int paramCount,
410
- HostFunctionType func) override {
411
- return plain_.createFunctionFromHostFunction(
412
- name, paramCount, DecoratedHostFunction(*this, std::move(func)));
413
- };
414
- Value call(
415
- const Function& f,
416
- const Value& jsThis,
417
- const Value* args,
418
- size_t count) override {
419
- return plain_.call(f, jsThis, args, count);
420
- };
421
- Value callAsConstructor(const Function& f, const Value* args, size_t count)
422
- override {
423
- return plain_.callAsConstructor(f, args, count);
424
- };
425
-
426
- // Private data for managing scopes.
427
- Runtime::ScopeState* pushScope() override {
428
- return plain_.pushScope();
429
- }
430
- void popScope(Runtime::ScopeState* ss) override {
431
- plain_.popScope(ss);
432
- }
433
-
434
- bool strictEquals(const Symbol& a, const Symbol& b) const override {
435
- return plain_.strictEquals(a, b);
436
- };
437
- #if JSI_VERSION >= 6
438
- bool strictEquals(const BigInt& a, const BigInt& b) const override {
439
- return plain_.strictEquals(a, b);
440
- };
441
- #endif
442
- bool strictEquals(const String& a, const String& b) const override {
443
- return plain_.strictEquals(a, b);
444
- };
445
- bool strictEquals(const Object& a, const Object& b) const override {
446
- return plain_.strictEquals(a, b);
447
- };
448
-
449
- bool instanceOf(const Object& o, const Function& f) override {
450
- return plain_.instanceOf(o, f);
451
- };
452
-
453
- // jsi::Instrumentation methods
454
-
455
- std::string getRecordedGCStats() override {
456
- return plain().instrumentation().getRecordedGCStats();
457
- }
458
-
459
- std::unordered_map<std::string, int64_t> getHeapInfo(
460
- bool includeExpensive) override {
461
- return plain().instrumentation().getHeapInfo(includeExpensive);
462
- }
463
-
464
- void collectGarbage(std::string cause) override {
465
- plain().instrumentation().collectGarbage(std::move(cause));
466
- }
467
-
468
- void startTrackingHeapObjectStackTraces(
469
- std::function<void(
470
- uint64_t,
471
- std::chrono::microseconds,
472
- std::vector<HeapStatsUpdate>)> callback) override {
473
- plain().instrumentation().startTrackingHeapObjectStackTraces(
474
- std::move(callback));
475
- }
476
-
477
- void stopTrackingHeapObjectStackTraces() override {
478
- plain().instrumentation().stopTrackingHeapObjectStackTraces();
479
- }
480
-
481
- void startHeapSampling(size_t samplingInterval) override {
482
- plain().instrumentation().startHeapSampling(samplingInterval);
483
- }
484
-
485
- void stopHeapSampling(std::ostream& os) override {
486
- plain().instrumentation().stopHeapSampling(os);
487
- }
488
-
489
- #if JSI_VERSION >= 13
490
- void createSnapshotToFile(
491
- const std::string& path,
492
- const HeapSnapshotOptions& options) override {
493
- plain().instrumentation().createSnapshotToFile(path, options);
494
- }
495
- #else
496
- void createSnapshotToFile(const std::string& path) override {
497
- plain().instrumentation().createSnapshotToFile(path);
498
- }
499
- #endif
500
-
501
- #if JSI_VERSION >= 13
502
- void createSnapshotToStream(
503
- std::ostream& os,
504
- const HeapSnapshotOptions& options) override {
505
- plain().instrumentation().createSnapshotToStream(os, options);
506
- }
507
- #else
508
- void createSnapshotToStream(std::ostream& os) override {
509
- plain().instrumentation().createSnapshotToStream(os);
510
- }
511
- #endif
512
-
513
- std::string flushAndDisableBridgeTrafficTrace() override {
514
- return const_cast<Plain&>(plain())
515
- .instrumentation()
516
- .flushAndDisableBridgeTrafficTrace();
517
- }
518
-
519
- void writeBasicBlockProfileTraceToFile(
520
- const std::string& fileName) const override {
521
- const_cast<Plain&>(plain())
522
- .instrumentation()
523
- .writeBasicBlockProfileTraceToFile(fileName);
524
- }
525
-
526
- /// Dump external profiler symbols to the given file name.
527
- void dumpProfilerSymbolsToFile(const std::string& fileName) const override {
528
- const_cast<Plain&>(plain()).instrumentation().dumpProfilerSymbolsToFile(
529
- fileName);
530
- }
531
-
532
- private:
533
- Plain& plain_;
534
- };
535
-
536
- namespace detail {
537
-
538
- // This metaprogramming allows the With type's methods to be
539
- // optional.
540
-
541
- template <typename T, typename U = void>
542
- struct BeforeCaller {
543
- static void before(T&) {}
544
- };
545
-
546
- template <typename T, typename U = void>
547
- struct AfterCaller {
548
- static void after(T&) {}
549
- };
550
-
551
- // decltype((void)&...) is either SFINAE, or void.
552
- // So, if SFINAE does not happen for T, then this specialization exists
553
- // for BeforeCaller<T, void>, and always applies. If not, only the
554
- // default above exists, and that is used instead.
555
- template <typename T>
556
- struct BeforeCaller<T, decltype((void)&T::before)> {
557
- static void before(T& t) {
558
- t.before();
559
- }
560
- };
561
-
562
- template <typename T>
563
- struct AfterCaller<T, decltype((void)&T::after)> {
564
- static void after(T& t) {
565
- t.after();
566
- }
567
- };
568
-
569
- // It's possible to use multiple decorators by nesting
570
- // WithRuntimeDecorator<...>, but this specialization allows use of
571
- // std::tuple of decorator classes instead. See testlib.cpp for an
572
- // example.
573
- template <typename... T>
574
- struct BeforeCaller<std::tuple<T...>> {
575
- static void before(std::tuple<T...>& tuple) {
576
- all_before<0, T...>(tuple);
577
- }
578
-
579
- private:
580
- template <size_t N, typename U, typename... Rest>
581
- static void all_before(std::tuple<T...>& tuple) {
582
- detail::BeforeCaller<U>::before(std::get<N>(tuple));
583
- all_before<N + 1, Rest...>(tuple);
584
- }
585
-
586
- template <size_t N>
587
- static void all_before(std::tuple<T...>&) {}
588
- };
589
-
590
- template <typename... T>
591
- struct AfterCaller<std::tuple<T...>> {
592
- static void after(std::tuple<T...>& tuple) {
593
- all_after<0, T...>(tuple);
594
- }
595
-
596
- private:
597
- template <size_t N, typename U, typename... Rest>
598
- static void all_after(std::tuple<T...>& tuple) {
599
- all_after<N + 1, Rest...>(tuple);
600
- detail::AfterCaller<U>::after(std::get<N>(tuple));
601
- }
602
-
603
- template <size_t N>
604
- static void all_after(std::tuple<T...>&) {}
605
- };
606
-
607
- } // namespace detail
608
-
609
- // A decorator which implements an around idiom. A With instance is
610
- // RAII constructed before each call to the undecorated class; the
611
- // ctor is passed a single argument of type WithArg&. Plain and Base
612
- // are used as in the base class.
613
- template <typename With, typename Plain = Runtime, typename Base = Runtime>
614
- class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> {
615
- public:
616
- using RD = RuntimeDecorator<Plain, Base>;
617
-
618
- // The reference arguments to the ctor are stored, but not used by
619
- // the ctor, and there is no ctor, so they can be passed members of
620
- // the derived class.
621
- WithRuntimeDecorator(Plain& plain, With& with) : RD(plain), with_(with) {}
622
-
623
- Value evaluateJavaScript(
624
- const std::shared_ptr<const Buffer>& buffer,
625
- const std::string& sourceURL) override {
626
- Around around{with_};
627
- return RD::evaluateJavaScript(buffer, sourceURL);
628
- }
629
- std::shared_ptr<const PreparedJavaScript> prepareJavaScript(
630
- const std::shared_ptr<const Buffer>& buffer,
631
- std::string sourceURL) override {
632
- Around around{with_};
633
- return RD::prepareJavaScript(buffer, std::move(sourceURL));
634
- }
635
- Value evaluatePreparedJavaScript(
636
- const std::shared_ptr<const PreparedJavaScript>& js) override {
637
- Around around{with_};
638
- return RD::evaluatePreparedJavaScript(js);
639
- }
640
- #if JSI_VERSION >= 12
641
- void queueMicrotask(const Function& callback) override {
642
- Around around{with_};
643
- RD::queueMicrotask(callback);
644
- }
645
- #endif
646
- #if JSI_VERSION >= 4
647
- bool drainMicrotasks(int maxMicrotasksHint) override {
648
- Around around{with_};
649
- return RD::drainMicrotasks(maxMicrotasksHint);
650
- }
651
- #endif
652
- Object global() override {
653
- Around around{with_};
654
- return RD::global();
655
- }
656
- std::string description() override {
657
- Around around{with_};
658
- return RD::description();
659
- };
660
- bool isInspectable() override {
661
- Around around{with_};
662
- return RD::isInspectable();
663
- };
664
-
665
- // The jsi:: prefix is necessary because MSVC compiler complains C2247:
666
- // Instrumentation is not accessible because RuntimeDecorator uses private
667
- // to inherit from Instrumentation.
668
- // TODO(T40821815) Consider removing this workaround when updating MSVC
669
- jsi::Instrumentation& instrumentation() override {
670
- Around around{with_};
671
- return RD::instrumentation();
672
- }
673
-
674
- protected:
675
- Runtime::PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override {
676
- Around around{with_};
677
- return RD::cloneSymbol(pv);
678
- };
679
- #if JSI_VERSION >= 6
680
- Runtime::PointerValue* cloneBigInt(const Runtime::PointerValue* pv) override {
681
- Around around{with_};
682
- return RD::cloneBigInt(pv);
683
- };
684
- #endif
685
- Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override {
686
- Around around{with_};
687
- return RD::cloneString(pv);
688
- };
689
- Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override {
690
- Around around{with_};
691
- return RD::cloneObject(pv);
692
- };
693
- Runtime::PointerValue* clonePropNameID(
694
- const Runtime::PointerValue* pv) override {
695
- Around around{with_};
696
- return RD::clonePropNameID(pv);
697
- };
698
-
699
- PropNameID createPropNameIDFromAscii(const char* str, size_t length)
700
- override {
701
- Around around{with_};
702
- return RD::createPropNameIDFromAscii(str, length);
703
- };
704
- PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length)
705
- override {
706
- Around around{with_};
707
- return RD::createPropNameIDFromUtf8(utf8, length);
708
- };
709
- #if JSI_VERSION >= 19
710
- PropNameID createPropNameIDFromUtf16(const char16_t* utf16, size_t length)
711
- override {
712
- Around around{with_};
713
- return RD::createPropNameIDFromUtf16(utf16, length);
714
- }
715
- #endif
716
- PropNameID createPropNameIDFromString(const String& str) override {
717
- Around around{with_};
718
- return RD::createPropNameIDFromString(str);
719
- };
720
- #if JSI_VERSION >= 5
721
- PropNameID createPropNameIDFromSymbol(const Symbol& sym) override {
722
- Around around{with_};
723
- return RD::createPropNameIDFromSymbol(sym);
724
- };
725
- #endif
726
- std::string utf8(const PropNameID& id) override {
727
- Around around{with_};
728
- return RD::utf8(id);
729
- };
730
- bool compare(const PropNameID& a, const PropNameID& b) override {
731
- Around around{with_};
732
- return RD::compare(a, b);
733
- };
734
-
735
- std::string symbolToString(const Symbol& sym) override {
736
- Around around{with_};
737
- return RD::symbolToString(sym);
738
- };
739
-
740
- #if JSI_VERSION >= 8
741
- BigInt createBigIntFromInt64(int64_t i) override {
742
- Around around{with_};
743
- return RD::createBigIntFromInt64(i);
744
- };
745
- BigInt createBigIntFromUint64(uint64_t i) override {
746
- Around around{with_};
747
- return RD::createBigIntFromUint64(i);
748
- };
749
- bool bigintIsInt64(const BigInt& bi) override {
750
- Around around{with_};
751
- return RD::bigintIsInt64(bi);
752
- };
753
- bool bigintIsUint64(const BigInt& bi) override {
754
- Around around{with_};
755
- return RD::bigintIsUint64(bi);
756
- };
757
- uint64_t truncate(const BigInt& bi) override {
758
- Around around{with_};
759
- return RD::truncate(bi);
760
- };
761
- String bigintToString(const BigInt& bi, int i) override {
762
- Around around{with_};
763
- return RD::bigintToString(bi, i);
764
- };
765
- #endif
766
-
767
- String createStringFromAscii(const char* str, size_t length) override {
768
- Around around{with_};
769
- return RD::createStringFromAscii(str, length);
770
- };
771
- String createStringFromUtf8(const uint8_t* utf8, size_t length) override {
772
- Around around{with_};
773
- return RD::createStringFromUtf8(utf8, length);
774
- };
775
- #if JSI_VERSION >= 19
776
- String createStringFromUtf16(const char16_t* utf16, size_t length) override {
777
- Around around{with_};
778
- return RD::createStringFromUtf16(utf16, length);
779
- }
780
- #endif
781
- std::string utf8(const String& s) override {
782
- Around around{with_};
783
- return RD::utf8(s);
784
- }
785
-
786
- #if JSI_VERSION >= 14
787
- std::u16string utf16(const String& str) override {
788
- Around around{with_};
789
- return RD::utf16(str);
790
- }
791
- std::u16string utf16(const PropNameID& sym) override {
792
- Around around{with_};
793
- return RD::utf16(sym);
794
- }
795
- #endif
796
-
797
- #if JSI_VERSION >= 16
798
- void getStringData(
799
- const jsi::String& str,
800
- void* ctx,
801
- void (
802
- *cb)(void* ctx, bool ascii, const void* data, size_t num)) override {
803
- Around around{with_};
804
- RD::getStringData(str, ctx, cb);
805
- }
806
-
807
- void getPropNameIdData(
808
- const jsi::PropNameID& sym,
809
- void* ctx,
810
- void (
811
- *cb)(void* ctx, bool ascii, const void* data, size_t num)) override {
812
- Around around{with_};
813
- RD::getPropNameIdData(sym, ctx, cb);
814
- }
815
- #endif
816
-
817
- Value createValueFromJsonUtf8(const uint8_t* json, size_t length) override {
818
- Around around{with_};
819
- return RD::createValueFromJsonUtf8(json, length);
820
- };
821
-
822
- #if JSI_VERSION >= 18
823
- Object createObjectWithPrototype(const Value& prototype) override {
824
- Around around{with_};
825
- return RD::createObjectWithPrototype(prototype);
826
- }
827
- #endif
828
-
829
- Object createObject() override {
830
- Around around{with_};
831
- return RD::createObject();
832
- };
833
- Object createObject(std::shared_ptr<HostObject> ho) override {
834
- Around around{with_};
835
- return RD::createObject(std::move(ho));
836
- };
837
- std::shared_ptr<HostObject> getHostObject(const jsi::Object& o) override {
838
- Around around{with_};
839
- return RD::getHostObject(o);
840
- };
841
- HostFunctionType& getHostFunction(const jsi::Function& f) override {
842
- Around around{with_};
843
- return RD::getHostFunction(f);
844
- };
845
-
846
- #if JSI_VERSION >= 7
847
- bool hasNativeState(const Object& o) override {
848
- Around around{with_};
849
- return RD::hasNativeState(o);
850
- };
851
- std::shared_ptr<NativeState> getNativeState(const Object& o) override {
852
- Around around{with_};
853
- return RD::getNativeState(o);
854
- };
855
- void setNativeState(const Object& o, std::shared_ptr<NativeState> state)
856
- override {
857
- Around around{with_};
858
- RD::setNativeState(o, state);
859
- };
860
- #endif
861
-
862
- #if JSI_VERSION >= 17
863
- void setPrototypeOf(const Object& object, const Value& prototype) override {
864
- Around around{with_};
865
- RD::setPrototypeOf(object, prototype);
866
- }
867
-
868
- Value getPrototypeOf(const Object& object) override {
869
- Around around{with_};
870
- return RD::getPrototypeOf(object);
871
- }
872
- #endif
873
-
874
- Value getProperty(const Object& o, const PropNameID& name) override {
875
- Around around{with_};
876
- return RD::getProperty(o, name);
877
- };
878
- Value getProperty(const Object& o, const String& name) override {
879
- Around around{with_};
880
- return RD::getProperty(o, name);
881
- };
882
- bool hasProperty(const Object& o, const PropNameID& name) override {
883
- Around around{with_};
884
- return RD::hasProperty(o, name);
885
- };
886
- bool hasProperty(const Object& o, const String& name) override {
887
- Around around{with_};
888
- return RD::hasProperty(o, name);
889
- };
890
- void setPropertyValue(
891
- JSI_CONST_10 Object& o,
892
- const PropNameID& name,
893
- const Value& value) override {
894
- Around around{with_};
895
- RD::setPropertyValue(o, name, value);
896
- };
897
- void setPropertyValue(
898
- JSI_CONST_10 Object& o,
899
- const String& name,
900
- const Value& value) override {
901
- Around around{with_};
902
- RD::setPropertyValue(o, name, value);
903
- };
904
-
905
- bool isArray(const Object& o) const override {
906
- Around around{with_};
907
- return RD::isArray(o);
908
- };
909
- bool isArrayBuffer(const Object& o) const override {
910
- Around around{with_};
911
- return RD::isArrayBuffer(o);
912
- };
913
- bool isFunction(const Object& o) const override {
914
- Around around{with_};
915
- return RD::isFunction(o);
916
- };
917
- bool isHostObject(const jsi::Object& o) const override {
918
- Around around{with_};
919
- return RD::isHostObject(o);
920
- };
921
- bool isHostFunction(const jsi::Function& f) const override {
922
- Around around{with_};
923
- return RD::isHostFunction(f);
924
- };
925
- Array getPropertyNames(const Object& o) override {
926
- Around around{with_};
927
- return RD::getPropertyNames(o);
928
- };
929
-
930
- WeakObject createWeakObject(const Object& o) override {
931
- Around around{with_};
932
- return RD::createWeakObject(o);
933
- };
934
- Value lockWeakObject(JSI_NO_CONST_3 JSI_CONST_10 WeakObject& wo) override {
935
- Around around{with_};
936
- return RD::lockWeakObject(wo);
937
- };
938
-
939
- Array createArray(size_t length) override {
940
- Around around{with_};
941
- return RD::createArray(length);
942
- };
943
- #if JSI_VERSION >= 9
944
- ArrayBuffer createArrayBuffer(
945
- std::shared_ptr<MutableBuffer> buffer) override {
946
- return RD::createArrayBuffer(std::move(buffer));
947
- };
948
- #endif
949
- size_t size(const Array& a) override {
950
- Around around{with_};
951
- return RD::size(a);
952
- };
953
- size_t size(const ArrayBuffer& ab) override {
954
- Around around{with_};
955
- return RD::size(ab);
956
- };
957
- uint8_t* data(const ArrayBuffer& ab) override {
958
- Around around{with_};
959
- return RD::data(ab);
960
- };
961
- Value getValueAtIndex(const Array& a, size_t i) override {
962
- Around around{with_};
963
- return RD::getValueAtIndex(a, i);
964
- };
965
- void setValueAtIndexImpl(JSI_CONST_10 Array& a, size_t i, const Value& value)
966
- override {
967
- Around around{with_};
968
- RD::setValueAtIndexImpl(a, i, value);
969
- };
970
-
971
- Function createFunctionFromHostFunction(
972
- const PropNameID& name,
973
- unsigned int paramCount,
974
- HostFunctionType func) override {
975
- Around around{with_};
976
- return RD::createFunctionFromHostFunction(
977
- name, paramCount, std::move(func));
978
- };
979
- Value call(
980
- const Function& f,
981
- const Value& jsThis,
982
- const Value* args,
983
- size_t count) override {
984
- Around around{with_};
985
- return RD::call(f, jsThis, args, count);
986
- };
987
- Value callAsConstructor(const Function& f, const Value* args, size_t count)
988
- override {
989
- Around around{with_};
990
- return RD::callAsConstructor(f, args, count);
991
- };
992
-
993
- // Private data for managing scopes.
994
- Runtime::ScopeState* pushScope() override {
995
- Around around{with_};
996
- return RD::pushScope();
997
- }
998
- void popScope(Runtime::ScopeState* ss) override {
999
- Around around{with_};
1000
- RD::popScope(ss);
1001
- }
1002
-
1003
- bool strictEquals(const Symbol& a, const Symbol& b) const override {
1004
- Around around{with_};
1005
- return RD::strictEquals(a, b);
1006
- };
1007
-
1008
- #if JSI_VERSION >= 6
1009
- bool strictEquals(const BigInt& a, const BigInt& b) const override {
1010
- Around around{with_};
1011
- return RD::strictEquals(a, b);
1012
- };
1013
- #endif
1014
-
1015
- bool strictEquals(const String& a, const String& b) const override {
1016
- Around around{with_};
1017
- return RD::strictEquals(a, b);
1018
- };
1019
- bool strictEquals(const Object& a, const Object& b) const override {
1020
- Around around{with_};
1021
- return RD::strictEquals(a, b);
1022
- };
1023
-
1024
- bool instanceOf(const Object& o, const Function& f) override {
1025
- Around around{with_};
1026
- return RD::instanceOf(o, f);
1027
- };
1028
-
1029
- #if JSI_VERSION >= 11
1030
- void setExternalMemoryPressure(const jsi::Object& obj, size_t amount)
1031
- override {
1032
- Around around{with_};
1033
- RD::setExternalMemoryPressure(obj, amount);
1034
- };
1035
- #endif
1036
-
1037
- private:
1038
- // Wrap an RAII type around With& to guarantee after always happens.
1039
- struct Around {
1040
- Around(With& with) : with_(with) {
1041
- detail::BeforeCaller<With>::before(with_);
1042
- }
1043
- ~Around() {
1044
- detail::AfterCaller<With>::after(with_);
1045
- }
1046
-
1047
- With& with_;
1048
- };
1049
-
1050
- With& with_;
1051
- };
1052
-
1053
- } // namespace jsi
1054
- } // namespace facebook