src: use String::Utf8Length with isolate

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Michaël Zasso 2018-08-26 10:30:32 +02:00
parent 17dd620e58
commit b2f0cfa6b0
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
4 changed files with 7 additions and 6 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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));
@ -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
@ -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,

View File

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