Skip to content

Commit

Permalink
platform flags to match process init flags
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoroz committed Sep 4, 2024
1 parent 3fb3e2b commit 9b60f91
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 deletions.
43 changes: 20 additions & 23 deletions src/node_api_embedding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,45 +224,42 @@ std::vector<const char*> ToCStringVector(const std::vector<std::string>& vec) {
node::ProcessInitializationFlags::Flags GetProcessInitializationFlags(
node_api_platform_flags flags) {
uint32_t result = node::ProcessInitializationFlags::kNoFlags;
if ((flags & node_api_platform_enable_env_var) == 0) {
// Disable reading the NODE_OPTIONS environment variable.
if ((flags & node_api_platform_enable_stdio_inheritance) != 0) {
result |= node::ProcessInitializationFlags::kEnableStdioInheritance;
}
if ((flags & node_api_platform_disable_node_options_env) != 0) {
result |= node::ProcessInitializationFlags::kDisableNodeOptionsEnv;
}
if ((flags & node_api_platform_init_icu) == 0) {
// Do not initialize ICU.
if ((flags & node_api_platform_disable_cli_options) != 0) {
result |= node::ProcessInitializationFlags::kDisableCLIOptions;
}
if ((flags & node_api_platform_no_icu) != 0) {
result |= node::ProcessInitializationFlags::kNoICU;
}
// Do not modify stdio file descriptor or TTY state.
result |= node::ProcessInitializationFlags::kNoStdioInitialization;
// Do not register Node.js-specific signal handlers
// and reset other signal handlers to default state.
result |= node::ProcessInitializationFlags::kNoDefaultSignalHandling;
// Do not perform V8 initialization.
if ((flags & node_api_platform_no_stdio_initialization) != 0) {
result |= node::ProcessInitializationFlags::kNoStdioInitialization;
}
if ((flags & node_api_platform_no_default_signal_handling) != 0) {
result |= node::ProcessInitializationFlags::kNoDefaultSignalHandling;
}
result |= node::ProcessInitializationFlags::kNoInitializeV8;
// Do not initialize a default Node.js-provided V8 platform instance.
result |= node::ProcessInitializationFlags::kNoInitializeNodeV8Platform;
if ((flags & node_api_platform_init_openssl) == 0) {
// Do not initialize OpenSSL config.
if ((flags & node_api_platform_no_init_openssl) != 0) {
result |= node::ProcessInitializationFlags::kNoInitOpenSSL;
}
if ((flags & node_api_platform_parse_global_debug_vars) == 0) {
// Do not initialize Node.js debugging based on environment variables.
if ((flags & node_api_platform_no_parse_global_debug_variables) != 0) {
result |= node::ProcessInitializationFlags::kNoParseGlobalDebugVariables;
}
if ((flags & node_api_platform_adjust_resource_limits) == 0) {
// Do not adjust OS resource limits for this process.
if ((flags & node_api_platform_no_adjust_resource_limits) != 0) {
result |= node::ProcessInitializationFlags::kNoAdjustResourceLimits;
}
if ((flags & node_api_platform_no_large_pages) != 0) {
// Do not map code segments into large pages for this process.
if ((flags & node_api_platform_no_use_large_pages) != 0) {
result |= node::ProcessInitializationFlags::kNoUseLargePages;
}
if ((flags & node_api_platform_print_help_or_version) == 0) {
// Skip printing output for --help, --version, --v8-options.
if ((flags & node_api_platform_no_print_help_or_version_output) != 0) {
result |= node::ProcessInitializationFlags::kNoPrintHelpOrVersionOutput;
}
if ((flags & node_api_platform_generate_predictable_snapshot) == 0) {
// Initialize the process for predictable snapshot generation.
if ((flags & node_api_platform_generate_predictable_snapshot) != 0) {
result |= node::ProcessInitializationFlags::kGeneratePredictableSnapshot;
}
return static_cast<node::ProcessInitializationFlags::Flags>(result);
Expand Down
39 changes: 24 additions & 15 deletions src/node_api_embedding.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@ typedef struct node_api_env_options__* node_api_env_options;

typedef enum {
node_api_platform_no_flags = 0,
// Enable reading the NODE_OPTIONS environment variable.
node_api_platform_enable_env_var = 1 << 0,
// Initialize ICU.
node_api_platform_init_icu = 1 << 1,
// Initialize OpenSSL config.
node_api_platform_init_openssl = 1 << 2,
// Initialize Node.js debugging based on environment variables.
node_api_platform_parse_global_debug_vars = 1 << 3,
// Adjust OS resource limits for this process.
node_api_platform_adjust_resource_limits = 1 << 4,
// Enable stdio inheritance, which is disabled by default.
// This flag is also implied by node_api_platform_no_stdio_initialization.
node_api_platform_enable_stdio_inheritance = 1 << 0,
// Disable reading the NODE_OPTIONS environment variable.
node_api_platform_disable_node_options_env = 1 << 1,
// Do not parse CLI options.
node_api_platform_disable_cli_options = 1 << 2,
// Do not initialize ICU.
node_api_platform_no_icu = 1 << 3,
// Do not modify stdio file descriptor or TTY state.
node_api_platform_no_stdio_initialization = 1 << 4,
// Do not register Node.js-specific signal handlers
// and reset other signal handlers to default state.
node_api_platform_no_default_signal_handling = 1 << 5,
// Do not initialize OpenSSL config.
node_api_platform_no_init_openssl = 1 << 8,
// Do not initialize Node.js debugging based on environment variables.
node_api_platform_no_parse_global_debug_variables = 1 << 9,
// Do not adjust OS resource limits for this process.
node_api_platform_no_adjust_resource_limits = 1 << 10,
// Do not map code segments into large pages for this process.
node_api_platform_no_large_pages = 1 << 5,
// Allow printing output for --help, --version, --v8-options.
node_api_platform_print_help_or_version = 1 << 6,
node_api_platform_no_use_large_pages = 1 << 11,
// Skip printing output for --help, --version, --v8-options.
node_api_platform_no_print_help_or_version_output = 1 << 12,
// Initialize the process for predictable snapshot generation.
node_api_platform_generate_predictable_snapshot = 1 << 7,
node_api_platform_generate_predictable_snapshot = 1 << 14,
} node_api_platform_flags;

typedef enum {
Expand Down Expand Up @@ -122,7 +132,6 @@ EXTERN_C_END

#endif // SRC_NODE_API_EMBEDDING_H_

// TODO: (vmoroz) Match node_api_platform_flags to the existing Node.js flags.
// TODO: (vmoroz) Remove the main_script parameter.
// TODO: (vmoroz) Add startup callback with process and require parameters.
// TODO: (vmoroz) Add ABI-safe way to access internal module functionality.
Expand Down
2 changes: 1 addition & 1 deletion test/embedding/embedtest_node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" int32_t test_main_node_api(int32_t argc, char* argv[]) {
int32_t exit_code = 0;
node_api_initialize_platform(argc,
argv,
node_api_platform_no_flags,
node_api_platform_disable_node_options_env,
get_errors,
NULL,
&early_return,
Expand Down
2 changes: 1 addition & 1 deletion test/embedding/embedtest_snapshot_node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" int32_t test_main_snapshot_node_api(int32_t argc, char* argv[]) {
std::vector<std::string> errors;
node_api_initialize_platform(argc,
argv,
node_api_platform_no_flags,
node_api_platform_disable_node_options_env,
GetMessageVector,
&errors,
&early_return,
Expand Down

0 comments on commit 9b60f91

Please sign in to comment.