From a645f829f4fd3e0810fbf23d3f6debbde9a96cfc Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Thu, 9 Aug 2018 18:51:56 -0400 Subject: [PATCH 1/2] src: add READONLY_STRING_PROPERTY and simplify config Bit of tidying up where we set different config values.. --- src/node_config.cc | 70 +++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/src/node_config.cc b/src/node_config.cc index dd5ee666486874..00a1832db516d4 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -29,6 +29,18 @@ using v8::Value; True(isolate), ReadOnly).FromJust(); \ } while (0) +#define READONLY_STRING_PROPERTY(obj, str, val) \ + do { \ + obj->DefineOwnProperty(context, \ + FIXED_ONE_BYTE_STRING(isolate, str), \ + String::NewFromUtf8( \ + isolate, \ + val.data(), \ + v8::NewStringType::kNormal).ToLocalChecked(), \ + ReadOnly).FromJust(); \ + } while (0) + + #define READONLY_PROPERTY(obj, name, value) \ do { \ obj->DefineOwnProperty(env->context(), \ @@ -60,13 +72,7 @@ static void Initialize(Local target, READONLY_BOOLEAN_PROPERTY("hasTracing"); #endif - target->DefineOwnProperty( - context, - FIXED_ONE_BYTE_STRING(isolate, "icuDataDir"), - String::NewFromUtf8(isolate, - icu_data_dir.data(), - v8::NewStringType::kNormal).ToLocalChecked(), - ReadOnly).FromJust(); + READONLY_STRING_PROPERTY(target, "icuDataDir", icu_data_dir); #endif // NODE_HAVE_I18N_SUPPORT @@ -78,13 +84,7 @@ static void Initialize(Local target, if (config_experimental_modules) { READONLY_BOOLEAN_PROPERTY("experimentalModules"); if (!config_userland_loader.empty()) { - target->DefineOwnProperty( - context, - FIXED_ONE_BYTE_STRING(isolate, "userLoader"), - String::NewFromUtf8(isolate, - config_userland_loader.data(), - v8::NewStringType::kNormal).ToLocalChecked(), - ReadOnly).FromJust(); + READONLY_STRING_PROPERTY(target, "userLoader", config_userland_loader); } } @@ -111,41 +111,21 @@ static void Initialize(Local target, Number::New(env->isolate(), 8 * sizeof(intptr_t))); if (!config_warning_file.empty()) { - target->DefineOwnProperty( - context, - FIXED_ONE_BYTE_STRING(isolate, "warningFile"), - String::NewFromUtf8(isolate, - config_warning_file.data(), - v8::NewStringType::kNormal).ToLocalChecked(), - ReadOnly).FromJust(); + READONLY_STRING_PROPERTY(target, "warningFile", config_warning_file); } Local debugOptions = Object::New(isolate); + READONLY_PROPERTY(target, "debugOptions", debugOptions); + + READONLY_STRING_PROPERTY(debugOptions, "host", debug_options.host_name()); + + READONLY_PROPERTY(debugOptions, + "port", + Integer::New(isolate, debug_options.port())); - target->DefineOwnProperty( - context, - FIXED_ONE_BYTE_STRING(isolate, "debugOptions"), - debugOptions, ReadOnly).FromJust(); - - debugOptions->DefineOwnProperty( - context, - FIXED_ONE_BYTE_STRING(isolate, "host"), - String::NewFromUtf8(isolate, - debug_options.host_name().c_str(), - v8::NewStringType::kNormal).ToLocalChecked(), - ReadOnly).FromJust(); - - debugOptions->DefineOwnProperty( - context, - env->port_string(), - Integer::New(isolate, debug_options.port()), - ReadOnly).FromJust(); - - debugOptions->DefineOwnProperty( - context, - FIXED_ONE_BYTE_STRING(isolate, "inspectorEnabled"), - Boolean::New(isolate, debug_options.inspector_enabled()), ReadOnly) - .FromJust(); + READONLY_PROPERTY(debugOptions, + "inspectorEnabled", + Boolean::New(isolate, debug_options.inspector_enabled())); } // InitConfig } // namespace node From e562279949903132533789a3471ca4fb964fbbc1 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Thu, 9 Aug 2018 19:35:13 -0400 Subject: [PATCH 2/2] squash!: fixup @addaleax nits --- src/node_config.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/node_config.cc b/src/node_config.cc index 00a1832db516d4..62fd4ef81e093c 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -29,15 +29,15 @@ using v8::Value; True(isolate), ReadOnly).FromJust(); \ } while (0) -#define READONLY_STRING_PROPERTY(obj, str, val) \ - do { \ - obj->DefineOwnProperty(context, \ - FIXED_ONE_BYTE_STRING(isolate, str), \ - String::NewFromUtf8( \ - isolate, \ - val.data(), \ - v8::NewStringType::kNormal).ToLocalChecked(), \ - ReadOnly).FromJust(); \ +#define READONLY_STRING_PROPERTY(obj, str, val) \ + do { \ + (obj)->DefineOwnProperty(context, \ + FIXED_ONE_BYTE_STRING(isolate, str), \ + String::NewFromUtf8( \ + isolate, \ + val.data(), \ + v8::NewStringType::kNormal).ToLocalChecked(), \ + ReadOnly).FromJust(); \ } while (0)