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
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 3 additions & 1 deletion src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,9 @@ void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) {
char canonical_ip[INET6_ADDRSTRLEN];
const int af = (rc == 4 ? AF_INET : AF_INET6);
CHECK_EQ(0, uv_inet_ntop(af, &result, canonical_ip, sizeof(canonical_ip)));
args.GetReturnValue().Set(String::NewFromUtf8(isolate, canonical_ip));
v8::NewStringType type = v8::NewStringType::kNormal;
v8::MaybeLocal<String> val = String::NewFromUtf8(isolate, canonical_ip, type);
args.GetReturnValue().Set(val.ToLocalChecked());
}

void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
Expand Down
18 changes: 12 additions & 6 deletions src/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Local<Value> ErrnoException(Isolate* isolate,
Local<String> path_string;
if (path != nullptr) {
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
path_string = String::NewFromUtf8(env->isolate(), path);
path_string = String::NewFromUtf8(env->isolate(), path,
v8::NewStringType::kNormal).ToLocalChecked();
}

if (path_string.IsEmpty() == false) {
Expand All @@ -65,16 +66,18 @@ Local<Value> ErrnoException(Isolate* isolate,
}

static Local<String> StringFromPath(Isolate* isolate, const char* path) {
v8::NewStringType type = v8::NewStringType::kNormal;
#ifdef _WIN32
if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) {
return String::Concat(FIXED_ONE_BYTE_STRING(isolate, "\\\\"),
String::NewFromUtf8(isolate, path + 8));
String::NewFromUtf8(isolate, path + 8, type)
.ToLocalChecked());
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
return String::NewFromUtf8(isolate, path + 4);
return String::NewFromUtf8(isolate, path + 4, type).ToLocalChecked();
}
#endif

return String::NewFromUtf8(isolate, path);
return String::NewFromUtf8(isolate, path, type).ToLocalChecked();
}


Expand Down Expand Up @@ -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)?

if (path) {
Local<String> cons1 =
String::Concat(message, FIXED_ONE_BYTE_STRING(isolate, " '"));
Local<String> cons2 =
String::Concat(cons1, String::NewFromUtf8(isolate, path));
String::Concat(cons1,
String::NewFromUtf8(isolate, path, type).ToLocalChecked());
Local<String> cons3 =
String::Concat(cons2, FIXED_ONE_BYTE_STRING(isolate, "'"));
e = Exception::Error(cons3);
Expand All @@ -195,7 +200,8 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
obj->Set(env->errno_string(), Integer::New(isolate, errorno));

if (path != nullptr) {
obj->Set(env->path_string(), String::NewFromUtf8(isolate, path));
obj->Set(env->path_string(),
String::NewFromUtf8(isolate, path, type).ToLocalChecked());
}

if (syscall != nullptr) {
Expand Down
28 changes: 14 additions & 14 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
BIO_get_mem_ptr(bio.get(), &mem);
info->Set(context, env->subject_string(),
String::NewFromUtf8(env->isolate(), mem->data,
String::kNormalString,
mem->length)).FromJust();
NewStringType::kNormal,
mem->length).ToLocalChecked()).FromJust();
}
USE(BIO_reset(bio.get()));

Expand All @@ -1579,8 +1579,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
BIO_get_mem_ptr(bio.get(), &mem);
info->Set(context, env->issuer_string(),
String::NewFromUtf8(env->isolate(), mem->data,
String::kNormalString,
mem->length)).FromJust();
NewStringType::kNormal,
mem->length).ToLocalChecked()).FromJust();
}
USE(BIO_reset(bio.get()));

Expand All @@ -1607,8 +1607,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
BIO_get_mem_ptr(bio.get(), &mem);
info->Set(context, keys[i],
String::NewFromUtf8(env->isolate(), mem->data,
String::kNormalString,
mem->length)).FromJust();
NewStringType::kNormal,
mem->length).ToLocalChecked()).FromJust();

USE(BIO_reset(bio.get()));
}
Expand All @@ -1626,8 +1626,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
BIO_get_mem_ptr(bio.get(), &mem);
info->Set(context, env->modulus_string(),
String::NewFromUtf8(env->isolate(), mem->data,
String::kNormalString,
mem->length)).FromJust();
NewStringType::kNormal,
mem->length).ToLocalChecked()).FromJust();
USE(BIO_reset(bio.get()));

uint64_t exponent_word = static_cast<uint64_t>(BN_get_word(e));
Expand All @@ -1641,8 +1641,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
BIO_get_mem_ptr(bio.get(), &mem);
info->Set(context, env->exponent_string(),
String::NewFromUtf8(env->isolate(), mem->data,
String::kNormalString,
mem->length)).FromJust();
NewStringType::kNormal,
mem->length).ToLocalChecked()).FromJust();
USE(BIO_reset(bio.get()));

int size = i2d_RSA_PUBKEY(rsa.get(), nullptr);
Expand All @@ -1661,16 +1661,16 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
BIO_get_mem_ptr(bio.get(), &mem);
info->Set(context, env->valid_from_string(),
String::NewFromUtf8(env->isolate(), mem->data,
String::kNormalString,
mem->length)).FromJust();
NewStringType::kNormal,
mem->length).ToLocalChecked()).FromJust();
USE(BIO_reset(bio.get()));

ASN1_TIME_print(bio.get(), X509_get_notAfter(cert));
BIO_get_mem_ptr(bio.get(), &mem);
info->Set(context, env->valid_to_string(),
String::NewFromUtf8(env->isolate(), mem->data,
String::kNormalString,
mem->length)).FromJust();
NewStringType::kNormal,
mem->length).ToLocalChecked()).FromJust();
bio.reset();

unsigned char md[EVP_MAX_MD_SIZE];
Expand Down