react-native-windows 0.82.0 → 0.82.3

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 (36) hide show
  1. package/Microsoft.ReactNative/Base/CxxReactIncludes.h +11 -0
  2. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +52 -2
  3. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +70 -49
  4. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +4 -1
  5. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/WindowsTextLayoutManager.cpp +7 -2
  6. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -1
  7. package/Microsoft.ReactNative/Pch/pch.h +2 -0
  8. package/Microsoft.ReactNative/ReactHost/CrashManager.cpp +5 -0
  9. package/Microsoft.ReactNative/ReactHost/ReactNativeHeaders.h +1 -0
  10. package/PropertySheets/CIBuildOptimizations.props +29 -0
  11. package/PropertySheets/External/Microsoft.ReactNative.Composition.CppLib.props +10 -0
  12. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppLib.props +10 -0
  13. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  14. package/README.md +1 -1
  15. package/ReactCommon/ReactCommon.vcxproj +10 -10
  16. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/Instance.cpp +379 -0
  17. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +47 -0
  18. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSIndexedRAMBundle.cpp +143 -0
  19. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/MethodCall.cpp +98 -0
  20. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ModuleRegistry.cpp +254 -0
  21. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +9 -0
  22. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/RAMBundleRegistry.cpp +91 -0
  23. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ReactMarker.cpp +147 -0
  24. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSIExecutor.cpp +622 -0
  25. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSINativeModules.cpp +121 -0
  26. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/webperformance/NativePerformance.cpp +409 -0
  27. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/BaseViewProps.cpp +628 -0
  28. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventDispatcher.cpp +79 -0
  29. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventQueueProcessor.cpp +138 -0
  30. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/uimanager/UIManager.cpp +732 -0
  31. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +687 -0
  32. package/Scripts/OfficeReact.Win32.nuspec +0 -11
  33. package/Shared/Networking/WinRTWebSocketResource.cpp +5 -4
  34. package/Shared/Shared.vcxitems +9 -9
  35. package/package.json +1 -1
  36. package/templates/cpp-app/windows/MyApp/MyApp.vcxproj +2 -0
