Skip to content

Commit 2b9366f

Browse files
authored
Merge pull request #472 from Yi2255/feature-void
feature/void
2 parents fe1d0e5 + d6cbd0c commit 2b9366f

16 files changed

+504
-396
lines changed

Diff for: Sources/Fuzzilli/Base/ProgramBuilder.swift

+5
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,11 @@ public class ProgramBuilder {
20392039
return emit(TypeOf(), withInputs: [v]).output
20402040
}
20412041

2042+
@discardableResult
2043+
public func void(_ v: Variable) -> Variable {
2044+
return emit(Void_(), withInputs: [v]).output
2045+
}
2046+
20422047
@discardableResult
20432048
public func testInstanceOf(_ v: Variable, _ type: Variable) -> Variable {
20442049
return emit(TestInstanceOf(), withInputs: [v, type]).output

Diff for: Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

+1
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,5 @@ public let codeGeneratorWeights = [
193193
"ApiConstructorCallGenerator": 15,
194194
"ApiMethodCallGenerator": 15,
195195
"ApiFunctionCallGenerator": 15,
196+
"VoidGenerator": 1,
196197
]

Diff for: Sources/Fuzzilli/CodeGen/CodeGenerators.swift

+4
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ public let CodeGenerators: [CodeGenerator] = [
974974
b.compare(type, with: rhs, using: .strictEqual)
975975
},
976976

977+
CodeGenerator("VoidGenerator", inputs: .one) { b, val in
978+
b.void(val)
979+
},
980+
977981
CodeGenerator("InstanceOfGenerator", inputs: .preferred(.anything, .constructor())) { b, val, cls in
978982
b.testInstanceOf(val, cls)
979983
},

Diff for: Sources/Fuzzilli/Compiler/Compiler.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,9 @@ public class JavaScriptCompiler {
10591059
if unaryExpression.operator == "typeof" {
10601060
let argument = try compileExpression(unaryExpression.argument)
10611061
return emit(TypeOf(), withInputs: [argument]).output
1062+
} else if unaryExpression.operator == "void" {
1063+
let argument = try compileExpression(unaryExpression.argument)
1064+
return emit(Void_(), withInputs: [argument]).output
10621065
} else if unaryExpression.operator == "delete" {
10631066
guard case .memberExpression(let memberExpression) = unaryExpression.argument.expression else {
10641067
throw CompilerError.invalidNodeError("delete operator must be applied to a member expression")

Diff for: Sources/Fuzzilli/FuzzIL/Instruction.swift

+4
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ extension Instruction: ProtobufConvertible {
565565
}
566566
case .typeOf:
567567
$0.typeOf = Fuzzilli_Protobuf_TypeOf()
568+
case .void:
569+
$0.void = Fuzzilli_Protobuf_Void()
568570
case .testInstanceOf:
569571
$0.testInstanceOf = Fuzzilli_Protobuf_TestInstanceOf()
570572
case .testIn:
@@ -1042,6 +1044,8 @@ extension Instruction: ProtobufConvertible {
10421044
op = ConfigureComputedProperty(flags: flags, type: try convertEnum(p.type, PropertyType.allCases))
10431045
case .typeOf:
10441046
op = TypeOf()
1047+
case .void:
1048+
op = Void_()
10451049
case .testInstanceOf:
10461050
op = TestInstanceOf()
10471051
case .testIn:

Diff for: Sources/Fuzzilli/FuzzIL/JSTyper.swift

+3
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ public struct JSTyper: Analyzer {
676676
case .typeOf:
677677
set(instr.output, .string)
678678

679+
case .void:
680+
set(instr.output, .undefined)
681+
679682
case .testInstanceOf:
680683
set(instr.output, .boolean)
681684

Diff for: Sources/Fuzzilli/FuzzIL/JsOperations.swift

+8
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,14 @@ final class TypeOf: JsOperation {
10301030
}
10311031
}
10321032

1033+
final class Void_: JsOperation {
1034+
override var opcode: Opcode { .void(self) }
1035+
1036+
init() {
1037+
super.init(numInputs: 1, numOutputs: 1)
1038+
}
1039+
}
1040+
10331041
final class TestInstanceOf: JsOperation {
10341042
override var opcode: Opcode { .testInstanceOf(self) }
10351043

Diff for: Sources/Fuzzilli/FuzzIL/Opcodes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ enum Opcode {
106106
case deleteComputedProperty(DeleteComputedProperty)
107107
case configureComputedProperty(ConfigureComputedProperty)
108108
case typeOf(TypeOf)
109+
case void(Void_)
109110
case testInstanceOf(TestInstanceOf)
110111
case testIn(TestIn)
111112
case beginPlainFunction(BeginPlainFunction)

Diff for: Sources/Fuzzilli/Lifting/FuzzILLifter.swift

+3
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ public class FuzzILLifter: Lifter {
366366
case .typeOf:
367367
w.emit("\(output()) <- TypeOf \(input(0))")
368368

369+
case .void:
370+
w.emit("\(output()) <- Void_ \(input(0))")
371+
369372
case .testInstanceOf:
370373
w.emit("\(output()) <- TestInstanceOf \(input(0)), \(input(1))")
371374

Diff for: Sources/Fuzzilli/Lifting/JavaScriptLifter.swift

+4
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ public class JavaScriptLifter: Lifter {
642642
let expr = UnaryExpression.new() + "typeof " + input(0)
643643
w.assign(expr, to: instr.output)
644644

645+
case .void:
646+
let expr = UnaryExpression.new() + "void " + input(0)
647+
w.assign(expr, to: instr.output)
648+
645649
case .testInstanceOf:
646650
let lhs = input(0)
647651
let rhs = input(1)

Diff for: Sources/Fuzzilli/Protobuf/operations.pb.swift

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// DO NOT EDIT.
22
// swift-format-ignore-file
3+
// swiftlint:disable all
34
//
45
// Generated by the Swift generator plugin for the protocol buffer compiler.
56
// Source: operations.proto
@@ -21,7 +22,6 @@
2122
// See the License for the specific language governing permissions and
2223
// limitations under the License.
2324

24-
import Foundation
2525
import SwiftProtobuf
2626

2727
// If the compiler emits an error on this type, it is because this file
@@ -1278,6 +1278,16 @@ public struct Fuzzilli_Protobuf_TypeOf: Sendable {
12781278
public init() {}
12791279
}
12801280

1281+
public struct Fuzzilli_Protobuf_Void: Sendable {
1282+
// SwiftProtobuf.Message conformance is added in an extension below. See the
1283+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
1284+
// methods supported on all messages.
1285+
1286+
public var unknownFields = SwiftProtobuf.UnknownStorage()
1287+
1288+
public init() {}
1289+
}
1290+
12811291
public struct Fuzzilli_Protobuf_TestInstanceOf: Sendable {
12821292
// SwiftProtobuf.Message conformance is added in an extension below. See the
12831293
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
@@ -4885,6 +4895,25 @@ extension Fuzzilli_Protobuf_TypeOf: SwiftProtobuf.Message, SwiftProtobuf._Messag
48854895
}
48864896
}
48874897

4898+
extension Fuzzilli_Protobuf_Void: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
4899+
public static let protoMessageName: String = _protobuf_package + ".Void"
4900+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
4901+
4902+
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
4903+
// Load everything into unknown fields
4904+
while try decoder.nextFieldNumber() != nil {}
4905+
}
4906+
4907+
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
4908+
try unknownFields.traverse(visitor: &visitor)
4909+
}
4910+
4911+
public static func ==(lhs: Fuzzilli_Protobuf_Void, rhs: Fuzzilli_Protobuf_Void) -> Bool {
4912+
if lhs.unknownFields != rhs.unknownFields {return false}
4913+
return true
4914+
}
4915+
}
4916+
48884917
extension Fuzzilli_Protobuf_TestInstanceOf: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
48894918
public static let protoMessageName: String = _protobuf_package + ".TestInstanceOf"
48904919
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()

Diff for: Sources/Fuzzilli/Protobuf/operations.proto

+3
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ message ConfigureComputedProperty {
337337
message TypeOf {
338338
}
339339

340+
message Void {
341+
}
342+
340343
message TestInstanceOf {
341344
}
342345

0 commit comments

Comments
 (0)