File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments