Skip to content
Open
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
7 changes: 2 additions & 5 deletions Sources/Fuzzilli/Compiler/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1160,13 +1160,10 @@ public class JavaScriptCompiler {
fatalError("V8IntrinsicIdentifiers must be handled as part of their surrounding CallExpression")

case .awaitExpression(let awaitExpression):
// TODO await is also allowed at the top level of a module
if !contextAnalyzer.context.contains(.asyncFunction) {
throw CompilerError.invalidNodeError("`await` is currently only supported in async functions")
}
// Await is also allowed at the top level of a module
// workerd requires that support
let argument = try compileExpression(awaitExpression.argument)
return emit(Await(), withInputs: [argument]).output

}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/Compiler/Parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function tryReadFile(path) {

// Parse the given JavaScript script and return an AST compatible with Fuzzilli's protobuf-based AST format.
function parse(script, proto) {
let ast = Parser.parse(script, { plugins: ["v8intrinsic"] });
let ast = Parser.parse(script, { allowAwaitOutsideFunction: true, plugins: ["topLevelAwait","v8intrinsic"] });

function assertNoError(err) {
if (err) throw err;
Expand Down
9 changes: 6 additions & 3 deletions Sources/Fuzzilli/FuzzIL/Code.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,12 @@ public struct Code: Collection {
throw FuzzilliError.codeVerificationError("variable \(input) is not visible anymore")
}
}

guard instr.op.requiredContext.isSubset(of: contextAnalyzer.context) else {
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")

// allow top-level await
if !(instr.op is Await) {
guard instr.op.requiredContext.isSubset(of: contextAnalyzer.context) else {
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
}
}

// Ensure that the instruction exists in the right context
Expand Down