Skip to content

Commit

Permalink
Implements compilation of arrays with spreading
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasWienand committed Sep 20, 2024
1 parent 148e143 commit 8e4401c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Sources/Fuzzilli/Compiler/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -833,17 +833,31 @@ public class JavaScriptCompiler {
case .arrayExpression(let arrayExpression):
var elements = [Variable]()
var undefined: Variable? = nil
var spreads = [Bool]()
for elem in arrayExpression.elements {
if elem.expression == nil {
if undefined == nil {
undefined = emit(LoadUndefined()).output
}
elements.append(undefined!)
spreads.append(false)
} else {
elements.append(try compileExpression(elem))
if case .spreadElement(let spreadElement) = elem.expression {
elements.append(try compileExpression(spreadElement.argument))
spreads.append(true)
}
else {
elements.append(try compileExpression(elem))
spreads.append(false)
}
}
}
return emit(CreateArray(numInitialValues: elements.count), withInputs: elements).output
if spreads.contains(true) {
return emit(CreateArrayWithSpread(spreads: spreads), withInputs: elements).output
}
else {
return emit(CreateArray(numInitialValues: elements.count), withInputs: elements).output
}

case .functionExpression(let functionExpression):
let parameters = convertParameters(functionExpression.parameters)
Expand Down

0 comments on commit 8e4401c

Please sign in to comment.