Skip to content

Commit dfc288e

Browse files
addaleaxnodejs-github-bot
authored andcommitted
src: clean up embedder API
Remove deprecated APIs (and deprecate one legacy API). PR-URL: #35897 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 09af8c8 commit dfc288e

10 files changed

+17
-170
lines changed

src/api/environment.cc

+2-30
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,6 @@ void SetIsolateUpForNode(v8::Isolate* isolate) {
264264
SetIsolateUpForNode(isolate, settings);
265265
}
266266

267-
Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {
268-
return NewIsolate(allocator, event_loop, GetMainThreadMultiIsolatePlatform());
269-
}
270-
271267
// TODO(joyeecheung): we may want to expose this, but then we need to be
272268
// careful about what we override in the params.
273269
Isolate* NewIsolate(Isolate::CreateParams* params,
@@ -327,18 +323,6 @@ struct InspectorParentHandleImpl : public InspectorParentHandle {
327323
};
328324
#endif
329325

330-
Environment* CreateEnvironment(IsolateData* isolate_data,
331-
Local<Context> context,
332-
int argc,
333-
const char* const* argv,
334-
int exec_argc,
335-
const char* const* exec_argv) {
336-
return CreateEnvironment(
337-
isolate_data, context,
338-
std::vector<std::string>(argv, argv + argc),
339-
std::vector<std::string>(exec_argv, exec_argv + exec_argc));
340-
}
341-
342326
Environment* CreateEnvironment(
343327
IsolateData* isolate_data,
344328
Local<Context> context,
@@ -410,16 +394,9 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
410394
#endif
411395
}
412396

413-
void LoadEnvironment(Environment* env) {
414-
USE(LoadEnvironment(env,
415-
StartExecutionCallback{},
416-
{}));
417-
}
418-
419397
MaybeLocal<Value> LoadEnvironment(
420398
Environment* env,
421-
StartExecutionCallback cb,
422-
std::unique_ptr<InspectorParentHandle> removeme) {
399+
StartExecutionCallback cb) {
423400
env->InitializeLibuv();
424401
env->InitializeDiagnostics();
425402

@@ -428,8 +405,7 @@ MaybeLocal<Value> LoadEnvironment(
428405

429406
MaybeLocal<Value> LoadEnvironment(
430407
Environment* env,
431-
const char* main_script_source_utf8,
432-
std::unique_ptr<InspectorParentHandle> removeme) {
408+
const char* main_script_source_utf8) {
433409
CHECK_NOT_NULL(main_script_source_utf8);
434410
return LoadEnvironment(
435411
env,
@@ -460,10 +436,6 @@ Environment* GetCurrentEnvironment(Local<Context> context) {
460436
return Environment::GetCurrent(context);
461437
}
462438

463-
MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
464-
return per_process::v8_platform.Platform();
465-
}
466-
467439
MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env) {
468440
return GetMultiIsolatePlatform(env->isolate_data());
469441
}

src/api/hooks.cc

-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ void RunAtExit(Environment* env) {
2222
env->RunAtExitCallbacks();
2323
}
2424

25-
void AtExit(void (*cb)(void* arg), void* arg) {
26-
auto env = Environment::GetThreadLocalEnv();
27-
AtExit(env, cb, arg);
28-
}
29-
3025
void AtExit(Environment* env, void (*cb)(void* arg), void* arg) {
3126
CHECK_NOT_NULL(env);
3227
env->AtExit(cb, arg);

src/env-inl.h

-4
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,6 @@ inline T* Environment::AddBindingData(
383383
return item.get();
384384
}
385385

386-
inline Environment* Environment::GetThreadLocalEnv() {
387-
return static_cast<Environment*>(uv_key_get(&thread_local_env));
388-
}
389-
390386
inline v8::Isolate* Environment::isolate() const {
391387
return isolate_;
392388
}

src/env.cc

-10
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ void IsolateData::MemoryInfo(MemoryTracker* tracker) const {
227227
// TODO(joyeecheung): implement MemoryRetainer in the option classes.
228228
}
229229

230-
void InitThreadLocalOnce() {
231-
CHECK_EQ(0, uv_key_create(&Environment::thread_local_env));
232-
}
233-
234230
void TrackingTraceStateObserver::UpdateTraceCategoryState() {
235231
if (!env_->owns_process_state() || !env_->can_call_into_js()) {
236232
// Ideally, we’d have a consistent story that treats all threads/Environment
@@ -370,10 +366,6 @@ Environment::Environment(IsolateData* isolate_data,
370366
inspector_agent_ = std::make_unique<inspector::Agent>(this);
371367
#endif
372368

373-
static uv_once_t init_once = UV_ONCE_INIT;
374-
uv_once(&init_once, InitThreadLocalOnce);
375-
uv_key_set(&thread_local_env, this);
376-
377369
if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) {
378370
trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this);
379371
if (TracingController* tracing_controller = writer->GetTracingController())
@@ -1143,8 +1135,6 @@ void AsyncHooks::grow_async_ids_stack() {
11431135
async_ids_stack_.GetJSArray()).Check();
11441136
}
11451137

1146-
uv_key_t Environment::thread_local_env = {};
1147-
11481138
void Environment::Exit(int exit_code) {
11491139
if (options()->trace_exit) {
11501140
HandleScope handle_scope(isolate());

src/env.h

-3
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,6 @@ class Environment : public MemoryRetainer {
10081008
BaseObjectPtr<BaseObject>,
10091009
FastStringKey::Hash> BindingDataStore;
10101010

1011-
static uv_key_t thread_local_env;
1012-
static inline Environment* GetThreadLocalEnv();
1013-
10141011
// Create an Environment without initializing a main Context. Use
10151012
// InitializeMainContext() to initialize a main context for it.
10161013
Environment(IsolateData* isolate_data,

src/node.cc

-45
Original file line numberDiff line numberDiff line change
@@ -947,51 +947,6 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
947947
return 0;
948948
}
949949

950-
// TODO(addaleax): Deprecate and eventually remove this.
951-
void Init(int* argc,
952-
const char** argv,
953-
int* exec_argc,
954-
const char*** exec_argv) {
955-
std::vector<std::string> argv_(argv, argv + *argc); // NOLINT
956-
std::vector<std::string> exec_argv_;
957-
std::vector<std::string> errors;
958-
959-
// This (approximately) duplicates some logic that has been moved to
960-
// node::Start(), with the difference that here we explicitly call `exit()`.
961-
int exit_code = InitializeNodeWithArgs(&argv_, &exec_argv_, &errors);
962-
963-
for (const std::string& error : errors)
964-
fprintf(stderr, "%s: %s\n", argv_.at(0).c_str(), error.c_str());
965-
if (exit_code != 0) exit(exit_code);
966-
967-
if (per_process::cli_options->print_version) {
968-
printf("%s\n", NODE_VERSION);
969-
exit(0);
970-
}
971-
972-
if (per_process::cli_options->print_bash_completion) {
973-
std::string completion = options_parser::GetBashCompletion();
974-
printf("%s\n", completion.c_str());
975-
exit(0);
976-
}
977-
978-
if (per_process::cli_options->print_v8_help) {
979-
V8::SetFlagsFromString("--help", static_cast<size_t>(6));
980-
exit(0);
981-
}
982-
983-
*argc = argv_.size();
984-
*exec_argc = exec_argv_.size();
985-
// These leak memory, because, in the original code of this function, no
986-
// extra allocations were visible. This should be okay because this function
987-
// is only supposed to be called once per process, though.
988-
*exec_argv = Malloc<const char*>(*exec_argc);
989-
for (int i = 0; i < *exec_argc; ++i)
990-
(*exec_argv)[i] = strdup(exec_argv_[i].c_str());
991-
for (int i = 0; i < *argc; ++i)
992-
argv[i] = strdup(argv_[i].c_str());
993-
}
994-
995950
InitializationResult InitializeOncePerProcess(int argc, char** argv) {
996951
// Initialized the enabled list for Debug() calls with system
997952
// environment variables.

src/node.h

+7-55
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,6 @@ NODE_EXTERN int Start(int argc, char* argv[]);
222222
// in the loop and / or actively executing JavaScript code).
223223
NODE_EXTERN int Stop(Environment* env);
224224

225-
// It is recommended to use InitializeNodeWithArgs() instead as an embedder.
226-
// Init() calls InitializeNodeWithArgs() and exits the process with the exit
227-
// code returned from it.
228-
NODE_DEPRECATED("Use InitializeNodeWithArgs() instead",
229-
NODE_EXTERN void Init(int* argc,
230-
const char** argv,
231-
int* exec_argc,
232-
const char*** exec_argv));
233225
// Set up per-process state needed to run Node.js. This will consume arguments
234226
// from argv, fill exec_argv, and possibly add errors resulting from parsing
235227
// the arguments to `errors`. The return value is a suggested exit code for the
@@ -357,11 +349,9 @@ NODE_EXTERN void SetIsolateUpForNode(v8::Isolate* isolate);
357349
// This is a convenience method equivalent to using SetIsolateCreateParams(),
358350
// Isolate::Allocate(), MultiIsolatePlatform::RegisterIsolate(),
359351
// Isolate::Initialize(), and SetIsolateUpForNode().
360-
NODE_EXTERN v8::Isolate* NewIsolate(ArrayBufferAllocator* allocator,
361-
struct uv_loop_s* event_loop);
362352
NODE_EXTERN v8::Isolate* NewIsolate(ArrayBufferAllocator* allocator,
363353
struct uv_loop_s* event_loop,
364-
MultiIsolatePlatform* platform);
354+
MultiIsolatePlatform* platform = nullptr);
365355
NODE_EXTERN v8::Isolate* NewIsolate(
366356
std::shared_ptr<ArrayBufferAllocator> allocator,
367357
struct uv_loop_s* event_loop,
@@ -422,14 +412,6 @@ struct InspectorParentHandle {
422412
// TODO(addaleax): Maybe move per-Environment options parsing here.
423413
// Returns nullptr when the Environment cannot be created e.g. there are
424414
// pending JavaScript exceptions.
425-
// It is recommended to use the second variant taking a flags argument.
426-
NODE_DEPRECATED("Use overload taking a flags argument",
427-
NODE_EXTERN Environment* CreateEnvironment(IsolateData* isolate_data,
428-
v8::Local<v8::Context> context,
429-
int argc,
430-
const char* const* argv,
431-
int exec_argc,
432-
const char* const* exec_argv));
433415
NODE_EXTERN Environment* CreateEnvironment(
434416
IsolateData* isolate_data,
435417
v8::Local<v8::Context> context,
@@ -459,18 +441,12 @@ struct StartExecutionCallbackInfo {
459441
using StartExecutionCallback =
460442
std::function<v8::MaybeLocal<v8::Value>(const StartExecutionCallbackInfo&)>;
461443

462-
NODE_DEPRECATED("Use variants returning MaybeLocal<> instead",
463-
NODE_EXTERN void LoadEnvironment(Environment* env));
464-
// The `InspectorParentHandle` arguments here are ignored and not used.
465-
// For passing `InspectorParentHandle`, use `CreateEnvironment()`.
466444
NODE_EXTERN v8::MaybeLocal<v8::Value> LoadEnvironment(
467445
Environment* env,
468-
StartExecutionCallback cb,
469-
std::unique_ptr<InspectorParentHandle> ignored_donotuse_removeme = {});
446+
StartExecutionCallback cb);
470447
NODE_EXTERN v8::MaybeLocal<v8::Value> LoadEnvironment(
471448
Environment* env,
472-
const char* main_script_source_utf8,
473-
std::unique_ptr<InspectorParentHandle> ignored_donotuse_removeme = {});
449+
const char* main_script_source_utf8);
474450
NODE_EXTERN void FreeEnvironment(Environment* env);
475451

476452
// Set a callback that is called when process.exit() is called from JS,
@@ -498,25 +474,17 @@ NODE_EXTERN v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(
498474
v8::Local<v8::Value> exception,
499475
v8::Local<v8::Array> trace);
500476

501-
// This returns the MultiIsolatePlatform used in the main thread of Node.js.
502-
// If NODE_USE_V8_PLATFORM has not been defined when Node.js was built,
503-
// it returns nullptr.
504-
NODE_DEPRECATED("Use GetMultiIsolatePlatform(env) instead",
505-
NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform());
506477
// This returns the MultiIsolatePlatform used for an Environment or IsolateData
507478
// instance, if one exists.
508479
NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env);
509480
NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env);
510481

511-
// Legacy variants of MultiIsolatePlatform::Create().
512-
NODE_DEPRECATED("Use variant taking a v8::TracingController* pointer instead",
482+
NODE_DEPRECATED("Use MultiIsolatePlatform::Create() instead",
513483
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
514484
int thread_pool_size,
515-
node::tracing::TracingController* tracing_controller));
516-
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
517-
int thread_pool_size,
518-
v8::TracingController* tracing_controller);
519-
NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform);
485+
v8::TracingController* tracing_controller));
486+
NODE_DEPRECATED("Use MultiIsolatePlatform::Create() instead",
487+
NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform));
520488

521489
// Get/set the currently active tracing controller. Using CreatePlatform()
522490
// will implicitly set this by default. This is global and should be initialized
@@ -920,29 +888,13 @@ NODE_EXTERN void AddLinkedBinding(Environment* env,
920888
addon_context_register_func fn,
921889
void* priv);
922890

923-
/* Called after the event loop exits but before the VM is disposed.
924-
* Callbacks are run in reverse order of registration, i.e. newest first.
925-
*
926-
* You should always use the three-argument variant (or, for addons,
927-
* AddEnvironmentCleanupHook) in order to avoid relying on global state.
928-
*/
929-
NODE_DEPRECATED(
930-
"Use the three-argument variant of AtExit() or AddEnvironmentCleanupHook()",
931-
NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = nullptr));
932-
933891
/* Registers a callback with the passed-in Environment instance. The callback
934892
* is called after the event loop exits, but before the VM is disposed.
935893
* Callbacks are run in reverse order of registration, i.e. newest first.
936894
*/
937895
NODE_EXTERN void AtExit(Environment* env,
938896
void (*cb)(void* arg),
939897
void* arg);
940-
NODE_DEPRECATED(
941-
"Use the three-argument variant of AtExit() or AddEnvironmentCleanupHook()",
942-
inline void AtExit(Environment* env,
943-
void (*cb)(void* arg)) {
944-
AtExit(env, cb, nullptr);
945-
})
946898

947899
typedef double async_id;
948900
struct async_context {

src/node_main_instance.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) {
139139
Context::Scope context_scope(env->context());
140140

141141
if (exit_code == 0) {
142-
LoadEnvironment(env.get());
142+
LoadEnvironment(env.get(), StartExecutionCallback{});
143143

144144
exit_code = SpinEventLoop(env.get()).FromMaybe(1);
145145
}

test/cctest/test_environment.cc

+5-15
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,7 @@ TEST_F(EnvironmentTest, AtExitWithEnvironment) {
182182
const Argv argv;
183183
Env env {handle_scope, argv};
184184

185-
AtExit(*env, at_exit_callback1);
186-
RunAtExit(*env);
187-
EXPECT_TRUE(called_cb_1);
188-
}
189-
190-
TEST_F(EnvironmentTest, AtExitWithoutEnvironment) {
191-
const v8::HandleScope handle_scope(isolate_);
192-
const Argv argv;
193-
Env env {handle_scope, argv};
194-
195-
AtExit(at_exit_callback1); // No Environment is passed to AtExit.
185+
AtExit(*env, at_exit_callback1, nullptr);
196186
RunAtExit(*env);
197187
EXPECT_TRUE(called_cb_1);
198188
}
@@ -203,8 +193,8 @@ TEST_F(EnvironmentTest, AtExitOrder) {
203193
Env env {handle_scope, argv};
204194

205195
// Test that callbacks are run in reverse order.
206-
AtExit(*env, at_exit_callback_ordered1);
207-
AtExit(*env, at_exit_callback_ordered2);
196+
AtExit(*env, at_exit_callback_ordered1, nullptr);
197+
AtExit(*env, at_exit_callback_ordered2, nullptr);
208198
RunAtExit(*env);
209199
EXPECT_TRUE(called_cb_ordered_1);
210200
EXPECT_TRUE(called_cb_ordered_2);
@@ -239,8 +229,8 @@ TEST_F(EnvironmentTest, MultipleEnvironmentsPerIsolate) {
239229
Env env1 {handle_scope, argv};
240230
Env env2 {handle_scope, argv, node::EnvironmentFlags::kNoFlags};
241231

242-
AtExit(*env1, at_exit_callback1);
243-
AtExit(*env2, at_exit_callback2);
232+
AtExit(*env1, at_exit_callback1, nullptr);
233+
AtExit(*env2, at_exit_callback2, nullptr);
244234
RunAtExit(*env1);
245235
EXPECT_TRUE(called_cb_1);
246236
EXPECT_FALSE(called_cb_2);

test/cctest/test_platform.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ TEST_F(NodeZeroIsolateTestFixture, IsolatePlatformDelegateTest) {
9393
std::unique_ptr<node::Environment, decltype(&node::FreeEnvironment)>
9494
environment{node::CreateEnvironment(isolate_data.get(),
9595
context,
96-
0, nullptr,
97-
0, nullptr),
96+
{},
97+
{}),
9898
node::FreeEnvironment};
9999
CHECK(environment);
100100
}

0 commit comments

Comments
 (0)