Skip to content

Commit e9bafb9

Browse files
committed
allow async on the top level
1 parent 10ff06a commit e9bafb9

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Sources/Fuzzilli/Compiler/Compiler.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,13 +1160,10 @@ public class JavaScriptCompiler {
11601160
fatalError("V8IntrinsicIdentifiers must be handled as part of their surrounding CallExpression")
11611161

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

Sources/Fuzzilli/Compiler/Parser/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function tryReadFile(path) {
3434

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

3939
function assertNoError(err) {
4040
if (err) throw err;

Sources/Fuzzilli/FuzzIL/Code.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,12 @@ public struct Code: Collection {
239239
throw FuzzilliError.codeVerificationError("variable \(input) is not visible anymore")
240240
}
241241
}
242-
243-
guard instr.op.requiredContext.isSubset(of: contextAnalyzer.context) else {
244-
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
242+
243+
// allow top-level await
244+
if !instr.op is Await {
245+
guard instr.op.requiredContext.isSubset(of: contextAnalyzer.context) else {
246+
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
247+
}
245248
}
246249

247250
// Ensure that the instruction exists in the right context

0 commit comments

Comments
 (0)