Skip to content

Commit

Permalink
Add void feature to the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
vi3tL0u1s committed Dec 2, 2024
1 parent 0360a7a commit bb872e1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Sources/Fuzzilli/Compiler/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,13 @@ public class JavaScriptCompiler {
if unaryExpression.operator == "typeof" {
return emit(TypeOf(), withInputs: [argument]).output
}

// Handle `void` operator
if unaryExpression.operator == "void" {
// Emit a UnaryOperation for the void operator
return emit(UnaryOperation(.Void), withInputs: [argument]).output
}

guard let op = UnaryOperator(rawValue: unaryExpression.operator) else {
throw CompilerError.invalidNodeError("invalid unary operator: \(unaryExpression.operator)")
}
Expand Down
2 changes: 1 addition & 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
1 change: 1 addition & 0 deletions Sources/Fuzzilli/Protobuf/program.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: program.proto
Expand Down
1 change: 1 addition & 0 deletions Sources/Fuzzilli/Protobuf/sync.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: sync.proto
Expand Down
10 changes: 10 additions & 0 deletions Tests/FuzzilliTests/CompilerTests/basic_void.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const test = void 1;
console.log(test);
// Expected output: undefined

void console.log('expression evaluated');
// Expected output: "expression evaluated"

void (function iife() {
console.log('iife is executed');
})();

0 comments on commit bb872e1

Please sign in to comment.