@@ -0,0 +1,622 @@
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
+ #if _MSC_VER
9
+ #pragma warning(push)
10
+ #pragma warning(disable : 4996) // deprecated APIs
11
+ #endif
12
+ #include "jsireact/JSIExecutor.h"
13
+
14
+ #include <cxxreact/ErrorUtils.h>
15
+ #include <cxxreact/JSBigString.h>
16
+ #include <cxxreact/ModuleRegistry.h>
17
+ #include <cxxreact/ReactMarker.h>
18
+ #include <cxxreact/TraceSection.h>
19
+ #include <folly/json.h>
20
+ #include <glog/logging.h>
21
+ #include <jsi/JSIDynamic.h>
22
+ #include <jsi/instrumentation.h>
23
+ #include <reactperflogger/BridgeNativeModulePerfLogger.h>
24
+
25
+ #include <sstream>
26
+ #include <stdexcept>
27
+
28
+ using namespace facebook::jsi;
29
+
30
+ namespace facebook::react {
31
+
32
+ #ifndef RCT_FIT_RM_OLD_RUNTIME
33
+
34
+ class JSIExecutor::NativeModuleProxy : public jsi::HostObject {
35
+ public:
36
+ NativeModuleProxy(std::shared_ptr<JSINativeModules> nativeModules)
37
+ : weakNativeModules_(nativeModules) {}
38
+
39
+ Value get(Runtime& rt, const PropNameID& name) override {
40
+ if (name.utf8(rt) == "name") {
41
+ return jsi::String::createFromAscii(rt, "NativeModules");
42
+ }
43
+
44
+ auto nativeModules = weakNativeModules_.lock();
45
+ if (!nativeModules) {
46
+ return nullptr;
47
+ }
48
+
49
+ return nativeModules->getModule(rt, name);
50
+ }
51
+
52
+ void set(Runtime&, const PropNameID&, const Value&) override {
53
+ throw std::runtime_error(
54
+ "Unable to put on NativeModules: Operation unsupported");
55
+ }
56
+
57
+ private:
58
+ std::weak_ptr<JSINativeModules> weakNativeModules_;
59
+ };
60
+
61
+ namespace {
62
+
63
+ // basename_r isn't in all iOS SDKs, so use this simple version instead.
64
+ std::string simpleBasename(const std::string& path) {
65
+ size_t pos = path.rfind('/');
66
+ return (pos != std::string::npos) ? path.substr(pos) : path;
67
+ }
68
+
69
+ } // namespace
70
+
71
+ JSIExecutor::JSIExecutor(
72
+ std::shared_ptr<jsi::Runtime> runtime,
73
+ std::shared_ptr<ExecutorDelegate> delegate,
74
+ const JSIScopedTimeoutInvoker& scopedTimeoutInvoker,
75
+ RuntimeInstaller runtimeInstaller)
76
+ : runtime_(runtime),
77
+ delegate_(delegate),
78
+ nativeModules_(std::make_shared<JSINativeModules>(
79
+ delegate ? delegate->getModuleRegistry() : nullptr)),
80
+ moduleRegistry_(delegate ? delegate->getModuleRegistry() : nullptr),
81
+ scopedTimeoutInvoker_(scopedTimeoutInvoker),
82
+ runtimeInstaller_(runtimeInstaller) {
83
+ runtime_->global().setProperty(
84
+ *runtime, "__jsiExecutorDescription", runtime->description());
85
+ }
86
+
87
+ void JSIExecutor::initializeRuntime() {
88
+ TraceSection s("JSIExecutor::initializeRuntime");
89
+
90
+ bindNativePerformanceNow(*runtime_);
91
+
92
+ runtime_->global().setProperty(
93
+ *runtime_,
94
+ "nativeModuleProxy",
95
+ Object::createFromHostObject(
96
+ *runtime_, std::make_shared<NativeModuleProxy>(nativeModules_)));
97
+
98
+ runtime_->global().setProperty(
99
+ *runtime_,
100
+ "nativeFlushQueueImmediate",
101
+ Function::createFromHostFunction(
102
+ *runtime_,
103
+ PropNameID::forAscii(*runtime_, "nativeFlushQueueImmediate"),
104
+ 1,
105
+ [this](
106
+ jsi::Runtime&,
107
+ const jsi::Value&,
108
+ const jsi::Value* args,
109
+ size_t count) {
110
+ if (count != 1) {
111
+ throw std::invalid_argument(
112
+ "nativeFlushQueueImmediate arg count must be 1");
113
+ }
114
+ callNativeModules(args[0], false);
115
+ return Value::undefined();
116
+ }));
117
+
118
+ runtime_->global().setProperty(
119
+ *runtime_,
120
+ "nativeCallSyncHook",
121
+ Function::createFromHostFunction(
122
+ *runtime_,
123
+ PropNameID::forAscii(*runtime_, "nativeCallSyncHook"),
124
+ 1,
125
+ [this](
126
+ jsi::Runtime&,
127
+ const jsi::Value&,
128
+ const jsi::Value* args,
129
+ size_t count) { return nativeCallSyncHook(args, count); }));
130
+
131
+ runtime_->global().setProperty(
132
+ *runtime_,
133
+ "globalEvalWithSourceUrl",
134
+ Function::createFromHostFunction(
135
+ *runtime_,
136
+ PropNameID::forAscii(*runtime_, "globalEvalWithSourceUrl"),
137
+ 1,
138
+ [this](
139
+ jsi::Runtime&,
140
+ const jsi::Value&,
141
+ const jsi::Value* args,
142
+ size_t count) { return globalEvalWithSourceUrl(args, count); }));
143
+
144
+ if (runtimeInstaller_) {
145
+ runtimeInstaller_(*runtime_);
146
+ }
147
+ bool hasLogger = false;
148
+ {
149
+ std::shared_lock lock(ReactMarker::logTaggedMarkerImplMutex);
150
+ hasLogger = ReactMarker::logTaggedMarkerImpl != nullptr;
151
+ }
152
+ if (hasLogger) {
153
+ ReactMarker::logMarker(ReactMarker::CREATE_REACT_CONTEXT_STOP);
154
+ }
155
+ }
156
+
157
+ void JSIExecutor::loadBundle(
158
+ std::unique_ptr<const JSBigString> script,
159
+ std::string sourceURL) {
160
+ TraceSection s("JSIExecutor::loadBundle");
161
+ bool hasLogger = false;
162
+ {
163
+ std::shared_lock lock(ReactMarker::logTaggedMarkerImplMutex);
164
+ hasLogger = ReactMarker::logTaggedMarkerImpl != nullptr;
165
+ }
166
+ std::string scriptName = simpleBasename(sourceURL);
167
+ if (hasLogger) {
168
+ ReactMarker::logTaggedMarker(
169
+ ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str());
170
+ }
171
+ runtime_->evaluateJavaScript(
172
+ std::make_unique<BigStringBuffer>(std::move(script)), sourceURL);
173
+ flush();
174
+ if (hasLogger) {
175
+ ReactMarker::logTaggedMarker(
176
+ ReactMarker::RUN_JS_BUNDLE_STOP, scriptName.c_str());
177
+ ReactMarker::logMarker(ReactMarker::INIT_REACT_RUNTIME_STOP);
178
+ ReactMarker::logMarker(ReactMarker::APP_STARTUP_STOP);
179
+ }
180
+ }
181
+
182
+ void JSIExecutor::setBundleRegistry(std::unique_ptr<RAMBundleRegistry> r) {
183
+ if (!bundleRegistry_) {
184
+ runtime_->global().setProperty(
185
+ *runtime_,
186
+ "nativeRequire",
187
+ Function::createFromHostFunction(
188
+ *runtime_,
189
+ PropNameID::forAscii(*runtime_, "nativeRequire"),
190
+ 2,
191
+ [this](
192
+ [[maybe_unused]] Runtime& rt,
193
+ const facebook::jsi::Value&,
194
+ const facebook::jsi::Value* args,
195
+ size_t count) { return nativeRequire(args, count); }));
196
+ }
197
+ bundleRegistry_ = std::move(r);
198
+ }
199
+
200
+ void JSIExecutor::registerBundle(
201
+ uint32_t bundleId,
202
+ const std::string& bundlePath) {
203
+ auto tag = std::to_string(bundleId);
204
+ ReactMarker::logTaggedMarker(
205
+ ReactMarker::REGISTER_JS_SEGMENT_START, tag.c_str());
206
+ if (bundleRegistry_) {
207
+ bundleRegistry_->registerBundle(bundleId, bundlePath);
208
+ } else {
209
+ auto script = JSBigFileString::fromPath(bundlePath);
210
+ if (script->size() == 0) {
211
+ throw std::invalid_argument(
212
+ "Empty bundle registered with ID " + tag + " from " + bundlePath);
213
+ }
214
+ runtime_->evaluateJavaScript(
215
+ std::make_unique<BigStringBuffer>(std::move(script)),
216
+ JSExecutor::getSyntheticBundlePath(bundleId, bundlePath));
217
+ }
218
+ ReactMarker::logTaggedMarker(
219
+ ReactMarker::REGISTER_JS_SEGMENT_STOP, tag.c_str());
220
+ }
221
+
222
+ void JSIExecutor::callFunction(
223
+ const std::string& moduleId,
224
+ const std::string& methodId,
225
+ const folly::dynamic& arguments) {
226
+ TraceSection s(
227
+ "JSIExecutor::callFunction", "moduleId", moduleId, "methodId", methodId);
228
+ if (!callFunctionReturnFlushedQueue_) {
229
+ bindBridge();
230
+ }
231
+
232
+ // Construct the error message producer in case this times out.
233
+ // This is executed on a background thread, so it must capture its parameters
234
+ // by value.
235
+ auto errorProducer = [=] {
236
+ std::stringstream ss;
237
+ ss << "moduleID: " << moduleId << " methodID: " << methodId;
238
+ return ss.str();
239
+ };
240
+
241
+ Value ret = Value::undefined();
242
+ try {
243
+ scopedTimeoutInvoker_(
244
+ [&] {
245
+ ret = callFunctionReturnFlushedQueue_->call(
246
+ *runtime_,
247
+ moduleId,
248
+ methodId,
249
+ valueFromDynamic(*runtime_, arguments));
250
+ },
251
+ std::move(errorProducer));
252
+ } catch (...) {
253
+ std::throw_with_nested(
254
+ std::runtime_error("Error calling " + moduleId + "." + methodId));
255
+ }
256
+
257
+ callNativeModules(ret, true);
258
+ }
259
+
260
+ void JSIExecutor::invokeCallback(
261
+ const double callbackId,
262
+ const folly::dynamic& arguments) {
263
+ TraceSection s("JSIExecutor::invokeCallback", "callbackId", callbackId);
264
+ if (!invokeCallbackAndReturnFlushedQueue_) {
265
+ bindBridge();
266
+ }
267
+ Value ret;
268
+ try {
269
+ ret = invokeCallbackAndReturnFlushedQueue_->call(
270
+ *runtime_, callbackId, valueFromDynamic(*runtime_, arguments));
271
+ } catch (...) {
272
+ std::throw_with_nested(std::runtime_error(
273
+ "Error invoking callback " + std::to_string(callbackId)));
274
+ }
275
+
276
+ callNativeModules(ret, true);
277
+ }
278
+
279
+ void JSIExecutor::setGlobalVariable(
280
+ std::string propName,
281
+ std::unique_ptr<const JSBigString> jsonValue) {
282
+ TraceSection s("JSIExecutor::setGlobalVariable", "propName", propName);
283
+ runtime_->global().setProperty(
284
+ *runtime_,
285
+ propName.c_str(),
286
+ Value::createFromJsonUtf8(
287
+ *runtime_,
288
+ reinterpret_cast<const uint8_t*>(jsonValue->c_str()),
289
+ jsonValue->size()));
290
+ }
291
+
292
+ std::string JSIExecutor::getDescription() {
293
+ return "JSI (" + runtime_->description() + ")";
294
+ }
295
+
296
+ void* JSIExecutor::getJavaScriptContext() {
297
+ return runtime_.get();
298
+ }
299
+
300
+ bool JSIExecutor::isInspectable() {
301
+ return runtime_->isInspectable();
302
+ }
303
+
304
+ void JSIExecutor::handleMemoryPressure(int pressureLevel) {
305
+ // The level is an enum value passed by the Android OS to an onTrimMemory
306
+ // event callback. Defined in ComponentCallbacks2.
307
+ enum AndroidMemoryPressure {
308
+ TRIM_MEMORY_BACKGROUND = 40,
309
+ TRIM_MEMORY_COMPLETE = 80,
310
+ TRIM_MEMORY_MODERATE = 60,
311
+ TRIM_MEMORY_RUNNING_CRITICAL = 15,
312
+ TRIM_MEMORY_RUNNING_LOW = 10,
313
+ TRIM_MEMORY_RUNNING_MODERATE = 5,
314
+ TRIM_MEMORY_UI_HIDDEN = 20,
315
+ };
316
+ const char* levelName;
317
+ switch (pressureLevel) {
318
+ case TRIM_MEMORY_BACKGROUND:
319
+ levelName = "TRIM_MEMORY_BACKGROUND";
320
+ break;
321
+ case TRIM_MEMORY_COMPLETE:
322
+ levelName = "TRIM_MEMORY_COMPLETE";
323
+ break;
324
+ case TRIM_MEMORY_MODERATE:
325
+ levelName = "TRIM_MEMORY_MODERATE";
326
+ break;
327
+ case TRIM_MEMORY_RUNNING_CRITICAL:
328
+ levelName = "TRIM_MEMORY_RUNNING_CRITICAL";
329
+ break;
330
+ case TRIM_MEMORY_RUNNING_LOW:
331
+ levelName = "TRIM_MEMORY_RUNNING_LOW";
332
+ break;
333
+ case TRIM_MEMORY_RUNNING_MODERATE:
334
+ levelName = "TRIM_MEMORY_RUNNING_MODERATE";
335
+ break;
336
+ case TRIM_MEMORY_UI_HIDDEN:
337
+ levelName = "TRIM_MEMORY_UI_HIDDEN";
338
+ break;
339
+ default:
340
+ levelName = "UNKNOWN";
341
+ break;
342
+ }
343
+
344
+ switch (pressureLevel) {
345
+ case TRIM_MEMORY_RUNNING_LOW:
346
+ case TRIM_MEMORY_RUNNING_MODERATE:
347
+ case TRIM_MEMORY_UI_HIDDEN:
348
+ // For non-severe memory trims, do nothing.
349
+ LOG(INFO) << "Memory warning (pressure level: " << levelName
350
+ << ") received by JS VM, ignoring because it's non-severe";
351
+ break;
352
+ case TRIM_MEMORY_BACKGROUND:
353
+ case TRIM_MEMORY_COMPLETE:
354
+ case TRIM_MEMORY_MODERATE:
355
+ case TRIM_MEMORY_RUNNING_CRITICAL:
356
+ // For now, pressureLevel is unused by collectGarbage.
357
+ // This may change in the future if the JS GC has different styles of
358
+ // collections.
359
+ LOG(INFO) << "Memory warning (pressure level: " << levelName
360
+ << ") received by JS VM, running a GC";
361
+ runtime_->instrumentation().collectGarbage(levelName);
362
+ break;
363
+ default:
364
+ // Use the raw number instead of the name here since the name is
365
+ // meaningless.
366
+ LOG(WARNING) << "Memory warning (pressure level: " << pressureLevel
367
+ << ") received by JS VM, unrecognized pressure level";
368
+ break;
369
+ }
370
+ }
371
+
372
+ void JSIExecutor::bindBridge() {
373
+ std::call_once(bindFlag_, [this] {
374
+ TraceSection s("JSIExecutor::bindBridge (once)");
375
+ Value batchedBridgeValue =
376
+ runtime_->global().getProperty(*runtime_, "__fbBatchedBridge");
377
+ if (batchedBridgeValue.isUndefined() || !batchedBridgeValue.isObject()) {
378
+ throw JSINativeException(
379
+ "Could not get BatchedBridge, make sure your bundle is packaged correctly");
380
+ }
381
+
382
+ Object batchedBridge = batchedBridgeValue.asObject(*runtime_);
383
+ callFunctionReturnFlushedQueue_ = batchedBridge.getPropertyAsFunction(
384
+ *runtime_, "callFunctionReturnFlushedQueue");
385
+ invokeCallbackAndReturnFlushedQueue_ = batchedBridge.getPropertyAsFunction(
386
+ *runtime_, "invokeCallbackAndReturnFlushedQueue");
387
+ flushedQueue_ =
388
+ batchedBridge.getPropertyAsFunction(*runtime_, "flushedQueue");
389
+ });
390
+ }
391
+
392
+ void JSIExecutor::callNativeModules(const Value& queue, bool isEndOfBatch) {
393
+ TraceSection s("JSIExecutor::callNativeModules");
394
+ // If this fails, you need to pass a fully functional delegate with a
395
+ // module registry to the factory/ctor.
396
+ CHECK(delegate_) << "Attempting to use native modules without a delegate";
397
+ #if 0 // maybe useful for debugging
398
+ std::string json = runtime_->global().getPropertyAsObject(*runtime_, "JSON")
399
+ .getPropertyAsFunction(*runtime_, "stringify").call(*runtime_, queue)
400
+ .getString(*runtime_).utf8(*runtime_);
401
+ #endif
402
+ BridgeNativeModulePerfLogger::asyncMethodCallBatchPreprocessStart();
403
+
404
+ delegate_->callNativeModules(
405
+ *this, dynamicFromValue(*runtime_, queue), isEndOfBatch);
406
+ }
407
+
408
+ void JSIExecutor::flush() {
409
+ TraceSection s("JSIExecutor::flush");
410
+ if (flushedQueue_) {
411
+ Value ret = flushedQueue_->call(*runtime_);
412
+ callNativeModules(ret, true);
413
+ return;
414
+ }
415
+
416
+ // When a native module is called from JS, BatchedBridge.enqueueNativeCall()
417
+ // is invoked. For that to work, require('BatchedBridge') has to be called,
418
+ // and when that happens, __fbBatchedBridge is set as a side effect.
419
+ Value batchedBridge =
420
+ runtime_->global().getProperty(*runtime_, "__fbBatchedBridge");
421
+ // So here, if __fbBatchedBridge doesn't exist, then we know no native calls
422
+ // have happened, and we were able to determine this without forcing
423
+ // BatchedBridge to be loaded as a side effect.
424
+ if (!batchedBridge.isUndefined()) {
425
+ // If calls were made, we bind to the JS bridge methods, and use them to
426
+ // get the pending queue of native calls.
427
+ bindBridge();
428
+ Value ret = flushedQueue_->call(*runtime_);
429
+ callNativeModules(ret, true);
430
+ } else if (delegate_) {
431
+ // If we have a delegate, we need to call it; we pass a null list to
432
+ // callNativeModules, since we know there are no native calls, without
433
+ // calling into JS again. If no calls were made and there's no delegate,
434
+ // nothing happens, which is correct.
435
+ callNativeModules(nullptr, true);
436
+ }
437
+ }
438
+
439
+ Value JSIExecutor::nativeRequire(const Value* args, size_t count) {
440
+ if (count > 2 || count == 0) {
441
+ throw std::invalid_argument("Got wrong number of args");
442
+ }
443
+
444
+ auto moduleId = static_cast<uint32_t>(args[0].getNumber());
445
+ uint32_t bundleId =
446
+ count == 2 ? static_cast<uint32_t>(args[1].getNumber()) : 0;
447
+ auto module = bundleRegistry_->getModule(bundleId, moduleId);
448
+
449
+ runtime_->evaluateJavaScript(
450
+ std::make_unique<StringBuffer>(module.code), module.name);
451
+ return facebook::jsi::Value();
452
+ }
453
+
454
+ Value JSIExecutor::nativeCallSyncHook(const Value* args, size_t count) {
455
+ if (count != 3) {
456
+ throw std::invalid_argument("nativeCallSyncHook arg count must be 3");
457
+ }
458
+
459
+ if (!args[2].isObject() || !args[2].asObject(*runtime_).isArray(*runtime_)) {
460
+ throw std::invalid_argument("method parameters should be array");
461
+ }
462
+
463
+ unsigned int moduleId = static_cast<unsigned int>(args[0].getNumber());
464
+ unsigned int methodId = static_cast<unsigned int>(args[1].getNumber());
465
+ std::string moduleName;
466
+ std::string methodName;
467
+
468
+ if (moduleRegistry_) {
469
+ moduleName = moduleRegistry_->getModuleName(moduleId);
470
+ methodName = moduleRegistry_->getModuleSyncMethodName(moduleId, methodId);
471
+
472
+ BridgeNativeModulePerfLogger::syncMethodCallStart(
473
+ moduleName.c_str(), methodName.c_str());
474
+
475
+ BridgeNativeModulePerfLogger::syncMethodCallArgConversionStart(
476
+ moduleName.c_str(), methodName.c_str());
477
+ }
478
+
479
+ MethodCallResult result = delegate_->callSerializableNativeHook(
480
+ *this, moduleId, methodId, dynamicFromValue(*runtime_, args[2]));
481
+
482
+ /**
483
+ * Note:
484
+ * In RCTNativeModule, std::nullopt is returned from
485
+ * callSerializableNativeHook when executing a NativeModule method fails.
486
+ * Therefore, it's safe to not terminate the syncMethodCall when std::nullopt
487
+ * is returned.
488
+ *
489
+ * TODO: In JavaNativeModule, std::nullopt is returned when the synchronous
490
+ * NativeModule method has the void return type. Change this to return
491
+ * folly::dynamic(nullptr) instead, so that std::nullopt is reserved for
492
+ * exceptional scenarios.
493
+ *
494
+ * TODO: Investigate CxxModule infra to see if std::nullopt is used for
495
+ * returns in exceptional scenarios.
496
+ **/
497
+
498
+ if (!result.has_value()) {
499
+ return Value::undefined();
500
+ }
501
+
502
+ Value returnValue = valueFromDynamic(*runtime_, result.value());
503
+
504
+ if (moduleRegistry_) {
505
+ BridgeNativeModulePerfLogger::syncMethodCallReturnConversionEnd(
506
+ moduleName.c_str(), methodName.c_str());
507
+ BridgeNativeModulePerfLogger::syncMethodCallEnd(
508
+ moduleName.c_str(), methodName.c_str());
509
+ }
510
+
511
+ return returnValue;
512
+ }
513
+
514
+ Value JSIExecutor::globalEvalWithSourceUrl(const Value* args, size_t count) {
515
+ if (count != 1 && count != 2) {
516
+ throw std::invalid_argument(
517
+ "globalEvalWithSourceUrl arg count must be 1 or 2");
518
+ }
519
+
520
+ auto code = args[0].asString(*runtime_).utf8(*runtime_);
521
+ std::string url;
522
+ if (count > 1 && args[1].isString()) {
523
+ url = args[1].asString(*runtime_).utf8(*runtime_);
524
+ }
525
+
526
+ return runtime_->evaluateJavaScript(
527
+ std::make_unique<StringBuffer>(std::move(code)), url);
528
+ }
529
+
530
+ #else // RCT_FIT_RM_OLD_RUNTIME
531
+
532
+ JSIExecutor::JSIExecutor(
533
+ std::shared_ptr<jsi::Runtime> runtime,
534
+ std::shared_ptr<ExecutorDelegate> delegate,
535
+ const JSIScopedTimeoutInvoker& scopedTimeoutInvoker,
536
+ RuntimeInstaller runtimeInstaller) {}
537
+
538
+ void JSIExecutor::initializeRuntime() {}
539
+
540
+ void JSIExecutor::loadBundle(
541
+ std::unique_ptr<const JSBigString> script,
542
+ std::string sourceURL) {}
543
+
544
+ void JSIExecutor::registerBundle(
545
+ uint32_t bundleId,
546
+ const std::string& bundlePath) {}
547
+
548
+ void JSIExecutor::callFunction(
549
+ const std::string& moduleId,
550
+ const std::string& methodId,
551
+ const folly::dynamic& arguments) {}
552
+
553
+ void JSIExecutor::invokeCallback(
554
+ const double callbackId,
555
+ const folly::dynamic& arguments) {}
556
+
557
+ void JSIExecutor::setGlobalVariable(
558
+ std::string propName,
559
+ std::unique_ptr<const JSBigString> jsonValue) {}
560
+
561
+ std::string JSIExecutor::getDescription() {
562
+ return "null";
563
+ }
564
+
565
+ void* JSIExecutor::getJavaScriptContext() {
566
+ return nullptr;
567
+ }
568
+
569
+ bool JSIExecutor::isInspectable() {
570
+ return false;
571
+ }
572
+
573
+ void JSIExecutor::handleMemoryPressure(int pressureLevel) {}
574
+
575
+ void JSIExecutor::flush() {}
576
+
577
+ #endif // RCT_FIT_RM_OLD_RUNTIME
578
+
579
+ void bindNativeLogger(Runtime& runtime, Logger logger) {
580
+ runtime.global().setProperty(
581
+ runtime,
582
+ "nativeLoggingHook",
583
+ Function::createFromHostFunction(
584
+ runtime,
585
+ PropNameID::forAscii(runtime, "nativeLoggingHook"),
586
+ 2,
587
+ [logger = std::move(logger)](
588
+ jsi::Runtime& runtime,
589
+ const jsi::Value&,
590
+ const jsi::Value* args,
591
+ size_t count) {
592
+ if (count != 2) {
593
+ throw std::invalid_argument(
594
+ "nativeLoggingHook takes 2 arguments");
595
+ }
596
+ logger(
597
+ args[0].asString(runtime).utf8(runtime),
598
+ static_cast<unsigned int>(args[1].asNumber()));
599
+ return Value::undefined();
600
+ }));
601
+ }
602
+
603
+ void bindNativePerformanceNow(Runtime& runtime) {
604
+ runtime.global().setProperty(
605
+ runtime,
606
+ "nativePerformanceNow",
607
+ Function::createFromHostFunction(
608
+ runtime,
609
+ PropNameID::forAscii(runtime, "nativePerformanceNow"),
610
+ 0,
611
+ [](jsi::Runtime& runtime,
612
+ const jsi::Value&,
613
+ const jsi::Value* args,
614
+ size_t /*count*/) {
615
+ return HighResTimeStamp::now().toDOMHighResTimeStamp();
616
+ }));
617
+ }
618
+
619
+ } // namespace facebook::react
620
+ #if _MSC_VER
621
+ #pragma warning(pop)
622
+ #endif