Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/Fuzzilli/CodeGen/CodeGenerators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ public let CodeGenerators: [CodeGenerator] = [

// TODO: for now we simply look for numbers, since those probably make the most sense for binary operations. But we may also want BigInts or strings sometimes.
let rhs = b.randomVariable(forUseAs: .number)
b.updateProperty(propertyName, of: obj, with: rhs, using: chooseUniform(from: BinaryOperator.allCases))
b.updateProperty(propertyName, of: obj, with: rhs, using: chooseUniform(from: BinaryOperator.allCaseWithoutNCO()))
},

CodeGenerator("PropertyRemovalGenerator", inputs: .preferred(.object())) { b, obj in
Expand Down Expand Up @@ -895,7 +895,7 @@ public let CodeGenerators: [CodeGenerator] = [
let index = b.randomIndex()
// TODO: for now we simply look for numbers, since those probably make the most sense for binary operations. But we may also want BigInts or strings sometimes.
let rhs = b.randomVariable(forUseAs: .number)
b.updateElement(index, of: obj, with: rhs, using: chooseUniform(from: BinaryOperator.allCases))
b.updateElement(index, of: obj, with: rhs, using: chooseUniform(from: BinaryOperator.allCaseWithoutNCO()))
},

CodeGenerator("ElementRemovalGenerator", inputs: .preferred(.object())) { b, obj in
Expand Down Expand Up @@ -937,7 +937,7 @@ public let CodeGenerators: [CodeGenerator] = [
let propertyName = b.randomVariable()
// TODO: for now we simply look for numbers, since those probably make the most sense for binary operations. But we may also want BigInts or strings sometimes.
let rhs = b.randomVariable(forUseAs: .number)
b.updateComputedProperty(propertyName, of: obj, with: rhs, using: chooseUniform(from: BinaryOperator.allCases))
b.updateComputedProperty(propertyName, of: obj, with: rhs, using: chooseUniform(from: BinaryOperator.allCaseWithoutNCO()))
},

CodeGenerator("ComputedPropertyRemovalGenerator", inputs: .preferred(.object())) { b, obj in
Expand Down Expand Up @@ -1228,7 +1228,7 @@ public let CodeGenerators: [CodeGenerator] = [
guard !b.currentClassDefinition.privateProperties.isEmpty else { return }
let propertyName = chooseUniform(from: b.currentClassDefinition.privateProperties)
b.buildTryCatchFinally(tryBody: {
b.updatePrivateProperty(propertyName, of: obj, with: value, using: chooseUniform(from: BinaryOperator.allCases))
b.updatePrivateProperty(propertyName, of: obj, with: value, using: chooseUniform(from: BinaryOperator.allCaseWithoutNCO()))
}, catchBody: { e in })
},

Expand Down Expand Up @@ -1281,7 +1281,7 @@ public let CodeGenerators: [CodeGenerator] = [

// TODO: for now we simply look for numbers, since those probably make the most sense for binary operations. But we may also want BigInts or strings sometimes.
let rhs = b.randomVariable(forUseAs: .number)
b.updateSuperProperty(propertyName, with: rhs, using: chooseUniform(from: BinaryOperator.allCases))
b.updateSuperProperty(propertyName, with: rhs, using: chooseUniform(from: BinaryOperator.allCaseWithoutNCO()))
},

RecursiveCodeGenerator("IfElseGenerator", inputs: .preferred(.boolean) ){ b, cond in
Expand Down
3 changes: 2 additions & 1 deletion Sources/Fuzzilli/FuzzIL/JSTyper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ public struct JSTyper: Analyzer {
.UnRShift:
return maybeBigIntOr(.integer)
case .LogicAnd,
.LogicOr:
.LogicOr,
.NCO:
return state.type(of: inputs[0]) | state.type(of: inputs[1])
}
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/Fuzzilli/FuzzIL/JsOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1403,12 +1403,19 @@ public enum BinaryOperator: String, CaseIterable {
case RShift = ">>"
case Exp = "**"
case UnRShift = ">>>"
// Nullish coalescing operator (??)
case NCO = "??"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'NCO' is maybe a little weird because none of the other operators have "operator" in their name. 'NC' is maybe a bit short/unintuitive though, so how about just calling it NullCoalesce?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Thanks!


var token: String {
return self.rawValue
}

static public func allCaseWithoutNCO() -> Array<BinaryOperator> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the idea behind this? Why is the new operator special?

return BinaryOperator.allCases.filter { $0 != .NCO }
}
}


final class BinaryOperation: JsOperation {
override var opcode: Opcode { .binaryOperation(self) }

Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/Mutators/RuntimeAssistedMutator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public class RuntimeAssistedMutator: Mutator {
case LogicalAnd = "LOGICAL_AND"
case LogicalOr = "LOGICAL_OR"
case LogicalNot = "LOGICAL_NOT"
case NCO = "NCO"
case BitwiseAnd = "BITWISE_AND"
case BitwiseOr = "BITWISE_OR"
case BitwiseXor = "BITWISE_XOR"
Expand Down Expand Up @@ -385,6 +386,8 @@ extension RuntimeAssistedMutator.Action {
try translateBinaryOperation(.BitOr)
case .BitwiseXor:
try translateBinaryOperation(.Xor)
case .NCO:
try translateBinaryOperation(.NCO)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will also need to update the corresponding JavaScript code, see here:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much. I missed something here.

case .LeftShift:
try translateBinaryOperation(.LShift)
case .SignedRightShift:
Expand Down