Skip to content

Commit

Permalink
WebAssembly: opcodes for table.grow and table.size are mixed up
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=218644

Patch by Sergey Rubanov <chi187@gmail.com> on 2020-11-13
Reviewed by Yusuke Suzuki.

JSTests:

* wasm/stress/table-grow-table-size.js: Added.
(async test):
* wasm/wasm.json:

Source/JavaScriptCore:

* wasm/wasm.json:

LayoutTests:

* workers/wasm-references/test.js:

Canonical link: https://commits.webkit.org/231563@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269790 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
chicoxyzzy authored and webkit-commit-queue committed Nov 13, 2020
1 parent e1fe024 commit 16b856e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 8 deletions.
11 changes: 11 additions & 0 deletions JSTests/ChangeLog
@@ -1,3 +1,14 @@
2020-11-13 Sergey Rubanov <chi187@gmail.com>

WebAssembly: opcodes for table.grow and table.size are mixed up
https://bugs.webkit.org/show_bug.cgi?id=218644

Reviewed by Yusuke Suzuki.

* wasm/stress/table-grow-table-size.js: Added.
(async test):
* wasm/wasm.json:

2020-11-13 Sergey Rubanov <chi187@gmail.com>

WebAssembly: update wabt.js
Expand Down
22 changes: 22 additions & 0 deletions JSTests/wasm/stress/table-grow-table-size.js
@@ -0,0 +1,22 @@
//@ requireOptions("--useWebAssemblyReferences=1")
import { instantiate } from "../wabt-wrapper.js";
import * as assert from "../assert.js";

let wat = `
(module
(table $table 0 externref)
(func (export "size") (result i32) (table.size $table))
(func (export "grow") (param $sz i32) (result i32)
(table.grow $table (ref.null extern) (local.get $sz))
)
)
`;
async function test() {
const instance = await instantiate(wat, {}, {reference_types: true});
const {size, grow} = instance.exports;
assert.eq(size(), 0);
assert.eq(grow(42), 0);
assert.eq(size(), 42);
}

