Skip to content

Commit

Permalink
Support feature/nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi2255 committed Nov 18, 2024
1 parent 0e20cd5 commit 6f2e6dc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
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,
.NullCoalesce:
return state.type(of: inputs[0]) | state.type(of: inputs[1])
}
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/Fuzzilli/FuzzIL/JsOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,8 @@ public enum BinaryOperator: String, CaseIterable {
case RShift = ">>"
case Exp = "**"
case UnRShift = ">>>"
// Nullish coalescing operator (??)
case NullCoalesce = "??"

var token: String {
return self.rawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ struct JavaScriptRuntimeAssistedMutatorLifting {
const OP_LOGICAL_AND = 'LOGICAL_AND';
const OP_LOGICAL_OR = 'LOGICAL_OR';
const OP_LOGICAL_NOT = 'LOGICAL_NOT';
const OP_LOGICAL_NullCoalesce = 'LOGICAL_NullCoalesce';
const OP_BITWISE_AND = 'BITWISE_AND';
const OP_BITWISE_OR = 'BITWISE_OR';
Expand Down Expand Up @@ -511,6 +512,7 @@ struct JavaScriptRuntimeAssistedMutatorLifting {
[OP_LOGICAL_AND]: (inputs) => inputs[0] && inputs[1],
[OP_LOGICAL_OR]: (inputs) => inputs[0] || inputs[1],
[OP_LOGICAL_NOT]: (inputs) => !inputs[0],
[OP_LOGICAL_NullCoalesce]: (inputs) => inputs[0] ?? inputs[1],
[OP_BITWISE_AND]: (inputs) => inputs[0] & inputs[1],
[OP_BITWISE_OR]: (inputs) => inputs[0] | inputs[1],
[OP_BITWISE_XOR]: (inputs) => inputs[0] ^ inputs[1],
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 NullCoalesce = "NullCoalesce"
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 .NullCoalesce:
try translateBinaryOperation(.NullCoalesce)
case .LeftShift:
try translateBinaryOperation(.LShift)
case .SignedRightShift:
Expand Down

0 comments on commit 6f2e6dc

Please sign in to comment.