Commit 15d3bcbd authored by Thibaud Michaud's avatar Thibaud Michaud Committed by V8 LUCI CQ

Reland "[wasm][eh] Rename Exception to Tag in the JS API"

This is a reland of 0b091e9b

Some blink web tests have been temporarily disabled to allow landing
changes to the JS API in V8.

Original change's description:
> [wasm][eh] Rename Exception to Tag in the JS API
>
> See:
> https://github.com/WebAssembly/exception-handling/issues/159
>
> This change only does the rename where it's observable. This should also
> be renamed throughout the codebase for consistency and will be done
> separately.
>
> R=ahaas@chromium.org
>
> Bug: v8:8091
> Change-Id: Iec1118194981dfd33be6e30256b6e72d12143e1f
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021172
> Reviewed-by: Andreas Haas <ahaas@chromium.org>
> Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#75718}

Bug: v8:8091
Change-Id: Id5375b5287fff81b8e0096377a55ef63e6d9b985
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3035083
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75785}
parent e677a9e3
......@@ -1507,15 +1507,15 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
}
case kExternalException: {
if (!value->IsWasmExceptionObject()) {
ReportLinkError("exception import requires a WebAssembly.Exception",
index, module_name, import_name);
ReportLinkError("tag import requires a WebAssembly.Tag", index,
module_name, import_name);
return -1;
}
Handle<WasmExceptionObject> imported_exception =
Handle<WasmExceptionObject>::cast(value);
if (!imported_exception->MatchesSignature(
module_->exceptions[import.index].sig)) {
ReportLinkError("imported exception does not match the expected type",
ReportLinkError("imported tag does not match the expected type",
index, module_name, import_name);
return -1;
}
......
......@@ -1408,19 +1408,19 @@ uint32_t GetIterableLength(i::Isolate* isolate, Local<Context> context,
} // namespace
// WebAssembly.Exception
void WebAssemblyException(const v8::FunctionCallbackInfo<v8::Value>& args) {
// WebAssembly.Tag
void WebAssemblyTag(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Exception()");
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Tag()");
if (!args.IsConstructCall()) {
thrower.TypeError("WebAssembly.Exception must be invoked with 'new'");
thrower.TypeError("WebAssembly.Tag must be invoked with 'new'");
return;
}
if (!args[0]->IsObject()) {
thrower.TypeError("Argument 0 must be an exception type");
thrower.TypeError("Argument 0 must be a tag type");
return;
}
......@@ -1435,7 +1435,7 @@ void WebAssemblyException(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::Value> parameters_value;
if (!parameters_maybe.ToLocal(&parameters_value) ||
!parameters_value->IsObject()) {
thrower.TypeError("Argument 0 must be an exception type with 'parameters'");
thrower.TypeError("Argument 0 must be a tag type with 'parameters'");
return;
}
Local<Object> parameters = parameters_value.As<Object>();
......@@ -2287,8 +2287,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Setup Exception
if (enabled_features.has_eh()) {
Handle<JSFunction> exception_constructor = InstallConstructorFunc(
isolate, webassembly, "Exception", WebAssemblyException);
Handle<JSFunction> exception_constructor =
InstallConstructorFunc(isolate, webassembly, "Tag", WebAssemblyTag);
context->set_wasm_exception_constructor(*exception_constructor);
SetDummyInstanceTemplate(isolate, exception_constructor);
JSFunction::EnsureHasInitialMap(exception_constructor);
......@@ -2349,7 +2349,7 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
void WasmJs::InstallConditionalFeatures(Isolate* isolate,
Handle<Context> context) {
// Exception handling may have been enabled by an origin trial. If so, make
// sure that the {WebAssembly.Exception} constructor is set up.
// sure that the {WebAssembly.Tag} constructor is set up.
auto enabled_features = i::wasm::WasmFeatures::FromContext(isolate, context);
if (enabled_features.has_eh()) {
Handle<JSGlobalObject> global = handle(context->global_object(), isolate);
......@@ -2368,7 +2368,7 @@ void WasmJs::InstallConditionalFeatures(Isolate* isolate,
}
Handle<JSObject> webassembly = Handle<JSObject>::cast(webassembly_obj);
// Setup Exception
Handle<String> exception_name = v8_str(isolate, "Exception");
Handle<String> exception_name = v8_str(isolate, "Tag");
if (JSObject::HasOwnProperty(webassembly, exception_name).FromMaybe(true)) {
// The {Exception} constructor already exists, there is nothing more to
// do.
......@@ -2377,14 +2377,14 @@ void WasmJs::InstallConditionalFeatures(Isolate* isolate,
bool has_prototype = true;
Handle<JSFunction> exception_constructor =
CreateFunc(isolate, exception_name, WebAssemblyException, has_prototype,
CreateFunc(isolate, exception_name, WebAssemblyTag, has_prototype,
SideEffectType::kHasNoSideEffect);
exception_constructor->shared().set_length(1);
auto result = Object::SetProperty(
isolate, webassembly, exception_name, exception_constructor,
StoreOrigin::kNamed, Just(ShouldThrow::kDontThrow));
if (result.is_null()) {
// Setting the {Exception} constructor failed. We just bail out.
// Setting the {Tag} constructor failed. We just bail out.
return;
}
// Install the constructor on the context.
......
......@@ -9,27 +9,27 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestImport() {
print(arguments.callee.name);
assertThrows(() => new WebAssembly.Exception(), TypeError,
/Argument 0 must be an exception type/);
assertThrows(() => new WebAssembly.Exception({}), TypeError,
/Argument 0 must be an exception type with 'parameters'/);
assertThrows(() => new WebAssembly.Exception({parameters: ['foo']}), TypeError,
assertThrows(() => new WebAssembly.Tag(), TypeError,
/Argument 0 must be a tag type/);
assertThrows(() => new WebAssembly.Tag({}), TypeError,
/Argument 0 must be a tag type with 'parameters'/);
assertThrows(() => new WebAssembly.Tag({parameters: ['foo']}), TypeError,
/Argument 0 parameter type at index #0 must be a value type/);
assertThrows(() => new WebAssembly.Exception({parameters: {}}), TypeError,
assertThrows(() => new WebAssembly.Tag({parameters: {}}), TypeError,
/Argument 0 contains parameters without 'length'/);
let js_except_i32 = new WebAssembly.Exception({parameters: ['i32']});
let js_except_v = new WebAssembly.Exception({parameters: []});
let js_except_i32 = new WebAssembly.Tag({parameters: ['i32']});
let js_except_v = new WebAssembly.Tag({parameters: []});
let builder = new WasmModuleBuilder();
builder.addImportedException("m", "ex", kSig_v_i);
assertDoesNotThrow(() => builder.instantiate({ m: { ex: js_except_i32 }}));
assertThrows(
() => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError,
/imported exception does not match the expected type/);
/imported tag does not match the expected type/);
assertThrows(
() => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError,
/imported exception does not match the expected type/);
/imported tag does not match the expected type/);
})();
(function TestExport() {
......@@ -41,14 +41,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex'));
assertEquals("object", typeof instance.exports.ex);
assertInstanceof(instance.exports.ex, WebAssembly.Exception);
assertSame(instance.exports.ex.constructor, WebAssembly.Exception);
assertInstanceof(instance.exports.ex, WebAssembly.Tag);
assertSame(instance.exports.ex.constructor, WebAssembly.Tag);
})();
(function TestImportExport() {
print(arguments.callee.name);
let js_ex_i32 = new WebAssembly.Exception({parameters: ['i32']});
let js_ex_i32 = new WebAssembly.Tag({parameters: ['i32']});
let builder = new WasmModuleBuilder();
let index = builder.addImportedException("m", "ex", kSig_v_i);
builder.addExportOfKind("ex", kExternalException, index);
......
......@@ -53,7 +53,7 @@ function NewExportedException() {
/module is not an object or function/);
assertThrows(
() => builder.instantiate({ m: {}}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/);
/tag import requires a WebAssembly.Tag/);
})();
(function TestImportValueMismatch() {
......@@ -63,14 +63,14 @@ function NewExportedException() {
assertThrows(
() => builder.instantiate({ m: { ex: 23 }}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/);
/tag import requires a WebAssembly.Tag/);
assertThrows(
() => builder.instantiate({ m: { ex: {} }}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/);
/tag import requires a WebAssembly.Tag/);
var monkey = Object.create(NewExportedException());
assertThrows(
() => builder.instantiate({ m: { ex: monkey }}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/);
/tag import requires a WebAssembly.Tag/);
})();
(function TestImportSignatureMismatch() {
......@@ -81,7 +81,7 @@ function NewExportedException() {
assertThrows(
() => builder.instantiate({ m: { ex: exported }}), WebAssembly.LinkError,
/imported exception does not match the expected type/);
/imported tag does not match the expected type/);
})();
(function TestImportModuleGetImports() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment