Skip to content

Commit 89d2d77

Browse files
committed
Implements global property iterator for loop
1 parent 434d594 commit 89d2d77

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Sources/Fuzzilli/Compiler/Compiler.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,12 @@ public class JavaScriptCompiler {
431431
emit(EndForInLoop())
432432

433433
case .identifier(let identifier):
434-
guard let loopVar = lookupIdentifier(identifier.name) else {
435-
// TODO instead of throwing an error, we should create a global property with the identifier name
436-
throw CompilerError.unsupportedFeatureError("Identifier '\(identifier.name)' not found for for-in loop.")
434+
let loopVar: Variable
435+
if let existingVar = lookupIdentifier(identifier.name) {
436+
loopVar = existingVar
437+
} else {
438+
loopVar = emit(LoadNamedVariable(identifier.name)).output
439+
map(identifier.name, to: loopVar)
437440
}
438441
emit(BeginForInLoopWithReassignment(), withInputs: [obj, loopVar])
439442
try enterNewScope {
@@ -459,9 +462,12 @@ public class JavaScriptCompiler {
459462
emit(EndForOfLoop())
460463

461464
case .identifier(let identifier):
462-
guard let loopVar = lookupIdentifier(identifier.name) else {
463-
// TODO instead of throwing an error, we should create a global property with the identifier name
464-
throw CompilerError.unsupportedFeatureError("Identifier '\(identifier.name)' not found for for-of loop.")
465+
let loopVar: Variable
466+
if let existingVar = lookupIdentifier(identifier.name) {
467+
loopVar = existingVar
468+
} else {
469+
loopVar = emit(LoadNamedVariable(identifier.name)).output
470+
map(identifier.name, to: loopVar)
465471
}
466472
emit(BeginForOfLoopWithReassignment(), withInputs: [obj, loopVar])
467473
try enterNewScope {

0 commit comments

Comments
 (0)