[wasm] Always restore context in OnFinishedCompile

The callback to AsyncStreamingProcessor::OnFinishedStream would
call into v8 internals without restoring the current context if
the processed module had no code. Instead, now always restore the
context before doing any finishing work.

Bug: chromium:915493
Change-Id: Ib779df81301ad1e3597515a4173c9a57efc593ac
Reviewed-on: https://chromium-review.googlesource.com/c/1397672
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58612}
This commit is contained in:
Stephan Herhut 2019-01-07 16:16:23 +01:00 committed by Commit Bot
parent afa95fb4e4
commit a76d560ef8

View File

@ -3031,6 +3031,13 @@ void AsyncStreamingProcessor::OnFinishedStream(OwnedVector<uint8_t> bytes) {
FinishAsyncCompileJobWithError(std::move(result));
return;
}
// We have to open a HandleScope and prepare the Context for
// PrepareRuntimeObjects and FinishCompile as this is a callback from the
// embedder.
HandleScope scope(job_->isolate_);
SaveContext saved_context(job_->isolate_);
job_->isolate_->set_context(*job_->native_context_);
bool needs_finish = job_->DecrementAndCheckFinisherCount();
if (job_->native_module_ == nullptr) {
// We are processing a WebAssembly module without code section. Create the
@ -3041,9 +3048,6 @@ void AsyncStreamingProcessor::OnFinishedStream(OwnedVector<uint8_t> bytes) {
job_->wire_bytes_ = ModuleWireBytes(bytes.as_vector());
job_->native_module_->SetWireBytes(std::move(bytes));
if (needs_finish) {
HandleScope scope(job_->isolate_);
SaveContext saved_context(job_->isolate_);
job_->isolate_->set_context(*job_->native_context_);
job_->FinishCompile(true);
}
}