Commit 518b5c1c authored by Kim-Anh Tran's avatar Kim-Anh Tran Committed by Commit Bot

[wasm] Pass copy of local pointer to lambda when adding callback

Previously a step-dependent reference was captured, which would not
exist anymore as soon as we change steps in async compilation. This fix
makes sure that we capture the pointer by copy, not by reference.

Change-Id: I7ff7e87b67b2fd379e6642d844a4c770cadf1f6c
Reviewed-on: https://chromium-review.googlesource.com/970964Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Kim-Anh Tran <kimanh@google.com>
Cr-Commit-Position: refs/heads/master@{#52079}
parent eace3d97
......@@ -3041,21 +3041,27 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
CompilationState* compilation_state =
job_->compiled_module_->GetNativeModule()->compilation_state();
compilation_state->AddCallback(
[&](CompilationEvent event, Handle<Object> error_reason) {
switch (event) {
case CompilationEvent::kFinishedBaselineCompilation:
if (job_->DecrementAndCheckFinisherCount()) {
job_->DoSync<FinishCompile>();
}
return;
case CompilationEvent::kFailedCompilation:
job_->DoSync<CompileFailed>(error_reason);
return;
}
UNREACHABLE();
});
{
// Instance field {job_} cannot be captured by copy, therefore
// we need to add a local helper variable {job}. We want to
// capture the {job} pointer by copy, as it otherwise is dependent
// on the current step we are in.
AsyncCompileJob* job = job_;
compilation_state->AddCallback(
[job](CompilationEvent event, Handle<Object> error_reason) {
switch (event) {
case CompilationEvent::kFinishedBaselineCompilation:
if (job->DecrementAndCheckFinisherCount()) {
job->DoSync<FinishCompile>();
}
return;
case CompilationEvent::kFailedCompilation:
job->DoSync<CompileFailed>(error_reason);
return;
}
UNREACHABLE();
});
}
if (start_compilation_) {
// TODO(ahaas): Try to remove the {start_compilation_} check when
// streaming decoding is done in the background. If
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment