@@ -263,21 +263,6 @@ inline v8impl::Persistent<v8::Value>* NodePersistentFromJsDeferred(
263
263
return reinterpret_cast <v8impl::Persistent<v8::Value>*>(local);
264
264
}
265
265
266
- struct PlatformWrapper {
267
- explicit PlatformWrapper (int argc,
268
- char ** argv,
269
- int exec_argc,
270
- char ** exec_argv,
271
- int32_t _api_version)
272
- : args(argv, argv + argc),
273
- exec_args(exec_argv, exec_argv + exec_argc),
274
- api_version(_api_version) {}
275
- std::unique_ptr<node::MultiIsolatePlatform> platform;
276
- std::vector<std::string> args;
277
- std::vector<std::string> exec_args;
278
- int32_t api_version;
279
- };
280
-
281
266
class EmbeddedEnvironment : public node ::EmbeddedEnvironment {
282
267
public:
283
268
explicit EmbeddedEnvironment (
@@ -988,49 +973,48 @@ napi_status NAPI_CDECL napi_get_last_error_info(
988
973
}
989
974
990
975
napi_status NAPI_CDECL
991
- napi_create_platform_version (int argc,
992
- char ** argv,
993
- int exec_argc,
994
- char ** exec_argv,
995
- napi_error_message_handler err_handler,
996
- napi_platform* result,
997
- int32_t api_version) {
976
+ napi_create_platform (int argc,
977
+ char ** argv,
978
+ napi_error_message_handler err_handler,
979
+ napi_platform* result) {
998
980
argv = uv_setup_args (argc, argv);
999
- std::vector<std::string> errors_vec;
1000
-
1001
- v8impl::PlatformWrapper* platform = new v8impl::PlatformWrapper (
1002
- argc, argv, exec_argc, exec_argv, api_version);
1003
- if (platform->args .size () < 1 ) platform->args .push_back (" libnode" );
981
+ std::vector<std::string> args (argv, argv + argc);
982
+ if (args.size () < 1 ) args.push_back (" libnode" );
1004
983
1005
- int exit_code = node::InitializeNodeWithArgs (
1006
- &platform->args , &platform->exec_args , &errors_vec);
984
+ std::unique_ptr<node::InitializationResult> node_platform =
985
+ node::InitializeOncePerProcess (
986
+ args,
987
+ {node::ProcessInitializationFlags::kNoInitializeV8 ,
988
+ node::ProcessInitializationFlags::kNoInitializeNodeV8Platform });
1007
989
1008
- for (const std::string& error : errors_vec ) {
990
+ for (const std::string& error : node_platform-> errors () ) {
1009
991
if (err_handler != nullptr ) {
1010
992
err_handler (error.c_str ());
1011
993
} else {
1012
994
fprintf (stderr, " %s\n " , error.c_str ());
1013
995
}
1014
996
}
1015
-
1016
- if (exit_code != 0 ) {
997
+ if (node_platform->early_return () != 0 ) {
1017
998
return napi_generic_failure;
1018
999
}
1019
1000
1020
1001
auto thread_pool_size = node::per_process::cli_options->v8_thread_pool_size ;
1021
- platform->platform = node::MultiIsolatePlatform::Create (thread_pool_size);
1022
- v8::V8::InitializePlatform (platform->platform .get ());
1002
+ std::unique_ptr<node::MultiIsolatePlatform> v8_platform =
1003
+ node::MultiIsolatePlatform::Create (thread_pool_size);
1004
+ v8::V8::InitializePlatform (v8_platform.get ());
1023
1005
v8::V8::Initialize ();
1024
- *result = reinterpret_cast <napi_platform>(platform);
1006
+ reinterpret_cast <node::InitializationResultImpl*>(node_platform.get ())
1007
+ ->platform_ = v8_platform.release ();
1008
+ *result = reinterpret_cast <napi_platform>(node_platform.release ());
1025
1009
return napi_ok;
1026
1010
}
1027
1011
1028
1012
napi_status NAPI_CDECL napi_destroy_platform (napi_platform platform) {
1029
- auto wrapper = reinterpret_cast <v8impl::PlatformWrapper *>(platform);
1013
+ auto wrapper = reinterpret_cast <node::InitializationResult *>(platform);
1030
1014
v8::V8::Dispose ();
1031
1015
v8::V8::DisposePlatform ();
1032
-
1033
- // The node::CommonEnvironmentSetup::Create uniq_ptr is destroyed here
1016
+ node::TearDownOncePerProcess ();
1017
+ delete wrapper-> platform ();
1034
1018
delete wrapper;
1035
1019
return napi_ok;
1036
1020
}
@@ -1039,12 +1023,13 @@ napi_status NAPI_CDECL
1039
1023
napi_create_environment (napi_platform platform,
1040
1024
napi_error_message_handler err_handler,
1041
1025
const char * main_script,
1026
+ int32_t api_version,
1042
1027
napi_env* result) {
1043
- auto wrapper = reinterpret_cast <v8impl::PlatformWrapper *>(platform);
1028
+ auto wrapper = reinterpret_cast <node::InitializationResult *>(platform);
1044
1029
std::vector<std::string> errors_vec;
1045
1030
1046
1031
auto setup = node::CommonEnvironmentSetup::Create (
1047
- wrapper->platform . get (), &errors_vec, wrapper->args , wrapper->exec_args );
1032
+ wrapper->platform (), &errors_vec, wrapper->args () , wrapper->exec_args () );
1048
1033
1049
1034
for (const std::string& error : errors_vec) {
1050
1035
if (err_handler != nullptr ) {
@@ -1076,9 +1061,9 @@ napi_create_environment(napi_platform platform,
1076
1061
new v8impl::EmbeddedEnvironment (std::move (setup), main_resource);
1077
1062
1078
1063
std::string filename =
1079
- wrapper->args .size () > 1 ? wrapper->args [1 ] : " <internal>" ;
1080
- auto env__ = new node_napi_env__ (
1081
- emb_env->setup ()->context (), filename, wrapper-> api_version );
1064
+ wrapper->args () .size () > 1 ? wrapper->args () [1 ] : " <internal>" ;
1065
+ auto env__ =
1066
+ new node_napi_env__ ( emb_env->setup ()->context (), filename, api_version);
1082
1067
emb_env->setup ()->env ()->set_embedded (emb_env);
1083
1068
env__->node_env ()->AddCleanupHook (
1084
1069
[](void * arg) { static_cast <napi_env>(arg)->Unref (); },
@@ -1128,6 +1113,8 @@ napi_status NAPI_CDECL napi_destroy_environment(napi_env env, int* exit_code) {
1128
1113
// and the v8::locker
1129
1114
delete emb_env;
1130
1115
1116
+ cppgc::ShutdownProcess ();
1117
+
1131
1118
return napi_ok;
1132
1119
}
1133
1120
0 commit comments