Chromium Code Reviews| Index: src/wasm/wasm-js.cc |
| diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc |
| index 8f9e05b3e3d4522dd8d5d973181300f630468f84..a4a4d762652a480bb08d338d3be2cfe8f001e2ed 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) { |
|
Derek Schuff
2016/03/07 20:37:17
should we also throw if the length is 0 or otherwi
titzer
2016/03/07 20:39:53
Done.
|
| + thrower.Error("ArrayBuffer argument is empty"); |
| + } |
| + } else if (args[0]->IsUint8Array()) { |
| + // A Uint8Array was passed. |
| + Local<Uint8Array> array = Local<Uint8Array>::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}; |
| } |