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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 i::Handle<i::JSObject> i_obj = | 221 i::Handle<i::JSObject> i_obj = |
222 i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*obj)); | 222 i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*obj)); |
223 | 223 |
224 i::Handle<i::JSReceiver> ffi = i::Handle<i::JSObject>::null(); | 224 i::Handle<i::JSReceiver> ffi = i::Handle<i::JSObject>::null(); |
225 if (args.Length() > 1 && args[1]->IsObject()) { | 225 if (args.Length() > 1 && args[1]->IsObject()) { |
226 Local<Object> obj = Local<Object>::Cast(args[1]); | 226 Local<Object> obj = Local<Object>::Cast(args[1]); |
227 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); | 227 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); |
228 } | 228 } |
229 | 229 |
230 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); | 230 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); |
231 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { | 231 if (args.Length() > 2 && args[2]->IsObject()) { |
232 Local<Object> obj = Local<Object>::Cast(args[2]); | 232 Local<Object> obj = Local<Object>::Cast(args[2]); |
233 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); | 233 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); |
234 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); | 234 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) { |
| 235 memory = i::WasmJs::GetWasmMemoryArrayBuffer(i_isolate, mem_obj); |
| 236 } else { |
| 237 thrower.TypeError("Argument 2 must be a WebAssembly.Memory"); |
| 238 } |
235 } | 239 } |
236 i::MaybeHandle<i::JSObject> instance = | 240 i::MaybeHandle<i::JSObject> instance = |
237 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); | 241 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); |
238 if (instance.is_null()) { | 242 if (instance.is_null()) { |
239 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); | 243 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); |
240 return; | 244 return; |
241 } | 245 } |
242 DCHECK(!i_isolate->has_pending_exception()); | 246 DCHECK(!i_isolate->has_pending_exception()); |
243 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 247 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
244 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); | 248 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 if (!memory_object->IsUndefined(isolate)) { | 858 if (!memory_object->IsUndefined(isolate)) { |
855 DCHECK(IsWasmMemoryObject(isolate, memory_object)); | 859 DCHECK(IsWasmMemoryObject(isolate, memory_object)); |
856 // TODO(gdeepti): This should be a weak list of instance objects | 860 // TODO(gdeepti): This should be a weak list of instance objects |
857 // for instances that share memory. | 861 // for instances that share memory. |
858 JSObject::cast(*memory_object) | 862 JSObject::cast(*memory_object) |
859 ->SetInternalField(kWasmMemoryInstanceObject, *instance); | 863 ->SetInternalField(kWasmMemoryInstanceObject, *instance); |
860 } | 864 } |
861 } | 865 } |
862 } // namespace internal | 866 } // namespace internal |
863 } // namespace v8 | 867 } // namespace v8 |
OLD | NEW |