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:
parent
17dd620e58
commit
b2f0cfa6b0
@ -19,7 +19,7 @@ void CallWithString(const FunctionCallbackInfo<Value>& args) {
|
|||||||
assert(args.Length() == 1 && args[0]->IsString());
|
assert(args.Length() == 1 && args[0]->IsString());
|
||||||
if (args.Length() == 1 && args[0]->IsString()) {
|
if (args.Length() == 1 && args[0]->IsString()) {
|
||||||
Local<String> str = args[0].As<String>();
|
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];
|
char* buf = new char[length];
|
||||||
str->WriteUtf8(args.GetIsolate(), buf, length);
|
str->WriteUtf8(args.GetIsolate(), buf, length);
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
|
@ -2399,7 +2399,7 @@ napi_status napi_get_value_string_utf8(napi_env env,
|
|||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
CHECK_ARG(env, result);
|
CHECK_ARG(env, result);
|
||||||
*result = val.As<v8::String>()->Utf8Length();
|
*result = val.As<v8::String>()->Utf8Length(env->isolate);
|
||||||
} else {
|
} else {
|
||||||
int copied = val.As<v8::String>()->WriteUtf8(
|
int copied = val.As<v8::String>()->WriteUtf8(
|
||||||
env->isolate,
|
env->isolate,
|
||||||
|
@ -599,7 +599,7 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
|
|||||||
// Can't use StringBytes::Write() in all cases. For example if attempting
|
// Can't use StringBytes::Write() in all cases. For example if attempting
|
||||||
// to write a two byte character into a one byte Buffer.
|
// to write a two byte character into a one byte Buffer.
|
||||||
if (enc == UTF8) {
|
if (enc == UTF8) {
|
||||||
str_length = str_obj->Utf8Length();
|
str_length = str_obj->Utf8Length(env->isolate());
|
||||||
node::Utf8Value str(env->isolate(), args[1]);
|
node::Utf8Value str(env->isolate(), args[1]);
|
||||||
memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length));
|
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) {
|
void ByteLengthUtf8(const FunctionCallbackInfo<Value> &args) {
|
||||||
|
Environment* env = Environment::GetCurrent(args);
|
||||||
CHECK(args[0]->IsString());
|
CHECK(args[0]->IsString());
|
||||||
|
|
||||||
// Fast case: avoid StringBytes on UTF8 string. Jump to v8.
|
// 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
|
// 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());
|
CHECK(args[0]->IsString());
|
||||||
|
|
||||||
Local<String> str = args[0].As<String>();
|
Local<String> str = args[0].As<String>();
|
||||||
size_t length = str->Utf8Length();
|
size_t length = str->Utf8Length(isolate);
|
||||||
char* data = node::UncheckedMalloc(length);
|
char* data = node::UncheckedMalloc(length);
|
||||||
str->WriteUtf8(isolate,
|
str->WriteUtf8(isolate,
|
||||||
data,
|
data,
|
||||||
|
@ -465,7 +465,7 @@ size_t StringBytes::Size(Isolate* isolate,
|
|||||||
|
|
||||||
case BUFFER:
|
case BUFFER:
|
||||||
case UTF8:
|
case UTF8:
|
||||||
return str->Utf8Length();
|
return str->Utf8Length(isolate);
|
||||||
|
|
||||||
case UCS2:
|
case UCS2:
|
||||||
return str->Length() * sizeof(uint16_t);
|
return str->Length() * sizeof(uint16_t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user