Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ The <dfn method for="Memory">type()</dfn> method steps are:
<pre class="idl">
enum TableKind {
"externref",
"anyfunc",
Comment thread
gahaas marked this conversation as resolved.
"funcref",
// Note: More values may be added in future iterations,
// e.g., typed function references, typed GC references
};
Expand Down Expand Up @@ -848,7 +848,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address

The algorithm <dfn abstract-op>ToTableKind</dfn>(|t|) performs the following steps:

1. If |t| equals [=funcref=], return "{{TableKind/anyfunc}}".
1. If |t| equals [=funcref=], return "{{TableKind/funcref}}".
1. If |t| equals [=externref=], return "{{TableKind/externref}}".
1. Assert: This step is not reached.

Expand Down 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
2 changes: 1 addition & 1 deletion interpreter/script/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let spectest = {
global_i64: 666n,
global_f32: 666,
global_f64: 666,
table: new WebAssembly.Table({initial: 10, maximum: 20, element: 'anyfunc'}),
table: new WebAssembly.Table({initial: 10, maximum: 20, element: 'funcref'}),
memory: new WebAssembly.Memory({initial: 1, maximum: 2})
};

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: 3 additions & 3 deletions test/core/binary.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@
(module binary
"\00asm" "\01\00\00\00"
"\05\03\01" ;; table section with one entry
"\70" ;; anyfunc
"\70" ;; funcref
"\02" ;; malformed table limits flag
)
"integer too large"
Expand All @@ -1416,7 +1416,7 @@
(module binary
"\00asm" "\01\00\00\00"
"\05\04\01" ;; table section with one entry
"\70" ;; anyfunc
"\70" ;; funcref
"\02" ;; malformed table limits flag
"\00" ;; dummy byte
)
Expand All @@ -1426,7 +1426,7 @@
(module binary
"\00asm" "\01\00\00\00"
"\05\06\01" ;; table section with one entry
"\70" ;; anyfunc
"\70" ;; funcref
"\81\00" ;; malformed table limits flag as LEB128
"\00\00" ;; dummy bytes
)
Expand Down
2 changes: 1 addition & 1 deletion test/harness/async_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function reinitializeRegistry() {
table: new WebAssembly.Table({
initial: 10,
maximum: 20,
element: "anyfunc"
element: "funcref"
}),
memory: new WebAssembly.Memory({ initial: 1, maximum: 2 })
};
Expand Down
2 changes: 1 addition & 1 deletion test/harness/sync_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function reinitializeRegistry() {
global_i32: 666,
global_f32: 666,
global_f64: 666,
table: new WebAssembly.Table({initial: 10, maximum: 20, element: 'anyfunc'}),
table: new WebAssembly.Table({initial: 10, maximum: 20, element: 'funcref'}),
memory: new WebAssembly.Memory({initial: 1, maximum: 2})
};
let handler = {
Expand Down
2 changes: 1 addition & 1 deletion test/js-api/bad-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function test_bad_imports(t) {
[WebAssembly.Table, "WebAssembly.Table"],
[WebAssembly.Table.prototype, "WebAssembly.Table.prototype"],
[Object.create(WebAssembly.Table.prototype), "Object.create(WebAssembly.Table.prototype)"],
[new WebAssembly.Table({"element": "anyfunc", "initial": 256}), "WebAssembly.Table object (too large)"],
[new WebAssembly.Table({"element": "funcref", "initial": 256}), "WebAssembly.Table object (too large)"],
Comment thread
gahaas marked this conversation as resolved.
Outdated
];

for (const [value, name = format_value(value)] of nonTables) {
Expand Down
2 changes: 1 addition & 1 deletion test/js-api/instanceTestFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const instanceTestFactory = [
"fn": function() {},
"global": 0,
"memory": new WebAssembly.Memory({ "initial": 64, maximum: 128 }),
"table": new WebAssembly.Table({ "element": "anyfunc", "initial": 64, maximum: 128 }),
"table": new WebAssembly.Table({ "element": "funcref", "initial": 64, maximum: 128 }),
},
get "module2"() {
assert_unreached("Should not get modules that are not imported");
Expand Down
4 changes: 2 additions & 2 deletions test/js-api/limits.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ test(() => {
assert_throws(
new RangeError(),
() => new WebAssembly.Table(
{element : "anyfunc", initial : kJSEmbeddingMaxTableSize + 1}));
{element : "funcref", initial : kJSEmbeddingMaxTableSize + 1}));

let memory = new WebAssembly.Table(
{initial : 1, maximum : kJSEmbeddingMaxTableSize + 1, element: "anyfunc"});
{initial : 1, maximum : kJSEmbeddingMaxTableSize + 1, element: "funcref"});
assert_throws(new RangeError(),
() => memory.grow(kJSEmbeddingMaxTableSize));
}, `Grow WebAssembly.Table object beyond the embedder-defined limit`);
Expand Down
2 changes: 1 addition & 1 deletion test/js-api/prototypes.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test(() => {

test(() => {
class _Table extends WebAssembly.Table {}
let table = new _Table({initial: 0, element: "anyfunc"});
let table = new _Table({initial: 0, element: "funcref"});
assert_true(table instanceof _Table, "_Table instanceof _Table");
assert_true(table instanceof WebAssembly.Table, "_Table instanceof WebAssembly.Table");
}, "_Table");
Expand Down
26 changes: 16 additions & 10 deletions test/js-api/table/constructor.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test(() => {
}, "No arguments");

test(() => {
const argument = { "element": "anyfunc", "initial": 0 };
const argument = { "element": "funcref", "initial": 0 };
assert_throws_js(TypeError, () => WebAssembly.Table(argument));
}, "Calling");

Expand Down Expand Up @@ -54,7 +54,7 @@ test(() => {
}, "Invalid descriptor argument");

test(() => {
assert_throws_js(TypeError, () => new WebAssembly.Table({ "element": "anyfunc", "initial": undefined }));
assert_throws_js(TypeError, () => new WebAssembly.Table({ "element": "funcref", "initial": undefined }));
}, "Undefined initial value in descriptor");

test(() => {
Expand All @@ -72,20 +72,20 @@ const outOfRangeValues = [

for (const value of outOfRangeValues) {
test(() => {
assert_throws_js(TypeError, () => new WebAssembly.Table({ "element": "anyfunc", "initial": value }));
assert_throws_js(TypeError, () => new WebAssembly.Table({ "element": "funcref", "initial": value }));
}, `Out-of-range initial value in descriptor: ${format_value(value)}`);

test(() => {
assert_throws_js(TypeError, () => new WebAssembly.Table({ "element": "anyfunc", "initial": 0, "maximum": value }));
assert_throws_js(TypeError, () => new WebAssembly.Table({ "element": "funcref", "initial": 0, "maximum": value }));
}, `Out-of-range maximum value in descriptor: ${format_value(value)}`);
}

test(() => {
assert_throws_js(RangeError, () => new WebAssembly.Table({ "element": "anyfunc", "initial": 10, "maximum": 9 }));
assert_throws_js(RangeError, () => new WebAssembly.Table({ "element": "funcref", "initial": 10, "maximum": 9 }));
}, "Initial value exceeds maximum");

test(() => {
const argument = { "element": "anyfunc", "initial": 0 };
const argument = { "element": "funcref", "initial": 0 };
const table = new WebAssembly.Table(argument);
assert_Table(table, { "length": 0 });
}, "Basic (zero)");
Expand All @@ -97,7 +97,13 @@ test(() => {
}, "Basic (non-zero)");

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

test(() => {
const argument = { "element": "funcref", "initial": 0 };
const table = new WebAssembly.Table(argument, {});
assert_Table(table, { "length": 0 });
}, "Stray argument");
Expand All @@ -110,7 +116,7 @@ test(() => {
get(o, x) {
switch (x) {
case "element":
return "anyfunc";
return "funcref";
case "initial":
case "maximum":
return 0;
Expand All @@ -126,7 +132,7 @@ test(() => {
test(() => {
const table = new WebAssembly.Table({
"element": {
toString() { return "anyfunc"; },
toString() { return "funcref"; },
},
"initial": 1,
});
Expand Down Expand Up @@ -162,7 +168,7 @@ test(() => {
return {
toString() {
order.push("element toString");
return "anyfunc";
return "funcref";
},
};
},
Expand Down
24 changes: 12 additions & 12 deletions test/js-api/table/get-set.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ setup(() => {
});

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.get());
}, "Missing arguments: get");
Expand Down Expand Up @@ -53,7 +53,7 @@ test(t => {
}, "Branding: get");

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.set());
assert_throws_js(TypeError, () => table.set(0));
Expand Down Expand Up @@ -85,7 +85,7 @@ test(t => {
}, "Branding: set");

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, [null, null, null, null, null]);

Expand All @@ -102,7 +102,7 @@ test(() => {
}, "Basic");

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, [null, null, null, null, null]);

Expand All @@ -120,7 +120,7 @@ test(() => {
}, "Growing");

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, [null, null, null, null, null]);

Expand All @@ -134,7 +134,7 @@ test(() => {
}, "Setting out-of-bounds");

test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, [null]);

Expand All @@ -156,7 +156,7 @@ test(() => {
}, "Setting non-function");

test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, [null]);

Expand All @@ -166,7 +166,7 @@ test(() => {
}, "Setting non-wasm function");

test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, [null]);

Expand All @@ -189,20 +189,20 @@ const outOfRangeValues = [

for (const value of outOfRangeValues) {
test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.get(value));
}, `Getting out-of-range argument: ${format_value(value)}`);

test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.set(value, null));
}, `Setting out-of-range argument: ${format_value(value)}`);
}

