@@ -2368,8 +2368,7 @@ class AsyncCompileJob::DecodeModule : public AsyncCompileJob::CompileStep {
23682368 job_->DoSync <DecodeFail>(std::move (result));
23692369 } else {
23702370 // Decode passed.
2371- job_->module_ = std::move (result.val );
2372- job_->DoSync <PrepareAndStartCompile>(true );
2371+ job_->DoSync <PrepareAndStartCompile>(std::move (result.val ), true );
23732372 }
23742373 }
23752374};
@@ -2397,10 +2396,12 @@ class AsyncCompileJob::DecodeFail : public CompileStep {
23972396// ==========================================================================
23982397class AsyncCompileJob ::PrepareAndStartCompile : public CompileStep {
23992398 public:
2400- explicit PrepareAndStartCompile (bool start_compilation)
2401- : start_compilation_(start_compilation) {}
2399+ PrepareAndStartCompile (std::shared_ptr<const WasmModule> module ,
2400+ bool start_compilation)
2401+ : module_(module ), start_compilation_(start_compilation) {}
24022402
24032403 private:
2404+ std::shared_ptr<const WasmModule> module_;
24042405 bool start_compilation_;
24052406
24062407 void RunInForeground () override {
@@ -2411,7 +2412,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
24112412 job_->background_task_manager_ .CancelAndWait ();
24122413
24132414 // Embedder usage count for declared shared memories.
2414- if (job_-> module_ ->has_shared_memory ) {
2415+ if (module_->has_shared_memory ) {
24152416 job_->isolate_ ->CountUsage (
24162417 v8::Isolate::UseCounterFeature::kWasmSharedMemory );
24172418 }
@@ -2421,7 +2422,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
24212422 Handle<Script> script = CreateWasmScript (job_->isolate_ , job_->wire_bytes_ );
24222423 Handle<ByteArray> asm_js_offset_table;
24232424
2424- const WasmModule* module = job_-> module_ .get ();
2425+ const WasmModule* module = module_.get ();
24252426 ModuleEnv env = CreateDefaultModuleEnv (module );
24262427 // TODO(wasm): Improve efficiency of storing module wire bytes. Only store
24272428 // relevant sections, not function bodies
@@ -2433,7 +2434,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
24332434 // breakpoints on a (potentially empty) subset of the instances.
24342435 // Create the module object.
24352436 job_->module_object_ = WasmModuleObject::New (
2436- job_->isolate_ , job_->enabled_features_ , job_-> module_ , env,
2437+ job_->isolate_ , job_->enabled_features_ , module_, env,
24372438 {std::move (job_->bytes_copy_ ), job_->wire_bytes_ .length ()}, script,
24382439 asm_js_offset_table);
24392440 job_->native_module_ = job_->module_object_ ->native_module ();
@@ -2559,8 +2560,8 @@ class AsyncCompileJob::FinishModule : public CompileStep {
25592560 TRACE_COMPILE (" (6) Finish module...\n " );
25602561 job_->AsyncCompileSucceeded (job_->module_object_ );
25612562
2562- size_t num_functions =
2563- job_-> module_ -> functions . size () - job_->module_ ->num_imported_functions ;
2563+ size_t num_functions = job_-> native_module_ -> num_functions () -
2564+ job_->native_module_ ->num_imported_functions () ;
25642565 if (job_->native_module_ ->compilation_state ()->compile_mode () ==
25652566 CompileMode::kRegular ||
25662567 num_functions == 0 ) {
@@ -2621,7 +2622,6 @@ bool AsyncStreamingProcessor::ProcessModuleHeader(Vector<const uint8_t> bytes,
26212622 TRACE_STREAMING (" Process module header...\n " );
26222623 decoder_.StartDecoding (job_->async_counters ().get (),
26232624 job_->isolate ()->wasm_engine ()->allocator ());
2624- job_->module_ = decoder_.shared_module ();
26252625 decoder_.DecodeModuleHeader (bytes, offset);
26262626 if (!decoder_.ok ()) {
26272627 FinishAsyncCompileJobWithError (decoder_.FinishDecoding (false ));
@@ -2672,7 +2672,8 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader(size_t functions_count,
26722672 FinishAsyncCompileJobWithError (decoder_.FinishDecoding (false ));
26732673 return false ;
26742674 }
2675- job_->NextStep <AsyncCompileJob::PrepareAndStartCompile>(false );
2675+ job_->NextStep <AsyncCompileJob::PrepareAndStartCompile>(
2676+ decoder_.shared_module (), false );
26762677 // Execute the PrepareAndStartCompile step immediately and not in a separate
26772678 // task.
26782679 job_->ExecuteForegroundTaskImmediately ();
@@ -2725,14 +2726,13 @@ void AsyncStreamingProcessor::OnFinishedStream(OwnedVector<uint8_t> bytes) {
27252726 }
27262727 ModuleResult result = decoder_.FinishDecoding (false );
27272728 DCHECK (result.ok ());
2728- DCHECK_EQ (job_->module_ , result.val );
27292729 if (job_->DecrementAndCheckFinisherCount ()) {
27302730 if (job_->native_module_ == nullptr ) {
27312731 // We are processing a WebAssembly module without code section. We need to
27322732 // prepare compilation first before we can finish it.
27332733 // {PrepareAndStartCompile} will call {FinishCompile} by itself if there
27342734 // is no code section.
2735- job_->DoSync <AsyncCompileJob::PrepareAndStartCompile>(true );
2735+ job_->DoSync <AsyncCompileJob::PrepareAndStartCompile>(result. val , true );
27362736 } else {
27372737 HandleScope scope (job_->isolate_ );
27382738 SaveContext saved_context (job_->isolate_ );
0 commit comments