OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api-natives.h" | 5 #include "src/api-natives.h" |
6 #include "src/api.h" | 6 #include "src/api.h" |
7 #include "src/asmjs/asm-js.h" | 7 #include "src/asmjs/asm-js.h" |
8 #include "src/asmjs/asm-typer.h" | 8 #include "src/asmjs/asm-typer.h" |
9 #include "src/asmjs/asm-wasm-builder.h" | 9 #include "src/asmjs/asm-wasm-builder.h" |
10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const byte* end = nullptr; | 49 const byte* end = nullptr; |
50 | 50 |
51 if (source->IsArrayBuffer()) { | 51 if (source->IsArrayBuffer()) { |
52 // A raw array buffer was passed. | 52 // A raw array buffer was passed. |
53 Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(source); | 53 Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(source); |
54 ArrayBuffer::Contents contents = buffer->GetContents(); | 54 ArrayBuffer::Contents contents = buffer->GetContents(); |
55 | 55 |
56 start = reinterpret_cast<const byte*>(contents.Data()); | 56 start = reinterpret_cast<const byte*>(contents.Data()); |
57 end = start + contents.ByteLength(); | 57 end = start + contents.ByteLength(); |
58 | 58 |
59 if (start == nullptr || end == start) { | |
60 thrower->CompileError("ArrayBuffer argument is empty"); | |
61 } | |
62 } else if (source->IsTypedArray()) { | 59 } else if (source->IsTypedArray()) { |
63 // A TypedArray was passed. | 60 // A TypedArray was passed. |
64 Local<TypedArray> array = Local<TypedArray>::Cast(source); | 61 Local<TypedArray> array = Local<TypedArray>::Cast(source); |
65 Local<ArrayBuffer> buffer = array->Buffer(); | 62 Local<ArrayBuffer> buffer = array->Buffer(); |
66 | 63 |
67 ArrayBuffer::Contents contents = buffer->GetContents(); | 64 ArrayBuffer::Contents contents = buffer->GetContents(); |
68 | 65 |
69 start = | 66 start = |
70 reinterpret_cast<const byte*>(contents.Data()) + array->ByteOffset(); | 67 reinterpret_cast<const byte*>(contents.Data()) + array->ByteOffset(); |
71 end = start + array->ByteLength(); | 68 end = start + array->ByteLength(); |
72 | 69 |
73 if (start == nullptr || end == start) { | |
74 thrower->CompileError("ArrayBuffer argument is empty"); | |
75 } | |
76 } else { | 70 } else { |
77 thrower->TypeError("Argument 0 must be an ArrayBuffer or Uint8Array"); | 71 thrower->TypeError("Argument 0 must be an ArrayBuffer or Uint8Array"); |
78 } | 72 } |
79 | 73 if (start == nullptr || end == start) { |
| 74 thrower->CompileError("BufferSource argument is empty"); |
| 75 } |
80 return {start, end}; | 76 return {start, end}; |
81 } | 77 } |
82 | 78 |
83 static i::MaybeHandle<i::WasmModuleObject> CreateModuleObject( | 79 static i::MaybeHandle<i::WasmModuleObject> CreateModuleObject( |
84 v8::Isolate* isolate, const v8::Local<v8::Value> source, | 80 v8::Isolate* isolate, const v8::Local<v8::Value> source, |
85 ErrorThrower* thrower) { | 81 ErrorThrower* thrower) { |
86 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 82 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
87 i::MaybeHandle<i::JSObject> nothing; | 83 i::MaybeHandle<i::JSObject> nothing; |
88 | 84 |
89 RawBuffer buffer = GetRawBufferSource(source, thrower); | 85 RawBuffer buffer = GetRawBufferSource(source, thrower); |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 887 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
892 return HasBrand(value, symbol); | 888 return HasBrand(value, symbol); |
893 } | 889 } |
894 | 890 |
895 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 891 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
896 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 892 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
897 return HasBrand(value, symbol); | 893 return HasBrand(value, symbol); |
898 } | 894 } |
899 } // namespace internal | 895 } // namespace internal |
900 } // namespace v8 | 896 } // namespace v8 |
OLD | NEW |