Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/wasm/wasm-js.cc

Issue 2977113002: [wasm] Fix user properties for exported wasm functions and add extensive tests. (Closed)
Patch Set: debug verify Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 return function; 861 return function;
862 } 862 }
863 863
864 void WasmJs::Install(Isolate* isolate) { 864 void WasmJs::Install(Isolate* isolate) {
865 Handle<JSGlobalObject> global = isolate->global_object(); 865 Handle<JSGlobalObject> global = isolate->global_object();
866 Handle<Context> context(global->native_context(), isolate); 866 Handle<Context> context(global->native_context(), isolate);
867 // Check if the map is already installed and do nothing otherwise. 867 // Check if the map is already installed and do nothing otherwise.
868 if (context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) return; 868 if (context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) return;
869 869
870 // Install Maps. 870 // Install Maps.
871 Handle<Map> prev_map = Handle<Map>(context->sloppy_function_map(), isolate); 871 {
872 Handle<Map> prev_map = Handle<Map>(context->sloppy_function_map(), isolate);
872 873
873 InstanceType instance_type = prev_map->instance_type(); 874 InstanceType instance_type = prev_map->instance_type();
874 int embedder_fields = JSObject::GetEmbedderFieldCount(*prev_map); 875 int embedder_fields = JSObject::GetEmbedderFieldCount(*prev_map);
875 CHECK_EQ(0, embedder_fields); 876 CHECK_EQ(0, embedder_fields);
876 int pre_allocated = 877 int pre_allocated =
877 prev_map->GetInObjectProperties() - prev_map->unused_property_fields(); 878 prev_map->GetInObjectProperties() - prev_map->unused_property_fields();
878 int instance_size = 0; 879 int instance_size = 0;
879 int in_object_properties = WasmExportedFunction::kFieldCount; 880 int in_object_properties = WasmExportedFunction::kFieldCount;
880 JSFunction::CalculateInstanceSizeHelper(instance_type, embedder_fields, 881 JSFunction::CalculateInstanceSizeHelper(
881 in_object_properties, &instance_size, 882 instance_type, embedder_fields, in_object_properties, &instance_size,
882 &in_object_properties); 883 &in_object_properties);
883 884
884 int unused_property_fields = in_object_properties - pre_allocated; 885 // Double-check our math.
885 Handle<Map> map = Map::CopyInitialMap( 886 CHECK_EQ(WasmExportedFunction::kSize, instance_size);
886 prev_map, instance_size, in_object_properties, unused_property_fields);
887 887
888 context->set_wasm_function_map(*map); 888 int unused_property_fields = in_object_properties - pre_allocated;
889 Handle<Map> map = Map::CopyInitialMap(
890 prev_map, instance_size, in_object_properties, unused_property_fields);
891 map->set_unused_property_fields(unused_property_fields -
892 WasmExportedFunction::kFieldCount);
893
894 // We have to install descriptors into the map, because the {instance}
895 // and {func_index} fields of the exported functions are allocated as
896 // in-object properties, which must be reflected in the map.
897 Map::EnsureDescriptorSlack(map, WasmExportedFunction::kFieldCount);
898
899 PropertyAttributes rw_attribs =
900 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
901
902 {
903 // Add instance.
904 Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
905 Descriptor d =
906 Descriptor::DataField(symbol, WasmExportedFunction::kInstanceIndex,
907 rw_attribs, Representation::Tagged());
908 map->AppendDescriptor(&d);
909 }
910
911 {
912 // Add function_index.
913 Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
914 Descriptor d = Descriptor::DataField(
915 symbol, WasmExportedFunction::kFunctionIndexIndex, rw_attribs,
916 Representation::Tagged());
917 map->AppendDescriptor(&d);
918 }
919
920 context->set_wasm_function_map(*map);
921 // Double-check we created a proper map.
922 #if DEBUG
923 map->HeapObjectVerify();
924 #endif
925 }
889 926
890 Factory* factory = isolate->factory(); 927 Factory* factory = isolate->factory();
891 928
892 // Install the JS API. 929 // Install the JS API.
893 930
894 // Setup WebAssembly 931 // Setup WebAssembly
895 Handle<String> name = v8_str(isolate, "WebAssembly"); 932 Handle<String> name = v8_str(isolate, "WebAssembly");
896 Handle<JSFunction> cons = factory->NewFunction(isolate->strict_function_map(), 933 Handle<JSFunction> cons = factory->NewFunction(isolate->strict_function_map(),
897 name, MaybeHandle<Code>()); 934 name, MaybeHandle<Code>());
898 JSFunction::SetPrototype(cons, isolate->initial_object_prototype()); 935 JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 isolate->native_context()->wasm_link_error_function()); 1032 isolate->native_context()->wasm_link_error_function());
996 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(), 1033 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(),
997 link_error, attributes); 1034 link_error, attributes);
998 Handle<JSFunction> runtime_error( 1035 Handle<JSFunction> runtime_error(
999 isolate->native_context()->wasm_runtime_error_function()); 1036 isolate->native_context()->wasm_runtime_error_function());
1000 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(), 1037 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(),
1001 runtime_error, attributes); 1038 runtime_error, attributes);
1002 } 1039 }
1003 } // namespace internal 1040 } // namespace internal
1004 } // namespace v8 1041 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/wasm/user-properties.js » ('j') | test/mjsunit/wasm/user-properties.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698