@@ -1223,6 +1223,14 @@ static void EncodeInto(const FunctionCallbackInfo<Value>& args) {
12231223 results[1 ] = written;
12241224}
12251225
1226+ static void IsUtf8 (const FunctionCallbackInfo<Value>& args) {
1227+ CHECK_GE (args.Length (), 1 );
1228+ CHECK (args[0 ]->IsArrayBuffer ());
1229+ Local<ArrayBuffer> input = args[0 ].As <ArrayBuffer>();
1230+ auto external = static_cast <const char *>(input->Data ());
1231+ args.GetReturnValue ().Set (
1232+ simdutf::validate_utf8 (external, input->ByteLength ()));
1233+ }
12261234
12271235void SetBufferPrototype (const FunctionCallbackInfo<Value>& args) {
12281236 Environment* env = Environment::GetCurrent (args);
@@ -1358,6 +1366,8 @@ void Initialize(Local<Object> target,
13581366 SetMethod (context, target, " encodeInto" , EncodeInto);
13591367 SetMethodNoSideEffect (context, target, " encodeUtf8String" , EncodeUtf8String);
13601368
1369+ SetMethodNoSideEffect (context, target, " isUtf8" , IsUtf8);
1370+
13611371 target
13621372 ->Set (context,
13631373 FIXED_ONE_BYTE_STRING (isolate, " kMaxLength" ),
@@ -1413,6 +1423,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
14131423 registry->Register (EncodeInto);
14141424 registry->Register (EncodeUtf8String);
14151425
1426+ registry->Register (IsUtf8);
1427+
14161428 registry->Register (StringSlice<ASCII>);
14171429 registry->Register (StringSlice<BASE64>);
14181430 registry->Register (StringSlice<BASE64URL>);
0 commit comments