Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

ryzokuken
Copy link
Contributor

@ryzokuken ryzokuken commented Jul 21, 2018

Remove all calls to deprecated v8 functions (here: String::NewFromUtf8) inside
the code (src directory only).

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Files
  • src/async_wrap.cc
  • src/cares_wrap.cc
  • src/env-inl.h
  • src/exceptions.cc
  • src/heap_utils.cc
  • src/module_wrap.cc
  • src/node.cc
  • src/node.h
  • src/node_api.cc
  • src/node_config.cc
  • src/node_crypto.cc
  • src/node_file.cc
  • src/node_i18n.cc
  • src/node_internals.h
  • src/node_os.cc
  • src/node_perf.cc
  • src/node_process.cc
  • src/node_trace_events.cc
  • src/node_url.cc
  • src/node_util.cc
  • src/node_v8.cc
  • src/spawn_sync.cc
  • src/string_bytes.cc
  • src/string_decoder.cc

@ryzokuken
Copy link
Contributor Author

/cc @hashseed

@ryzokuken ryzokuken changed the title [WIP] v8: remove calls to deprecated v8 functions (NewFromUtf8) [WIP] src: remove calls to deprecated v8 functions (NewFromUtf8) Jul 21, 2018
Remove all calls to deprecated v8 functions (here: String::NewFromUtf8) inside
the code (src directory only).
@@ -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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Contributor Author

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.

@@ -179,11 +182,13 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
}
Local<String> message = OneByteString(env->isolate(), msg);

v8::NewStringType type = v8::NewStringType::kNormal;
Copy link
Member

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)?

Copy link
Member

@addaleax addaleax left a 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();
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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.

@@ -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)
Copy link
Member

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?

Copy link
Contributor Author

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.
@ryzokuken ryzokuken changed the title [WIP] src: remove calls to deprecated v8 functions (NewFromUtf8) src: remove calls to deprecated v8 functions (NewFromUtf8) Jul 21, 2018
@ryzokuken
Copy link
Contributor Author

@ryzokuken
Copy link
Contributor Author

CI passed! Will be landing this once the 72 hours period passes.

@addaleax
Copy link
Member

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!

@addaleax addaleax closed this Jul 29, 2018
addaleax pushed a commit that referenced this pull request Jul 29, 2018
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>
addaleax pushed a commit that referenced this pull request Jul 29, 2018
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>
addaleax pushed a commit that referenced this pull request Jul 29, 2018
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>
@ryzokuken
Copy link
Contributor Author

It totally is, thanks for landing this!

targos pushed a commit that referenced this pull request Jul 31, 2018
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>
targos pushed a commit that referenced this pull request Jul 31, 2018
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>
targos pushed a commit that referenced this pull request Jul 31, 2018
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>
@targos targos mentioned this pull request Jul 31, 2018
Copy link
Member

@hashseed hashseed left a 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();
Copy link
Member

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());
Copy link
Member

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,
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants