Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ enum ValueType {
"f32",
"f64",
"externref",
"anyfunc",
"funcref",
Comment on lines 953 to +954

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should keep both, and test that new Global({ type: "funcref" }) works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How would it work if we keep both? Wouldn't that mean that they are different types? How should I define then what the result of type() is?
My idea was that there is only one type, funcref, but the string anyfunc is accepted as an alias in the constructor. Internally, in the non-observable parts of the spec, only funcref is used. Then type() could remain mostly unchanged, because we don't have to merge the return value for funcref and anyfunc somehow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Internally, we only use the "core" types, and the IDL enum here is only a way to expose them to JS. ToValueType then maps both enum values to [=funcref=], and FromValueType only creates the "funcref" value. (Those are both already correct in the PR.) Does that make sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are saying that this is the set of strings that is allowed to be used in a GlobalType, and not the internal type. Fair enough, I added anyfunc back. PTAL

};
</pre>

Expand Down Expand Up @@ -1002,6 +1002,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
1. If |s| equals "i64", return [=i64=].
1. If |s| equals "f32", return [=f32=].
1. If |s| equals "f64", return [=f64=].
1. If |s| equals "funcref", return [=funcref=].
1. If |s| equals "anyfunc", return [=funcref=].
1. If |s| equals "externref", return [=externref=].
1. Assert: This step is not reached.
Expand All @@ -1015,7 +1016,7 @@ The algorithm <dfn abstract-op>FromValueType</dfn>(|s|) performs the following s
1. If |s| equals [=i64=], return "{{ValueType/i64}}".
1. If |s| equals [=f32=], return "{{ValueType/f32}}".
1. If |s| equals [=f64=], return "{{ValueType/f64}}".
1. If |s| equals [=funcref=], return "{{ValueType/anyfunc}}".
1. If |s| equals [=funcref=], return "{{ValueType/funcref}}".
1. If |s| equals [=externref=], return "{{ValueType/externref}}".
1. Assert: This step is not reached.

Expand Down
4 changes: 2 additions & 2 deletions proposals/js-types/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ All Wasm types can be defined by a simple grammar. This grammar could be mapped

```TypeScript
type ValueType = "i32" | "i64" | "f32" | "f64"
type ElemType = "anyfunc"
type ElemType = "funcref"
type GlobalType = {value: ValueType, mutable: boolean}
type MemoryType = {limits: Limits}
type TableType = {limits: Limits, element: ElemType}
Expand Down Expand Up @@ -200,7 +200,7 @@ function print(...args) {
for (let x of args) console.log(x + "\n")
}

let table = new Table({element: "anyfunc", minimum: 10});
let table = new Table({element: "funcref", minimum: 10});

let print_i32 = new WebAssembly.Function({parameters: ["i32"], results: []}, print);
table.set(0, print_i32);
Expand Down
6 changes: 6 additions & 0 deletions test/js-api/table/constructor.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ test(() => {
assert_Table(table, { "length": 5 });
}, "Basic (non-zero)");

test(() => {
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_Table(table, { "length": 5 });
}, "Basic with 'funcref'");

test(() => {
const argument = { "element": "anyfunc", "initial": 0 };
const table = new WebAssembly.Table(argument, {});
Expand Down