[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/970964
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Kim-Anh Tran <kimanh@google.com>
Cr-Commit-Position: refs/heads/master@{#52079}
This commit is contained in:
Kim-Anh Tran 2018-03-20 16:52:11 +01:00 committed by Commit Bot
parent eace3d9713
commit 518b5c1c96

View File

@ -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