Skip to content

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

@nodejs-github-bot
Copy link
Collaborator

@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).
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.

}
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
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.

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
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.

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 <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: James M Snell <[email protected]>
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 <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: James M Snell <[email protected]>
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 <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@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 <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: James M Snell <[email protected]>
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 <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: James M Snell <[email protected]>
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 <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@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 :)

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.

"_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.

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.

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