Skip to content

Commit

Permalink
Merge pull request #472 from Yi2255/feature-void
Browse files Browse the repository at this point in the history
feature/void
  • Loading branch information
saelo authored Dec 4, 2024
2 parents fe1d0e5 + d6cbd0c commit 2b9366f
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 396 deletions.
5 changes: 5 additions & 0 deletions Sources/Fuzzilli/Base/ProgramBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,11 @@ public class ProgramBuilder {
return emit(TypeOf(), withInputs: [v]).output
}

@discardableResult
public func void(_ v: Variable) -> Variable {
return emit(Void_(), withInputs: [v]).output
}

@discardableResult
public func testInstanceOf(_ v: Variable, _ type: Variable) -> Variable {
return emit(TestInstanceOf(), withInputs: [v, type]).output
Expand Down
1 change: 1 addition & 0 deletions Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,5 @@ public let codeGeneratorWeights = [
"ApiConstructorCallGenerator": 15,
"ApiMethodCallGenerator": 15,
"ApiFunctionCallGenerator": 15,
"VoidGenerator": 1,
]
4 changes: 4 additions & 0 deletions Sources/Fuzzilli/CodeGen/CodeGenerators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,10 @@ public let CodeGenerators: [CodeGenerator] = [
b.compare(type, with: rhs, using: .strictEqual)
},

CodeGenerator("VoidGenerator", inputs: .one) { b, val in
b.void(val)
},

CodeGenerator("InstanceOfGenerator", inputs: .preferred(.anything, .constructor())) { b, val, cls in
b.testInstanceOf(val, cls)
},
Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/Compiler/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,9 @@ public class JavaScriptCompiler {
if unaryExpression.operator == "typeof" {
let argument = try compileExpression(unaryExpression.argument)
return emit(TypeOf(), withInputs: [argument]).output
} else if unaryExpression.operator == "void" {
let argument = try compileExpression(unaryExpression.argument)
return emit(Void_(), withInputs: [argument]).output
} else if unaryExpression.operator == "delete" {
guard case .memberExpression(let memberExpression) = unaryExpression.argument.expression else {
throw CompilerError.invalidNodeError("delete operator must be applied to a member expression")
Expand Down
4 changes: 4 additions & 0 deletions Sources/Fuzzilli/FuzzIL/Instruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ extension Instruction: ProtobufConvertible {
}
case .typeOf:
$0.typeOf = Fuzzilli_Protobuf_TypeOf()
case .void:
$0.void = Fuzzilli_Protobuf_Void()
case .testInstanceOf:
$0.testInstanceOf = Fuzzilli_Protobuf_TestInstanceOf()
case .testIn:
Expand Down Expand Up @@ -1042,6 +1044,8 @@ extension Instruction: ProtobufConvertible {
op = ConfigureComputedProperty(flags: flags, type: try convertEnum(p.type, PropertyType.allCases))
case .typeOf:
op = TypeOf()
case .void:
op = Void_()
case .testInstanceOf:
op = TestInstanceOf()
case .testIn:
Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/FuzzIL/JSTyper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@ public struct JSTyper: Analyzer {
case .typeOf:
set(instr.output, .string)

case .void:
set(instr.output, .undefined)

case .testInstanceOf:
set(instr.output, .boolean)

Expand Down
8 changes: 8 additions & 0 deletions Sources/Fuzzilli/FuzzIL/JsOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,14 @@ final class TypeOf: JsOperation {
}
}

final class Void_: JsOperation {
override var opcode: Opcode { .void(self) }

init() {
super.init(numInputs: 1, numOutputs: 1)
}
}

final class TestInstanceOf: JsOperation {
override var opcode: Opcode { .testInstanceOf(self) }

Expand Down
1 change: 1 addition & 0 deletions Sources/Fuzzilli/FuzzIL/Opcodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum Opcode {
case deleteComputedProperty(DeleteComputedProperty)
case configureComputedProperty(ConfigureComputedProperty)
case typeOf(TypeOf)
case void(Void_)
case testInstanceOf(TestInstanceOf)
case testIn(TestIn)
case beginPlainFunction(BeginPlainFunction)
Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/Lifting/FuzzILLifter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ public class FuzzILLifter: Lifter {
case .typeOf:
w.emit("\(output()) <- TypeOf \(input(0))")

case .void:
w.emit("\(output()) <- Void_ \(input(0))")

case .testInstanceOf:
w.emit("\(output()) <- TestInstanceOf \(input(0)), \(input(1))")

Expand Down
4 changes: 4 additions & 0 deletions Sources/Fuzzilli/Lifting/JavaScriptLifter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ public class JavaScriptLifter: Lifter {
let expr = UnaryExpression.new() + "typeof " + input(0)
w.assign(expr, to: instr.output)

case .void:
let expr = UnaryExpression.new() + "void " + input(0)
w.assign(expr, to: instr.output)

case .testInstanceOf:
let lhs = input(0)
let rhs = input(1)
Expand Down
31 changes: 30 additions & 1 deletion Sources/Fuzzilli/Protobuf/operations.pb.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// DO NOT EDIT.
// swift-format-ignore-file
// swiftlint:disable all
//
// Generated by the Swift generator plugin for the protocol buffer compiler.
// Source: operations.proto
Expand All @@ -21,7 +22,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import SwiftProtobuf

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

public struct Fuzzilli_Protobuf_Void: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

public var unknownFields = SwiftProtobuf.UnknownStorage()

public init() {}
}

public struct Fuzzilli_Protobuf_TestInstanceOf: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
Expand Down Expand Up @@ -4885,6 +4895,25 @@ extension Fuzzilli_Protobuf_TypeOf: SwiftProtobuf.Message, SwiftProtobuf._Messag
}
}

extension Fuzzilli_Protobuf_Void: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
public static let protoMessageName: String = _protobuf_package + ".Void"
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()

public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
// Load everything into unknown fields
while try decoder.nextFieldNumber() != nil {}
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
try unknownFields.traverse(visitor: &visitor)
}

public static func ==(lhs: Fuzzilli_Protobuf_Void, rhs: Fuzzilli_Protobuf_Void) -> Bool {
if lhs.unknownFields != rhs.unknownFields {return false}
return true
}
}

extension Fuzzilli_Protobuf_TestInstanceOf: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
public static let protoMessageName: String = _protobuf_package + ".TestInstanceOf"
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/Protobuf/operations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ message ConfigureComputedProperty {
message TypeOf {
}

message Void {
}

message TestInstanceOf {
}

Expand Down
Loading

0 comments on commit 2b9366f

Please sign in to comment.