assert.asyncTest(test());
6 changes: 3 additions & 3 deletions JSTests/wasm/wasm.json
Expand Up @@ -69,9 +69,9 @@
"set_global": { "category": "special", "value": 36, "return": [], "parameter": ["any"], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "write a global variable" },
"table.get": { "category": "special", "value": 37, "return": ["externref"], "parameter": ["i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "get a table value" },
"table.set": { "category": "special", "value": 38, "return": [], "parameter": ["i32", "externref"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "set a table value" },
"table.size": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": [], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "get the size of a table", "extendedOp": 15 },
"table.grow": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 16 },
"table.fill": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["i32", "externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "fill entries [i,i+n) with the given value", "extendedOp": 17 },
"table.grow": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 15 },
"table.size": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": [], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "get the size of a table", "extendedOp": 16 },
"table.fill": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["i32", "externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "fill entries [i,i+n) with the given value", "extendedOp": 17 },
"call": { "category": "call", "value": 16, "return": ["call"], "parameter": ["call"], "immediate": [{"name": "function_index", "type": "varuint32"}], "description": "call a function by its index" },
"call_indirect": { "category": "call", "value": 17, "return": ["call"], "parameter": ["call"], "immediate": [{"name": "type_index", "type": "varuint32"}, {"name": "table_index","type": "varuint32"}],"description": "call a function indirect with an expected signature" },
"i32.load8_s": { "category": "memory", "value": 44, "return": ["i32"], "parameter": ["addr"], "immediate": [{"name": "flags", "type": "varuint32"}, {"name": "offset", "type": "varuint32"}], "description": "load from memory" },
Expand Down
9 changes: 9 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,12 @@
2020-11-13 Sergey Rubanov <chi187@gmail.com>

WebAssembly: opcodes for table.grow and table.size are mixed up
https://bugs.webkit.org/show_bug.cgi?id=218644

Reviewed by Yusuke Suzuki.

* workers/wasm-references/test.js:

2020-11-12 Darin Adler <darin@apple.com>

Remove unused advanced plug-in features: snapshotting and plug-in load policy
Expand Down
4 changes: 2 additions & 2 deletions LayoutTests/workers/wasm-references/test.js
Expand Up @@ -239,8 +239,8 @@ const WASM_JSON = `
"set_global": { "category": "special", "value": 36, "return": [], "parameter": ["any"], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "write a global variable" },
"table.get": { "category": "special", "value": 37, "return": ["externref"], "parameter": ["i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "get a table value" },
"table.set": { "category": "special", "value": 38, "return": [], "parameter": ["i32", "externref"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "set a table value" },
"table.size": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": [], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "get the size of a table", "extendedOp": 15 },
"table.grow": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["externref", "i32"], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 16 },
"table.grow": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["externref", "i32"], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 15 },
"table.size": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": [], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "get the size of a table", "extendedOp": 16 },
"table.fill": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["i32", "externref", "i32"], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "fill entries [i,i+n) with the given value", "extendedOp": 17 },
"call": { "category": "call", "value": 16, "return": ["call"], "parameter": ["call"], "immediate": [{"name": "function_index", "type": "varuint32"}], "description": "call a function by its index" },
"call_indirect": { "category": "call", "value": 17, "return": ["call"], "parameter": ["call"], "immediate": [{"name": "type_index", "type": "varuint32"}, {"name": "table_index","type": "varuint32"}],"description": "call a function indirect with an expected signature" },
Expand Down
9 changes: 9 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,12 @@
2020-11-13 Sergey Rubanov <chi187@gmail.com>

WebAssembly: opcodes for table.grow and table.size are mixed up
https://bugs.webkit.org/show_bug.cgi?id=218644

Reviewed by Yusuke Suzuki.

* wasm/wasm.json:

2020-11-12 Devin Rousso <drousso@apple.com>

Web Inspector: ensure that `JSON::ArrayOf<T>` doesn't allow `addItem` to be called with a type other than `T`
Expand Down
6 changes: 3 additions & 3 deletions Source/JavaScriptCore/wasm/wasm.json
Expand Up @@ -69,9 +69,9 @@
"set_global": { "category": "special", "value": 36, "return": [], "parameter": ["any"], "immediate": [{"name": "global_index", "type": "varuint32"}], "description": "write a global variable" },
"table.get": { "category": "special", "value": 37, "return": ["externref"], "parameter": ["i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "get a table value" },
"table.set": { "category": "special", "value": 38, "return": [], "parameter": ["i32", "externref"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "set a table value" },
"table.size": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": [], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "get the size of a table", "extendedOp": 15 },
"table.grow": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 16 },
"table.fill": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["i32", "externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "fill entries [i,i+n) with the given value", "extendedOp": 17 },
"table.grow": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 15 },
"table.size": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": [], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "get the size of a table", "extendedOp": 16 },
"table.fill": { "category": "exttable", "value": 252, "return": ["i32"], "parameter": ["i32", "externref", "i32"], "immediate": [{"name": "table_index", "type": "varuint32"}], "description": "fill entries [i,i+n) with the given value", "extendedOp": 17 },
"call": { "category": "call", "value": 16, "return": ["call"], "parameter": ["call"], "immediate": [{"name": "function_index", "type": "varuint32"}], "description": "call a function by its index" },
"call_indirect": { "category": "call", "value": 17, "return": ["call"], "parameter": ["call"], "immediate": [{"name": "type_index", "type": "varuint32"}, {"name": "table_index","type": "varuint32"}],"description": "call a function indirect with an expected signature" },
"i32.load8_s": { "category": "memory", "value": 44, "return": ["i32"], "parameter": ["addr"], "immediate": [{"name": "flags", "type": "varuint32"}, {"name": "offset", "type": "varuint32"}], "description": "load from memory" },
Expand Down

0 comments on commit 16b856e

Please sign in to comment.