mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:42:43 +00:00 
			
		
		
		
	LibJS/Bytecode: Do not clobber completion value with VariableDeclaration
While the completion value of a variable declaration is specified to be empty, we might already have a completion value in the accumulator from a previous statement. Preserve it so as to avoid clobbering it. This fixes 6 tests on test262.
This commit is contained in:
		
							parent
							
								
									bd2c3ace68
								
							
						
					
					
						commit
						0df7255fe7
					
				
					 1 changed files with 6 additions and 0 deletions
				
			
		|  | @ -1353,6 +1353,11 @@ static Bytecode::CodeGenerationErrorOr<void> assign_accumulator_to_variable_decl | ||||||
| 
 | 
 | ||||||
| Bytecode::CodeGenerationErrorOr<void> VariableDeclaration::generate_bytecode(Bytecode::Generator& generator) const | Bytecode::CodeGenerationErrorOr<void> VariableDeclaration::generate_bytecode(Bytecode::Generator& generator) const | ||||||
| { | { | ||||||
|  |     // The completion value of a VariableDeclaration is empty, but there might already be a non-empty
 | ||||||
|  |     // completion value in the accumulator. We need to save it and restore it after the declaration executed.
 | ||||||
|  |     auto saved_accumulator = generator.allocate_register(); | ||||||
|  |     generator.emit<Bytecode::Op::Store>(saved_accumulator); | ||||||
|  | 
 | ||||||
|     for (auto& declarator : m_declarations) { |     for (auto& declarator : m_declarations) { | ||||||
|         if (declarator->init()) { |         if (declarator->init()) { | ||||||
|             if (auto const* lhs = declarator->target().get_pointer<NonnullRefPtr<Identifier const>>()) { |             if (auto const* lhs = declarator->target().get_pointer<NonnullRefPtr<Identifier const>>()) { | ||||||
|  | @ -1367,6 +1372,7 @@ Bytecode::CodeGenerationErrorOr<void> VariableDeclaration::generate_bytecode(Byt | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     generator.emit<Bytecode::Op::Load>(saved_accumulator); | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Daniel Bertalan
						Daniel Bertalan