| 2378 | } |
| 2379 | |
| 2380 | void WasmRuntime::executeMainFileAsync(String filename, const std::function<void(bool)>& handler) { |
| 2381 | if (!_scheduler) { |
| 2382 | scheduleUpdate(); |
| 2383 | } |
| 2384 | auto instance = New<WasmInstance>(); |
| 2385 | auto moduleId = allocModuleId(instance.get()); |
| 2386 | if (moduleId == 0) { |
| 2387 | Error("failed to allocate wasm module id for {}", filename.toString()); |
| 2388 | handler(false); |
| 2389 | return; |
| 2390 | } |
| 2391 | instance->setModuleId(moduleId); |
| 2392 | auto* instancePtr = instance.get(); |
| 2393 | _instances.push_back(std::move(instance)); |
| 2394 | instancePtr->executeMainFileAsync(filename, [this, instancePtr, handler](bool result) { |
| 2395 | if (!result) { |
| 2396 | releaseModuleId(instancePtr->getModuleId()); |
| 2397 | auto it = std::find_if(_instances.begin(), _instances.end(), [instancePtr](const auto& item) { |
| 2398 | return item.get() == instancePtr; |
| 2399 | }); |
| 2400 | if (it != _instances.end()) { |
| 2401 | _instances.erase(it); |
| 2402 | } |
| 2403 | } |
| 2404 | handler(result); |
| 2405 | }); |
| 2406 | } |
| 2407 | |
| 2408 | void WasmInstance::executeMainFileAsync(String filename, const std::function<void(bool)>& handler) { |
| 2409 | if (_wasm.first || _loading) { |
nothing calls this directly
no test coverage detected