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()) { |
Mircea Trofin
2016/10/28 22:16:29
please separate support for WebAssembly.Memory in
Eric Holk
2016/10/29 00:04:30
Done: https://codereview.chromium.org/2460773003/
| |
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); | |
titzer
2016/10/28 16:24:57
Can we split out the WebAssembly.Memory requiremen
Eric Holk
2016/10/28 18:44:40
Sure. I'll add a couple more cases to make sure we
| |
236 } | |
235 } | 237 } |
236 i::MaybeHandle<i::JSObject> instance = | 238 i::MaybeHandle<i::JSObject> instance = |
237 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); | 239 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); |
238 if (instance.is_null()) { | 240 if (instance.is_null()) { |
239 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); | 241 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); |
240 return; | 242 return; |
241 } | 243 } |
242 DCHECK(!i_isolate->has_pending_exception()); | 244 DCHECK(!i_isolate->has_pending_exception()); |
243 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 245 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
244 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); | 246 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 // There has been an exception, just return. | 358 // There has been an exception, just return. |
357 return; | 359 return; |
358 } | 360 } |
359 if (has_maximum.FromJust()) { | 361 if (has_maximum.FromJust()) { |
360 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, | 362 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, |
361 &maximum, initial, 65536)) { | 363 &maximum, initial, 65536)) { |
362 return; | 364 return; |
363 } | 365 } |
364 } | 366 } |
365 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 367 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
366 i::Handle<i::JSArrayBuffer> buffer = | |
367 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); | |
368 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * | 368 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * |
369 static_cast<size_t>(initial); | 369 static_cast<size_t>(initial); |
370 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); | 370 i::Handle<i::JSArrayBuffer> buffer = |
371 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages); | |
371 | 372 |
372 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject( | 373 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject( |
373 i_isolate, buffer, has_maximum.FromJust(), maximum); | 374 i_isolate, buffer, has_maximum.FromJust(), maximum); |
374 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 375 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
375 return_value.Set(Utils::ToLocal(memory_obj)); | 376 return_value.Set(Utils::ToLocal(memory_obj)); |
376 } | 377 } |
377 | 378 |
378 void WebAssemblyTableGetLength( | 379 void WebAssemblyTableGetLength( |
379 const v8::FunctionCallbackInfo<v8::Value>& args) { | 380 const v8::FunctionCallbackInfo<v8::Value>& args) { |
380 v8::Isolate* isolate = args.GetIsolate(); | 381 v8::Isolate* isolate = args.GetIsolate(); |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
854 if (!memory_object->IsUndefined(isolate)) { | 855 if (!memory_object->IsUndefined(isolate)) { |
855 DCHECK(IsWasmMemoryObject(isolate, memory_object)); | 856 DCHECK(IsWasmMemoryObject(isolate, memory_object)); |
856 // TODO(gdeepti): This should be a weak list of instance objects | 857 // TODO(gdeepti): This should be a weak list of instance objects |
857 // for instances that share memory. | 858 // for instances that share memory. |
858 JSObject::cast(*memory_object) | 859 JSObject::cast(*memory_object) |
859 ->SetInternalField(kWasmMemoryInstanceObject, *instance); | 860 ->SetInternalField(kWasmMemoryInstanceObject, *instance); |
860 } | 861 } |
861 } | 862 } |
862 } // namespace internal | 863 } // namespace internal |
863 } // namespace v8 | 864 } // namespace v8 |
OLD | NEW |