@@ -59,9 +59,11 @@ using v8::ArrayBuffer;
5959using v8::ArrayBufferView;
6060using v8::BackingStore;
6161using v8::BackingStoreInitializationMode;
62+ using v8::CFunction;
6263using v8::Context;
6364using v8::EscapableHandleScope;
64- using v8::FastApiTypedArray;
65+ using v8::FastApiCallbackOptions;
66+ using v8::FastOneByteString;
6567using v8::FunctionCallbackInfo;
6668using v8::Global;
6769using v8::HandleScope;
@@ -513,9 +515,9 @@ MaybeLocal<Object> New(Environment* env,
513515 free (data);
514516 };
515517 std::unique_ptr<BackingStore> bs =
516- v8:: ArrayBuffer::NewBackingStore (data, length, free_callback, nullptr );
518+ ArrayBuffer::NewBackingStore (data, length, free_callback, nullptr );
517519
518- Local<ArrayBuffer> ab = v8:: ArrayBuffer::New (env->isolate (), std::move (bs));
520+ Local<ArrayBuffer> ab = ArrayBuffer::New (env->isolate (), std::move (bs));
519521
520522 Local<Object> obj;
521523 if (Buffer::New (env, ab, 0 , length).ToLocal (&obj))
@@ -560,40 +562,47 @@ void StringSlice(const FunctionCallbackInfo<Value>& args) {
560562 args.GetReturnValue ().Set (ret);
561563}
562564
565+ void CopyImpl (Local<Value> source_obj,
566+ Local<Value> target_obj,
567+ const uint32_t target_start,
568+ const uint32_t source_start,
569+ const uint32_t to_copy) {
570+ ArrayBufferViewContents<char > source (source_obj);
571+ SPREAD_BUFFER_ARG (target_obj, target);
572+
573+ memmove (target_data + target_start, source.data () + source_start, to_copy);
574+ }
575+
563576// Assume caller has properly validated args.
564577void SlowCopy (const FunctionCallbackInfo<Value>& args) {
565- Environment* env = Environment::GetCurrent (args);
566-
567- ArrayBufferViewContents<char > source (args[0 ]);
568- SPREAD_BUFFER_ARG (args[1 ].As <Object>(), target);
578+ Local<Value> source_obj = args[0 ];
579+ Local<Value> target_obj = args[1 ];
580+ const uint32_t target_start = args[2 ].As <Uint32>()->Value ();
581+ const uint32_t source_start = args[3 ].As <Uint32>()->Value ();
582+ const uint32_t to_copy = args[4 ].As <Uint32>()->Value ();
569583
570- const auto target_start = args[2 ]->Uint32Value (env->context ()).ToChecked ();
571- const auto source_start = args[3 ]->Uint32Value (env->context ()).ToChecked ();
572- const auto to_copy = args[4 ]->Uint32Value (env->context ()).ToChecked ();
584+ CopyImpl (source_obj, target_obj, target_start, source_start, to_copy);
573585
574- memmove (target_data + target_start, source.data () + source_start, to_copy);
575586 args.GetReturnValue ().Set (to_copy);
576587}
577588
578589// Assume caller has properly validated args.
579590uint32_t FastCopy (Local<Value> receiver,
580- const v8::FastApiTypedArray< uint8_t >& source ,
581- const v8::FastApiTypedArray< uint8_t >& target ,
591+ Local<Value> source_obj ,
592+ Local<Value> target_obj ,
582593 uint32_t target_start,
583594 uint32_t source_start,
584- uint32_t to_copy) {
585- uint8_t * source_data;
586- CHECK (source.getStorageIfAligned (&source_data));
595+ uint32_t to_copy,
596+ // NOLINTNEXTLINE(runtime/references)
597+ FastApiCallbackOptions& options) {
598+ HandleScope scope (options.isolate );
587599
588- uint8_t * target_data;
589- CHECK (target.getStorageIfAligned (&target_data));
590-
591- memmove (target_data + target_start, source_data + source_start, to_copy);
600+ CopyImpl (source_obj, target_obj, target_start, source_start, to_copy);
592601
593602 return to_copy;
594603}
595604
596- static v8:: CFunction fast_copy (v8:: CFunction::Make(FastCopy));
605+ static CFunction fast_copy (CFunction::Make(FastCopy));
597606
598607void Fill (const FunctionCallbackInfo<Value>& args) {
599608 Environment* env = Environment::GetCurrent (args);
@@ -730,7 +739,7 @@ void SlowByteLengthUtf8(const FunctionCallbackInfo<Value>& args) {
730739}
731740
732741uint32_t FastByteLengthUtf8 (Local<Value> receiver,
733- const v8:: FastOneByteString& source) {
742+ const FastOneByteString& source) {
734743 // For short inputs, the function call overhead to simdutf is maybe
735744 // not worth it, reserve simdutf for long strings.
736745 if (source.length > 128 ) {
@@ -772,8 +781,7 @@ uint32_t FastByteLengthUtf8(Local<Value> receiver,
772781 return answer;
773782}
774783
775- static v8::CFunction fast_byte_length_utf8 (
776- v8::CFunction::Make (FastByteLengthUtf8));
784+ static CFunction fast_byte_length_utf8 (CFunction::Make(FastByteLengthUtf8));
777785
778786// Normalize val to be an integer in the range of [1, -1] since
779787// implementations of memcmp() can vary by platform.
@@ -836,39 +844,39 @@ void CompareOffset(const FunctionCallbackInfo<Value> &args) {
836844 args.GetReturnValue ().Set (val);
837845}
838846
847+ int32_t CompareImpl (Local<Value> a_obj, Local<Value> b_obj) {
848+ ArrayBufferViewContents<char > a (a_obj);
849+ ArrayBufferViewContents<char > b (b_obj);
850+
851+ size_t cmp_length = std::min (a.length (), b.length ());
852+
853+ return normalizeCompareVal (
854+ cmp_length > 0 ? memcmp (a.data (), b.data (), cmp_length) : 0 ,
855+ a.length (),
856+ b.length ());
857+ }
858+
839859void Compare (const FunctionCallbackInfo<Value> &args) {
840860 Environment* env = Environment::GetCurrent (args);
841-
842861 THROW_AND_RETURN_UNLESS_BUFFER (env, args[0 ]);
843862 THROW_AND_RETURN_UNLESS_BUFFER (env, args[1 ]);
844- ArrayBufferViewContents<char > a (args[0 ]);
845- ArrayBufferViewContents<char > b (args[1 ]);
846863
847- size_t cmp_length = std::min (a. length (), b. length () );
864+ int val = CompareImpl (args[ 0 ], args[ 1 ] );
848865
849- int val = normalizeCompareVal (cmp_length > 0 ?
850- memcmp (a.data (), b.data (), cmp_length) : 0 ,
851- a.length (), b.length ());
852866 args.GetReturnValue ().Set (val);
853867}
854868
855- int32_t FastCompare (v8::Local<v8::Value>,
856- const FastApiTypedArray<uint8_t >& a,
857- const FastApiTypedArray<uint8_t >& b) {
858- uint8_t * data_a;
859- uint8_t * data_b;
860- CHECK (a.getStorageIfAligned (&data_a));
861- CHECK (b.getStorageIfAligned (&data_b));
862-
863- size_t cmp_length = std::min (a.length (), b.length ());
869+ int32_t FastCompare (Local<Value>,
870+ Local<Value> a_obj,
871+ Local<Value> b_obj,
872+ // NOLINTNEXTLINE(runtime/references)
873+ FastApiCallbackOptions& options) {
874+ HandleScope scope (options.isolate );
864875
865- return normalizeCompareVal (
866- cmp_length > 0 ? memcmp (data_a, data_b, cmp_length) : 0 ,
867- a.length (),
868- b.length ());
876+ return CompareImpl (a_obj, b_obj);
869877}
870878
871- static v8:: CFunction fast_compare (v8:: CFunction::Make(FastCompare));
879+ static CFunction fast_compare (CFunction::Make(FastCompare));
872880
873881// Computes the offset for starting an indexOf or lastIndexOf search.
874882// Returns either a valid offset in [0...<length - 1>], ie inside the Buffer,
@@ -1098,11 +1106,13 @@ void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
10981106 result == haystack_length ? -1 : static_cast <int >(result));
10991107}
11001108
1101- int32_t IndexOfNumber (const uint8_t * buffer_data,
1102- size_t buffer_length,
1103- uint32_t needle,
1104- int64_t offset_i64,
1105- bool is_forward) {
1109+ int32_t IndexOfNumberImpl (Local<Value> buffer_obj,
1110+ const uint32_t needle,
1111+ const int64_t offset_i64,
1112+ const bool is_forward) {
1113+ ArrayBufferViewContents<uint8_t > buffer (buffer_obj);
1114+ const uint8_t * buffer_data = buffer.data ();
1115+ const size_t buffer_length = buffer.length ();
11061116 int64_t opt_offset = IndexOfOffset (buffer_length, offset_i64, 1 , is_forward);
11071117 if (opt_offset <= -1 || buffer_length == 0 ) {
11081118 return -1 ;
@@ -1126,29 +1136,28 @@ void SlowIndexOfNumber(const FunctionCallbackInfo<Value>& args) {
11261136 CHECK (args[3 ]->IsBoolean ());
11271137
11281138 THROW_AND_RETURN_UNLESS_BUFFER (Environment::GetCurrent (args), args[0 ]);
1129- ArrayBufferViewContents<uint8_t > buffer (args[0 ]);
11301139
1140+ Local<Value> buffer_obj = args[0 ];
11311141 uint32_t needle = args[1 ].As <Uint32>()->Value ();
11321142 int64_t offset_i64 = args[2 ].As <Integer>()->Value ();
11331143 bool is_forward = args[3 ]->IsTrue ();
11341144
1135- args.GetReturnValue ().Set (IndexOfNumber (
1136- buffer. data (), buffer. length () , needle, offset_i64, is_forward));
1145+ args.GetReturnValue ().Set (
1146+ IndexOfNumberImpl (buffer_obj , needle, offset_i64, is_forward));
11371147}
11381148
1139- int32_t FastIndexOfNumber (v8:: Local<v8:: Value>,
1140- const FastApiTypedArray< uint8_t >& buffer ,
1149+ int32_t FastIndexOfNumber (Local<Value>,
1150+ Local<Value> buffer_obj ,
11411151 uint32_t needle,
11421152 int64_t offset_i64,
1143- bool is_forward) {
1144- uint8_t * buffer_data;
1145- CHECK (buffer. getStorageIfAligned (&buffer_data));
1146- return IndexOfNumber (
1147- buffer_data, buffer. length () , needle, offset_i64, is_forward);
1153+ bool is_forward,
1154+ // NOLINTNEXTLINE(runtime/references)
1155+ FastApiCallbackOptions& options) {
1156+ HandleScope scope (options. isolate );
1157+ return IndexOfNumberImpl (buffer_obj , needle, offset_i64, is_forward);
11481158}
11491159
1150- static v8::CFunction fast_index_of_number (
1151- v8::CFunction::Make (FastIndexOfNumber));
1160+ static CFunction fast_index_of_number (CFunction::Make(FastIndexOfNumber));
11521161
11531162void Swap16 (const FunctionCallbackInfo<Value>& args) {
11541163 Environment* env = Environment::GetCurrent (args);
@@ -1491,29 +1500,30 @@ void SlowWriteString(const FunctionCallbackInfo<Value>& args) {
14911500
14921501template <encoding encoding>
14931502uint32_t FastWriteString (Local<Value> receiver,
1494- const v8::FastApiTypedArray< uint8_t >& dst ,
1495- const v8:: FastOneByteString& src,
1503+ Local<Value> dst_obj ,
1504+ const FastOneByteString& src,
14961505 uint32_t offset,
1497- uint32_t max_length) {
1498- uint8_t * dst_data;
1499- CHECK (dst.getStorageIfAligned (&dst_data));
1500- CHECK (offset <= dst.length ());
1501- CHECK (dst.length () - offset <= std::numeric_limits<uint32_t >::max ());
1506+ uint32_t max_length,
1507+ // NOLINTNEXTLINE(runtime/references)
1508+ FastApiCallbackOptions& options) {
1509+ HandleScope handle_scope (options.isolate );
1510+ SPREAD_BUFFER_ARG (dst_obj, dst);
1511+ CHECK (offset <= dst_length);
1512+ CHECK (dst_length - offset <= std::numeric_limits<uint32_t >::max ());
15021513 TRACK_V8_FAST_API_CALL (" buffer.writeString" );
15031514
15041515 return WriteOneByteString<encoding>(
15051516 src.data ,
15061517 src.length ,
15071518 reinterpret_cast <char *>(dst_data + offset),
1508- std::min<uint32_t >(dst. length () - offset, max_length));
1519+ std::min<uint32_t >(dst_length - offset, max_length));
15091520}
15101521
1511- static v8::CFunction fast_write_string_ascii (
1512- v8::CFunction::Make (FastWriteString<ASCII>));
1513- static v8::CFunction fast_write_string_latin1 (
1514- v8::CFunction::Make (FastWriteString<LATIN1>));
1515- static v8::CFunction fast_write_string_utf8 (
1516- v8::CFunction::Make (FastWriteString<UTF8>));
1522+ static CFunction fast_write_string_ascii (
1523+ CFunction::Make (FastWriteString<ASCII>));
1524+ static CFunction fast_write_string_latin1 (
1525+ CFunction::Make (FastWriteString<LATIN1>));
1526+ static CFunction fast_write_string_utf8 (CFunction::Make(FastWriteString<UTF8>));
15171527
15181528void Initialize (Local<Object> target,
15191529 Local<Value> unused,
0 commit comments