forked from mykmelez/gecko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1546138 - Wasm: Implement 'ref.func'. r=bbouvier
This commit implements the 'ref.func' instruction by emitting an instance call to WasmInstanceObject::getExportedFunction. The referenced function must be used in an element segment to validate. See [1] for more details. [1] WebAssembly/reference-types#31 Differential Revision: https://phabricator.services.mozilla.com/D40586
- Loading branch information
Showing
14 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// |jit-test| skip-if: !wasmReftypesEnabled() | ||
|
||
// 'ref.func' parses, validates and returns a non-null value | ||
wasmFullPass(` | ||
(module | ||
(elem declared $run) | ||
(func $run (result i32) | ||
ref.func $run | ||
ref.is_null | ||
) | ||
(export "run" $run) | ||
) | ||
`, 0); | ||
|
||
// function returning reference to itself | ||
{ | ||
let {f1} = wasmEvalText(` | ||
(module | ||
(elem declared $f1) | ||
(func $f1 (result funcref) ref.func $f1) | ||
(export "f1" $f1) | ||
) | ||
`).exports; | ||
assertEq(f1(), f1); | ||
} | ||
|
||
// function returning reference to a different function | ||
{ | ||
let {f1, f2} = wasmEvalText(` | ||
(module | ||
(elem declared $f1) | ||
(func $f1) | ||
(func $f2 (result funcref) ref.func $f1) | ||
(export "f1" $f1) | ||
(export "f2" $f2) | ||
) | ||
`).exports; | ||
assertEq(f2(), f1); | ||
} | ||
|
||
// function returning reference to function in a different module | ||
{ | ||
let i1 = wasmEvalText(` | ||
(module | ||
(elem declared $f1) | ||
(func $f1) | ||
(export "f1" $f1) | ||
) | ||
`); | ||
let i2 = wasmEvalText(` | ||
(module | ||
(import $f1 "" "f1" (func)) | ||
(elem declared $f1) | ||
(func $f2 (result funcref) ref.func $f1) | ||
(export "f1" $f1) | ||
(export "f2" $f2) | ||
) | ||
`, {"": i1.exports}); | ||
|
||
let f1 = i1.exports.f1; | ||
let f2 = i2.exports.f2; | ||
assertEq(f2(), f1); | ||
} | ||
|
||
// function index must be valid | ||
assertErrorMessage(() => { | ||
wasmEvalText(` | ||
(module | ||
(func (result funcref) ref.func 10) | ||
) | ||
`); | ||
}, WebAssembly.CompileError, /function index out of range/); | ||
|
||
function validFuncRefText(forwardDeclare) { | ||
return wasmEvalText(` | ||
(module | ||
(table 1 funcref) | ||
(func $test (result funcref) ref.func $referenced) | ||
(func $referenced) | ||
${forwardDeclare} | ||
) | ||
`); | ||
} | ||
|
||
// referenced function must be forward declared somehow | ||
assertErrorMessage(() => validFuncRefText(''), WebAssembly.CompileError, /function index is not in an element segment/); | ||
|
||
// referenced function can be forward declared via segments | ||
assertEq(validFuncRefText('(elem 0 (i32.const 0) $referenced)') instanceof WebAssembly.Instance, true); | ||
assertEq(validFuncRefText('(elem passive $referenced)') instanceof WebAssembly.Instance, true); | ||
assertEq(validFuncRefText('(elem declared $referenced)') instanceof WebAssembly.Instance, true); | ||
|
||
// referenced function cannot be forward declared via start section or export | ||
assertErrorMessage(() => validFuncRefText('(start $referenced)'), WebAssembly.CompileError, /function index is not in an element segment/); | ||
assertErrorMessage(() => validFuncRefText('(export "referenced" $referenced)'), WebAssembly.CompileError, /function index is not in an element segment/); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.