@@ -1223,6 +1223,13 @@ 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 (simdutf::validate_utf8 (external, input->ByteLength ()));
1232+ }
12261233
12271234void SetBufferPrototype (const FunctionCallbackInfo<Value>& args) {
12281235 Environment* env = Environment::GetCurrent (args);
@@ -1358,6 +1365,8 @@ void Initialize(Local<Object> target,
13581365 SetMethod (context, target, " encodeInto" , EncodeInto);
13591366 SetMethodNoSideEffect (context, target, " encodeUtf8String" , EncodeUtf8String);
13601367
1368+ SetMethodNoSideEffect (context, target, " isUtf8" , IsUtf8);
1369+
13611370 target
13621371 ->Set (context,
13631372 FIXED_ONE_BYTE_STRING (isolate, " kMaxLength" ),
@@ -1413,6 +1422,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
14131422 registry->Register (EncodeInto);
14141423 registry->Register (EncodeUtf8String);
14151424
1425+ registry->Register (IsUtf8);
1426+
14161427 registry->Register (StringSlice<ASCII>);
14171428 registry->Register (StringSlice<BASE64>);
14181429 registry->Register (StringSlice<BASE64URL>);
0 commit comments