fix: wasm code generation in the renderer (#25777)

This commit is contained in:
Shelley Vohr 2020-10-08 12:26:01 -07:00 committed by GitHub
parent 2ca2a88afc
commit 042d25e926
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 149 additions and 0 deletions

View file

@ -33,6 +33,7 @@
#include "shell/common/gin_helper/microtasks_scope.h"
#include "shell/common/mac/main_application_bundle.h"
#include "shell/common/node_includes.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_initializer.h" // nogncheck
#if !defined(MAS_BUILD)
#include "shell/common/crash_keys.h"
@ -152,6 +153,22 @@ void V8FatalErrorCallback(const char* location, const char* message) {
*zero = 0;
}
bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
v8::Local<v8::String>) {
// If we're running with contextIsolation enabled in the renderer process,
// fall back to Blink's logic.
v8::Isolate* isolate = context->GetIsolate();
if (node::Environment::GetCurrent(isolate) == nullptr) {
if (gin_helper::Locker::IsBrowserProcess())
return false;
return blink::V8Initializer::WasmCodeGenerationCheckCallbackInMainThread(
context, v8::String::Empty(isolate));
}
return node::Environment::AllowWasmCodeGenerationCallback(
context, v8::String::Empty(isolate));
}
// Initialize Node.js cli options to pass to Node.js
// See https://nodejs.org/api/cli.html#cli_options
void SetNodeCliFlags() {
@ -436,6 +453,10 @@ node::Environment* NodeBindings::CreateEnvironment(
return false;
};
// Use a custom callback here to allow us to leverage Blink's logic in the
// renderer process.
is.allow_wasm_code_generation_callback = AllowWasmCodeGenerationCallback;
if (browser_env_ == BrowserEnvironment::BROWSER) {
// Node.js requires that microtask checkpoints be explicitly invoked.
is.policy = v8::MicrotasksPolicy::kExplicit;