Skip to content

Commit 58d7a6e

Browse files
targosRafaelGSS
authored andcommitted
Revert "src: migrate String::Value to String::ValueView"
This reverts commit 45c6a9e. PR-URL: #55828 Fixes: #55826 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
1 parent cad557e commit 58d7a6e

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

src/inspector_js_api.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ static void AsyncTaskScheduledWrapper(const FunctionCallbackInfo<Value>& args) {
245245
Environment* env = Environment::GetCurrent(args);
246246

247247
CHECK(args[0]->IsString());
248-
249-
TwoByteValue task_name_buffer(args.GetIsolate(), args[0]);
250-
StringView task_name_view(*task_name_buffer, task_name_buffer.length());
248+
Local<String> task_name = args[0].As<String>();
249+
String::Value task_name_value(args.GetIsolate(), task_name);
250+
StringView task_name_view(*task_name_value, task_name_value.length());
251251

252252
CHECK(args[1]->IsNumber());
253253
int64_t task_id = args[1]->IntegerValue(env->context()).FromJust();

src/node_buffer.cc

+16-12
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,12 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
965965
size_t result = haystack_length;
966966

967967
if (enc == UCS2) {
968-
TwoByteValue needle_buffer(isolate, needle);
968+
String::Value needle_value(isolate, needle);
969+
if (*needle_value == nullptr) {
970+
return args.GetReturnValue().Set(-1);
971+
}
969972

970-
if (haystack_length < 2 || needle_buffer.length() < 1) {
973+
if (haystack_length < 2 || needle_value.length() < 1) {
971974
return args.GetReturnValue().Set(-1);
972975
}
973976

@@ -987,12 +990,13 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
987990
offset / 2,
988991
is_forward);
989992
} else {
990-
result = nbytes::SearchString(reinterpret_cast<const uint16_t*>(haystack),
991-
haystack_length / 2,
992-
needle_buffer.out(),
993-
needle_buffer.length(),
994-
offset / 2,
995-
is_forward);
993+
result =
994+
nbytes::SearchString(reinterpret_cast<const uint16_t*>(haystack),
995+
haystack_length / 2,
996+
reinterpret_cast<const uint16_t*>(*needle_value),
997+
needle_value.length(),
998+
offset / 2,
999+
is_forward);
9961000
}
9971001
result *= 2;
9981002
} else if (enc == UTF8) {
@@ -1292,10 +1296,10 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
12921296
input->Length(),
12931297
buffer.out());
12941298
} else {
1295-
String::ValueView value(env->isolate(), input);
1299+
String::Value value(env->isolate(), input);
12961300
MaybeStackBuffer<char> stack_buf(value.length());
12971301
size_t out_len = simdutf::convert_utf16_to_latin1(
1298-
reinterpret_cast<const char16_t*>(value.data16()),
1302+
reinterpret_cast<const char16_t*>(*value),
12991303
value.length(),
13001304
stack_buf.out());
13011305
if (out_len == 0) { // error
@@ -1352,8 +1356,8 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
13521356
buffer.SetLength(expected_length);
13531357
result = simdutf::base64_to_binary(data, input->Length(), buffer.out());
13541358
} else { // 16-bit case
1355-
String::ValueView value(env->isolate(), input);
1356-
auto data = reinterpret_cast<const char16_t*>(value.data16());
1359+
String::Value value(env->isolate(), input);
1360+
auto data = reinterpret_cast<const char16_t*>(*value);
13571361
size_t expected_length =
13581362
simdutf::maximal_binary_length_from_base64(data, value.length());
13591363
buffer.AllocateSufficientStorage(expected_length);

src/string_bytes.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ size_t StringBytes::Write(Isolate* isolate,
305305
input_view.length());
306306
}
307307
} else {
308+
String::Value value(isolate, str);
308309
size_t written_len = buflen;
309310
auto result = simdutf::base64_to_binary_safe(
310-
reinterpret_cast<const char16_t*>(input_view.data16()),
311-
input_view.length(),
311+
reinterpret_cast<const char16_t*>(*value),
312+
value.length(),
312313
buf,
313314
written_len,
314315
simdutf::base64_url);
@@ -318,8 +319,7 @@ size_t StringBytes::Write(Isolate* isolate,
318319
// The input does not follow the WHATWG forgiving-base64 specification
319320
// (adapted for base64url with + and / replaced by - and _).
320321
// https://infra.spec.whatwg.org/#forgiving-base64-decode
321-
nbytes = nbytes::Base64Decode(
322-
buf, buflen, input_view.data16(), input_view.length());
322+
nbytes = nbytes::Base64Decode(buf, buflen, *value, value.length());
323323
}
324324
}
325325
break;
@@ -344,19 +344,19 @@ size_t StringBytes::Write(Isolate* isolate,
344344
input_view.length());
345345
}
346346
} else {
347+
String::Value value(isolate, str);
347348
size_t written_len = buflen;
348349
auto result = simdutf::base64_to_binary_safe(
349-
reinterpret_cast<const char16_t*>(input_view.data16()),
350-
input_view.length(),
350+
reinterpret_cast<const char16_t*>(*value),
351+
value.length(),
351352
buf,
352353
written_len);
353354
if (result.error == simdutf::error_code::SUCCESS) {
354355
nbytes = written_len;
355356
} else {
356357
// The input does not follow the WHATWG base64 specification
357358
// https://infra.spec.whatwg.org/#forgiving-base64-decode
358-
nbytes = nbytes::Base64Decode(
359-
buf, buflen, input_view.data16(), input_view.length());
359+
nbytes = nbytes::Base64Decode(buf, buflen, *value, value.length());
360360
}
361361
}
362362
break;
@@ -369,8 +369,8 @@ size_t StringBytes::Write(Isolate* isolate,
369369
reinterpret_cast<const char*>(input_view.data8()),
370370
input_view.length());
371371
} else {
372-
String::ValueView value(isolate, str);
373-
nbytes = nbytes::HexDecode(buf, buflen, value.data8(), value.length());
372+
String::Value value(isolate, str);
373+
nbytes = nbytes::HexDecode(buf, buflen, *value, value.length());
374374
}
375375
break;
376376

0 commit comments

Comments
 (0)