test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);
let called = 0;
const value = {
Expand All @@ -217,7 +217,7 @@ test(() => {

test(() => {
const {fn} = functions;
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);

assert_equals(table.get(0, {}), null);
Expand Down
12 changes: 6 additions & 6 deletions test/js-api/table/grow.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function nulls(n) {
}

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.grow());
}, "Missing arguments");
Expand Down Expand Up @@ -37,7 +37,7 @@ test(t => {
}, "Branding");

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, nulls(5), "before");

Expand All @@ -47,7 +47,7 @@ test(() => {
}, "Basic");

test(() => {
const argument = { "element": "anyfunc", "initial": 3, "maximum": 5 };
const argument = { "element": "funcref", "initial": 3, "maximum": 5 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, nulls(3), "before");

Expand All @@ -57,7 +57,7 @@ test(() => {
}, "Reached maximum");

test(() => {
const argument = { "element": "anyfunc", "initial": 2, "maximum": 5 };
const argument = { "element": "funcref", "initial": 2, "maximum": 5 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, nulls(2), "before");

Expand All @@ -79,14 +79,14 @@ const outOfRangeValues = [

for (const value of outOfRangeValues) {
test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const argument = { "element": "funcref", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.grow(value));
}, `Out-of-range argument: ${format_value(value)}`);
}

test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const argument = { "element": "funcref", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_equal_to_array(table, nulls(5), "before");

Expand Down
Loading