Skip to content

Commit eff49a5

Browse files
marjakhV8-internal LUCI CQ
authored andcommitted
[js] Improve Iterator.zip fuzzing by passing it an iterable of iterables
Change-Id: I9e7e47344d5c9fb3e56545be210788e1d8e492ef Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9155596 Commit-Queue: Marja Hölttä <marja@chromium.org> Reviewed-by: Matthias Liedtke <mliedtke@google.com>
1 parent e4732f0 commit eff49a5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public let codeGeneratorWeights = [
225225
"ApiMethodCallGenerator": 15,
226226
"ApiFunctionCallGenerator": 15,
227227
"VoidGenerator": 1,
228+
"IteratorZipGenerator": 1,
228229

229230
// JS generators for wasm features (e.g. APIs on the WebAssembly global object).
230231
"WasmGlobalGenerator": 4,

Sources/Fuzzilli/CodeGen/CodeGenerators.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,38 @@ public let CodeGenerators: [CodeGenerator] = [
18701870
b.void(val)
18711871
},
18721872

1873+
CodeGenerator("IteratorZipGenerator", inputs: .one) { b, val in
1874+
// Create an iterable of iterables
1875+
let iterable : Variable;
1876+
let topLevelIterableSize = Int.random(in: 0...10)
1877+
if probability(0.8) {
1878+
// Use Array as the top level iterable
1879+
let iterables = (0..<topLevelIterableSize).map {_ in b.randomVariable(ofType: .iterable) ?? val}
1880+
iterable = b.createArray(with: iterables)
1881+
} else {
1882+
// Use Map as the top level iterable
1883+
let Map = b.createNamedVariable(forBuiltin: "Map")
1884+
// We want the created object to be used by following code generators, not the constructor
1885+
b.hide(Map)
1886+
iterable = b.construct(Map)
1887+
for _ in 0..<topLevelIterableSize {
1888+
// The key and the value don't need to be iterables themselves, any values will do.
1889+
let key = b.randomJsVariable()
1890+
let value = b.randomJsVariable()
1891+
b.callMethod("set", on: iterable, withArgs: [key, value])
1892+
}
1893+
}
1894+
1895+
let iteratorConstructor = b.createNamedVariable(forBuiltin: "Iterator")
1896+
let arguments : [Variable];
1897+
if probability(0.5) {
1898+
arguments = [iterable]
1899+
} else {
1900+
arguments = [iterable, b.createOptionsBag(.jsIteratorZipSettings)]
1901+
}
1902+
b.callMethod("zip", on: iteratorConstructor, withArgs: arguments)
1903+
},
1904+
18731905
CodeGenerator(
18741906
"InstanceOfGenerator", inputs: .preferred(.jsAnything, .constructor())
18751907
) { b, val, cls in

0 commit comments

Comments
 (0)