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

This is a reland of 0b091e9bd3

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: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75785}
This commit is contained in:
Thibaud Michaud 2021-07-13 17:32:18 +02:00 committed by V8 LUCI CQ
parent e677a9e33d
commit 15d3bcbd7f
4 changed files with 33 additions and 33 deletions

View File

@ -1507,15 +1507,15 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
} }
case kExternalException: { case kExternalException: {
if (!value->IsWasmExceptionObject()) { if (!value->IsWasmExceptionObject()) {
ReportLinkError("exception import requires a WebAssembly.Exception", ReportLinkError("tag import requires a WebAssembly.Tag", index,
index, module_name, import_name); module_name, import_name);
return -1; return -1;
} }
Handle<WasmExceptionObject> imported_exception = Handle<WasmExceptionObject> imported_exception =
Handle<WasmExceptionObject>::cast(value); Handle<WasmExceptionObject>::cast(value);
if (!imported_exception->MatchesSignature( if (!imported_exception->MatchesSignature(
module_->exceptions[import.index].sig)) { 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); index, module_name, import_name);
return -1; return -1;
} }

View File

@ -1408,19 +1408,19 @@ uint32_t GetIterableLength(i::Isolate* isolate, Local<Context> context,
} // namespace } // namespace
// WebAssembly.Exception // WebAssembly.Tag
void WebAssemblyException(const v8::FunctionCallbackInfo<v8::Value>& args) { void WebAssemblyTag(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate(); v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate); HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Exception()"); ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Tag()");
if (!args.IsConstructCall()) { if (!args.IsConstructCall()) {
thrower.TypeError("WebAssembly.Exception must be invoked with 'new'"); thrower.TypeError("WebAssembly.Tag must be invoked with 'new'");
return; return;
} }
if (!args[0]->IsObject()) { if (!args[0]->IsObject()) {
thrower.TypeError("Argument 0 must be an exception type"); thrower.TypeError("Argument 0 must be a tag type");
return; return;
} }
@ -1435,7 +1435,7 @@ void WebAssemblyException(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::Value> parameters_value; v8::Local<v8::Value> parameters_value;
if (!parameters_maybe.ToLocal(&parameters_value) || if (!parameters_maybe.ToLocal(&parameters_value) ||
!parameters_value->IsObject()) { !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; return;
} }
Local<Object> parameters = parameters_value.As<Object>(); Local<Object> parameters = parameters_value.As<Object>();
@ -2287,8 +2287,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Setup Exception // Setup Exception
if (enabled_features.has_eh()) { if (enabled_features.has_eh()) {
Handle<JSFunction> exception_constructor = InstallConstructorFunc( Handle<JSFunction> exception_constructor =
isolate, webassembly, "Exception", WebAssemblyException); InstallConstructorFunc(isolate, webassembly, "Tag", WebAssemblyTag);
context->set_wasm_exception_constructor(*exception_constructor); context->set_wasm_exception_constructor(*exception_constructor);
SetDummyInstanceTemplate(isolate, exception_constructor); SetDummyInstanceTemplate(isolate, exception_constructor);
JSFunction::EnsureHasInitialMap(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, void WasmJs::InstallConditionalFeatures(Isolate* isolate,
Handle<Context> context) { Handle<Context> context) {
// Exception handling may have been enabled by an origin trial. If so, make // 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); auto enabled_features = i::wasm::WasmFeatures::FromContext(isolate, context);
if (enabled_features.has_eh()) { if (enabled_features.has_eh()) {
Handle<JSGlobalObject> global = handle(context->global_object(), isolate); 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); Handle<JSObject> webassembly = Handle<JSObject>::cast(webassembly_obj);
// Setup Exception // 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)) { if (JSObject::HasOwnProperty(webassembly, exception_name).FromMaybe(true)) {
// The {Exception} constructor already exists, there is nothing more to // The {Exception} constructor already exists, there is nothing more to
// do. // do.
@ -2377,14 +2377,14 @@ void WasmJs::InstallConditionalFeatures(Isolate* isolate,
bool has_prototype = true; bool has_prototype = true;
Handle<JSFunction> exception_constructor = Handle<JSFunction> exception_constructor =
CreateFunc(isolate, exception_name, WebAssemblyException, has_prototype, CreateFunc(isolate, exception_name, WebAssemblyTag, has_prototype,
SideEffectType::kHasNoSideEffect); SideEffectType::kHasNoSideEffect);
exception_constructor->shared().set_length(1); exception_constructor->shared().set_length(1);
auto result = Object::SetProperty( auto result = Object::SetProperty(
isolate, webassembly, exception_name, exception_constructor, isolate, webassembly, exception_name, exception_constructor,
StoreOrigin::kNamed, Just(ShouldThrow::kDontThrow)); StoreOrigin::kNamed, Just(ShouldThrow::kDontThrow));
if (result.is_null()) { if (result.is_null()) {
// Setting the {Exception} constructor failed. We just bail out. // Setting the {Tag} constructor failed. We just bail out.
return; return;
} }
// Install the constructor on the context. // Install the constructor on the context.

View File

@ -9,27 +9,27 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestImport() { (function TestImport() {
print(arguments.callee.name); print(arguments.callee.name);
assertThrows(() => new WebAssembly.Exception(), TypeError, assertThrows(() => new WebAssembly.Tag(), TypeError,
/Argument 0 must be an exception type/); /Argument 0 must be a tag type/);
assertThrows(() => new WebAssembly.Exception({}), TypeError, assertThrows(() => new WebAssembly.Tag({}), TypeError,
/Argument 0 must be an exception type with 'parameters'/); /Argument 0 must be a tag type with 'parameters'/);
assertThrows(() => new WebAssembly.Exception({parameters: ['foo']}), TypeError, assertThrows(() => new WebAssembly.Tag({parameters: ['foo']}), TypeError,
/Argument 0 parameter type at index #0 must be a value type/); /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'/); /Argument 0 contains parameters without 'length'/);
let js_except_i32 = new WebAssembly.Exception({parameters: ['i32']}); let js_except_i32 = new WebAssembly.Tag({parameters: ['i32']});
let js_except_v = new WebAssembly.Exception({parameters: []}); let js_except_v = new WebAssembly.Tag({parameters: []});
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImportedException("m", "ex", kSig_v_i); builder.addImportedException("m", "ex", kSig_v_i);
assertDoesNotThrow(() => builder.instantiate({ m: { ex: js_except_i32 }})); assertDoesNotThrow(() => builder.instantiate({ m: { ex: js_except_i32 }}));
assertThrows( assertThrows(
() => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError, () => 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( assertThrows(
() => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError, () => 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() { (function TestExport() {
@ -41,14 +41,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex')); assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex'));
assertEquals("object", typeof instance.exports.ex); assertEquals("object", typeof instance.exports.ex);
assertInstanceof(instance.exports.ex, WebAssembly.Exception); assertInstanceof(instance.exports.ex, WebAssembly.Tag);
assertSame(instance.exports.ex.constructor, WebAssembly.Exception); assertSame(instance.exports.ex.constructor, WebAssembly.Tag);
})(); })();
(function TestImportExport() { (function TestImportExport() {
print(arguments.callee.name); 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 builder = new WasmModuleBuilder();
let index = builder.addImportedException("m", "ex", kSig_v_i); let index = builder.addImportedException("m", "ex", kSig_v_i);
builder.addExportOfKind("ex", kExternalException, index); builder.addExportOfKind("ex", kExternalException, index);

View File

@ -53,7 +53,7 @@ function NewExportedException() {
/module is not an object or function/); /module is not an object or function/);
assertThrows( assertThrows(
() => builder.instantiate({ m: {}}), WebAssembly.LinkError, () => builder.instantiate({ m: {}}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/); /tag import requires a WebAssembly.Tag/);
})(); })();
(function TestImportValueMismatch() { (function TestImportValueMismatch() {
@ -63,14 +63,14 @@ function NewExportedException() {
assertThrows( assertThrows(
() => builder.instantiate({ m: { ex: 23 }}), WebAssembly.LinkError, () => builder.instantiate({ m: { ex: 23 }}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/); /tag import requires a WebAssembly.Tag/);
assertThrows( assertThrows(
() => builder.instantiate({ m: { ex: {} }}), WebAssembly.LinkError, () => builder.instantiate({ m: { ex: {} }}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/); /tag import requires a WebAssembly.Tag/);
var monkey = Object.create(NewExportedException()); var monkey = Object.create(NewExportedException());
assertThrows( assertThrows(
() => builder.instantiate({ m: { ex: monkey }}), WebAssembly.LinkError, () => builder.instantiate({ m: { ex: monkey }}), WebAssembly.LinkError,
/exception import requires a WebAssembly.Exception/); /tag import requires a WebAssembly.Tag/);
})(); })();
(function TestImportSignatureMismatch() { (function TestImportSignatureMismatch() {
@ -81,7 +81,7 @@ function NewExportedException() {
assertThrows( assertThrows(
() => builder.instantiate({ m: { ex: exported }}), WebAssembly.LinkError, () => 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() { (function TestImportModuleGetImports() {