Skip to content

Commit

Permalink
src: clean up PER_ISOLATE_STRING_PROPERTIES, v2
Browse files Browse the repository at this point in the history
Remove strings from the PER_ISOLATE_STRING_PROPERTIES list that are
only used once during initialization.  It's less expensive to simply
create them when needed than turn them into v8::Eternal instances.

PR-URL: #8207
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
bnoordhuis committed Aug 23, 2016
1 parent a129639 commit b4ea3a0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 50 deletions.
15 changes: 0 additions & 15 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ namespace node {
#define PER_ISOLATE_STRING_PROPERTIES(V) \
V(address_string, "address") \
V(args_string, "args") \
V(argv_string, "argv") \
V(async, "async") \
V(async_queue_string, "_asyncQueue") \
V(bytes_string, "bytes") \
Expand All @@ -82,8 +81,6 @@ namespace node {
V(onclose_string, "_onclose") \
V(code_string, "code") \
V(cwd_string, "cwd") \
V(debug_port_string, "debugPort") \
V(debug_string, "debug") \
V(dest_string, "dest") \
V(detached_string, "detached") \
V(disposed_string, "_disposed") \
Expand All @@ -99,8 +96,6 @@ namespace node {
V(errno_string, "errno") \
V(error_string, "error") \
V(events_string, "_events") \
V(exec_argv_string, "execArgv") \
V(exec_path_string, "execPath") \
V(exiting_string, "_exiting") \
V(exit_code_string, "exitCode") \
V(exit_string, "exit") \
Expand All @@ -115,7 +110,6 @@ namespace node {
V(file_string, "file") \
V(fingerprint_string, "fingerprint") \
V(flags_string, "flags") \
V(fsevent_string, "FSEvent") \
V(gid_string, "gid") \
V(handle_string, "handle") \
V(heap_total_string, "heapTotal") \
Expand All @@ -129,7 +123,6 @@ namespace node {
V(input_string, "input") \
V(internal_string, "internal") \
V(ipv4_string, "IPv4") \
V(ipv6_lc_string, "ipv6") \
V(ipv6_string, "IPv6") \
V(isalive_string, "isAlive") \
V(isclosing_string, "isClosing") \
Expand All @@ -143,7 +136,6 @@ namespace node {
V(model_string, "model") \
V(modulus_string, "modulus") \
V(name_string, "name") \
V(need_imm_cb_string, "_needImmediateCallback") \
V(netmask_string, "netmask") \
V(nice_string, "nice") \
V(nsname_string, "nsname") \
Expand Down Expand Up @@ -215,19 +207,12 @@ namespace node {
V(ticketkeycallback_string, "onticketkeycallback") \
V(timeout_string, "timeout") \
V(times_string, "times") \
V(title_string, "title") \
V(tls_npn_string, "tls_npn") \
V(tls_alpn_string, "tls_alpn") \
V(tls_ocsp_string, "tls_ocsp") \
V(tls_sni_string, "tls_sni") \
V(tls_string, "tls") \
V(tls_ticket_string, "tlsTicket") \
V(type_string, "type") \
V(uid_string, "uid") \
V(unknown_string, "<unknown>") \
V(user_string, "user") \
V(username_string, "username") \
V(uv_string, "uv") \
V(valid_from_string, "valid_from") \
V(valid_to_string, "valid_to") \
V(verify_error_string, "verifyError") \
Expand Down
5 changes: 3 additions & 2 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ void FSEventWrap::Initialize(Local<Object> target,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);

auto fsevent_string = FIXED_ONE_BYTE_STRING(env->isolate(), "FSEvent");
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(env->fsevent_string());
t->SetClassName(fsevent_string);

env->SetProtoMethod(t, "start", Start);
env->SetProtoMethod(t, "close", Close);

target->Set(env->fsevent_string(), t->GetFunction());
target->Set(fsevent_string, t->GetFunction());
}


Expand Down
67 changes: 34 additions & 33 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2828,41 +2828,40 @@ static Local<Object> GetFeatures(Environment* env) {
Local<Value> debug = False(env->isolate());
#endif // defined(DEBUG) && DEBUG

obj->Set(env->debug_string(), debug);

obj->Set(env->uv_string(), True(env->isolate()));
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "debug"), debug);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "uv"), True(env->isolate()));
// TODO(bnoordhuis) ping libuv
obj->Set(env->ipv6_lc_string(), True(env->isolate()));
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));

#ifdef OPENSSL_NPN_NEGOTIATED
Local<Boolean> tls_npn = True(env->isolate());
#else
Local<Boolean> tls_npn = False(env->isolate());
#endif
obj->Set(env->tls_npn_string(), tls_npn);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_npn"), tls_npn);

#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
Local<Boolean> tls_alpn = True(env->isolate());
#else
Local<Boolean> tls_alpn = False(env->isolate());
#endif
obj->Set(env->tls_alpn_string(), tls_alpn);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), tls_alpn);

