fix: blend node and blink code generation policy when both are loaded (#36567)

This commit is contained in:
Jeremy Rose 2022-12-14 10:05:34 -08:00 committed by GitHub
parent f72e6551f0
commit 9e7fbc7021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 132 additions and 6 deletions

View file

@ -158,19 +158,35 @@ void V8FatalErrorCallback(const char* location, const char* message) {
}
bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
v8::Local<v8::String>) {
v8::Local<v8::String> source) {
// 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 (node::Environment::GetCurrent(context) == nullptr) {
if (gin_helper::Locker::IsBrowserProcess())
return false;
return blink::V8Initializer::WasmCodeGenerationCheckCallbackInMainThread(
context, v8::String::Empty(isolate));
context, source);
}
return node::AllowWasmCodeGenerationCallback(context,
v8::String::Empty(isolate));
return node::AllowWasmCodeGenerationCallback(context, source);
}
v8::ModifyCodeGenerationFromStringsResult ModifyCodeGenerationFromStrings(
v8::Local<v8::Context> context,
v8::Local<v8::Value> source,
bool is_code_like) {
// If we're running with contextIsolation enabled in the renderer process,
// fall back to Blink's logic.
if (node::Environment::GetCurrent(context) == nullptr) {
if (gin_helper::Locker::IsBrowserProcess()) {
NOTREACHED();
return {false, {}};
}
return blink::V8Initializer::CodeGenerationCheckCallbackInMainThread(
context, source, is_code_like);
}
return node::ModifyCodeGenerationFromStrings(context, source, is_code_like);
}
void ErrorMessageListener(v8::Local<v8::Message> message,
@ -543,6 +559,8 @@ node::Environment* NodeBindings::CreateEnvironment(
// Use a custom callback here to allow us to leverage Blink's logic in the
// renderer process.
is.allow_wasm_code_generation_callback = AllowWasmCodeGenerationCallback;
is.modify_code_generation_from_strings_callback =
ModifyCodeGenerationFromStrings;
if (browser_env_ == BrowserEnvironment::kBrowser ||
browser_env_ == BrowserEnvironment::kUtility) {