Skip to content

Commit 057e5e4

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] Add prototype property for WebAssembly.*
Bug: 440226707 Change-Id: If33749baa0b406b905630133d1a58db1177e2bf6 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8550380 Auto-Submit: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Manos Koukoutos <manoskouk@google.com> Commit-Queue: Manos Koukoutos <manoskouk@google.com>
1 parent a8af107 commit 057e5e4

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public class JavaScriptEnvironment: ComponentBase {
360360
registerObjectGroup(.jsWebAssemblyCompileOptions)
361361
registerObjectGroup(.jsWebAssemblyModuleConstructor)
362362
registerObjectGroup(.jsWebAssemblyGlobalConstructor)
363+
registerObjectGroup(.jsWebAssemblyGlobalPrototype)
363364
registerObjectGroup(.jsWebAssemblyInstanceConstructor)
364365
registerObjectGroup(.jsWebAssemblyInstance)
365366
registerObjectGroup(.jsWebAssemblyModule)
@@ -971,15 +972,16 @@ public extension ILType {
971972
// TODO: The first constructor argument can also be any typed array and .jsSharedArrayBuffer.
972973
static let jsWebAssemblyModuleConstructor =
973974
ILType.constructor([.plain(.jsArrayBuffer)] => .jsWebAssemblyModule)
974-
+ .object(ofGroup: "WebAssemblyModuleConstructor", withProperties: [],
975+
+ .object(ofGroup: "WebAssemblyModuleConstructor", withProperties: ["prototype"],
975976
withMethods: ["customSections", "imports", "exports"])
976977

977-
static let jsWasmGlobal = ILType.object(ofGroup: "WasmGlobal", withProperties: ["value"],
978-
withMethods: ["valueOf"])
979-
980978
static let jsWebAssemblyGlobalConstructor =
981-
ILType.constructor([.plain(.object()), .jsAnything] => .jsWasmGlobal)
982-
+ .object(ofGroup: "WebAssemblyGlobalConstructor", withProperties: [], withMethods: [])
979+
// We do not type the result as being part of the ObjectGroup "WasmGlobal" as that would
980+
// require to also add a WasmTypeExtension to its type. This is fine as the proper
981+
// construction of globals is done via the high-level Wasm operations and these builtins
982+
// only serve the purpose of fuzzing the API.
983+
ILType.constructor([.plain(.object()), .jsAnything] => .object(withProperties: ["value"], withMethods: ["valueOf"]))
984+
+ .object(ofGroup: "WebAssemblyGlobalConstructor", withProperties: ["prototype"], withMethods: [])
983985

984986
static let jsWebAssemblyInstance = ILType.object(ofGroup: "WebAssembly.Instance",
985987
withProperties: ["exports"])
@@ -1801,18 +1803,24 @@ public extension ObjectGroup {
18011803
static let jsWebAssemblyModuleConstructor = ObjectGroup(
18021804
name: "WebAssemblyModuleConstructor",
18031805
instanceType: .jsWebAssemblyModuleConstructor,
1804-
properties: [:],
1806+
properties: [
1807+
"prototype": .object()
1808+
],
18051809
methods: [
18061810
"customSections": [.plain(jsWebAssemblyModule.instanceType), .plain(.jsString)] => .jsArray,
18071811
"exports": [.plain(jsWebAssemblyModule.instanceType)] => .jsArray,
18081812
"imports": [.plain(jsWebAssemblyModule.instanceType)] => .jsArray,
18091813
]
18101814
)
18111815

1816+
static let jsWebAssemblyGlobalPrototype = createPrototypeObjectGroup(jsWasmGlobal)
1817+
18121818
static let jsWebAssemblyGlobalConstructor = ObjectGroup(
18131819
name: "WebAssemblyGlobalConstructor",
18141820
instanceType: .jsWebAssemblyGlobalConstructor,
1815-
properties: [:],
1821+
properties: [
1822+
"prototype": jsWebAssemblyGlobalPrototype.instanceType,
1823+
],
18161824
methods: [:]
18171825
)
18181826

@@ -1866,7 +1874,7 @@ public extension ObjectGroup {
18661874
/// ObjectGroup modelling JavaScript WebAssembly Global objects.
18671875
static let jsWasmGlobal = ObjectGroup(
18681876
name: "WasmGlobal",
1869-
instanceType: .jsWasmGlobal,
1877+
instanceType: nil,
18701878
properties: [
18711879
// TODO: Try using precise JS types based on the global's underlying valuetype (e.g. float for f32 and f64).
18721880
"value" : .jsAnything

Tests/FuzzilliTests/JSTyperTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,21 @@ class JSTyperTests: XCTestCase {
17171717
XCTAssert(b.type(of: wasmModuleConstructor).Is(.object(ofGroup: "WebAssemblyModuleConstructor")))
17181718
let wasmModule = b.construct(wasmModuleConstructor) // In theory this needs arguments.
17191719
XCTAssert(b.type(of: wasmModule).Is(.object(ofGroup: "WebAssembly.Module")))
1720+
1721+
let wasmGlobalConstructor = b.getProperty("Global", of: wasm)
1722+
XCTAssert(b.type(of: wasmGlobalConstructor).Is(.object(ofGroup: "WebAssemblyGlobalConstructor")))
1723+
let wasmGlobal = b.construct(wasmGlobalConstructor) // In theory this needs arguments.
1724+
// We do not type the constructed value as globals as the "WasmGlobal" object group expects
1725+
// to have a WasmTypeExtension.
1726+
XCTAssertFalse(b.type(of: wasmGlobal).Is(.object(ofGroup: "WasmGlobal")))
1727+
// The high-level IL instruction produces properly typed wasm globals.
1728+
let realWasmGlobal = b.createWasmGlobal(value: .wasmi32(1), isMutable: true)
1729+
XCTAssert(b.type(of: realWasmGlobal).Is(.object(ofGroup: "WasmGlobal")))
1730+
// The properly typed wasm globals can be used in conjunction with the
1731+
// WebAssembly.Global.prototype.valueOf() function.
1732+
let globalPrototype = b.getProperty("prototype", of: wasmGlobalConstructor)
1733+
let valueOf = b.getProperty("valueOf", of: globalPrototype)
1734+
XCTAssertEqual(b.type(of: valueOf), .unboundFunction([] => .jsAnything, receiver: .object(ofGroup: "WasmGlobal", withProperties: ["value"], withMethods: ["valueOf"])))
17201735
}
17211736

17221737
func testProducingGenerators() {

0 commit comments

Comments
 (0)