Skip to content

Commit

Permalink
[js-api] Exception -> Tag in wasm-module-builder
Browse files Browse the repository at this point in the history
Tags used to be called exceptions when this file was first created. Now
we use 'tag' for the entity that contains a type and is used in `throw`
and `catch`, and 'exception' for an object that contains a tag and a
payload. This PR reflects this change.
  • Loading branch information
aheejin authored and Ms2ger committed Feb 16, 2023
1 parent afe9461 commit 956b198
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions test/js-api/wasm-module-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let kElementSectionCode = 9; // Elements section
let kCodeSectionCode = 10; // Function code
let kDataSectionCode = 11; // Data segments
let kDataCountSectionCode = 12; // Data segment count (between Element & Code)
let kExceptionSectionCode = 13; // Exception section (between Global & Export)
let kTagSectionCode = 13; // Tag section (between Memory & Global)

// Name section types
let kModuleNameCode = 0;
Expand Down Expand Up @@ -104,13 +104,13 @@ let kExternalFunction = 0;
let kExternalTable = 1;
let kExternalMemory = 2;
let kExternalGlobal = 3;
let kExternalException = 4;
let kExternalTag = 4;

let kTableZero = 0;
let kMemoryZero = 0;
let kSegmentZero = 0;

let kExceptionAttribute = 0;
let kTagAttribute = 0;

// Useful signatures
let kSig_i_i = makeSig([kWasmI32], [kWasmI32]);
Expand Down Expand Up @@ -681,15 +681,15 @@ class WasmModuleBuilder {
this.exports = [];
this.globals = [];
this.tables = [];
this.exceptions = [];
this.tags = [];
this.functions = [];
this.element_segments = [];
this.data_segments = [];
this.explicit = [];
this.num_imported_funcs = 0;
this.num_imported_globals = 0;
this.num_imported_tables = 0;
this.num_imported_exceptions = 0;
this.num_imported_tags = 0;
return this;
}

Expand Down Expand Up @@ -752,10 +752,10 @@ class WasmModuleBuilder {
return table;
}

addException(type) {
addTag(type) {
let type_index = (typeof type) == "number" ? type : this.addType(type);
let except_index = this.exceptions.length + this.num_imported_exceptions;
this.exceptions.push(type_index);
let except_index = this.tags.length + this.num_imported_tags;
this.tags.push(type_index);
return except_index;
}

Expand Down Expand Up @@ -804,14 +804,14 @@ class WasmModuleBuilder {
return this.num_imported_tables++;
}

addImportedException(module, name, type) {
if (this.exceptions.length != 0) {
throw new Error('Imported exceptions must be declared before local ones');
addImportedTag(module, name, type) {
if (this.tags.length != 0) {
throw new Error('Imported tags must be declared before local ones');
}
let type_index = (typeof type) == "number" ? type : this.addType(type);
let o = {module: module, name: name, kind: kExternalException, type: type_index};
let o = {module: module, name: name, kind: kExternalTag, type: type_index};
this.imports.push(o);
return this.num_imported_exceptions++;
return this.num_imported_tags++;
}

addExport(name, index) {
Expand Down Expand Up @@ -938,8 +938,8 @@ class WasmModuleBuilder {
section.emit_u8(has_max ? 1 : 0); // flags
section.emit_u32v(imp.initial); // initial
if (has_max) section.emit_u32v(imp.maximum); // maximum
} else if (imp.kind == kExternalException) {
section.emit_u32v(kExceptionAttribute);
} else if (imp.kind == kExternalTag) {
section.emit_u32v(kTagAttribute);
section.emit_u32v(imp.type);
} else {
throw new Error("unknown/unsupported import kind " + imp.kind);
Expand Down Expand Up @@ -1036,13 +1036,13 @@ class WasmModuleBuilder {
});
}

// Add exceptions.
if (wasm.exceptions.length > 0) {
if (debug) print("emitting exceptions @ " + binary.length);
binary.emit_section(kExceptionSectionCode, section => {
section.emit_u32v(wasm.exceptions.length);
for (let type of wasm.exceptions) {
section.emit_u32v(kExceptionAttribute);
// Add tags.
if (wasm.tags.length > 0) {
if (debug) print("emitting tags @ " + binary.length);
binary.emit_section(kTagSectionCode, section => {
section.emit_u32v(wasm.tags.length);
for (let type of wasm.tags) {
section.emit_u32v(kTagAttribute);
section.emit_u32v(type);
}
});
Expand Down

0 comments on commit 956b198

Please sign in to comment.