Skip to content

Commit ab8d328

Browse files
committed
fixup! buffer: add fast api for isAscii & isUtf8
1 parent 3e56274 commit ab8d328

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

src/node_buffer.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,24 +1175,24 @@ void Swap64(const FunctionCallbackInfo<Value>& args) {
11751175
args.GetReturnValue().Set(args[0]);
11761176
}
11771177

1178-
bool FastIsUtf8(v8::Local<v8::Value>,
1179-
const v8::FastApiTypedArray<uint8_t>& buffer) {
1180-
uint8_t* buffer_data;
1181-
CHECK(buffer.getStorageIfAligned(&buffer_data));
1178+
bool FastIsUtf8(v8::Local<v8::Value>, Local<Value> buffer) {
11821179
TRACK_V8_FAST_API_CALL("buffer.isUtf8");
1180+
CHECK(buffer->IsTypedArray());
1181+
auto buffer_ = buffer.As<v8::TypedArray>()->Buffer();
1182+
auto buffer_data = buffer_->Data();
11831183
return simdutf::validate_utf8(reinterpret_cast<const char*>(buffer_data),
1184-
buffer.length());
1184+
buffer_->ByteLength());
11851185
}
11861186

11871187
static v8::CFunction fast_is_utf8(v8::CFunction::Make(FastIsUtf8));
11881188

1189-
bool FastIsAscii(v8::Local<v8::Value>,
1190-
const v8::FastApiTypedArray<uint8_t>& buffer) {
1191-
uint8_t* buffer_data;
1192-
CHECK(buffer.getStorageIfAligned(&buffer_data));
1189+
bool FastIsAscii(v8::Local<v8::Value>, Local<Value> buffer) {
11931190
TRACK_V8_FAST_API_CALL("buffer.isAscii");
1191+
CHECK(buffer->IsTypedArray());
1192+
auto buffer_ = buffer.As<v8::TypedArray>()->Buffer();
1193+
auto buffer_data = buffer_->Data();
11941194
return simdutf::validate_ascii(reinterpret_cast<const char*>(buffer_data),
1195-
buffer.length());
1195+
buffer_->ByteLength());
11961196
}
11971197

11981198
static v8::CFunction fast_is_ascii(v8::CFunction::Make(FastIsAscii));

src/node_external_reference.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> unused,
4242
using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> unused,
4343
v8::Local<v8::Object> receiver,
4444
bool);
45-
using CFunctionFastIsUtf8 = bool (*)(
46-
v8::Local<v8::Value>, const v8::FastApiTypedArray<uint8_t>& buffer);
4745
using CFunctionCallbackWithString =
4846
bool (*)(v8::Local<v8::Value>, const v8::FastOneByteString& input);
4947
using CFunctionCallbackWithStrings =
@@ -111,7 +109,6 @@ class ExternalReferenceRegistry {
111109
V(CFunctionCallbackValueReturnDoubleUnusedReceiver) \
112110
V(CFunctionCallbackWithInt64) \
113111
V(CFunctionCallbackWithBool) \
114-
V(CFunctionFastIsUtf8) \
115112
V(CFunctionCallbackWithString) \
116113
V(CFunctionCallbackWithStrings) \
117114
V(CFunctionCallbackWithTwoUint8Arrays) \

test/parallel/test-buffer-isutf8-isascii-fast-api.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ assert.strictEqual(buffer.isAscii(nonAsciiBuffer), false);
2424

2525
// Test detached buffers
2626
const detachedBuffer = new ArrayBuffer(10);
27-
try {
28-
detachedBuffer.detach();
29-
} catch (_e) {
30-
console.log('Skipping detached buffer tests - detach not supported');
31-
}
27+
// Let's detach the buffer if it's supported
28+
detachedBuffer.detach?.();
3229

3330
if (detachedBuffer.detached) {
3431
const typedArray = new Uint8Array(detachedBuffer);

0 commit comments

Comments
 (0)