Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js-api] Update wasm-module-builder.js for exnref #313

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions test/js-api/wasm-module-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ let kDeclFunctionImport = 0x02;
let kDeclFunctionLocals = 0x04;
let kDeclFunctionExport = 0x08;

// Local types
let kWasmStmt = 0x40;
// Value types and related
let kWasmVoid = 0x40;
let kWasmI32 = 0x7f;
let kWasmI64 = 0x7e;
let kWasmF32 = 0x7d;
Expand All @@ -107,6 +107,8 @@ let kWasmFuncRef = -0x10;
let kWasmAnyFunc = kWasmFuncRef; // Alias named as in the JS API spec
let kWasmExternRef = -0x11;
let kWasmAnyRef = -0x12;
let kWasmExnRef = -0x17;
let kWasmNullExnRef = -0x0c;

// Use the positive-byte versions inside function bodies.
let kLeb128Mask = 0x7f;
Expand All @@ -116,6 +118,8 @@ let kExternRefCode = kWasmExternRef & kLeb128Mask;
let kAnyRefCode = kWasmAnyRef & kLeb128Mask;
let kNullExternRefCode = kWasmNullExternRef & kLeb128Mask;
let kNullFuncRefCode = kWasmNullFuncRef & kLeb128Mask;
let kExnRefCode = kWasmExnRef & kLeb128Mask;
let kNullExnRefCode = kWasmNullExnRef & kLeb128Mask;
let kNullRefCode = kWasmNullRef & kLeb128Mask;

let kWasmRefNull = 0x63;
Expand All @@ -137,7 +141,7 @@ let kTableZero = 0;
let kMemoryZero = 0;
let kSegmentZero = 0;

let kTagAttribute = 0;
let kExceptionAttribute = 0;

// Useful signatures
let kSig_i_i = makeSig([kWasmI32], [kWasmI32]);
Expand Down Expand Up @@ -217,10 +221,9 @@ let kExprIf = 0x04;
let kExprElse = 0x05;
let kExprTry = 0x06;
let kExprCatch = 0x07;
let kExprCatchAll = 0x19;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These old instructions were not deleted; they were just moved below to maintain the sorted order of opcodes.

(This is not actually the same as what v8 file does; it refactored the old opcodes into a list, which I didn't pull in here: https://github.com/v8/v8/blob/8b52e5f026dc859cab827ec584f3eedbc0510459/test/mjsunit/wasm/wasm-module-builder.js#L261-L463. But the sorted order is maintained in this list too.)

let kExprThrow = 0x08;
let kExprRethrow = 0x09;
let kExprBrOnExn = 0x0a;
let kExprThrowRef = 0x0a;
let kExprEnd = 0x0b;
let kExprBr = 0x0c;
let kExprBrIf = 0x0d;
Expand All @@ -230,8 +233,10 @@ let kExprCallFunction = 0x10;
let kExprCallIndirect = 0x11;
let kExprReturnCall = 0x12;
let kExprReturnCallIndirect = 0x13;
let kExprCatchAll = 0x19;
let kExprDrop = 0x1a;
let kExprSelect = 0x1b;
let kExprTryTable = 0x1f;
let kExprLocalGet = 0x20;
let kExprLocalSet = 0x21;
let kExprLocalTee = 0x22;
Expand Down Expand Up @@ -494,6 +499,12 @@ let kExprI32x4Eq = 0x2c;
let kExprS1x4AllTrue = 0x75;
let kExprF32x4Min = 0x9e;

// Exception handling with exnref.
let kCatchNoRef = 0x0;
let kCatchRef = 0x1;
let kCatchAllNoRef = 0x2;
let kCatchAllRef = 0x3;

class Binary {
constructor() {
this.length = 0;
Expand Down Expand Up @@ -976,7 +987,7 @@ class WasmModuleBuilder {
section.emit_u32v(imp.initial); // initial
if (has_max) section.emit_u32v(imp.maximum); // maximum
} else if (imp.kind == kExternalTag) {
section.emit_u32v(kTagAttribute);
section.emit_u32v(kExceptionAttribute);
section.emit_u32v(imp.type);
} else {
throw new Error("unknown/unsupported import kind " + imp.kind);
Expand Down Expand Up @@ -1079,7 +1090,7 @@ class WasmModuleBuilder {
binary.emit_section(kTagSectionCode, section => {
section.emit_u32v(wasm.tags.length);
for (let type of wasm.tags) {
section.emit_u32v(kTagAttribute);
section.emit_u32v(kExceptionAttribute);
section.emit_u32v(type);
}
});
Expand Down
4 changes: 2 additions & 2 deletions test/legacy/exceptions/js-api/basic.tentative.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ promise_test(async () => {
const tagIndex= builder.addTag(kSig_v_r);
builder.addFunction("catch_exception", kSig_r_v)
.addBody([
kExprTry, kWasmStmt,
kExprTry, kWasmVoid,
kExprCallFunction, fnIndex,
kExprCatch, tagIndex,
kExprReturn,
Expand All @@ -100,7 +100,7 @@ promise_test(async () => {
const fnIndex = builder.addImport("module", "fn", kSig_v_v);
builder.addFunction("catch_and_rethrow", kSig_r_v)
.addBody([
kExprTry, kWasmStmt,
kExprTry, kWasmVoid,
kExprCallFunction, fnIndex,
kExprCatchAll,
kExprRethrow, 0x00,
Expand Down
10 changes: 5 additions & 5 deletions test/legacy/exceptions/js-api/identity.tentative.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test(() => {
builder
.addFunction("catch_js_tag_rethrow", kSig_v_v)
.addBody([
kExprTry, kWasmStmt,
kExprTry, kWasmVoid,
kExprCallFunction, throwJSTagExnIndex,
kExprCatch, jsTagIndex,
kExprDrop,
Expand All @@ -49,7 +49,7 @@ test(() => {
builder
.addFunction("catch_wasm_tag_rethrow", kSig_v_v)
.addBody([
kExprTry, kWasmStmt,
kExprTry, kWasmVoid,
kExprCallFunction, throwWasmTagExnIndex,
kExprCatch, wasmTagIndex,
kExprDrop,
Expand All @@ -63,7 +63,7 @@ test(() => {
builder
.addFunction("catch_all_js_tag_rethrow", kSig_v_v)
.addBody([
kExprTry, kWasmStmt,
kExprTry, kWasmVoid,
kExprCallFunction, throwJSTagExnIndex,
kExprCatchAll,
kExprRethrow, 0x00,
Expand All @@ -76,7 +76,7 @@ test(() => {
builder
.addFunction("catch_all_wasm_tag_rethrow", kSig_v_v)
.addBody([
kExprTry, kWasmStmt,
kExprTry, kWasmVoid,
kExprCallFunction, throwWasmTagExnIndex,
kExprCatchAll,
kExprRethrow, 0x00,
Expand All @@ -103,7 +103,7 @@ test(() => {
builder
.addFunction("catch_js_tag_throw_payload", kSig_v_v)
.addBody([
kExprTry, kWasmStmt,
kExprTry, kWasmVoid,
kExprCallFunction, throwJSTagExnIndex,
kExprCatch, jsTagIndex,
kExprThrow, jsTagIndex,
Expand Down
Loading