Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fb24c44

Browse filesBrowse files
anonrigtargos
authored andcommitted
src: rewrite task runner in c++
PR-URL: #52609 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent f5d9257 commit fb24c44
Copy full SHA for fb24c44

File tree

Expand file treeCollapse file tree

15 files changed

+404
-189
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

15 files changed

+404
-189
lines changed
Open diff view settings
Collapse file

‎lib/internal/main/run.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/run.js
-74Lines changed: 0 additions & 74 deletions
This file was deleted.
Collapse file

‎lib/internal/shell.js‎

Copy file name to clipboardExpand all lines: lib/internal/shell.js
-37Lines changed: 0 additions & 37 deletions
This file was deleted.
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
'src/node_stat_watcher.cc',
137137
'src/node_symbols.cc',
138138
'src/node_task_queue.cc',
139+
'src/node_task_runner.cc',
139140
'src/node_trace_events.cc',
140141
'src/node_types.cc',
141142
'src/node_url.cc',
@@ -397,6 +398,7 @@
397398
'test/cctest/test_base_object_ptr.cc',
398399
'test/cctest/test_cppgc.cc',
399400
'test/cctest/test_node_postmortem_metadata.cc',
401+
'test/cctest/test_node_task_runner.cc',
400402
'test/cctest/test_environment.cc',
401403
'test/cctest/test_linked_binding.cc',
402404
'test/cctest/test_node_api.cc',
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+21-8Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "node.h"
2323
#include "node_dotenv.h"
24+
#include "node_task_runner.h"
2425

2526
// ========== local headers ==========
2627

@@ -409,10 +410,6 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
409410
return StartExecution(env, "internal/main/watch_mode");
410411
}
411412

412-
if (!env->options()->run.empty()) {
413-
return StartExecution(env, "internal/main/run");
414-
}
415-
416413
if (!first_argv.empty() && first_argv != "-") {
417414
return StartExecution(env, "internal/main/run_main_module");
418415
}
@@ -1025,11 +1022,11 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
10251022
InitializeNodeWithArgsInternal(argv, exec_argv, errors, flags));
10261023
}
10271024

1028-
static std::unique_ptr<InitializationResultImpl>
1025+
static std::shared_ptr<InitializationResultImpl>
10291026
InitializeOncePerProcessInternal(const std::vector<std::string>& args,
10301027
ProcessInitializationFlags::Flags flags =
10311028
ProcessInitializationFlags::kNoFlags) {
1032-
auto result = std::make_unique<InitializationResultImpl>();
1029+
auto result = std::make_shared<InitializationResultImpl>();
10331030
result->args_ = args;
10341031

10351032
if (!(flags & ProcessInitializationFlags::kNoParseGlobalDebugVariables)) {
@@ -1059,6 +1056,22 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
10591056
}
10601057
}
10611058

