Skip to content

Commit

Permalink
src: use String::Utf8Length with isolate
Browse files Browse the repository at this point in the history
PR-URL: #22531
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
targos committed Aug 29, 2018
1 parent 17dd620 commit b2f0cfa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion benchmark/napi/function_args/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void CallWithString(const FunctionCallbackInfo<Value>& args) {
assert(args.Length() == 1 && args[0]->IsString());
if (args.Length() == 1 && args[0]->IsString()) {
Local<String> str = args[0].As<String>();
const int32_t length = str->Utf8Length() + 1;
const int32_t length = str->Utf8Length(args.GetIsolate()) + 1;
char* buf = new char[length];
str->WriteUtf8(args.GetIsolate(), buf, length);
delete [] buf;
Expand Down
2 changes: 1 addition & 1 deletion src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ napi_status napi_get_value_string_utf8(napi_env env,

if (!buf) {
CHECK_ARG(env, result);
*result = val.As<v8::String>()->Utf8Length();
*result = val.As<v8::String>()->Utf8Length(env->isolate);
} else {
int copied = val.As<v8::String>()->WriteUtf8(
env->isolate,
Expand Down
7 changes: 4 additions & 3 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
// Can't use StringBytes::Write() in all cases. For example if attempting
// to write a two byte character into a one byte Buffer.
if (enc == UTF8) {
str_length = str_obj->Utf8Length();
str_length = str_obj->Utf8Length(env->isolate());
node::Utf8Value str(env->isolate(), args[1]);
memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length));

Expand Down Expand Up @@ -689,10 +689,11 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) {
}

void ByteLengthUtf8(const FunctionCallbackInfo<Value> &args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsString());

// Fast case: avoid StringBytes on UTF8 string. Jump to v8.
args.GetReturnValue().Set(args[0].As<String>()->Utf8Length());
args.GetReturnValue().Set(args[0].As<String>()->Utf8Length(env->isolate()));
}

// Normalize val to be an integer in the range of [1, -1] since
Expand Down Expand Up @@ -1062,7 +1063,7 @@ static void EncodeUtf8String(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsString());

Local<String> str = args[0].As<String>();
size_t length = str->Utf8Length();
size_t length = str->Utf8Length(isolate);
char* data = node::UncheckedMalloc(length);
str->WriteUtf8(isolate,
data,
Expand Down
2 changes: 1 addition & 1 deletion src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ size_t StringBytes::Size(Isolate* isolate,

case BUFFER:
case UTF8:
return str->Utf8Length();
return str->Utf8Length(isolate);

case UCS2:
return str->Length() * sizeof(uint16_t);
Expand Down

0 comments on commit b2f0cfa

Please sign in to comment.