| 3576 | } |
| 3577 | |
| 3578 | void JavaScriptRuntime::preloadModule(const StringBox& path, int32_t maxDepth) { |
| 3579 | dispatchOnJsThreadAsync(nullptr, [=](JavaScriptEntryParameters& jsEntry) { |
| 3580 | VALDI_TRACE_META("Valdi.preloadModule", path); |
| 3581 | |
| 3582 | std::initializer_list<JSValueRef> params = { |
| 3583 | jsEntry.jsContext.newStringUTF8(path.toStringView(), jsEntry.exceptionTracker), |
| 3584 | jsEntry.jsContext.newNumber(maxDepth)}; |
| 3585 | |
| 3586 | if (!jsEntry.exceptionTracker) { |
| 3587 | return; |
| 3588 | } |
| 3589 | |
| 3590 | JSFunctionCallContext callContext(jsEntry.jsContext, params.begin(), params.size(), jsEntry.exceptionTracker); |
| 3591 | |
| 3592 | jsEntry.jsContext.callObjectProperty( |
| 3593 | _moduleLoader.get(), _propertyNameIndex.getJsName(kPreloadModulePropertyName), callContext); |
| 3594 | }); |
| 3595 | } |
| 3596 | |
| 3597 | void JavaScriptRuntime::preloadModules(const std::vector<StringBox>& paths, int32_t maxDepth) { |
| 3598 | _resourceManager.warmUpBundles(paths); |
| 3599 | |
| 3600 | // Read the yield chunk size live (not an init-time snapshot) so a COF ramp takes effect on the |
| 3601 | // next capture without an app restart, and so it is unaffected by runtime-init vs |
| 3602 | // config-availability ordering. 0 = evaluate the batch as a single uninterrupted task (default). |
| 3603 | int32_t chunkSize = 0; |
| 3604 | if (auto listener = getListener()) { |
| 3605 | auto runtimeTweaks = listener->getRuntimeTweaks(); |
| 3606 | if (runtimeTweaks != nullptr) { |
| 3607 | chunkSize = runtimeTweaks->preloadYieldChunkSize(); |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | dispatchOnJsThreadAsync(nullptr, [=](JavaScriptEntryParameters& jsEntry) { |
| 3612 | VALDI_TRACE("Valdi.preloadModules"); |
| 3613 | |
| 3614 | auto pathsArray = |
| 3615 | jsEntry.jsContext.newArrayWithValues(paths.size(), jsEntry.exceptionTracker, [&](size_t i) -> JSValueRef { |
| 3616 | return jsEntry.jsContext.newStringUTF8(paths[i].toStringView(), jsEntry.exceptionTracker); |
| 3617 | }); |
| 3618 | |
| 3619 | if (!jsEntry.exceptionTracker) { |
| 3620 | return; |
| 3621 | } |
| 3622 | |
| 3623 | // Third arg (chunkSize) is optional in ModuleLoader.preloadBatch; 0 preserves the original |
| 3624 | // single-task evaluation. > 0 makes it yield between chunks so the watchdog ack can run. |
| 3625 | std::initializer_list<JSValueRef> params = { |
| 3626 | pathsArray, jsEntry.jsContext.newNumber(maxDepth), jsEntry.jsContext.newNumber(chunkSize)}; |
| 3627 |
no test coverage detected