1059+
if (!per_process::cli_options->run.empty()) {
1060+
// TODO(@anonrig): Handle NODE_NO_WARNINGS, NODE_REDIRECT_WARNINGS,
1061+
// --disable-warning and --redirect-warnings.
1062+
if (per_process::cli_options->per_isolate->per_env->warnings) {
1063+
fprintf(stderr,
1064+
"ExperimentalWarning: Task runner is an experimental feature and "
1065+
"might change at any time\n\n");
1066+
}
1067+
1068+
auto positional_args = task_runner::GetPositionalArgs(args);
1069+
result->early_return_ = true;
1070+
task_runner::RunTask(
1071+
result, per_process::cli_options->run, positional_args);
1072+
return result;
1073+
}
1074+
10621075
if (!(flags & ProcessInitializationFlags::kNoPrintHelpOrVersionOutput)) {
10631076
if (per_process::cli_options->print_version) {
10641077
printf("%s\n", NODE_VERSION);
@@ -1218,7 +1231,7 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
12181231
return result;
12191232
}
12201233

1221-
std::unique_ptr<InitializationResult> InitializeOncePerProcess(
1234+
std::shared_ptr<InitializationResult> InitializeOncePerProcess(
12221235
const std::vector<std::string>& args,
12231236
ProcessInitializationFlags::Flags flags) {
12241237
return InitializeOncePerProcessInternal(args, flags);
@@ -1424,7 +1437,7 @@ static ExitCode StartInternal(int argc, char** argv) {
14241437
// Hack around with the argv pointer. Used for process.title = "blah".
14251438
argv = uv_setup_args(argc, argv);
14261439

1427-
std::unique_ptr<InitializationResultImpl> result =
1440+
std::shared_ptr<InitializationResultImpl> result =
14281441
InitializeOncePerProcessInternal(
14291442
std::vector<std::string>(argv, argv + argc));
14301443
for (const std::string& error : result->errors()) {
Collapse file

‎src/node.h‎

Copy file name to clipboardExpand all lines: src/node.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ NODE_DEPRECATED("Use InitializeOncePerProcess() instead",
349349
// including the arguments split into argv/exec_argv, a list of potential
350350
// errors encountered during initialization, and a potential suggested
351351
// exit code.
352-
NODE_EXTERN std::unique_ptr<InitializationResult> InitializeOncePerProcess(
352+
NODE_EXTERN std::shared_ptr<InitializationResult> InitializeOncePerProcess(
353353
const std::vector<std::string>& args,
354354
ProcessInitializationFlags::Flags flags =
355355
ProcessInitializationFlags::kNoFlags);
@@ -358,7 +358,7 @@ NODE_EXTERN std::unique_ptr<InitializationResult> InitializeOncePerProcess(
358358
NODE_EXTERN void TearDownOncePerProcess();
359359
// Convenience overload for specifying multiple flags without having
360360
// to worry about casts.
361-
inline std::unique_ptr<InitializationResult> InitializeOncePerProcess(
361+
inline std::shared_ptr<InitializationResult> InitializeOncePerProcess(
362362
const std::vector<std::string>& args,
363363
std::initializer_list<ProcessInitializationFlags::Flags> list) {
364364
uint64_t flags_accum = ProcessInitializationFlags::kNoFlags;
Collapse file

‎src/node_modules.cc‎

Copy file name to clipboardExpand all lines: src/node_modules.cc
-24Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -367,28 +367,6 @@ void BindingData::GetNearestParentPackageJSONType(
367367
args.GetReturnValue().Set(Array::New(realm->isolate(), values, 3));
368368
}
369369

370-
void BindingData::GetPackageJSONScripts(
371-
const FunctionCallbackInfo<Value>& args) {
372-
Realm* realm = Realm::GetCurrent(args);
373-
std::string_view path = "package.json";
374-
375-
THROW_IF_INSUFFICIENT_PERMISSIONS(
376-
realm->env(), permission::PermissionScope::kFileSystemRead, path);
377-
378-
auto package_json = GetPackageJSON(realm, path);
379-
if (package_json == nullptr) {
380-
printf("Can't read package.json\n");
381-
return;
382-
} else if (!package_json->scripts.has_value()) {
383-
printf("Can't read package.json \"scripts\" object\n");
384-
return;
385-
}
386-
387-
args.GetReturnValue().Set(
388-
ToV8Value(realm->context(), package_json->scripts.value())
389-
.ToLocalChecked());
390-
}
391-
392370
void BindingData::GetPackageScopeConfig(
393371
const FunctionCallbackInfo<Value>& args) {
394372
CHECK_GE(args.Length(), 1);
@@ -469,7 +447,6 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data,
469447
"getNearestParentPackageJSON",
470448
GetNearestParentPackageJSON);
471449
SetMethod(isolate, target, "getPackageScopeConfig", GetPackageScopeConfig);
472-
SetMethod(isolate, target, "getPackageJSONScripts", GetPackageJSONScripts);
473450
}
474451

475452
void BindingData::CreatePerContextProperties(Local<Object> target,
@@ -486,7 +463,6 @@ void BindingData::RegisterExternalReferences(
486463
registry->Register(GetNearestParentPackageJSONType);
487464
registry->Register(GetNearestParentPackageJSON);
488465
registry->Register(GetPackageScopeConfig);
489-
registry->Register(GetPackageJSONScripts);
490466
}
491467

492468
} // namespace modules
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
578578
"process V8 profiler output generated using --prof",
579579
&EnvironmentOptions::prof_process);
580580
// Options after --prof-process are passed through to the prof processor.
581-
AddAlias("--prof-process", { "--prof-process", "--" });
582-
AddOption("--run",
583-
"Run a script specified in package.json",
584-
&EnvironmentOptions::run);
581+
AddAlias("--prof-process", {"--prof-process", "--"});
585582
#if HAVE_INSPECTOR
586583
AddOption("--cpu-prof",
587584
"Start the V8 CPU profiler on start up, and write the CPU profile "
@@ -1085,6 +1082,10 @@ PerProcessOptionsParser::PerProcessOptionsParser(
10851082
"Generate a blob that can be embedded into the single executable "
10861083
"application",
10871084
&PerProcessOptions::experimental_sea_config);
1085+
1086+
AddOption("--run",
1087+
"Run a script specified in package.json",
1088+
&PerProcessOptions::run);
10881089
}
10891090

10901091
inline std::string RemoveBrackets(const std::string& host) {
Collapse file

‎src/node_options.h‎

Copy file name to clipboardExpand all lines: src/node_options.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ class EnvironmentOptions : public Options {
162162
bool heap_prof = false;
163163
#endif // HAVE_INSPECTOR
164164
std::string redirect_warnings;
165-
std::string run;
166165
std::string diagnostic_dir;
167166
std::string env_file;
168167
bool has_env_file_string = false;
@@ -282,6 +281,7 @@ class PerProcessOptions : public Options {
282281
bool print_v8_help = false;
283282
bool print_version = false;
284283
std::string experimental_sea_config;
284+
std::string run;
285285

286286
#ifdef NODE_HAVE_I18N_SUPPORT
287287
std::string icu_data_dir;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.