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/assert-scope.h" | 7 #include "src/assert-scope.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/execution.h" | 9 #include "src/execution.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 static_cast<v8::PropertyAttribute>(v8::DontEnum); | 858 static_cast<v8::PropertyAttribute>(v8::DontEnum); |
859 Utils::ToLocal(object)->SetAccessorProperty(Utils::ToLocal(name), | 859 Utils::ToLocal(object)->SetAccessorProperty(Utils::ToLocal(name), |
860 Utils::ToLocal(function), | 860 Utils::ToLocal(function), |
861 Local<Function>(), attributes); | 861 Local<Function>(), attributes); |
862 return function; | 862 return function; |
863 } | 863 } |
864 | 864 |
865 void WasmJs::Install(Isolate* isolate) { | 865 void WasmJs::Install(Isolate* isolate) { |
866 Handle<JSGlobalObject> global = isolate->global_object(); | 866 Handle<JSGlobalObject> global = isolate->global_object(); |
867 Handle<Context> context(global->native_context(), isolate); | 867 Handle<Context> context(global->native_context(), isolate); |
868 // Check if the map is already installed and do nothing otherwise. | 868 // Install the JS API once only. |
869 if (context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) return; | 869 Object* prev = context->get(Context::WASM_MODULE_CONSTRUCTOR_INDEX); |
870 | 870 if (!prev->IsUndefined(isolate)) { |
871 // Install Maps. | 871 DCHECK(prev->IsJSFunction()); |
872 Handle<Map> prev_map = Handle<Map>(context->sloppy_function_map(), isolate); | 872 return; |
873 | 873 } |
874 InstanceType instance_type = prev_map->instance_type(); | |
875 int embedder_fields = JSObject::GetEmbedderFieldCount(*prev_map); | |
876 CHECK_EQ(0, embedder_fields); | |
877 int pre_allocated = | |
878 prev_map->GetInObjectProperties() - prev_map->unused_property_fields(); | |
879 int instance_size = 0; | |
880 int in_object_properties = WasmExportedFunction::kFieldCount; | |
881 JSFunction::CalculateInstanceSizeHelper(instance_type, embedder_fields, | |
882 in_object_properties, &instance_size, | |
883 &in_object_properties); | |
884 | |
885 int unused_property_fields = in_object_properties - pre_allocated; | |
886 Handle<Map> map = Map::CopyInitialMap( | |
887 prev_map, instance_size, in_object_properties, unused_property_fields); | |
888 | |
889 context->set_wasm_function_map(*map); | |
890 | 874 |
891 Factory* factory = isolate->factory(); | 875 Factory* factory = isolate->factory(); |
892 | 876 |
893 // Install the JS API. | |
894 | |
895 // Setup WebAssembly | 877 // Setup WebAssembly |
896 Handle<String> name = v8_str(isolate, "WebAssembly"); | 878 Handle<String> name = v8_str(isolate, "WebAssembly"); |
897 Handle<JSFunction> cons = factory->NewFunction(isolate->strict_function_map(), | 879 Handle<JSFunction> cons = factory->NewFunction(isolate->strict_function_map(), |
898 name, MaybeHandle<Code>()); | 880 name, MaybeHandle<Code>()); |
899 JSFunction::SetPrototype(cons, isolate->initial_object_prototype()); | 881 JSFunction::SetPrototype(cons, isolate->initial_object_prototype()); |
900 cons->shared()->set_instance_class_name(*name); | 882 cons->shared()->set_instance_class_name(*name); |
901 Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED); | 883 Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED); |
902 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); | 884 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); |
903 JSObject::AddProperty(global, name, webassembly, attributes); | 885 JSObject::AddProperty(global, name, webassembly, attributes); |
904 PropertyAttributes ro_attributes = | 886 PropertyAttributes ro_attributes = |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 isolate->native_context()->wasm_link_error_function()); | 978 isolate->native_context()->wasm_link_error_function()); |
997 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(), | 979 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(), |
998 link_error, attributes); | 980 link_error, attributes); |
999 Handle<JSFunction> runtime_error( | 981 Handle<JSFunction> runtime_error( |
1000 isolate->native_context()->wasm_runtime_error_function()); | 982 isolate->native_context()->wasm_runtime_error_function()); |
1001 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(), | 983 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(), |
1002 runtime_error, attributes); | 984 runtime_error, attributes); |
1003 } | 985 } |
1004 } // namespace internal | 986 } // namespace internal |
1005 } // namespace v8 | 987 } // namespace v8 |
OLD | NEW |