-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WASM-Function-References] call_ref should subtype-check its arguments
https://bugs.webkit.org/show_bug.cgi?id=264649 Reviewed by Justin Michaud. Fixes a few issues with call_ref, mainly that it should subtype check its arguments. Also fixes other GC-related issues with call_ref such as needing to check that the target typedef is a function type, and using subtyping for the funcref argument itself. Also adds FIXME comments for a related bug for the runtime part. * JSTests/wasm/function-references/call_ref.js: (async invalidTypeIndex): * JSTests/wasm/gc/call_ref.js: Added. (testRefSubtyping): (testArgSubtyping): (testTypeDefCheck): * Source/JavaScriptCore/wasm/WasmFormat.h: (JSC::Wasm::isSubtypeIndex): * Source/JavaScriptCore/wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * Source/JavaScriptCore/wasm/WasmSlowPaths.cpp: (JSC::LLInt::doWasmCallIndirect): (JSC::LLInt::doWasmCallRef): Canonical link: https://commits.webkit.org/271780@main
- Loading branch information
Showing
5 changed files
with
60 additions
and
6 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
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,46 @@ | ||
//@ runWebAssemblySuite("--useWebAssemblyTypedFunctionReferences=true", "--useWebAssemblyGC=true") | ||
|
||
import * as assert from "../assert.js"; | ||
import { compile, instantiate } from "./wast-wrapper.js"; | ||
|
||
function testRefSubtyping() { | ||
// A call to a subtype should validate. | ||
instantiate(` | ||
(module | ||
(type (sub (func (param i32)))) | ||
(type (sub 0 (func (param i32)))) | ||
(global (ref 1) (ref.func 0)) | ||
(func (type 1)) | ||
(func (call_ref 0 (i32.const 3) (global.get 0))) | ||
) | ||
`); | ||
} | ||
|
||
function testArgSubtyping() { | ||
// Ensure that call_ref uses subtyping for arguments. | ||
instantiate(` | ||
(module | ||
(func (param eqref)) | ||
(global (ref 0) (ref.func 0)) | ||
(func (call_ref 0 (ref.i31 (i32.const 42)) (global.get 0))) | ||
) | ||
`); | ||
} | ||
|
||
function testTypeDefCheck() { | ||
// Non-func typedefs are invalid. | ||
assert.throws( | ||
() => instantiate(` | ||
(module | ||
(type (struct)) | ||
(func (call_ref 0 (ref.null func))) | ||
) | ||
`), | ||
WebAssembly.CompileError, | ||
"WebAssembly.Module doesn't validate: invalid type index (not a function signature) for call_ref, got 0, in function at index 0" | ||
); | ||
} | ||
|
||
testRefSubtyping(); | ||
testArgSubtyping(); | ||
testTypeDefCheck(); |
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