@@ -57,7 +57,7 @@ impl ByteCompiler<'_, '_> {
5757 }
5858
5959 self . push_empty_loop_jump_control ( use_expr) ;
60- let ( loop_start , loop_exit ) = self . emit_opcode_with_two_operands ( Opcode :: LoopStart ) ;
60+ self . emit_opcode ( Opcode :: LoopStart ) ;
6161 let initial_jump = self . jump ( ) ;
6262 let start_address = self . next_opcode_location ( ) ;
6363
@@ -81,7 +81,6 @@ impl ByteCompiler<'_, '_> {
8181 }
8282
8383 self . emit_opcode ( Opcode :: LoopContinue ) ;
84- self . patch_jump_with_target ( loop_start, start_address) ;
8584
8685 if let Some ( final_expr) = for_loop. final_expr ( ) {
8786 self . compile_expr ( final_expr, false ) ;
@@ -101,7 +100,9 @@ impl ByteCompiler<'_, '_> {
101100 self . emit ( Opcode :: Jump , & [ start_address] ) ;
102101
103102 self . patch_jump ( exit) ;
104- self . patch_jump ( loop_exit) ;
103+ if env_labels. is_some ( ) {
104+ self . emit_opcode ( Opcode :: PopEnvironment ) ;
105+ }
105106 self . pop_loop_control_info ( ) ;
106107 self . emit_opcode ( Opcode :: LoopEnd ) ;
107108
@@ -111,7 +112,6 @@ impl ByteCompiler<'_, '_> {
111112 if let Some ( iteration_env_labels) = iteration_env_labels {
112113 self . patch_jump_with_target ( iteration_env_labels, env_index) ;
113114 }
114- self . emit_opcode ( Opcode :: PopEnvironment ) ;
115115 }
116116 }
117117
@@ -154,12 +154,11 @@ impl ByteCompiler<'_, '_> {
154154 let early_exit = self . jump_if_null_or_undefined ( ) ;
155155 self . emit_opcode ( Opcode :: CreateForInIterator ) ;
156156
157- let ( loop_start , exit_label ) =
158- self . emit_opcode_with_two_operands ( Opcode :: IteratorLoopStart ) ;
157+ self . emit_opcode ( Opcode :: IteratorLoopStart ) ;
158+
159159 let start_address = self . next_opcode_location ( ) ;
160160 self . push_loop_control_info_for_of_in_loop ( label, start_address, use_expr) ;
161161 self . emit_opcode ( Opcode :: LoopContinue ) ;
162- self . patch_jump_with_target ( loop_start, start_address) ;
163162
164163 self . emit_opcode ( Opcode :: IteratorNext ) ;
165164 self . emit_opcode ( Opcode :: IteratorDone ) ;
@@ -233,7 +232,6 @@ impl ByteCompiler<'_, '_> {
233232 self . emit ( Opcode :: Jump , & [ start_address] ) ;
234233
235234 self . patch_jump ( exit) ;
236- self . patch_jump ( exit_label) ;
237235 self . pop_loop_control_info ( ) ;
238236 self . emit_opcode ( Opcode :: LoopEnd ) ;
239237
@@ -278,15 +276,14 @@ impl ByteCompiler<'_, '_> {
278276 self . emit_opcode ( Opcode :: GetIterator ) ;
279277 }
280278
281- let ( loop_start , loop_exit ) = self . emit_opcode_with_two_operands ( Opcode :: IteratorLoopStart ) ;
279+ self . emit_opcode ( Opcode :: IteratorLoopStart ) ;
282280 let start_address = self . next_opcode_location ( ) ;
283281 if for_of_loop. r#await ( ) {
284282 self . push_loop_control_info_for_await_of_loop ( label, start_address, use_expr) ;
285283 } else {
286284 self . push_loop_control_info_for_of_in_loop ( label, start_address, use_expr) ;
287285 }
288286 self . emit_opcode ( Opcode :: LoopContinue ) ;
289- self . patch_jump_with_target ( loop_start, start_address) ;
290287
291288 self . emit_opcode ( Opcode :: IteratorNext ) ;
292289 if for_of_loop. r#await ( ) {
@@ -381,7 +378,6 @@ impl ByteCompiler<'_, '_> {
381378 self . emit ( Opcode :: Jump , & [ start_address] ) ;
382379
383380 self . patch_jump ( exit) ;
384- self . patch_jump ( loop_exit) ;
385381 self . pop_loop_control_info ( ) ;
386382 self . emit_opcode ( Opcode :: LoopEnd ) ;
387383
@@ -394,11 +390,10 @@ impl ByteCompiler<'_, '_> {
394390 label : Option < Sym > ,
395391 use_expr : bool ,
396392 ) {
397- let ( loop_start , loop_exit ) = self . emit_opcode_with_two_operands ( Opcode :: LoopStart ) ;
393+ self . emit_opcode ( Opcode :: LoopStart ) ;
398394 let start_address = self . next_opcode_location ( ) ;
399395 self . emit_opcode ( Opcode :: LoopContinue ) ;
400396 self . push_loop_control_info ( label, start_address, use_expr) ;
401- self . patch_jump_with_target ( loop_start, start_address) ;
402397
403398 self . compile_expr ( while_loop. condition ( ) , true ) ;
404399 let exit = self . jump_if_false ( ) ;
@@ -408,7 +403,6 @@ impl ByteCompiler<'_, '_> {
408403 self . emit ( Opcode :: Jump , & [ start_address] ) ;
409404
410405 self . patch_jump ( exit) ;
411- self . patch_jump ( loop_exit) ;
412406 self . pop_loop_control_info ( ) ;
413407 self . emit_opcode ( Opcode :: LoopEnd ) ;
414408 }
@@ -419,12 +413,11 @@ impl ByteCompiler<'_, '_> {
419413 label : Option < Sym > ,
420414 use_expr : bool ,
421415 ) {
422- let ( loop_start , loop_exit ) = self . emit_opcode_with_two_operands ( Opcode :: LoopStart ) ;
416+ self . emit_opcode ( Opcode :: LoopStart ) ;
423417 let initial_label = self . jump ( ) ;
424418
425419 let start_address = self . next_opcode_location ( ) ;
426420
427- self . patch_jump_with_target ( loop_start, start_address) ;
428421 self . push_loop_control_info ( label, start_address, use_expr) ;
429422
430423 let condition_label_address = self . next_opcode_location ( ) ;
@@ -438,7 +431,6 @@ impl ByteCompiler<'_, '_> {
438431
439432 self . emit ( Opcode :: Jump , & [ condition_label_address] ) ;
440433 self . patch_jump ( exit) ;
441- self . patch_jump ( loop_exit) ;
442434
443435 self . pop_loop_control_info ( ) ;
444436 self . emit_opcode ( Opcode :: LoopEnd ) ;
0 commit comments