From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Adam Klein <adamk@chromium.org>
Date: Wed, 15 May 2024 09:16:00 +0200
Subject: cherry-pick: src: remove calls to recently deprecated V8 APIs

Node.js Commit: a6d54f179d997497a95c18456bef6bc3ee15e2c4
Node.js PR: https://github.com/nodejs/node/pull/52996
V8 API Removal CL: https://chromium-review.googlesource.com/c/v8/v8/+/5539888

This patch is slightly modified from the original commit in order to
resolve conflicts due to the base commit difference between the Node.js
PR and the current upgrade roll.

This patch is expected to be deleted once we catch up with a Node.js
upgrade that includes the original Node.js commit above.

diff --git a/src/module_wrap.cc b/src/module_wrap.cc
index ff658ec88e5161cd66536ee6e95dba675b16eccc..9bbb8ab908d8d992abb43254860d51f57f56387b 100644
--- a/src/module_wrap.cc
+++ b/src/module_wrap.cc
@@ -202,8 +202,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
       }
 
       Local<String> source_text = args[2].As<String>();
-      ScriptOrigin origin(isolate,
-                          url,
+      ScriptOrigin origin(url,
                           line_offset,
                           column_offset,
                           true,                             // is cross origin
@@ -464,7 +463,6 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
 
   ShouldNotAbortOnUncaughtScope no_abort_scope(realm->env());
   TryCatchScope try_catch(realm->env());
-  Isolate::SafeForTerminationScope safe_for_termination(isolate);
 
   bool timed_out = false;
   bool received_signal = false;
diff --git a/src/node_builtins.cc b/src/node_builtins.cc
index 4bf80aa6cc6385dc376fd0a3538efc27fe5bd0a2..3e37aa8b0c9696cceb3f3cfab9721f38c74a2fba 100644
--- a/src/node_builtins.cc
+++ b/src/node_builtins.cc
@@ -267,7 +267,7 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompileInternal(
   std::string filename_s = std::string("node:") + id;
   Local<String> filename =
       OneByteString(isolate, filename_s.c_str(), filename_s.size());
-  ScriptOrigin origin(isolate, filename, 0, 0, true);
+  ScriptOrigin origin(filename, 0, 0, true);
 
   BuiltinCodeCacheData cached_data{};
   {
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index 6456d87d4202c013aafe071adbac06852b3ae2c1..28ba7dbe66a44a43c39e3d75edf0be9513bcf732 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -877,16 +877,15 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
   host_defined_options->Set(
       isolate, loader::HostDefinedOptions::kID, id_symbol);
 
-  ScriptOrigin origin(isolate,
-                      filename,
-                      line_offset,                          // line offset
-                      column_offset,                        // column offset
-                      true,                                 // is cross origin
-                      -1,                                   // script id
-                      Local<Value>(),                       // source map URL
-                      false,                                // is opaque (?)
-                      false,                                // is WASM
-                      false,                                // is ES Module
+  ScriptOrigin origin(filename,
+                      line_offset,     // line offset
+                      column_offset,   // column offset
+                      true,            // is cross origin
+                      -1,              // script id
+                      Local<Value>(),  // source map URL
+                      false,           // is opaque (?)
+                      false,           // is WASM
+                      false,           // is ES Module
                       host_defined_options);
   ScriptCompiler::Source source(code, origin, cached_data);
   ScriptCompiler::CompileOptions compile_options =
@@ -998,7 +997,7 @@ MaybeLocal<Function> CompileFunction(Local<Context> context,
                                      Local<String> filename,
                                      Local<String> content,
                                      std::vector<Local<String>>* parameters) {
-  ScriptOrigin script_origin(context->GetIsolate(), filename, 0, 0, true);
+  ScriptOrigin script_origin(filename, 0, 0, true);
   ScriptCompiler::Source script_source(content, script_origin);
 
   return ScriptCompiler::CompileFunction(context,
@@ -1108,7 +1107,6 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
   }
 
   TryCatchScope try_catch(env);
-  Isolate::SafeForTerminationScope safe_for_termination(env->isolate());
   ContextifyScript* wrapped_script;
   ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.This(), false);
   Local<UnboundScript> unbound_script =
@@ -1286,8 +1284,7 @@ void ContextifyContext::CompileFunction(
   Local<PrimitiveArray> host_defined_options =
       GetHostDefinedOptions(isolate, id_symbol);
   ScriptCompiler::Source source =
-      GetCommonJSSourceInstance(isolate,
-                                code,
+      GetCommonJSSourceInstance(code,
                                 filename,
                                 line_offset,
                                 column_offset,
@@ -1342,15 +1339,13 @@ void ContextifyContext::CompileFunction(
 }
 
 ScriptCompiler::Source ContextifyContext::GetCommonJSSourceInstance(
-    Isolate* isolate,
     Local<String> code,
     Local<String> filename,
     int line_offset,
     int column_offset,
     Local<PrimitiveArray> host_defined_options,
     ScriptCompiler::CachedData* cached_data) {
-  ScriptOrigin origin(isolate,
-                      filename,
+  ScriptOrigin origin(filename,
                       line_offset,     // line offset
                       column_offset,   // column offset
                       true,            // is cross origin
@@ -1528,7 +1523,7 @@ void ContextifyContext::ContainsModuleSyntax(
   Local<PrimitiveArray> host_defined_options =
       GetHostDefinedOptions(isolate, id_symbol);
   ScriptCompiler::Source source = GetCommonJSSourceInstance(
-      isolate, code, filename, 0, 0, host_defined_options, nullptr);
+      code, filename, 0, 0, host_defined_options, nullptr);
   ScriptCompiler::CompileOptions options = GetCompileOptions(source);
 
   std::vector<Local<String>> params = GetCJSParameters(env->isolate_data());
@@ -1576,7 +1571,7 @@ void ContextifyContext::ContainsModuleSyntax(
               code,
               String::NewFromUtf8(isolate, "})();").ToLocalChecked());
           ScriptCompiler::Source wrapped_source = GetCommonJSSourceInstance(
-              isolate, code, filename, 0, 0, host_defined_options, nullptr);
+              code, filename, 0, 0, host_defined_options, nullptr);
           std::ignore = ScriptCompiler::CompileFunction(
               context,
               &wrapped_source,
@@ -1629,8 +1624,7 @@ static void CompileFunctionForCJSLoader(
 
   Local<Symbol> symbol = env->vm_dynamic_import_default_internal();
   Local<PrimitiveArray> hdo = GetHostDefinedOptions(isolate, symbol);
-  ScriptOrigin origin(isolate,
-                      filename,
+  ScriptOrigin origin(filename,
                       0,               // line offset
                       0,               // column offset
                       true,            // is cross origin
diff --git a/src/node_contextify.h b/src/node_contextify.h
index 517e3f44d324900222e1da961a4cd60bbb4a85f9..10715c7eb07715cc11e49734bd54747dad95f6a4 100644
--- a/src/node_contextify.h
+++ b/src/node_contextify.h
@@ -99,7 +99,6 @@ class ContextifyContext : public BaseObject {
       v8::Local<v8::Symbol> id_symbol,
       const errors::TryCatchScope& try_catch);
   static v8::ScriptCompiler::Source GetCommonJSSourceInstance(
-      v8::Isolate* isolate,
       v8::Local<v8::String> code,
       v8::Local<v8::String> filename,
       int line_offset,
diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc
index 64e38c83006a004ebc3519a5e9f8b04263244514..14e82cc80ff73084fb43b2ef07febfd2667a0abc 100644
--- a/test/cctest/test_environment.cc
+++ b/test/cctest/test_environment.cc
@@ -620,12 +620,9 @@ TEST_F(EnvironmentTest, SetImmediateMicrotasks) {
 
 #ifndef _WIN32  // No SIGINT on Windows.
 TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) {
-  // We need to go through the whole setup dance here because we want to
-  // set only_terminate_in_safe_scope.
   // Allocate and initialize Isolate.
   v8::Isolate::CreateParams create_params;
   create_params.array_buffer_allocator = allocator.get();
-  create_params.only_terminate_in_safe_scope = true;
   v8::Isolate* isolate = v8::Isolate::Allocate();
   CHECK_NOT_NULL(isolate);
   platform->RegisterIsolate(isolate, &current_loop);
