Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! src: remove calls to deprecated v8 functions (NewFromUtf8)
  • Loading branch information
ryzokuken committed Jul 21, 2018
commit c7caef85ed3def2b07a52ef13f4b763e12eb0ef6
36 changes: 23 additions & 13 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,8 @@ void AppendExceptionLine(Environment* env,
arrow[off] = '\n';
arrow[off + 1] = '\0';

Local<String> arrow_str = String::NewFromUtf8(env->isolate(), arrow);
Local<String> arrow_str = String::NewFromUtf8(env->isolate(), arrow,
v8::NewStringType::kNormal).ToLocalChecked();

const bool can_set_arrow = !arrow_str.IsEmpty() && !err_obj.IsEmpty();
// If allocating arrow_str failed, print it out. There's not much else to do.
Expand Down Expand Up @@ -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
Copy Markdown
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.

module->Set(exports_prop, exports);

if (mod->nm_context_register_func != nullptr) {
Expand All @@ -1765,7 +1767,8 @@ static void ProcessTitleGetter(Local<Name> property,
const PropertyCallbackInfo<Value>& info) {
char buffer[512];
uv_get_process_title(buffer, sizeof(buffer));
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buffer));
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buffer,
v8::NewStringType::kNormal).ToLocalChecked());
}


Expand All @@ -1790,7 +1793,8 @@ static void EnvGetter(Local<Name> property,
node::Utf8Value key(isolate, property);
const char* val = getenv(*key);
if (val) {
return info.GetReturnValue().Set(String::NewFromUtf8(isolate, val));
return info.GetReturnValue().Set(String::NewFromUtf8(isolate, val,
v8::NewStringType::kNormal).ToLocalChecked());
}
#else // _WIN32
node::TwoByteValue key(isolate, property);
Expand Down Expand Up @@ -1918,8 +1922,8 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
const int length = s ? s - var : strlen(var);
argv[idx] = String::NewFromUtf8(isolate,
var,
String::kNormalString,
length);
v8::NewStringType::kNormal,
length).ToLocalChecked();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
idx = 0;
Expand Down Expand Up @@ -2196,14 +2200,16 @@ void SetupProcessObject(Environment* env,
// process.argv
Local<Array> arguments = Array::New(env->isolate(), argc);
for (int i = 0; i < argc; ++i) {
arguments->Set(i, String::NewFromUtf8(env->isolate(), argv[i]));
arguments->Set(i, String::NewFromUtf8(env->isolate(), argv[i],
v8::NewStringType::kNormal).ToLocalChecked());
}
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]));
exec_arguments->Set(i, String::NewFromUtf8(env->isolate(), exec_argv[i],
v8::NewStringType::kNormal).ToLocalChecked());
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
exec_arguments);
Expand Down Expand Up @@ -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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also kInternalized here.

}

// -p, --print
Expand All @@ -2258,7 +2265,9 @@ void SetupProcessObject(Environment* env,
Local<Array> array = Array::New(env->isolate());
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
Local<String> module = String::NewFromUtf8(env->isolate(),
preload_modules[i].c_str());
preload_modules[i].c_str(),
v8::NewStringType::kNormal)
.ToLocalChecked();
array->Set(i, module);
}
READONLY_PROPERTY(process,
Expand Down Expand Up @@ -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::kNormal,
exec_path_len).ToLocalChecked();
} 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
Copy Markdown
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.)

Expand Down
12 changes: 8 additions & 4 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ NODE_EXTERN struct uv_loop_s* GetCurrentEventLoop(v8::Isolate* isolate);
v8::Isolate* isolate = target->GetIsolate(); \
v8::Local<v8::Context> context = isolate->GetCurrentContext(); \
v8::Local<v8::String> constant_name = \
v8::String::NewFromUtf8(isolate, #constant); \
v8::String::NewFromUtf8(isolate, #constant, \
v8::NewStringType::kNormal).ToLocalChecked(); \
v8::Local<v8::Number> constant_value = \
v8::Number::New(isolate, static_cast<double>(constant)); \
v8::PropertyAttribute constant_attributes = \
Expand Down Expand Up @@ -344,7 +345,8 @@ inline void NODE_SET_METHOD(v8::Local<v8::Template> recv,
v8::HandleScope handle_scope(isolate);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
callback);
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();
t->SetClassName(fn_name);
recv->Set(fn_name, t);
}
Expand All @@ -358,7 +360,8 @@ inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
callback);
v8::Local<v8::Function> fn = t->GetFunction();
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();
fn->SetName(fn_name);
recv->Set(fn_name, fn);
}
Expand All @@ -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
Copy Markdown
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.

t->SetClassName(fn_name);
recv->PrototypeTemplate()->Set(fn_name, t);
}
Expand Down