|
20 | 20 | #include <react/featureflags/ReactNativeFeatureFlags.h> |
21 | 21 | #include <react/performance/timeline/PerformanceEntryReporter.h> |
22 | 22 | #include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h> |
| 23 | +#include <react/runtime/JSEvaluationObserver.h> |
23 | 24 | #include <react/runtime/JSRuntimeBindings.h> |
24 | 25 | #include <react/timing/primitives.h> |
25 | 26 | #include <react/utils/jsi-utils.h> |
@@ -250,63 +251,65 @@ void ReactInstance::loadScript( |
250 | 251 | std::shared_ptr<const jsi::Buffer> buffer(std::move(script)); |
251 | 252 | std::string scriptName = simpleBasename(sourceURL); |
252 | 253 |
|
253 | | - runtimeScheduler_->scheduleWork( |
254 | | - [jsErrorHandler = jsErrorHandler_, |
255 | | - scriptName, |
256 | | - sourceURL = sourceURL, |
257 | | - buffer = std::move(buffer), |
258 | | - weakBufferedRuntimeExecuter = |
259 | | - std::weak_ptr<BufferedRuntimeExecutor>(bufferedRuntimeExecutor_), |
260 | | - beforeLoad, |
261 | | - afterLoad](jsi::Runtime& runtime) mutable { |
262 | | - if (beforeLoad) { |
263 | | - beforeLoad(runtime); |
264 | | - } |
265 | | - TraceSection s("ReactInstance::loadScript"); |
266 | | - bool hasLogger(ReactMarker::logTaggedMarkerImpl); |
267 | | - if (hasLogger) { |
268 | | - ReactMarker::logTaggedMarker( |
269 | | - ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str()); |
270 | | - ReactMarker::logMarker(ReactMarker::INIT_REACT_RUNTIME_START); |
271 | | - ReactMarker::logMarker(ReactMarker::APP_STARTUP_START); |
272 | | - } |
| 254 | + runtimeScheduler_->scheduleWork([jsErrorHandler = jsErrorHandler_, |
| 255 | + scriptName, |
| 256 | + sourceURL = sourceURL, |
| 257 | + buffer = std::move(buffer), |
| 258 | + weakBufferedRuntimeExecuter = |
| 259 | + std::weak_ptr<BufferedRuntimeExecutor>( |
| 260 | + bufferedRuntimeExecutor_), |
| 261 | + beforeLoad, |
| 262 | + afterLoad](jsi::Runtime& runtime) mutable { |
| 263 | + if (beforeLoad) { |
| 264 | + beforeLoad(runtime); |
| 265 | + } |
| 266 | + TraceSection s("ReactInstance::loadScript"); |
| 267 | + bool hasLogger(ReactMarker::logTaggedMarkerImpl); |
| 268 | + if (hasLogger) { |
| 269 | + ReactMarker::logTaggedMarker( |
| 270 | + ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str()); |
| 271 | + ReactMarker::logMarker(ReactMarker::INIT_REACT_RUNTIME_START); |
| 272 | + ReactMarker::logMarker(ReactMarker::APP_STARTUP_START); |
| 273 | + } |
273 | 274 |
|
274 | | - // Check if the shermes unit is avaliable. |
275 | | - auto* shUnitAPI = jsi::castInterface<hermes::IHermesSHUnit>(&runtime); |
276 | | - auto* shUnitCreator = |
277 | | - shUnitAPI ? shUnitAPI->getSHUnitCreator() : nullptr; |
278 | | - if (shUnitCreator) { |
279 | | - LOG(WARNING) << "ReactInstance: evaluateSHUnit"; |
280 | | - auto* hermesAPI = jsi::castInterface<hermes::IHermes>(&runtime); |
281 | | - hermesAPI->evaluateSHUnit(shUnitCreator); |
282 | | - } else { |
283 | | - LOG(WARNING) << "ReactInstance: evaluateJavaScript() with JS bundle"; |
284 | | - runtime.evaluateJavaScript(buffer, sourceURL); |
285 | | - } |
| 275 | + // Check if the shermes unit is avaliable. |
| 276 | + auto* shUnitAPI = jsi::castInterface<hermes::IHermesSHUnit>(&runtime); |
| 277 | + auto* shUnitCreator = shUnitAPI ? shUnitAPI->getSHUnitCreator() : nullptr; |
| 278 | + if (shUnitCreator) { |
| 279 | + LOG(WARNING) << "ReactInstance: evaluateSHUnit"; |
| 280 | + notifyJSEvaluation(JSEvaluationKind::SHUnit, nullptr, 0, sourceURL); |
| 281 | + auto* hermesAPI = jsi::castInterface<hermes::IHermes>(&runtime); |
| 282 | + hermesAPI->evaluateSHUnit(shUnitCreator); |
| 283 | + } else { |
| 284 | + LOG(WARNING) << "ReactInstance: evaluateJavaScript() with JS bundle"; |
| 285 | + notifyJSEvaluation( |
| 286 | + JSEvaluationKind::Bundle, buffer->data(), buffer->size(), sourceURL); |
| 287 | + runtime.evaluateJavaScript(buffer, sourceURL); |
| 288 | + } |
286 | 289 |
|
287 | | - /** |
288 | | - * TODO(T183610671): We need a safe/reliable way to enable the js |
289 | | - * pipeline from javascript. Remove this after we figure that out, or |
290 | | - * after we just remove the js pipeline. |
291 | | - */ |
292 | | - if (!jsErrorHandler->hasHandledFatalError()) { |
293 | | - jsErrorHandler->setRuntimeReady(); |
294 | | - } |
| 290 | + /** |
| 291 | + * TODO(T183610671): We need a safe/reliable way to enable the js |
| 292 | + * pipeline from javascript. Remove this after we figure that out, or |
| 293 | + * after we just remove the js pipeline. |
| 294 | + */ |
| 295 | + if (!jsErrorHandler->hasHandledFatalError()) { |
| 296 | + jsErrorHandler->setRuntimeReady(); |
| 297 | + } |
295 | 298 |
|
296 | | - if (hasLogger) { |
297 | | - ReactMarker::logTaggedMarker( |
298 | | - ReactMarker::RUN_JS_BUNDLE_STOP, scriptName.c_str()); |
299 | | - ReactMarker::logMarker(ReactMarker::INIT_REACT_RUNTIME_STOP); |
300 | | - ReactMarker::logMarker(ReactMarker::APP_STARTUP_STOP); |
301 | | - } |
302 | | - if (auto strongBufferedRuntimeExecuter = |
303 | | - weakBufferedRuntimeExecuter.lock()) { |
304 | | - strongBufferedRuntimeExecuter->flush(); |
305 | | - } |
306 | | - if (afterLoad) { |
307 | | - afterLoad(runtime); |
308 | | - } |
309 | | - }); |
| 299 | + if (hasLogger) { |
| 300 | + ReactMarker::logTaggedMarker( |
| 301 | + ReactMarker::RUN_JS_BUNDLE_STOP, scriptName.c_str()); |
| 302 | + ReactMarker::logMarker(ReactMarker::INIT_REACT_RUNTIME_STOP); |
| 303 | + ReactMarker::logMarker(ReactMarker::APP_STARTUP_STOP); |
| 304 | + } |
| 305 | + if (auto strongBufferedRuntimeExecuter = |
| 306 | + weakBufferedRuntimeExecuter.lock()) { |
| 307 | + strongBufferedRuntimeExecuter->flush(); |
| 308 | + } |
| 309 | + if (afterLoad) { |
| 310 | + afterLoad(runtime); |
| 311 | + } |
| 312 | + }); |
310 | 313 | } |
311 | 314 |
|
312 | 315 | namespace { |
@@ -442,20 +445,23 @@ void ReactInstance::registerSegment( |
442 | 445 | "Empty segment registered with ID " + std::to_string(segmentId) + |
443 | 446 | " from " + segmentPath); |
444 | 447 | } |
445 | | - runtimeScheduler_->scheduleWork( |
446 | | - [script = std::move(script), segmentId](jsi::Runtime& runtime) { |
447 | | - TraceSection s("ReactInstance::registerSegment"); |
448 | | - auto tag = std::to_string(segmentId); |
449 | | - ReactMarker::logTaggedMarker( |
450 | | - ReactMarker::REGISTER_JS_SEGMENT_START, tag.c_str()); |
451 | | - LOG(WARNING) << "Starting to evaluate segment " << segmentId |
452 | | - << " in ReactInstance::registerSegment"; |
453 | | - runtime.evaluateJavaScript(script, getSyntheticBundlePath(segmentId)); |
454 | | - LOG(WARNING) << "Finished evaluating segment " << segmentId |
455 | | - << " in ReactInstance::registerSegment"; |
456 | | - ReactMarker::logTaggedMarker( |
457 | | - ReactMarker::REGISTER_JS_SEGMENT_STOP, tag.c_str()); |
458 | | - }); |
| 448 | + runtimeScheduler_->scheduleWork([script = std::move(script), |
| 449 | + segmentId, |
| 450 | + segmentPath](jsi::Runtime& runtime) { |
| 451 | + TraceSection s("ReactInstance::registerSegment"); |
| 452 | + auto tag = std::to_string(segmentId); |
| 453 | + ReactMarker::logTaggedMarker( |
| 454 | + ReactMarker::REGISTER_JS_SEGMENT_START, tag.c_str()); |
| 455 | + LOG(WARNING) << "Starting to evaluate segment " << segmentId |
| 456 | + << " in ReactInstance::registerSegment"; |
| 457 | + notifyJSEvaluation( |
| 458 | + JSEvaluationKind::Segment, script->data(), script->size(), segmentPath); |
| 459 | + runtime.evaluateJavaScript(script, getSyntheticBundlePath(segmentId)); |
| 460 | + LOG(WARNING) << "Finished evaluating segment " << segmentId |
| 461 | + << " in ReactInstance::registerSegment"; |
| 462 | + ReactMarker::logTaggedMarker( |
| 463 | + ReactMarker::REGISTER_JS_SEGMENT_STOP, tag.c_str()); |
| 464 | + }); |
459 | 465 | } |
460 | 466 |
|
461 | 467 | namespace { |
@@ -531,6 +537,12 @@ void ReactInstance::initializeRuntime( |
531 | 537 | } |
532 | 538 | // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic) |
533 | 539 |
|
| 540 | + notifyJSEvaluation( |
| 541 | + JSEvaluationKind::DevServerEval, |
| 542 | + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
| 543 | + reinterpret_cast<const uint8_t*>(code.data()), |
| 544 | + code.size(), |
| 545 | + url); |
534 | 546 | return rt.evaluateJavaScript( |
535 | 547 | std::make_unique<jsi::StringBuffer>(std::move(code)), url); |
536 | 548 | })); |
|
0 commit comments