Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[WASM-References] Add support for active mods in element section
https://bugs.webkit.org/show_bug.cgi?id=219192 Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-02 Reviewed by Yusuke Suzuki. JSTests: Fix builder dsl to produce the right element section. It produces correct wasm code for the previous spec and for the ref-types spec because the core spec is binary compatible with the ref-types. https://webassembly.github.io/reference-types/core/binary/modules.html#element-section. Added basic tests for the element section. * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Element): * wasm/references-spec-tests/ref_null.js: (module): * wasm/references/element_active_mod.js: Added. (module): (basicTest): (refNullExternInElemsSection): * wasm/references/element_parsing.js: * wasm/references/multitable.js: Source/JavaScriptCore: Adjust wasm parser to parse new form of element section. https://webassembly.github.io/reference-types/core/binary/modules.html#element-section. * wasm/WasmEntryPlan.cpp: (JSC::Wasm::EntryPlan::prepare): * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): (JSC::Wasm::Element::active const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseElement): (JSC::Wasm::SectionParser::validateElementTableIdx): (JSC::Wasm::SectionParser::parseI32InitExpr): (JSC::Wasm::SectionParser::parseElemKind): (JSC::Wasm::SectionParser::parseIndexCountForElemSection): (JSC::Wasm::SectionParser::parseFuncIdxFromRefExpForElemSection): (JSC::Wasm::SectionParser::parseFuncIdxForElemSection): * wasm/WasmSectionParser.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Canonical link: https://commits.webkit.org/232035@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270344 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
eaa09ac
commit 741831a3e6268130ffae963e8e9ef32501bed77d
Showing
13 changed files
with
383 additions
and
51 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//@ runWebAssemblySuite("--useWebAssemblyReferences=true") | ||
import * as assert from '../assert.js'; | ||
|
||
function module(bytes, valid = true) { | ||
let buffer = new ArrayBuffer(bytes.length); | ||
let view = new Uint8Array(buffer); | ||
for (let i = 0; i < bytes.length; ++i) { | ||
view[i] = bytes.charCodeAt(i); | ||
} | ||
return new WebAssembly.Module(buffer); | ||
} | ||
|
||
function basicTest() { | ||
/* | ||
(module | ||
(func $f (result i32) | ||
(i32.const 37) | ||
) | ||
(func $g (result i32) | ||
(i32.const 42) | ||
) | ||
(table $t1 10 funcref) | ||
(table $t2 20 funcref) | ||
(elem (i32.const 3) funcref (ref.func $g) (ref.null func) (ref.func $f) (ref.null func)) | ||
(elem (table $t2) (i32.const 7) funcref (ref.func $f) (ref.null func) (ref.func $g)) | ||
(func (export "get_tbl1") (param $idx i32) (result funcref) | ||
(table.get $t1 (local.get $idx)) | ||
) | ||
(func (export "get_tbl2") (param $idx i32) (result funcref) | ||
(table.get $t2 (local.get $idx)) | ||
) | ||
) | ||
*/ | ||
let instance = new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x0a\x02\x60\x00\x01\x7f\x60\x01\x7f\x01\x70\x03\x05\x04\x00\x00\x01\x01\x04\x07\x02\x70\x00\x0a\x70\x00\x14\x07\x17\x02\x08\x67\x65\x74\x5f\x74\x62\x6c\x31\x00\x02\x08\x67\x65\x74\x5f\x74\x62\x6c\x32\x00\x03\x09\x22\x02\x04\x41\x03\x0b\x04\xd2\x01\x0b\xd0\x70\x0b\xd2\x00\x0b\xd0\x70\x0b\x06\x01\x41\x07\x0b\x70\x03\xd2\x00\x0b\xd0\x70\x0b\xd2\x01\x0b\x0a\x19\x04\x04\x00\x41\x25\x0b\x04\x00\x41\x2a\x0b\x06\x00\x20\x00\x25\x00\x0b\x06\x00\x20\x00\x25\x01\x0b")); | ||
|
||
assert.eq(instance.exports.get_tbl1(3)(), 42); | ||
assert.eq(instance.exports.get_tbl1(4), null); | ||
assert.eq(instance.exports.get_tbl1(5)(), 37); | ||
assert.eq(instance.exports.get_tbl1(6), null); | ||
|
||
assert.eq(instance.exports.get_tbl2(7)(), 37); | ||
assert.eq(instance.exports.get_tbl2(8), null); | ||
assert.eq(instance.exports.get_tbl2(9)(), 42); | ||
} | ||
|
||
function refNullExternInElemsSection() { | ||
/* | ||
(module | ||
(table $t 10 funcref) | ||
(elem (i32.const 3) funcref (ref.null extern)) | ||
) | ||
*/ | ||
assert.throws(() => module("\x00\x61\x73\x6d\x01\x00\x00\x00\x04\x04\x01\x70\x00\x0a\x09\x09\x01\x04\x41\x03\x0b\x01\xd0\x6f\x0b"), | ||
WebAssembly.CompileError, | ||
"WebAssembly.Module doesn't parse at byte 24: ref.null extern is forbidden in element section's, 0th element's 0th index (evaluating 'new WebAssembly.Module(buffer)')"); | ||
} | ||
|
||
basicTest(); | ||
refNullExternInElemsSection(); |
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.