-
- Notifications
You must be signed in to change notification settings - Fork 33.7k
src: remove calls to deprecated v8 functions (NewFromUtf8) #21926
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
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
| 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
| } | ||
| 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)?
addaleax left a comment
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
| 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.
| 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
| 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
| 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 :)
| 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.
| "_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.
| 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.
| 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