| 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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, | 566 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, |
| 567 FunctionCallback func) { | 567 FunctionCallback func) { |
| 568 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 568 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
| 569 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); | 569 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); |
| 570 return v8::Utils::OpenHandle(*local); | 570 return v8::Utils::OpenHandle(*local); |
| 571 } | 571 } |
| 572 | 572 |
| 573 namespace internal { | 573 namespace internal { |
| 574 | 574 |
| 575 Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject> object, | 575 Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject> object, |
| 576 const char* str, FunctionCallback func) { | 576 const char* str, FunctionCallback func, |
| 577 int length = 0) { |
| 577 Handle<String> name = v8_str(isolate, str); | 578 Handle<String> name = v8_str(isolate, str); |
| 578 Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func); | 579 Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func); |
| 579 Handle<JSFunction> function = | 580 Handle<JSFunction> function = |
| 580 ApiNatives::InstantiateFunction(temp).ToHandleChecked(); | 581 ApiNatives::InstantiateFunction(temp).ToHandleChecked(); |
| 582 JSFunction::SetName(function, name, isolate->factory()->empty_string()); |
| 583 function->shared()->set_length(length); |
| 581 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); | 584 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); |
| 582 JSObject::AddProperty(object, name, function, attributes); | 585 JSObject::AddProperty(object, name, function, attributes); |
| 583 return function; | 586 return function; |
| 584 } | 587 } |
| 585 | 588 |
| 586 Handle<JSFunction> InstallGetter(Isolate* isolate, Handle<JSObject> object, | 589 Handle<JSFunction> InstallGetter(Isolate* isolate, Handle<JSObject> object, |
| 587 const char* str, FunctionCallback func) { | 590 const char* str, FunctionCallback func) { |
| 588 Handle<String> name = v8_str(isolate, str); | 591 Handle<String> name = v8_str(isolate, str); |
| 589 Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func); | 592 Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func); |
| 590 Handle<JSFunction> function = | 593 Handle<JSFunction> function = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 Handle<String> name = v8_str(isolate, "WebAssembly"); | 632 Handle<String> name = v8_str(isolate, "WebAssembly"); |
| 630 Handle<JSFunction> cons = factory->NewFunction(name); | 633 Handle<JSFunction> cons = factory->NewFunction(name); |
| 631 JSFunction::SetInstancePrototype( | 634 JSFunction::SetInstancePrototype( |
| 632 cons, Handle<Object>(context->initial_object_prototype(), isolate)); | 635 cons, Handle<Object>(context->initial_object_prototype(), isolate)); |
| 633 cons->shared()->set_instance_class_name(*name); | 636 cons->shared()->set_instance_class_name(*name); |
| 634 Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED); | 637 Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED); |
| 635 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); | 638 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); |
| 636 JSObject::AddProperty(global, name, webassembly, attributes); | 639 JSObject::AddProperty(global, name, webassembly, attributes); |
| 637 | 640 |
| 638 // Setup compile | 641 // Setup compile |
| 639 InstallFunc(isolate, webassembly, "compile", WebAssemblyCompile); | 642 InstallFunc(isolate, webassembly, "compile", WebAssemblyCompile, 1); |
| 640 | 643 |
| 641 // Setup compile | 644 // Setup compile |
| 642 InstallFunc(isolate, webassembly, "validate", WebAssemblyValidate); | 645 InstallFunc(isolate, webassembly, "validate", WebAssemblyValidate, 1); |
| 643 | 646 |
| 644 // Setup Module | 647 // Setup Module |
| 645 Handle<JSFunction> module_constructor = | 648 Handle<JSFunction> module_constructor = |
| 646 InstallFunc(isolate, webassembly, "Module", WebAssemblyModule); | 649 InstallFunc(isolate, webassembly, "Module", WebAssemblyModule, 1); |
| 647 context->set_wasm_module_constructor(*module_constructor); | 650 context->set_wasm_module_constructor(*module_constructor); |
| 648 Handle<JSObject> module_proto = | 651 Handle<JSObject> module_proto = |
| 649 factory->NewJSObject(module_constructor, TENURED); | 652 factory->NewJSObject(module_constructor, TENURED); |
| 650 i::Handle<i::Map> map = isolate->factory()->NewMap( | 653 i::Handle<i::Map> map = isolate->factory()->NewMap( |
| 651 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + | 654 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + |
| 652 WasmModuleObject::kFieldCount * i::kPointerSize); | 655 WasmModuleObject::kFieldCount * i::kPointerSize); |
| 653 JSFunction::SetInitialMap(module_constructor, map, module_proto); | 656 JSFunction::SetInitialMap(module_constructor, map, module_proto); |
| 654 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(), | 657 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(), |
| 655 module_constructor, DONT_ENUM); | 658 module_constructor, DONT_ENUM); |
| 656 | 659 |
| 657 // Setup Instance | 660 // Setup Instance |
| 658 Handle<JSFunction> instance_constructor = | 661 Handle<JSFunction> instance_constructor = |
| 659 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstance); | 662 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstance, 1); |
| 660 context->set_wasm_instance_constructor(*instance_constructor); | 663 context->set_wasm_instance_constructor(*instance_constructor); |
| 661 | 664 |
| 662 // Setup Table | 665 // Setup Table |
| 663 Handle<JSFunction> table_constructor = | 666 Handle<JSFunction> table_constructor = |
| 664 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable); | 667 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable, 1); |
| 665 context->set_wasm_table_constructor(*table_constructor); | 668 context->set_wasm_table_constructor(*table_constructor); |
| 666 Handle<JSObject> table_proto = | 669 Handle<JSObject> table_proto = |
| 667 factory->NewJSObject(table_constructor, TENURED); | 670 factory->NewJSObject(table_constructor, TENURED); |
| 668 map = isolate->factory()->NewMap( | 671 map = isolate->factory()->NewMap( |
| 669 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + | 672 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + |
| 670 WasmTableObject::kFieldCount * i::kPointerSize); | 673 WasmTableObject::kFieldCount * i::kPointerSize); |
| 671 JSFunction::SetInitialMap(table_constructor, map, table_proto); | 674 JSFunction::SetInitialMap(table_constructor, map, table_proto); |
| 672 JSObject::AddProperty(table_proto, isolate->factory()->constructor_string(), | 675 JSObject::AddProperty(table_proto, isolate->factory()->constructor_string(), |
| 673 table_constructor, DONT_ENUM); | 676 table_constructor, DONT_ENUM); |
| 674 InstallGetter(isolate, table_proto, "length", WebAssemblyTableGetLength); | 677 InstallGetter(isolate, table_proto, "length", WebAssemblyTableGetLength); |
| 675 InstallFunc(isolate, table_proto, "grow", WebAssemblyTableGrow); | 678 InstallFunc(isolate, table_proto, "grow", WebAssemblyTableGrow, 1); |
| 676 InstallFunc(isolate, table_proto, "get", WebAssemblyTableGet); | 679 InstallFunc(isolate, table_proto, "get", WebAssemblyTableGet, 1); |
| 677 InstallFunc(isolate, table_proto, "set", WebAssemblyTableSet); | 680 InstallFunc(isolate, table_proto, "set", WebAssemblyTableSet, 2); |
| 678 | 681 |
| 679 // Setup Memory | 682 // Setup Memory |
| 680 Handle<JSFunction> memory_constructor = | 683 Handle<JSFunction> memory_constructor = |
| 681 InstallFunc(isolate, webassembly, "Memory", WebAssemblyMemory); | 684 InstallFunc(isolate, webassembly, "Memory", WebAssemblyMemory, 1); |
| 682 context->set_wasm_memory_constructor(*memory_constructor); | 685 context->set_wasm_memory_constructor(*memory_constructor); |
| 683 Handle<JSObject> memory_proto = | 686 Handle<JSObject> memory_proto = |
| 684 factory->NewJSObject(memory_constructor, TENURED); | 687 factory->NewJSObject(memory_constructor, TENURED); |
| 685 map = isolate->factory()->NewMap( | 688 map = isolate->factory()->NewMap( |
| 686 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + | 689 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + |
| 687 WasmMemoryObject::kFieldCount * i::kPointerSize); | 690 WasmMemoryObject::kFieldCount * i::kPointerSize); |
| 688 JSFunction::SetInitialMap(memory_constructor, map, memory_proto); | 691 JSFunction::SetInitialMap(memory_constructor, map, memory_proto); |
| 689 JSObject::AddProperty(memory_proto, isolate->factory()->constructor_string(), | 692 JSObject::AddProperty(memory_proto, isolate->factory()->constructor_string(), |
| 690 memory_constructor, DONT_ENUM); | 693 memory_constructor, DONT_ENUM); |
| 691 InstallFunc(isolate, memory_proto, "grow", WebAssemblyMemoryGrow); | 694 InstallFunc(isolate, memory_proto, "grow", WebAssemblyMemoryGrow, 1); |
| 692 InstallGetter(isolate, memory_proto, "buffer", WebAssemblyMemoryGetBuffer); | 695 InstallGetter(isolate, memory_proto, "buffer", WebAssemblyMemoryGetBuffer); |
| 693 | 696 |
| 694 // Setup errors | 697 // Setup errors |
| 695 attributes = static_cast<PropertyAttributes>(DONT_ENUM); | 698 attributes = static_cast<PropertyAttributes>(DONT_ENUM); |
| 696 Handle<JSFunction> compile_error( | 699 Handle<JSFunction> compile_error( |
| 697 isolate->native_context()->wasm_compile_error_function()); | 700 isolate->native_context()->wasm_compile_error_function()); |
| 698 JSObject::AddProperty(webassembly, isolate->factory()->CompileError_string(), | 701 JSObject::AddProperty(webassembly, isolate->factory()->CompileError_string(), |
| 699 compile_error, attributes); | 702 compile_error, attributes); |
| 700 Handle<JSFunction> link_error( | 703 Handle<JSFunction> link_error( |
| 701 isolate->native_context()->wasm_link_error_function()); | 704 isolate->native_context()->wasm_link_error_function()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 767 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
| 765 return HasBrand(value, symbol); | 768 return HasBrand(value, symbol); |
| 766 } | 769 } |
| 767 | 770 |
| 768 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 771 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
| 769 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 772 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
| 770 return HasBrand(value, symbol); | 773 return HasBrand(value, symbol); |
| 771 } | 774 } |
| 772 } // namespace internal | 775 } // namespace internal |
| 773 } // namespace v8 | 776 } // namespace v8 |
| OLD | NEW |