@@ -986,11 +986,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
986986 size_t result = haystack_length;
987987
988988 if (enc == UCS2) {
989- String::Value needle_value (isolate, needle);
990- if (*needle_value == nullptr ) {
991- return args.GetReturnValue ().Set (-1 );
992- }
993-
989+ TwoByteValue needle_value (isolate, needle);
994990 if (haystack_length < 2 || needle_value.length () < 1 ) {
995991 return args.GetReturnValue ().Set (-1 );
996992 }
@@ -1014,21 +1010,22 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
10141010 result =
10151011 nbytes::SearchString (reinterpret_cast <const uint16_t *>(haystack),
10161012 haystack_length / 2 ,
1017- reinterpret_cast < const uint16_t *>(* needle_value),
1013+ needle_value. out ( ),
10181014 needle_value.length (),
10191015 offset / 2 ,
10201016 is_forward);
10211017 }
10221018 result *= 2 ;
10231019 } else if (enc == UTF8) {
1024- String:: Utf8Value needle_value (isolate, needle);
1020+ Utf8Value needle_value (isolate, needle);
10251021 if (*needle_value == nullptr )
10261022 return args.GetReturnValue ().Set (-1 );
1023+ CHECK_GE (needle_length, needle_value.length ());
10271024
10281025 result =
10291026 nbytes::SearchString (reinterpret_cast <const uint8_t *>(haystack),
10301027 haystack_length,
1031- reinterpret_cast <const uint8_t *>(* needle_value),
1028+ reinterpret_cast <const uint8_t *>(needle_value. out () ),
10321029 needle_length,
10331030 offset,
10341031 is_forward);
@@ -1316,10 +1313,10 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
13161313 input->Length (),
13171314 buffer.out ());
13181315 } else {
1319- String::Value value (env->isolate (), input);
1316+ TwoByteValue value (env->isolate (), input);
13201317 MaybeStackBuffer<char > stack_buf (value.length ());
13211318 size_t out_len = simdutf::convert_utf16_to_latin1 (
1322- reinterpret_cast <const char16_t *>(* value),
1319+ reinterpret_cast <const char16_t *>(value. out () ),
13231320 value.length (),
13241321 stack_buf.out ());
13251322 if (out_len == 0 ) { // error
@@ -1370,8 +1367,8 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
13701367 buffer.SetLength (expected_length);
13711368 result = simdutf::base64_to_binary (data, input->Length (), buffer.out ());
13721369 } else { // 16-bit case
1373- String::Value value (env->isolate (), input);
1374- auto data = reinterpret_cast <const char16_t *>(* value);
1370+ TwoByteValue value (env->isolate (), input);
1371+ auto data = reinterpret_cast <const char16_t *>(value. out () );
13751372 size_t expected_length =
13761373 simdutf::maximal_binary_length_from_base64 (data, value.length ());
13771374 buffer.AllocateSufficientStorage (expected_length);
0 commit comments