-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: remove calls to deprecated v8 functions (NewFromUtf8) #21926
Conversation
/cc @hashseed |
Remove all calls to deprecated v8 functions (here: String::NewFromUtf8) inside the code (src directory only).
2b70708
to
b729e20
Compare
src/exceptions.cc
Outdated
@@ -67,14 +68,15 @@ Local<Value> ErrnoException(Isolate* isolate, | |||
static Local<String> StringFromPath(Isolate* isolate, const char* path) { | |||
#ifdef _WIN32 | |||
if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) { | |||
v8::NewStringType type = v8::NewStringType::kNormal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn’t look like this is in the right place. There are two more instances of NewFromUtf8
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, this one was unfinished. Thanks, will change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is unused now? Either way, I think it makes sense to keep these inline in the code (i.e. not create separate variables)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will make appropriate changes.
src/exceptions.cc
Outdated
@@ -179,11 +182,13 @@ Local<Value> WinapiErrnoException(Isolate* isolate, | |||
} | |||
Local<String> message = OneByteString(env->isolate(), msg); | |||
|
|||
v8::NewStringType type = v8::NewStringType::kNormal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do decide to create new variables for these, can you name the more expressively (e.g. new_string_type
or maybe string_type
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good :)
src/node.h
Outdated
@@ -374,7 +377,8 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv, | |||
v8::Local<v8::Signature> s = v8::Signature::New(isolate, recv); | |||
v8::Local<v8::FunctionTemplate> t = | |||
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), s); | |||
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name); | |||
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name, | |||
v8::NewStringType::kNormal).ToLocalChecked(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for everything in this header, kInternalized
would make more sense as the string type.
src/node.cc
Outdated
} else { | ||
exec_path_value = String::NewFromUtf8(env->isolate(), argv[0]); | ||
exec_path_value = String::NewFromUtf8(env->isolate(), argv[0], | ||
v8::NewStringType::kNormal).ToLocalChecked(); | ||
} | ||
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"), | ||
exec_path_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we expect process.execPath
to be long-lived, using internalized strings might make more sense. (It probably doesn’t matter all that much in individual cases like these, but the sum of the work we’re saving the GC might matter a bit.)
src/node_os.cc
Outdated
@@ -261,7 +261,8 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) { | |||
// contain non-ASCII characters. On UNIX, it's just a binary string with | |||
// no particular encoding but we treat it as a one-byte Latin-1 string. | |||
#ifdef _WIN32 | |||
name = String::NewFromUtf8(env->isolate(), raw_name); | |||
name = String::NewFromUtf8(env->isolate(), raw_name, | |||
v8::NewStringType::kNormal).ToLocalChecked(); | |||
#else | |||
name = OneByteString(env->isolate(), raw_name); | |||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: While it may be true that UNIX systems are somewhat encoding-agnostic here, it’s more than reasonable to assume UTF8 as the default as well. It’s what people will expect if they name the interface from any input that uses UTF-8, which should be the most frequent case by far these days.
I’d suggest either merging these directly in this PR, since you’re already touching the code, or leaving a TODO comment about it.
src/spawn_sync.cc
Outdated
@@ -683,7 +683,9 @@ Local<Object> SyncProcessRunner::BuildResultObject() { | |||
if (term_signal_ > 0) | |||
js_result->Set(context, env()->signal_string(), | |||
String::NewFromUtf8(env()->isolate(), | |||
signo_string(term_signal_))).FromJust(); | |||
signo_string(term_signal_), v8::NewStringType::kNormal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this hit the 80 char limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, dunno how autoformatting left this one out. Will do.
Use v8::NewStringType::kInternalized instead of v8::NewStringType::kNormal in different calls to v8::String::NewFromUtf8 in node.h and node.cc wherever it makes sense, to save the GC some work which would largely be redundant.
Use a UTF-8 encoded string for naming interfaces in unix, instead of using a binary encoding-agnostic string as had been done on windows previously.
CI passed! Will be landing this once the 72 hours period passes. |
Landed in 51812ff...07cb697 Did a minor update to the commit message in 07cb697 (the previous behaviour was not encoding-agnostic). Hope that’s okay! |
Remove all calls to deprecated v8 functions (here: String::NewFromUtf8) inside the code (src directory only). PR-URL: #21926 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Use v8::NewStringType::kInternalized instead of v8::NewStringType::kNormal in different calls to v8::String::NewFromUtf8 in node.h and node.cc wherever it makes sense, to save the GC some work which would largely be redundant. PR-URL: #21926 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Use a UTF-8 encoded string for naming interfaces in unix, instead of using Latin-1, as had been done on windows previously. PR-URL: #21926 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
It totally is, thanks for landing this! |
Remove all calls to deprecated v8 functions (here: String::NewFromUtf8) inside the code (src directory only). PR-URL: #21926 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Use v8::NewStringType::kInternalized instead of v8::NewStringType::kNormal in different calls to v8::String::NewFromUtf8 in node.h and node.cc wherever it makes sense, to save the GC some work which would largely be redundant. PR-URL: #21926 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Use a UTF-8 encoded string for naming interfaces in unix, instead of using Latin-1, as had been done on windows previously. PR-URL: #21926 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, you want to use kInternalized
for strings that are used as identifiers, e.g. variable names or property names.
Sorry for being late with this :)
@@ -1742,7 +1743,8 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) { | |||
|
|||
Local<Object> module = Object::New(env->isolate()); | |||
Local<Object> exports = Object::New(env->isolate()); | |||
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports"); | |||
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports", | |||
v8::NewStringType::kNormal).ToLocalChecked(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could argue that this should be kInternalized
.
@@ -2235,7 +2241,8 @@ void SetupProcessObject(Environment* env, | |||
if (eval_string) { | |||
READONLY_PROPERTY(process, | |||
"_eval", | |||
String::NewFromUtf8(env->isolate(), eval_string)); | |||
String::NewFromUtf8(env->isolate(), eval_string, | |||
v8::NewStringType::kNormal).ToLocalChecked()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also kInternalized
here.
@@ -2343,10 +2352,11 @@ void SetupProcessObject(Environment* env, | |||
if (uv_exepath(exec_path, &exec_path_len) == 0) { | |||
exec_path_value = String::NewFromUtf8(env->isolate(), | |||
exec_path, | |||
String::kNormalString, | |||
exec_path_len); | |||
v8::NewStringType::kInternalized, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here on the other hand I don't know why this needs to be internalized.
@@ -75,14 +75,18 @@ inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) { | |||
env->name_string(), | |||
String::NewFromUtf8(isolate, | |||
entry.name().c_str(), | |||
String::kNormalString), | |||
attr).FromJust(); | |||
v8::NewStringType::kNormal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kInternalized
attr).FromJust(); | ||
v8::NewStringType::kNormal) | ||
.ToLocalChecked(), | ||
attr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
Remove all calls to deprecated v8 functions (here: String::NewFromUtf8) inside
the code (src directory only).
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesFiles