From e3242a4858dbdef7c1af0ab6933de56fa69252ab Mon Sep 17 00:00:00 2001 From: Nico Hartmann Date: Tue, 20 Jul 2021 15:02:20 +0000 Subject: [PATCH] Revert "[wasm][eh] Add WebAssembly.Tag.type" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4cc547c759a8756a1215c90c37a57601a28d6736. Reason for revert: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64%20UBSan/17396/overview Original change's description: > [wasm][eh] Add WebAssembly.Tag.type > > R=​ahaas@chromium.org > > Bug: v8:8091 > Change-Id: Id069ffbf76bf836b613287788b1b1fccbb577475 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021173 > Reviewed-by: Andreas Haas > Reviewed-by: Jakob Kummerow > Commit-Queue: Thibaud Michaud > Cr-Commit-Position: refs/heads/master@{#75815} Bug: v8:8091 Change-Id: I2581f82e6bc8a622a833b79037b4e58f587918cc No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3041432 Reviewed-by: Nico Hartmann Commit-Queue: Nico Hartmann Cr-Commit-Position: refs/heads/master@{#75821} --- src/wasm/wasm-js.cc | 29 +---------- src/wasm/wasm-module.cc | 27 ++++------ src/wasm/wasm-module.h | 3 +- .../wasm/exceptions-type-reflection.js | 49 ------------------- 4 files changed, 12 insertions(+), 96 deletions(-) delete mode 100644 test/mjsunit/wasm/exceptions-type-reflection.js diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc index a4e4e3730a..c9e1bc433c 100644 --- a/src/wasm/wasm-js.cc +++ b/src/wasm/wasm-js.cc @@ -1466,7 +1466,7 @@ void WebAssemblyTag(const v8::FunctionCallbackInfo& args) { // Set the tag index to 0. It is only used for debugging purposes, and has no // meaningful value when declared outside of a wasm module. auto tag = i::WasmExceptionTag::New(i_isolate, 0); - i::Handle exception = + i::Handle exception = i::WasmExceptionObject::New(i_isolate, &sig, tag); args.GetReturnValue().Set(Utils::ToLocal(exception)); } @@ -1621,7 +1621,6 @@ constexpr const char* kName_WasmGlobalObject = "WebAssembly.Global"; constexpr const char* kName_WasmMemoryObject = "WebAssembly.Memory"; constexpr const char* kName_WasmInstanceObject = "WebAssembly.Instance"; constexpr const char* kName_WasmTableObject = "WebAssembly.Table"; -constexpr const char* kName_WasmExceptionObject = "WebAssembly.Tag"; #define EXTRACT_THIS(var, WasmType) \ i::Handle var; \ @@ -1853,25 +1852,6 @@ void WebAssemblyMemoryType(const v8::FunctionCallbackInfo& args) { args.GetReturnValue().Set(Utils::ToLocal(type)); } -// WebAssembly.Tag.type() -> FunctionType -void WebAssemblyTagType(const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); - HandleScope scope(isolate); - i::Isolate* i_isolate = reinterpret_cast(isolate); - ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Tag.type()"); - - EXTRACT_THIS(tag, WasmExceptionObject); - if (thrower.error()) return; - - int n = tag->serialized_signature().length(); - std::vector data(n); - tag->serialized_signature().copy_out(0, data.data(), n); - const i::wasm::FunctionSig sig{0, data.size(), data.data()}; - constexpr bool kForException = true; - auto type = i::wasm::GetTypeForFunction(i_isolate, &sig, kForException); - args.GetReturnValue().Set(Utils::ToLocal(type)); -} - void WebAssemblyGlobalGetValueCommon( const v8::FunctionCallbackInfo& args, const char* name) { v8::Isolate* isolate = args.GetIsolate(); @@ -2310,14 +2290,10 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) { Handle exception_constructor = InstallConstructorFunc(isolate, webassembly, "Tag", WebAssemblyTag); context->set_wasm_exception_constructor(*exception_constructor); - SetDummyInstanceTemplate(isolate, exception_constructor); JSFunction::EnsureHasInitialMap(exception_constructor); Handle exception_proto( JSObject::cast(exception_constructor->instance_prototype()), isolate); - if (enabled_features.has_type_reflection()) { - InstallFunc(isolate, exception_proto, "type", WebAssemblyTagType, 0); - } Handle exception_map = isolate->factory()->NewMap( i::WASM_EXCEPTION_OBJECT_TYPE, WasmExceptionObject::kHeaderSize); JSFunction::SetInitialMap(isolate, exception_constructor, exception_map, @@ -2417,9 +2393,6 @@ void WasmJs::InstallConditionalFeatures(Isolate* isolate, JSFunction::EnsureHasInitialMap(exception_constructor); Handle exception_proto( JSObject::cast(exception_constructor->instance_prototype()), isolate); - if (enabled_features.has_type_reflection()) { - InstallFunc(isolate, exception_proto, "type", WebAssemblyTagType, 0); - } Handle exception_map = isolate->factory()->NewMap( i::WASM_EXCEPTION_OBJECT_TYPE, WasmExceptionObject::kHeaderSize); JSFunction::SetInitialMap(isolate, exception_constructor, exception_map, diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc index caa2f7d59a..9de8ca4a08 100644 --- a/src/wasm/wasm-module.cc +++ b/src/wasm/wasm-module.cc @@ -237,8 +237,7 @@ Handle ToValueTypeString(Isolate* isolate, ValueType type) { } } // namespace -Handle GetTypeForFunction(Isolate* isolate, const FunctionSig* sig, - bool for_exception) { +Handle GetTypeForFunction(Isolate* isolate, const FunctionSig* sig) { Factory* factory = isolate->factory(); // Extract values for the {ValueType[]} arrays. @@ -249,29 +248,23 @@ Handle GetTypeForFunction(Isolate* isolate, const FunctionSig* sig, Handle type_value = ToValueTypeString(isolate, type); param_values->set(param_index++, *type_value); } + int result_index = 0; + int result_count = static_cast(sig->return_count()); + Handle result_values = factory->NewFixedArray(result_count); + for (ValueType type : sig->returns()) { + Handle type_value = ToValueTypeString(isolate, type); + result_values->set(result_index++, *type_value); + } // Create the resulting {FunctionType} object. Handle object_function = isolate->object_function(); Handle object = factory->NewJSObject(object_function); Handle params = factory->NewJSArrayWithElements(param_values); + Handle results = factory->NewJSArrayWithElements(result_values); Handle params_string = factory->InternalizeUtf8String("parameters"); Handle results_string = factory->InternalizeUtf8String("results"); JSObject::AddProperty(isolate, object, params_string, params, NONE); - - // Now add the result types if needed. - if (for_exception) { - DCHECK_EQ(sig->returns().size(), 0); - } else { - int result_index = 0; - int result_count = static_cast(sig->return_count()); - Handle result_values = factory->NewFixedArray(result_count); - for (ValueType type : sig->returns()) { - Handle type_value = ToValueTypeString(isolate, type); - result_values->set(result_index++, *type_value); - } - Handle results = factory->NewJSArrayWithElements(result_values); - JSObject::AddProperty(isolate, object, results_string, results, NONE); - } + JSObject::AddProperty(isolate, object, results_string, results, NONE); return object; } diff --git a/src/wasm/wasm-module.h b/src/wasm/wasm-module.h index 7c67a5a71b..6332393490 100644 --- a/src/wasm/wasm-module.h +++ b/src/wasm/wasm-module.h @@ -472,8 +472,7 @@ std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name); V8_EXPORT_PRIVATE bool IsWasmCodegenAllowed(Isolate* isolate, Handle context); -Handle GetTypeForFunction(Isolate* isolate, const FunctionSig* sig, - bool for_exception = false); +Handle GetTypeForFunction(Isolate* isolate, const FunctionSig* sig); Handle GetTypeForGlobal(Isolate* isolate, bool is_mutable, ValueType type); Handle GetTypeForMemory(Isolate* isolate, uint32_t min_size, diff --git a/test/mjsunit/wasm/exceptions-type-reflection.js b/test/mjsunit/wasm/exceptions-type-reflection.js deleted file mode 100644 index 3358ae330d..0000000000 --- a/test/mjsunit/wasm/exceptions-type-reflection.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2021 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --experimental-wasm-eh --experimental-wasm-type-reflection - -load("test/mjsunit/wasm/wasm-module-builder.js"); - -let testcases = [ -{types: {parameters:[]}, sig: kSig_v_v}, -{types: {parameters:["i32"]}, sig: kSig_v_i}, -{types: {parameters:["i64"]}, sig: kSig_v_l}, -{types: {parameters:["f64", "f64", "i32"]}, sig: kSig_v_ddi}, -{types: {parameters:["f32"]}, sig: kSig_v_f}, -]; - -(function TestExport() { - print(arguments.callee.name); - let builder = new WasmModuleBuilder(); - - testcases.forEach(function(expected, i) { - let except = builder.addException(expected.sig); - builder.addExportOfKind("ex" + i, kExternalException, except); - }); - - let instance = builder.instantiate(); - testcases.forEach(function(expected, i) { - assertEquals(instance.exports["ex" + i].type(), expected.types); - }); -})(); - -(function TestImportExport() { - print(arguments.callee.name); - - let builder = new WasmModuleBuilder(); - let imports = {m: {}}; - - testcases.forEach(function(expected, i) { - let t = new WebAssembly.Tag(expected.types); - let index = builder.addImportedException("m", "ex" + i, expected.sig); - builder.addExportOfKind("ex" + i, kExternalException, index); - imports.m["ex" + i] = t; - }); - - let instance = builder.instantiate(imports); - testcases.forEach(function(expected, i) { - assertEquals(instance.exports["ex" + i].type(), expected.types); - }) -})();