|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Adam Klein <adamk@chromium.org> |
| 3 | +Date: Wed, 15 May 2024 09:16:00 +0200 |
| 4 | +Subject: cherry-pick: src: remove calls to recently deprecated V8 APIs |
| 5 | + |
| 6 | +Node.js Commit: a6d54f179d997497a95c18456bef6bc3ee15e2c4 |
| 7 | +Node.js PR: https://github.com/nodejs/node/pull/52996 |
| 8 | +V8 API Removal CL: https://chromium-review.googlesource.com/c/v8/v8/+/5539888 |
| 9 | + |
| 10 | +This patch is slightly modified from the original commit in order to |
| 11 | +resolve conflicts due to the base commit difference between the Node.js |
| 12 | +PR and the current upgrade roll. |
| 13 | + |
| 14 | +This patch is expected to be deleted once we catch up with a Node.js |
| 15 | +upgrade that includes the original Node.js commit above. |
| 16 | + |
| 17 | +diff --git a/src/module_wrap.cc b/src/module_wrap.cc |
| 18 | +index 9ad67e0993da4c3e3f8a14681edbf941cf14e2e6..29ed378d32d452518dc929e60e6038ba4ca38a5c 100644 |
| 19 | +--- a/src/module_wrap.cc |
| 20 | ++++ b/src/module_wrap.cc |
| 21 | +@@ -186,8 +186,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { |
| 22 | + } |
| 23 | + |
| 24 | + Local<String> source_text = args[2].As<String>(); |
| 25 | +- ScriptOrigin origin(isolate, |
| 26 | +- url, |
| 27 | ++ ScriptOrigin origin(url, |
| 28 | + line_offset, |
| 29 | + column_offset, |
| 30 | + true, // is cross origin |
| 31 | +@@ -394,7 +393,6 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) { |
| 32 | + |
| 33 | + ShouldNotAbortOnUncaughtScope no_abort_scope(realm->env()); |
| 34 | + TryCatchScope try_catch(realm->env()); |
| 35 | +- Isolate::SafeForTerminationScope safe_for_termination(isolate); |
| 36 | + |
| 37 | + bool timed_out = false; |
| 38 | + bool received_signal = false; |
| 39 | +diff --git a/src/node_builtins.cc b/src/node_builtins.cc |
| 40 | +index f9a090f5c3e04403602ba383032e7f3230669a92..3f82db324d406e342abee23ab0d7f7c9807ff652 100644 |
| 41 | +--- a/src/node_builtins.cc |
| 42 | ++++ b/src/node_builtins.cc |
| 43 | +@@ -267,7 +267,7 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompileInternal( |
| 44 | + std::string filename_s = std::string("node:") + id; |
| 45 | + Local<String> filename = |
| 46 | + OneByteString(isolate, filename_s.c_str(), filename_s.size()); |
| 47 | +- ScriptOrigin origin(isolate, filename, 0, 0, true); |
| 48 | ++ ScriptOrigin origin(filename, 0, 0, true); |
| 49 | + |
| 50 | + BuiltinCodeCacheData cached_data{}; |
| 51 | + { |
| 52 | +diff --git a/src/node_contextify.cc b/src/node_contextify.cc |
| 53 | +index df1d9cb4fd0442ec6ce6164a136b7a5fbcbe5b67..f6969e635f692b17b4efca1dfbee086a0199db6e 100644 |
| 54 | +--- a/src/node_contextify.cc |
| 55 | ++++ b/src/node_contextify.cc |
| 56 | +@@ -850,16 +850,15 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) { |
| 57 | + host_defined_options->Set( |
| 58 | + isolate, loader::HostDefinedOptions::kID, id_symbol); |
| 59 | + |
| 60 | +- ScriptOrigin origin(isolate, |
| 61 | +- filename, |
| 62 | +- line_offset, // line offset |
| 63 | +- column_offset, // column offset |
| 64 | +- true, // is cross origin |
| 65 | +- -1, // script id |
| 66 | +- Local<Value>(), // source map URL |
| 67 | +- false, // is opaque (?) |
| 68 | +- false, // is WASM |
| 69 | +- false, // is ES Module |
| 70 | ++ ScriptOrigin origin(filename, |
| 71 | ++ line_offset, // line offset |
| 72 | ++ column_offset, // column offset |
| 73 | ++ true, // is cross origin |
| 74 | ++ -1, // script id |
| 75 | ++ Local<Value>(), // source map URL |
| 76 | ++ false, // is opaque (?) |
| 77 | ++ false, // is WASM |
| 78 | ++ false, // is ES Module |
| 79 | + host_defined_options); |
| 80 | + ScriptCompiler::Source source(code, origin, cached_data); |
| 81 | + ScriptCompiler::CompileOptions compile_options = |
| 82 | +@@ -971,7 +970,7 @@ MaybeLocal<Function> CompileFunction(Local<Context> context, |
| 83 | + Local<String> filename, |
| 84 | + Local<String> content, |
| 85 | + std::vector<Local<String>>* parameters) { |
| 86 | +- ScriptOrigin script_origin(context->GetIsolate(), filename, 0, 0, true); |
| 87 | ++ ScriptOrigin script_origin(filename, 0, 0, true); |
| 88 | + ScriptCompiler::Source script_source(content, script_origin); |
| 89 | + |
| 90 | + return ScriptCompiler::CompileFunction(context, |
| 91 | +@@ -1081,7 +1080,6 @@ bool ContextifyScript::EvalMachine(Local<Context> context, |
| 92 | + } |
| 93 | + |
| 94 | + TryCatchScope try_catch(env); |
| 95 | +- Isolate::SafeForTerminationScope safe_for_termination(env->isolate()); |
| 96 | + ContextifyScript* wrapped_script; |
| 97 | + ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.Holder(), false); |
| 98 | + Local<UnboundScript> unbound_script = |
| 99 | +@@ -1244,8 +1242,7 @@ void ContextifyContext::CompileFunction( |
| 100 | + Local<PrimitiveArray> host_defined_options = |
| 101 | + GetHostDefinedOptions(isolate, id_symbol); |
| 102 | + ScriptCompiler::Source source = |
| 103 | +- GetCommonJSSourceInstance(isolate, |
| 104 | +- code, |
| 105 | ++ GetCommonJSSourceInstance(code, |
| 106 | + filename, |
| 107 | + line_offset, |
| 108 | + column_offset, |
| 109 | +@@ -1300,15 +1297,13 @@ void ContextifyContext::CompileFunction( |
| 110 | + } |
| 111 | + |
| 112 | + ScriptCompiler::Source ContextifyContext::GetCommonJSSourceInstance( |
| 113 | +- Isolate* isolate, |
| 114 | + Local<String> code, |
| 115 | + Local<String> filename, |
| 116 | + int line_offset, |
| 117 | + int column_offset, |
| 118 | + Local<PrimitiveArray> host_defined_options, |
| 119 | + ScriptCompiler::CachedData* cached_data) { |
| 120 | +- ScriptOrigin origin(isolate, |
| 121 | +- filename, |
| 122 | ++ ScriptOrigin origin(filename, |
| 123 | + line_offset, // line offset |
| 124 | + column_offset, // column offset |
| 125 | + true, // is cross origin |
| 126 | +@@ -1486,7 +1481,7 @@ void ContextifyContext::ContainsModuleSyntax( |
| 127 | + Local<PrimitiveArray> host_defined_options = |
| 128 | + GetHostDefinedOptions(isolate, id_symbol); |
| 129 | + ScriptCompiler::Source source = GetCommonJSSourceInstance( |
| 130 | +- isolate, code, filename, 0, 0, host_defined_options, nullptr); |
| 131 | ++ code, filename, 0, 0, host_defined_options, nullptr); |
| 132 | + ScriptCompiler::CompileOptions options = GetCompileOptions(source); |
| 133 | + |
| 134 | + std::vector<Local<String>> params = GetCJSParameters(env->isolate_data()); |
| 135 | +@@ -1534,7 +1529,7 @@ void ContextifyContext::ContainsModuleSyntax( |
| 136 | + code, |
| 137 | + String::NewFromUtf8(isolate, "})();").ToLocalChecked()); |
| 138 | + ScriptCompiler::Source wrapped_source = GetCommonJSSourceInstance( |
| 139 | +- isolate, code, filename, 0, 0, host_defined_options, nullptr); |
| 140 | ++ code, filename, 0, 0, host_defined_options, nullptr); |
| 141 | + std::ignore = ScriptCompiler::CompileFunction( |
| 142 | + context, |
| 143 | + &wrapped_source, |
| 144 | +@@ -1587,8 +1582,7 @@ static void CompileFunctionForCJSLoader( |
| 145 | + |
| 146 | + Local<Symbol> symbol = env->vm_dynamic_import_default_internal(); |
| 147 | + Local<PrimitiveArray> hdo = GetHostDefinedOptions(isolate, symbol); |
| 148 | +- ScriptOrigin origin(isolate, |
| 149 | +- filename, |
| 150 | ++ ScriptOrigin origin(filename, |
| 151 | + 0, // line offset |
| 152 | + 0, // column offset |
| 153 | + true, // is cross origin |
| 154 | +diff --git a/src/node_contextify.h b/src/node_contextify.h |
| 155 | +index e96df803b7ec2aa1231d4ab5d4ae0fe863ceb672..d42b5e0c544e726fc3f6d8392a554df9aa480fe9 100644 |
| 156 | +--- a/src/node_contextify.h |
| 157 | ++++ b/src/node_contextify.h |
| 158 | +@@ -95,7 +95,6 @@ class ContextifyContext : public BaseObject { |
| 159 | + v8::Local<v8::Symbol> id_symbol, |
| 160 | + const errors::TryCatchScope& try_catch); |
| 161 | + static v8::ScriptCompiler::Source GetCommonJSSourceInstance( |
| 162 | +- v8::Isolate* isolate, |
| 163 | + v8::Local<v8::String> code, |
| 164 | + v8::Local<v8::String> filename, |
| 165 | + int line_offset, |
| 166 | +diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc |
| 167 | +index 64e38c83006a004ebc3519a5e9f8b04263244514..14e82cc80ff73084fb43b2ef07febfd2667a0abc 100644 |
| 168 | +--- a/test/cctest/test_environment.cc |
| 169 | ++++ b/test/cctest/test_environment.cc |
| 170 | +@@ -620,12 +620,9 @@ TEST_F(EnvironmentTest, SetImmediateMicrotasks) { |
| 171 | + |
| 172 | + #ifndef _WIN32 // No SIGINT on Windows. |
| 173 | + TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) { |
| 174 | +- // We need to go through the whole setup dance here because we want to |
| 175 | +- // set only_terminate_in_safe_scope. |
| 176 | + // Allocate and initialize Isolate. |
| 177 | + v8::Isolate::CreateParams create_params; |
| 178 | + create_params.array_buffer_allocator = allocator.get(); |
| 179 | +- create_params.only_terminate_in_safe_scope = true; |
| 180 | + v8::Isolate* isolate = v8::Isolate::Allocate(); |
| 181 | + CHECK_NOT_NULL(isolate); |
| 182 | + platform->RegisterIsolate(isolate, ¤t_loop); |
0 commit comments