Skip to content

Commit 8a3db83

Browse files
committed
support for top-level awaits
1 parent 20850d4 commit 8a3db83

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Sources/Fuzzilli/Compiler/Compiler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,10 @@ public class JavaScriptCompiler {
11611161

11621162
case .awaitExpression(let awaitExpression):
11631163
// TODO await is also allowed at the top level of a module
1164-
if !contextAnalyzer.context.contains(.asyncFunction) {
1164+
/*if !contextAnalyzer.context.contains(.asyncFunction) {
11651165
throw CompilerError.invalidNodeError("`await` is currently only supported in async functions")
11661166
}
1167+
*/
11671168
let argument = try compileExpression(awaitExpression.argument)
11681169
return emit(Await(), withInputs: [argument]).output
11691170

Sources/Fuzzilli/FuzzIL/Code.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,21 @@ 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+
if instr.op is Await {
244+
if !contextAnalyzer.context.contains(.asyncFunction)
245+
{
246+
if contextAnalyzer.context.contains(.subroutine) {
247+
if !contextAnalyzer.context.contains(.method) && !contextAnalyzer.context.contains(.classMethod) {
248+
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
249+
}
250+
}
251+
}
252+
// fall-through allow top-level await
253+
} else {
254+
guard instr.op.requiredContext.isSubset(of: contextAnalyzer.context) else {
255+
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
256+
}
245257
}
246258

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

0 commit comments

Comments
 (0)