|
33 | 33 | #include "string_bytes.h"
|
34 | 34 |
|
35 | 35 | #include "util-inl.h"
|
| 36 | +#include "util.h" |
36 | 37 | #include "v8-fast-api-calls.h"
|
37 | 38 | #include "v8.h"
|
38 | 39 |
|
@@ -61,6 +62,7 @@ using v8::BackingStore;
|
61 | 62 | using v8::BackingStoreInitializationMode;
|
62 | 63 | using v8::Context;
|
63 | 64 | using v8::EscapableHandleScope;
|
| 65 | +using v8::FastApiCallbackOptions; |
64 | 66 | using v8::FastApiTypedArray;
|
65 | 67 | using v8::FunctionCallbackInfo;
|
66 | 68 | using v8::Global;
|
@@ -1176,23 +1178,33 @@ void Swap64(const FunctionCallbackInfo<Value>& args) {
|
1176 | 1178 | }
|
1177 | 1179 |
|
1178 | 1180 | bool FastIsUtf8(v8::Local<v8::Value>,
|
1179 |
| - const v8::FastApiTypedArray<uint8_t>& buffer) { |
1180 |
| - uint8_t* buffer_data; |
1181 |
| - CHECK(buffer.getStorageIfAligned(&buffer_data)); |
| 1181 | + Local<Value> buffer, |
| 1182 | + FastApiCallbackOptions& options) { |
1182 | 1183 | TRACK_V8_FAST_API_CALL("buffer.isUtf8");
|
1183 |
| - return simdutf::validate_utf8(reinterpret_cast<const char*>(buffer_data), |
1184 |
| - buffer.length()); |
| 1184 | + ArrayBufferViewContents<uint8_t> view(buffer); |
| 1185 | + if (view.WasDetached()) { |
| 1186 | + node::THROW_ERR_INVALID_STATE(options.isolate, |
| 1187 | + "Cannot validate on a detached buffer"); |
| 1188 | + return false; |
| 1189 | + } |
| 1190 | + return simdutf::validate_utf8(reinterpret_cast<const char*>(view.data()), |
| 1191 | + view.length()); |
1185 | 1192 | }
|
1186 | 1193 |
|
1187 | 1194 | static v8::CFunction fast_is_utf8(v8::CFunction::Make(FastIsUtf8));
|
1188 | 1195 |
|
1189 | 1196 | bool FastIsAscii(v8::Local<v8::Value>,
|
1190 |
| - const v8::FastApiTypedArray<uint8_t>& buffer) { |
1191 |
| - uint8_t* buffer_data; |
1192 |
| - CHECK(buffer.getStorageIfAligned(&buffer_data)); |
| 1197 | + Local<Value> buffer, |
| 1198 | + FastApiCallbackOptions& options) { |
1193 | 1199 | TRACK_V8_FAST_API_CALL("buffer.isAscii");
|
1194 |
| - return simdutf::validate_ascii(reinterpret_cast<const char*>(buffer_data), |
1195 |
| - buffer.length()); |
| 1200 | + ArrayBufferViewContents<uint8_t> view(buffer); |
| 1201 | + if (view.WasDetached()) { |
| 1202 | + node::THROW_ERR_INVALID_STATE(options.isolate, |
| 1203 | + "Cannot validate on a detached buffer"); |
| 1204 | + return false; |
| 1205 | + } |
| 1206 | + return simdutf::validate_ascii(reinterpret_cast<const char*>(view.data()), |
| 1207 | + view.length()); |
1196 | 1208 | }
|
1197 | 1209 |
|
1198 | 1210 | static v8::CFunction fast_is_ascii(v8::CFunction::Make(FastIsAscii));
|
|
0 commit comments