#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
Local<Boolean> tls_sni = True(env->isolate());
#else
Local<Boolean> tls_sni = False(env->isolate());
#endif
obj->Set(env->tls_sni_string(), tls_sni);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), tls_sni);

#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
Local<Boolean> tls_ocsp = True(env->isolate());
#else
Local<Boolean> tls_ocsp = False(env->isolate());
#endif // !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
obj->Set(env->tls_ocsp_string(), tls_ocsp);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), tls_ocsp);

obj->Set(env->tls_string(),
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
Boolean::New(env->isolate(),
get_builtin_module("crypto") != nullptr));

Expand Down Expand Up @@ -2964,12 +2963,12 @@ void SetupProcessObject(Environment* env,

Local<Object> process = env->process_object();

auto maybe = process->SetAccessor(env->context(),
env->title_string(),
ProcessTitleGetter,
ProcessTitleSetter,
env->as_external());
CHECK(maybe.FromJust());
auto title_string = FIXED_ONE_BYTE_STRING(env->isolate(), "title");
CHECK(process->SetAccessor(env->context(),
title_string,
ProcessTitleGetter,
ProcessTitleSetter,
env->as_external()).FromJust());

// process.version
READONLY_PROPERTY(process,
Expand Down Expand Up @@ -3116,14 +3115,15 @@ void SetupProcessObject(Environment* env,
for (int i = 0; i < argc; ++i) {
arguments->Set(i, String::NewFromUtf8(env->isolate(), argv[i]));
}
process->Set(env->argv_string(), arguments);
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments);

// process.execArgv
Local<Array> exec_arguments = Array::New(env->isolate(), exec_argc);
for (int i = 0; i < exec_argc; ++i) {
exec_arguments->Set(i, String::NewFromUtf8(env->isolate(), exec_argv[i]));
}
process->Set(env->exec_argv_string(), exec_arguments);
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
exec_arguments);

// create process.env
Local<ObjectTemplate> process_env_template =
Expand All @@ -3140,12 +3140,13 @@ void SetupProcessObject(Environment* env,

READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid()));
READONLY_PROPERTY(process, "features", GetFeatures(env));
maybe = process->SetAccessor(env->context(),
env->need_imm_cb_string(),
NeedImmediateCallbackGetter,
NeedImmediateCallbackSetter,
env->as_external());
CHECK(maybe.FromJust());

auto need_immediate_callback_string =
FIXED_ONE_BYTE_STRING(env->isolate(), "_needImmediateCallback");
CHECK(process->SetAccessor(env->context(), need_immediate_callback_string,
NeedImmediateCallbackGetter,
NeedImmediateCallbackSetter,
env->as_external()).FromJust());

// -e, --eval
if (eval_string) {
Expand Down Expand Up @@ -3245,16 +3246,16 @@ void SetupProcessObject(Environment* env,
} else {
exec_path_value = String::NewFromUtf8(env->isolate(), argv[0]);
}
process->Set(env->exec_path_string(), exec_path_value);
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value);
delete[] exec_path;

maybe = process->SetAccessor(env->context(),
env->debug_port_string(),
DebugPortGetter,
DebugPortSetter,
env->as_external());
CHECK(maybe.FromJust());

auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort");
CHECK(process->SetAccessor(env->context(),
debug_port_string,
DebugPortGetter,
DebugPortSetter,
env->as_external()).FromJust());

// define various internal methods
env->SetMethod(process,
Expand Down Expand Up @@ -3313,8 +3314,8 @@ void SetupProcessObject(Environment* env,

// pre-set _events object for faster emit checks
Local<Object> events_obj = Object::New(env->isolate());
maybe = events_obj->SetPrototype(env->context(), Null(env->isolate()));
CHECK(maybe.FromJust());
CHECK(events_obj->SetPrototype(env->context(),
Null(env->isolate())).FromJust());
process->Set(env->events_string(), events_obj);
}

Expand Down

0 comments on commit b4ea3a0

Please sign in to comment.