Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Unified Diff: src/wasm/wasm-js.cc

Issue 1767203002: [wasm] Allow Uint8Array in _WASMEXP_.instantiateModule() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/wasm/test-wasm-module-builder.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-js.cc
diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc
index 8f9e05b3e3d4522dd8d5d973181300f630468f84..b88125bffd90f53bc08fc7997b856d8d55a72c6f 100644
--- a/src/wasm/wasm-js.cc
+++ b/src/wasm/wasm-js.cc
@@ -37,20 +37,43 @@ struct RawBuffer {
RawBuffer GetRawBufferArgument(
ErrorThrower& thrower, const v8::FunctionCallbackInfo<v8::Value>& args) {
- // TODO(titzer): allow typed array views.
- if (args.Length() < 1 || !args[0]->IsArrayBuffer()) {
+ if (args.Length() < 1) {
thrower.Error("Argument 0 must be an array buffer");
return {nullptr, nullptr};
}
- Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(args[0]);
- ArrayBuffer::Contents contents = buffer->GetContents();
- const byte* start = reinterpret_cast<const byte*>(contents.Data());
- const byte* end = start + contents.ByteLength();
+ const byte* start = nullptr;
+ const byte* end = nullptr;
- if (start == nullptr) {
- thrower.Error("ArrayBuffer argument is empty");
+ if (args[0]->IsArrayBuffer()) {
+ // A raw array buffer was passed.
+ Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(args[0]);
+ ArrayBuffer::Contents contents = buffer->GetContents();
+
+ start = reinterpret_cast<const byte*>(contents.Data());
+ end = start + contents.ByteLength();
+
+ if (start == nullptr || end == start) {
+ thrower.Error("ArrayBuffer argument is empty");
+ }
+ } else if (args[0]->IsTypedArray()) {
+ // A TypedArray was passed.
+ Local<TypedArray> array = Local<TypedArray>::Cast(args[0]);
+ Local<ArrayBuffer> buffer = array->Buffer();
+
+ ArrayBuffer::Contents contents = buffer->GetContents();
+
+ start =
+ reinterpret_cast<const byte*>(contents.Data()) + array->ByteOffset();
+ end = start + array->ByteLength();
+
+ if (start == nullptr || end == start) {
+ thrower.Error("ArrayBuffer argument is empty");
+ }
+ } else {
+ thrower.Error("Argument 0 must be an ArrayBuffer or Uint8Array");
}
+
return {start, end};
}
« no previous file with comments | « no previous file | test/mjsunit/wasm/test-wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698