77namespace node {
88namespace wasm_web_api {
99
10- using v8::ArrayBuffer;
11- using v8::ArrayBufferView;
1210using v8::Context;
1311using v8::Function;
1412using v8::FunctionCallbackInfo;
@@ -17,6 +15,7 @@ using v8::Isolate;
1715using v8::Local;
1816using v8::MaybeLocal;
1917using v8::Object;
18+ using v8::Uint8Array;
2019using v8::Value;
2120using v8::WasmStreaming;
2221
@@ -98,28 +97,17 @@ void WasmStreamingObject::Push(const FunctionCallbackInfo<Value>& args) {
9897 CHECK_EQ (args.Length (), 1 );
9998 Local<Value> chunk = args[0 ];
10099
101- // The start of the memory section backing the ArrayBuffer(View), the offset
102- // of the ArrayBuffer(View) within the memory section, and its size in bytes.
103- const void * bytes;
104- size_t offset;
105- size_t size;
106-
107- if (chunk->IsArrayBufferView ()) [[likely]] {
108- Local<ArrayBufferView> view = chunk.As <ArrayBufferView>();
109- bytes = view->Buffer ()->Data ();
110- offset = view->ByteOffset ();
111- size = view->ByteLength ();
112- } else if (chunk->IsArrayBuffer ()) [[likely]] {
113- Local<ArrayBuffer> buffer = chunk.As <ArrayBuffer>();
114- bytes = buffer->Data ();
115- offset = 0 ;
116- size = buffer->ByteLength ();
117- } else {
100+ if (!chunk->IsUint8Array ()) [[unlikely]] {
118101 return node::THROW_ERR_INVALID_ARG_TYPE (
119102 Environment::GetCurrent (args),
120- " chunk must be an ArrayBufferView or an ArrayBuffer " );
103+ " chunk must be a Uint8Array " );
121104 }
122105
106+ Local<Uint8Array> view = chunk.As <Uint8Array>();
107+ const void * bytes = view->Buffer ()->Data ();
108+ size_t offset = view->ByteOffset ();
109+ size_t size = view->ByteLength ();
110+
123111 // Forward the data to V8. Internally, V8 will make a copy.
124112 obj->streaming_ ->OnBytesReceived (static_cast <const uint8_t *>(bytes) + offset,
125113 size);
0 commit comments