Skip to content

Commit 332b035

Browse files
committed
src: use String::Utf8Length with isolate
PR-URL: #22531 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5f44ce8 commit 332b035

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

benchmark/napi/function_args/binding.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void CallWithString(const FunctionCallbackInfo<Value>& args) {
1919
assert(args.Length() == 1 && args[0]->IsString());
2020
if (args.Length() == 1 && args[0]->IsString()) {
2121
Local<String> str = args[0].As<String>();
22-
const int32_t length = str->Utf8Length() + 1;
22+
const int32_t length = str->Utf8Length(args.GetIsolate()) + 1;
2323
char* buf = new char[length];
2424
str->WriteUtf8(args.GetIsolate(), buf, length);
2525
delete [] buf;

src/node_api.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,7 @@ napi_status napi_get_value_string_utf8(napi_env env,
23992399

24002400
if (!buf) {
24012401
CHECK_ARG(env, result);
2402-
*result = val.As<v8::String>()->Utf8Length();
2402+
*result = val.As<v8::String>()->Utf8Length(env->isolate);
24032403
} else {
24042404
int copied = val.As<v8::String>()->WriteUtf8(
24052405
env->isolate,

src/node_buffer.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
599599
// Can't use StringBytes::Write() in all cases. For example if attempting
600600
// to write a two byte character into a one byte Buffer.
601601
if (enc == UTF8) {
602-
str_length = str_obj->Utf8Length();
602+
str_length = str_obj->Utf8Length(env->isolate());
603603
node::Utf8Value str(env->isolate(), args[1]);
604604
memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length));
605605

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

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

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

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

10641065
Local<String> str = args[0].As<String>();
1065-
size_t length = str->Utf8Length();
1066+
size_t length = str->Utf8Length(isolate);
10661067
char* data = node::UncheckedMalloc(length);
10671068
str->WriteUtf8(isolate,
10681069
data,

src/string_bytes.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ size_t StringBytes::Size(Isolate* isolate,
465465

466466
case BUFFER:
467467
case UTF8:
468-
return str->Utf8Length();
468+
return str->Utf8Length(isolate);
469469

470470
case UCS2:
471471
return str->Length() * sizeof(uint16_t);

0 commit comments

Comments
 (0)