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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); | 155 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); |
156 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { | 156 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { |
157 Local<Object> obj = Local<Object>::Cast(args[2]); | 157 Local<Object> obj = Local<Object>::Cast(args[2]); |
158 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); | 158 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); |
159 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); | 159 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); |
160 } | 160 } |
161 | 161 |
162 object = i::wasm::WasmModule::Instantiate( | 162 object = i::wasm::WasmModule::Instantiate( |
163 isolate, thrower, module_object.ToHandleChecked(), ffi, memory); | 163 isolate, module_object.ToHandleChecked(), ffi, memory); |
164 if (!object.is_null()) { | 164 if (!object.is_null()) { |
165 args.GetReturnValue().Set(v8::Utils::ToLocal(object.ToHandleChecked())); | 165 args.GetReturnValue().Set(v8::Utils::ToLocal(object.ToHandleChecked())); |
166 } | 166 } |
167 } | 167 } |
168 return object; | 168 return object; |
169 } | 169 } |
170 | 170 |
171 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) { | 171 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) { |
172 HandleScope scope(args.GetIsolate()); | 172 HandleScope scope(args.GetIsolate()); |
173 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); | 173 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 Local<Object> obj = Local<Object>::Cast(args[1]); | 289 Local<Object> obj = Local<Object>::Cast(args[1]); |
290 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); | 290 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); |
291 } | 291 } |
292 | 292 |
293 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); | 293 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); |
294 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { | 294 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { |
295 Local<Object> obj = Local<Object>::Cast(args[2]); | 295 Local<Object> obj = Local<Object>::Cast(args[2]); |
296 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); | 296 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); |
297 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); | 297 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); |
298 } | 298 } |
299 i::MaybeHandle<i::JSObject> instance = i::wasm::WasmModule::Instantiate( | 299 i::MaybeHandle<i::JSObject> instance = |
300 i_isolate, &thrower, module_obj, ffi, memory); | 300 i::wasm::WasmModule::Instantiate(i_isolate, module_obj, ffi, memory); |
301 if (instance.is_null()) { | 301 if (instance.is_null()) { |
302 if (!thrower.error()) thrower.Error("Could not instantiate module"); | 302 thrower.Error("Could not instantiate module"); |
303 return; | 303 return; |
304 } | 304 } |
305 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 305 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
306 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); | 306 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); |
307 } | 307 } |
308 | 308 |
309 bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower, | 309 bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower, |
310 Local<Context> context, Local<v8::Object> object, | 310 Local<Context> context, Local<v8::Object> object, |
311 Local<String> property, int* result, int lower_bound, | 311 Local<String> property, int* result, int lower_bound, |
312 int upper_bound) { | 312 int upper_bound) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 if (reinterpret_cast<i::Isolate*>(isolate)->has_pending_exception() || | 381 if (reinterpret_cast<i::Isolate*>(isolate)->has_pending_exception() || |
382 thrower.error()) { | 382 thrower.error()) { |
383 return; | 383 return; |
384 } else { | 384 } else { |
385 // There was no error, the property just does not exist. | 385 // There was no error, the property just does not exist. |
386 has_maximum = false; | 386 has_maximum = false; |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 390 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
391 i::Handle<i::JSFunction> table_ctor( | 391 i::Handle<i::JSFunction> table_cons( |
392 i_isolate->native_context()->wasm_table_constructor()); | 392 i_isolate->native_context()->wasm_table_constructor()); |
393 i::Handle<i::JSObject> table_obj = | 393 i::Handle<i::JSObject> table_obj = |
394 i_isolate->factory()->NewJSObject(table_ctor); | 394 i_isolate->factory()->NewJSObject(table_cons); |
395 i::Handle<i::FixedArray> fixed_array = | 395 i::Handle<i::FixedArray> fixed_array = |
396 i_isolate->factory()->NewFixedArray(initial); | 396 i_isolate->factory()->NewFixedArray(initial); |
397 i::Object* null = i_isolate->heap()->null_value(); | 397 i::Object* null = i_isolate->heap()->null_value(); |
398 for (int i = 0; i < initial; ++i) fixed_array->set(i, null); | 398 for (int i = 0; i < initial; ++i) fixed_array->set(i, null); |
399 table_obj->SetInternalField(0, *fixed_array); | 399 table_obj->SetInternalField(0, *fixed_array); |
400 table_obj->SetInternalField( | 400 table_obj->SetInternalField( |
401 1, has_maximum | 401 1, has_maximum |
402 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) | 402 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) |
403 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); | 403 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); |
404 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym()); | 404 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym()); |
405 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check(); | 405 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check(); |
406 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 406 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
407 return_value.Set(Utils::ToLocal(table_obj)); | 407 return_value.Set(Utils::ToLocal(table_obj)); |
408 } | 408 } |
409 | |
410 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { | 409 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { |
411 v8::Isolate* isolate = args.GetIsolate(); | 410 v8::Isolate* isolate = args.GetIsolate(); |
412 HandleScope scope(isolate); | 411 HandleScope scope(isolate); |
413 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), | 412 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), |
414 "WebAssembly.Module()"); | 413 "WebAssembly.Module()"); |
415 if (args.Length() < 1 || !args[0]->IsObject()) { | 414 if (args.Length() < 1 || !args[0]->IsObject()) { |
416 thrower.TypeError("Argument 0 must be a table descriptor"); | 415 thrower.TypeError("Argument 0 must be a table descriptor"); |
417 return; | 416 return; |
418 } | 417 } |
419 Local<Context> context = isolate->GetCurrentContext(); | 418 Local<Context> context = isolate->GetCurrentContext(); |
(...skipping 10 matching lines...) Expand all Loading... |
430 65536)) { | 429 65536)) { |
431 if (reinterpret_cast<i::Isolate*>(isolate)->has_pending_exception() || | 430 if (reinterpret_cast<i::Isolate*>(isolate)->has_pending_exception() || |
432 thrower.error()) { | 431 thrower.error()) { |
433 return; | 432 return; |
434 } else { | 433 } else { |
435 // There was no error, the property just does not exist. | 434 // There was no error, the property just does not exist. |
436 has_maximum = false; | 435 has_maximum = false; |
437 } | 436 } |
438 } | 437 } |
439 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 438 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 439 i::Handle<i::JSFunction> memory_cons( |
| 440 i_isolate->native_context()->wasm_memory_constructor()); |
| 441 i::Handle<i::JSObject> memory_obj = |
| 442 i_isolate->factory()->NewJSObject(memory_cons); |
440 i::Handle<i::JSArrayBuffer> buffer = | 443 i::Handle<i::JSArrayBuffer> buffer = |
441 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); | 444 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); |
442 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * | 445 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * |
443 static_cast<size_t>(initial); | 446 static_cast<size_t>(initial); |
444 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); | 447 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); |
445 | 448 memory_obj->SetInternalField(0, *buffer); |
446 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject( | 449 memory_obj->SetInternalField( |
447 i_isolate, buffer, has_maximum, maximum); | 450 1, has_maximum |
| 451 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) |
| 452 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); |
| 453 i::Handle<i::Symbol> memory_sym( |
| 454 i_isolate->native_context()->wasm_memory_sym()); |
| 455 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check(); |
448 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 456 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
449 return_value.Set(Utils::ToLocal(memory_obj)); | 457 return_value.Set(Utils::ToLocal(memory_obj)); |
450 } | 458 } |
451 void WebAssemblyTableGetLength( | 459 void WebAssemblyTableGetLength( |
452 const v8::FunctionCallbackInfo<v8::Value>& args) { | 460 const v8::FunctionCallbackInfo<v8::Value>& args) { |
453 // TODO(rossberg) | 461 // TODO(rossberg) |
454 } | 462 } |
455 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { | 463 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { |
456 // TODO(rossberg) | 464 // TODO(rossberg) |
457 } | 465 } |
(...skipping 19 matching lines...) Expand all Loading... |
477 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 485 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
478 i::Handle<i::JSObject> receiver = | 486 i::Handle<i::JSObject> receiver = |
479 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This())); | 487 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This())); |
480 i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate); | 488 i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate); |
481 DCHECK(buffer->IsJSArrayBuffer()); | 489 DCHECK(buffer->IsJSArrayBuffer()); |
482 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 490 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
483 return_value.Set(Utils::ToLocal(buffer)); | 491 return_value.Set(Utils::ToLocal(buffer)); |
484 } | 492 } |
485 } // namespace | 493 } // namespace |
486 | 494 |
487 i::Handle<i::JSObject> i::WasmJs::CreateWasmMemoryObject( | |
488 i::Isolate* i_isolate, i::Handle<i::JSArrayBuffer> buffer, bool has_maximum, | |
489 int maximum) { | |
490 i::Handle<i::JSFunction> memory_ctor( | |
491 i_isolate->native_context()->wasm_memory_constructor()); | |
492 i::Handle<i::JSObject> memory_obj = | |
493 i_isolate->factory()->NewJSObject(memory_ctor); | |
494 memory_obj->SetInternalField(0, *buffer); | |
495 memory_obj->SetInternalField( | |
496 1, has_maximum | |
497 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) | |
498 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); | |
499 i::Handle<i::Symbol> memory_sym( | |
500 i_isolate->native_context()->wasm_memory_sym()); | |
501 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check(); | |
502 return memory_obj; | |
503 } | |
504 | |
505 // TODO(titzer): we use the API to create the function template because the | 495 // TODO(titzer): we use the API to create the function template because the |
506 // internal guts are too ugly to replicate here. | 496 // internal guts are too ugly to replicate here. |
507 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, | 497 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, |
508 FunctionCallback func) { | 498 FunctionCallback func) { |
509 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 499 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
510 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); | 500 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); |
511 return v8::Utils::OpenHandle(*local); | 501 return v8::Utils::OpenHandle(*local); |
512 } | 502 } |
513 | 503 |
514 namespace internal { | 504 namespace internal { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 int unused_property_fields = in_object_properties - pre_allocated; | 687 int unused_property_fields = in_object_properties - pre_allocated; |
698 Handle<Map> map = Map::CopyInitialMap( | 688 Handle<Map> map = Map::CopyInitialMap( |
699 prev_map, instance_size, in_object_properties, unused_property_fields); | 689 prev_map, instance_size, in_object_properties, unused_property_fields); |
700 | 690 |
701 context->set_wasm_function_map(*map); | 691 context->set_wasm_function_map(*map); |
702 } | 692 } |
703 } | 693 } |
704 | 694 |
705 } // namespace internal | 695 } // namespace internal |
706 } // namespace v8 | 696 } // namespace v8 |
OLD | NEW |