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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 i::wasm::ModuleWireBytes GetFirstArgumentAsBytes( | 119 i::wasm::ModuleWireBytes GetFirstArgumentAsBytes( |
120 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { | 120 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { |
121 if (args.Length() < 1) { | 121 if (args.Length() < 1) { |
122 thrower->TypeError("Argument 0 must be a buffer source"); | 122 thrower->TypeError("Argument 0 must be a buffer source"); |
123 return i::wasm::ModuleWireBytes(nullptr, nullptr); | 123 return i::wasm::ModuleWireBytes(nullptr, nullptr); |
124 } | 124 } |
125 | 125 |
126 const byte* start = nullptr; | 126 const byte* start = nullptr; |
127 const byte* end = nullptr; | 127 size_t length = 0; |
128 v8::Local<v8::Value> source = args[0]; | 128 v8::Local<v8::Value> source = args[0]; |
129 if (source->IsArrayBuffer()) { | 129 if (source->IsArrayBuffer()) { |
130 // A raw array buffer was passed. | 130 // A raw array buffer was passed. |
131 Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(source); | 131 Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(source); |
132 ArrayBuffer::Contents contents = buffer->GetContents(); | 132 ArrayBuffer::Contents contents = buffer->GetContents(); |
133 | 133 |
134 start = reinterpret_cast<const byte*>(contents.Data()); | 134 start = reinterpret_cast<const byte*>(contents.Data()); |
135 end = start + contents.ByteLength(); | 135 length = contents.ByteLength(); |
136 | |
137 } else if (source->IsTypedArray()) { | 136 } else if (source->IsTypedArray()) { |
138 // A TypedArray was passed. | 137 // A TypedArray was passed. |
139 Local<TypedArray> array = Local<TypedArray>::Cast(source); | 138 Local<TypedArray> array = Local<TypedArray>::Cast(source); |
140 Local<ArrayBuffer> buffer = array->Buffer(); | 139 Local<ArrayBuffer> buffer = array->Buffer(); |
141 | 140 |
142 ArrayBuffer::Contents contents = buffer->GetContents(); | 141 ArrayBuffer::Contents contents = buffer->GetContents(); |
143 | 142 |
144 start = | 143 start = |
145 reinterpret_cast<const byte*>(contents.Data()) + array->ByteOffset(); | 144 reinterpret_cast<const byte*>(contents.Data()) + array->ByteOffset(); |
146 end = start + array->ByteLength(); | 145 length = array->ByteLength(); |
147 | |
148 } else { | 146 } else { |
149 thrower->TypeError("Argument 0 must be a buffer source"); | 147 thrower->TypeError("Argument 0 must be a buffer source"); |
150 } | 148 } |
151 if (start == nullptr || end == start) { | 149 DCHECK_IMPLIES(length, start != nullptr); |
| 150 if (length == 0) { |
152 thrower->CompileError("BufferSource argument is empty"); | 151 thrower->CompileError("BufferSource argument is empty"); |
153 } | 152 } |
| 153 if (length > i::wasm::kV8MaxWasmModuleSize) { |
| 154 thrower->RangeError("buffer source exceeds maximum size of %zu (is %zu)", |
| 155 i::wasm::kV8MaxWasmModuleSize, length); |
| 156 } |
| 157 if (thrower->error()) return i::wasm::ModuleWireBytes(nullptr, nullptr); |
154 // TODO(titzer): use the handle as well? | 158 // TODO(titzer): use the handle as well? |
155 return i::wasm::ModuleWireBytes(start, end); | 159 return i::wasm::ModuleWireBytes(start, start + length); |
156 } | 160 } |
157 | 161 |
158 i::MaybeHandle<i::JSReceiver> GetSecondArgumentAsImports( | 162 i::MaybeHandle<i::JSReceiver> GetSecondArgumentAsImports( |
159 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { | 163 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { |
160 if (args.Length() < 2) return {}; | 164 if (args.Length() < 2) return {}; |
161 if (args[1]->IsUndefined()) return {}; | 165 if (args[1]->IsUndefined()) return {}; |
162 | 166 |
163 if (!args[1]->IsObject()) { | 167 if (!args[1]->IsObject()) { |
164 thrower->TypeError("Argument 1 must be an object"); | 168 thrower->TypeError("Argument 1 must be an object"); |
165 return {}; | 169 return {}; |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 916 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
913 return HasBrand(value, symbol); | 917 return HasBrand(value, symbol); |
914 } | 918 } |
915 | 919 |
916 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 920 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
917 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 921 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
918 return HasBrand(value, symbol); | 922 return HasBrand(value, symbol); |
919 } | 923 } |
920 } // namespace internal | 924 } // namespace internal |
921 } // namespace v8 | 925 } // namespace v8 |
OLD | NEW |