| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibJS/AST.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  | #include <LibJS/Bytecode/BasicBlock.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | #include <LibJS/Bytecode/Generator.h>
 | 
					
						
							|  |  |  | #include <LibJS/Bytecode/Instruction.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-11 01:35:01 +04:30
										 |  |  | #include <LibJS/Bytecode/Op.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | #include <LibJS/Bytecode/Register.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Generator::Generator() | 
					
						
							| 
									
										
										
										
											2021-06-09 10:02:01 +02:00
										 |  |  |     : m_string_table(make<StringTable>()) | 
					
						
							| 
									
										
										
										
											2021-10-24 15:34:30 +02:00
										 |  |  |     , m_identifier_table(make<IdentifierTable>()) | 
					
						
							| 
									
										
										
										
											2023-07-13 10:49:07 +02:00
										 |  |  |     , m_regex_table(make<RegexTable>()) | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  | CodeGenerationErrorOr<NonnullOwnPtr<Executable>> Generator::generate(ASTNode const& node, FunctionKind enclosing_function_kind) | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     Generator generator; | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  |     generator.switch_to_basic_block(generator.make_block()); | 
					
						
							| 
									
										
										
										
											2021-11-11 00:46:07 +03:30
										 |  |  |     generator.m_enclosing_function_kind = enclosing_function_kind; | 
					
						
							|  |  |  |     if (generator.is_in_generator_or_async_function()) { | 
					
						
							| 
									
										
										
										
											2021-06-11 01:38:30 +04:30
										 |  |  |         // Immediately yield with no value.
 | 
					
						
							|  |  |  |         auto& start_block = generator.make_block(); | 
					
						
							|  |  |  |         generator.emit<Bytecode::Op::Yield>(Label { start_block }); | 
					
						
							|  |  |  |         generator.switch_to_basic_block(start_block); | 
					
						
							| 
									
										
										
										
											2022-11-25 23:14:08 +00:00
										 |  |  |         // NOTE: This doesn't have to handle received throw/return completions, as GeneratorObject::resume_abrupt
 | 
					
						
							|  |  |  |         //       will not enter the generator from the SuspendedStart state and immediately completes the generator.
 | 
					
						
							| 
									
										
										
										
											2021-06-11 01:38:30 +04:30
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  |     TRY(node.generate_bytecode(generator)); | 
					
						
							| 
									
										
										
										
											2021-11-11 00:46:07 +03:30
										 |  |  |     if (generator.is_in_generator_or_async_function()) { | 
					
						
							| 
									
										
										
										
											2021-06-11 01:38:30 +04:30
										 |  |  |         // Terminate all unterminated blocks with yield return
 | 
					
						
							|  |  |  |         for (auto& block : generator.m_root_basic_blocks) { | 
					
						
							| 
									
										
										
										
											2023-03-06 17:16:25 +01:00
										 |  |  |             if (block->is_terminated()) | 
					
						
							| 
									
										
										
										
											2021-06-11 01:38:30 +04:30
										 |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2023-03-06 17:16:25 +01:00
										 |  |  |             generator.switch_to_basic_block(*block); | 
					
						
							| 
									
										
										
										
											2021-06-11 01:38:30 +04:30
										 |  |  |             generator.emit<Bytecode::Op::LoadImmediate>(js_undefined()); | 
					
						
							|  |  |  |             generator.emit<Bytecode::Op::Yield>(nullptr); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-07-17 18:56:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool is_strict_mode = false; | 
					
						
							|  |  |  |     if (is<Program>(node)) | 
					
						
							|  |  |  |         is_strict_mode = static_cast<Program const&>(node).is_strict_mode(); | 
					
						
							|  |  |  |     else if (is<FunctionBody>(node)) | 
					
						
							|  |  |  |         is_strict_mode = static_cast<FunctionBody const&>(node).in_strict_mode(); | 
					
						
							|  |  |  |     else if (is<FunctionDeclaration>(node)) | 
					
						
							|  |  |  |         is_strict_mode = static_cast<FunctionDeclaration const&>(node).is_strict_mode(); | 
					
						
							|  |  |  |     else if (is<FunctionExpression>(node)) | 
					
						
							|  |  |  |         is_strict_mode = static_cast<FunctionExpression const&>(node).is_strict_mode(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  |     Vector<PropertyLookupCache> property_lookup_caches; | 
					
						
							|  |  |  |     property_lookup_caches.resize(generator.m_next_property_lookup_cache); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 04:06:59 +02:00
										 |  |  |     Vector<GlobalVariableCache> global_variable_caches; | 
					
						
							|  |  |  |     global_variable_caches.resize(generator.m_next_global_variable_cache); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-31 13:25:39 +01:00
										 |  |  |     return adopt_own(*new Executable { | 
					
						
							|  |  |  |         .name = {}, | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  |         .property_lookup_caches = move(property_lookup_caches), | 
					
						
							| 
									
										
										
										
											2023-07-12 04:06:59 +02:00
										 |  |  |         .global_variable_caches = move(global_variable_caches), | 
					
						
							| 
									
										
										
										
											2022-01-31 13:25:39 +01:00
										 |  |  |         .basic_blocks = move(generator.m_root_basic_blocks), | 
					
						
							|  |  |  |         .string_table = move(generator.m_string_table), | 
					
						
							|  |  |  |         .identifier_table = move(generator.m_identifier_table), | 
					
						
							| 
									
										
										
										
											2023-07-13 10:49:07 +02:00
										 |  |  |         .regex_table = move(generator.m_regex_table), | 
					
						
							| 
									
										
										
										
											2022-07-17 18:56:36 +01:00
										 |  |  |         .number_of_registers = generator.m_next_register, | 
					
						
							| 
									
										
										
										
											2023-06-15 12:36:57 +02:00
										 |  |  |         .is_strict_mode = is_strict_mode, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-09 00:50:42 +02:00
										 |  |  | void Generator::grow(size_t additional_size) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  |     VERIFY(m_current_basic_block); | 
					
						
							|  |  |  |     m_current_basic_block->grow(additional_size); | 
					
						
							| 
									
										
										
										
											2021-06-09 00:50:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void* Generator::next_slot() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  |     VERIFY(m_current_basic_block); | 
					
						
							|  |  |  |     return m_current_basic_block->next_slot(); | 
					
						
							| 
									
										
										
										
											2021-06-09 00:50:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | Register Generator::allocate_register() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VERIFY(m_next_register != NumericLimits<u32>::max()); | 
					
						
							|  |  |  |     return Register { m_next_register++ }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-06 13:33:02 +02:00
										 |  |  | Label Generator::nearest_continuable_scope() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |     return m_continuable_scopes.last().bytecode_target; | 
					
						
							| 
									
										
										
										
											2021-06-06 13:33:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 16:34:47 +02:00
										 |  |  | void Generator::block_declaration_instantiation(ScopeNode const& scope_node) | 
					
						
							| 
									
										
										
										
											2022-03-14 02:34:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-06-16 16:34:47 +02:00
										 |  |  |     start_boundary(BlockBoundaryType::LeaveLexicalEnvironment); | 
					
						
							|  |  |  |     emit<Bytecode::Op::BlockDeclarationInstantiation>(scope_node); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Generator::begin_variable_scope() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     start_boundary(BlockBoundaryType::LeaveLexicalEnvironment); | 
					
						
							| 
									
										
										
										
											2023-06-16 16:43:24 +02:00
										 |  |  |     emit<Bytecode::Op::CreateLexicalEnvironment>(); | 
					
						
							| 
									
										
										
										
											2022-03-14 02:34:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Generator::end_variable_scope() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-06-16 16:34:47 +02:00
										 |  |  |     end_boundary(BlockBoundaryType::LeaveLexicalEnvironment); | 
					
						
							| 
									
										
										
										
											2022-03-14 02:34:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 16:34:47 +02:00
										 |  |  |     if (!m_current_basic_block->is_terminated()) { | 
					
						
							| 
									
										
										
										
											2023-06-16 16:43:24 +02:00
										 |  |  |         emit<Bytecode::Op::LeaveLexicalEnvironment>(); | 
					
						
							| 
									
										
										
										
											2022-03-14 02:34:01 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 19:23:00 -05:00
										 |  |  | void Generator::begin_continuable_scope(Label continue_target, Vector<DeprecatedFlyString> const& language_label_set) | 
					
						
							| 
									
										
										
										
											2021-06-06 13:33:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |     m_continuable_scopes.append({ continue_target, language_label_set }); | 
					
						
							| 
									
										
										
										
											2022-03-13 11:51:02 +03:30
										 |  |  |     start_boundary(BlockBoundaryType::Continue); | 
					
						
							| 
									
										
										
										
											2021-06-06 13:33:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Generator::end_continuable_scope() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_continuable_scopes.take_last(); | 
					
						
							| 
									
										
										
										
											2022-03-13 11:51:02 +03:30
										 |  |  |     end_boundary(BlockBoundaryType::Continue); | 
					
						
							| 
									
										
										
										
											2021-06-06 13:33:02 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 20:28:43 +08:00
										 |  |  | Label Generator::nearest_breakable_scope() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |     return m_breakable_scopes.last().bytecode_target; | 
					
						
							| 
									
										
										
										
											2021-06-10 20:28:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 19:23:00 -05:00
										 |  |  | void Generator::begin_breakable_scope(Label breakable_target, Vector<DeprecatedFlyString> const& language_label_set) | 
					
						
							| 
									
										
										
										
											2021-06-10 20:28:43 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |     m_breakable_scopes.append({ breakable_target, language_label_set }); | 
					
						
							| 
									
										
										
										
											2022-03-13 11:51:02 +03:30
										 |  |  |     start_boundary(BlockBoundaryType::Break); | 
					
						
							| 
									
										
										
										
											2021-06-10 20:28:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-06-06 13:33:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 20:28:43 +08:00
										 |  |  | void Generator::end_breakable_scope() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_breakable_scopes.take_last(); | 
					
						
							| 
									
										
										
										
											2022-03-13 11:51:02 +03:30
										 |  |  |     end_boundary(BlockBoundaryType::Break); | 
					
						
							| 
									
										
										
										
											2021-06-10 20:28:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  | CodeGenerationErrorOr<Generator::ReferenceRegisters> Generator::emit_super_reference(MemberExpression const& expression) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VERIFY(is<SuperExpression>(expression.object())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
 | 
					
						
							|  |  |  |     // 1. Let env be GetThisEnvironment().
 | 
					
						
							|  |  |  |     // 2. Let actualThis be ? env.GetThisBinding().
 | 
					
						
							|  |  |  |     auto actual_this_register = allocate_register(); | 
					
						
							|  |  |  |     emit<Bytecode::Op::ResolveThisBinding>(); | 
					
						
							|  |  |  |     emit<Bytecode::Op::Store>(actual_this_register); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Optional<Bytecode::Register> computed_property_value_register; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (expression.is_computed()) { | 
					
						
							|  |  |  |         // SuperProperty : super [ Expression ]
 | 
					
						
							|  |  |  |         // 3. Let propertyNameReference be ? Evaluation of Expression.
 | 
					
						
							|  |  |  |         // 4. Let propertyNameValue be ? GetValue(propertyNameReference).
 | 
					
						
							|  |  |  |         TRY(expression.property().generate_bytecode(*this)); | 
					
						
							|  |  |  |         computed_property_value_register = allocate_register(); | 
					
						
							|  |  |  |         emit<Bytecode::Op::Store>(*computed_property_value_register); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 5/7. Return ? MakeSuperPropertyReference(actualThis, propertyKey, strict).
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://tc39.es/ecma262/#sec-makesuperpropertyreference
 | 
					
						
							|  |  |  |     // 1. Let env be GetThisEnvironment().
 | 
					
						
							|  |  |  |     // 2. Assert: env.HasSuperBinding() is true.
 | 
					
						
							|  |  |  |     // 3. Let baseValue be ? env.GetSuperBase().
 | 
					
						
							|  |  |  |     auto super_base_register = allocate_register(); | 
					
						
							|  |  |  |     emit<Bytecode::Op::ResolveSuperBase>(); | 
					
						
							|  |  |  |     emit<Bytecode::Op::Store>(super_base_register); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 4. Return the Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }.
 | 
					
						
							|  |  |  |     return ReferenceRegisters { | 
					
						
							|  |  |  |         .base = super_base_register, | 
					
						
							|  |  |  |         .referenced_name = move(computed_property_value_register), | 
					
						
							|  |  |  |         .this_value = actual_this_register, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  | CodeGenerationErrorOr<void> Generator::emit_load_from_reference(JS::ASTNode const& node) | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (is<Identifier>(node)) { | 
					
						
							|  |  |  |         auto& identifier = static_cast<Identifier const&>(node); | 
					
						
							| 
									
										
										
										
											2023-07-05 02:17:10 +02:00
										 |  |  |         TRY(identifier.generate_bytecode(*this)); | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  |         return {}; | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (is<MemberExpression>(node)) { | 
					
						
							|  |  |  |         auto& expression = static_cast<MemberExpression const&>(node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 18:45:16 +01:00
										 |  |  |         // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
 | 
					
						
							|  |  |  |         if (is<SuperExpression>(expression.object())) { | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  |             auto super_reference = TRY(emit_super_reference(expression)); | 
					
						
							| 
									
										
										
										
											2023-05-15 18:45:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  |             if (super_reference.referenced_name.has_value()) { | 
					
						
							| 
									
										
										
										
											2023-05-15 18:45:16 +01:00
										 |  |  |                 // 5. Let propertyKey be ? ToPropertyKey(propertyNameValue).
 | 
					
						
							|  |  |  |                 // FIXME: This does ToPropertyKey out of order, which is observable by Symbol.toPrimitive!
 | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  |                 emit<Bytecode::Op::Load>(*super_reference.referenced_name); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::GetByValueWithThis>(super_reference.base, super_reference.this_value); | 
					
						
							| 
									
										
										
										
											2023-05-15 18:45:16 +01:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 // 3. Let propertyKey be StringValue of IdentifierName.
 | 
					
						
							|  |  |  |                 auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  |                 emit_get_by_id_with_this(identifier_table_ref, super_reference.this_value); | 
					
						
							| 
									
										
										
										
											2023-05-15 18:45:16 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-05-15 18:45:16 +01:00
										 |  |  |             TRY(expression.object().generate_bytecode(*this)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (expression.is_computed()) { | 
					
						
							|  |  |  |                 auto object_reg = allocate_register(); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::Store>(object_reg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 TRY(expression.property().generate_bytecode(*this)); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::GetByValue>(object_reg); | 
					
						
							|  |  |  |             } else if (expression.property().is_identifier()) { | 
					
						
							|  |  |  |                 auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  |                 emit_get_by_id(identifier_table_ref); | 
					
						
							| 
									
										
										
										
											2023-06-23 08:16:17 +02:00
										 |  |  |             } else if (expression.property().is_private_identifier()) { | 
					
						
							|  |  |  |                 auto identifier_table_ref = intern_identifier(verify_cast<PrivateIdentifier>(expression.property()).string()); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::GetPrivateById>(identifier_table_ref); | 
					
						
							| 
									
										
										
										
											2023-05-15 18:45:16 +01:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 return CodeGenerationError { | 
					
						
							|  |  |  |                     &expression, | 
					
						
							|  |  |  |                     "Unimplemented non-computed member expression"sv | 
					
						
							|  |  |  |                 }; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  |         return {}; | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  | CodeGenerationErrorOr<void> Generator::emit_store_to_reference(JS::ASTNode const& node) | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (is<Identifier>(node)) { | 
					
						
							|  |  |  |         auto& identifier = static_cast<Identifier const&>(node); | 
					
						
							| 
									
										
										
										
											2023-07-05 02:17:10 +02:00
										 |  |  |         emit_set_variable(identifier); | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  |         return {}; | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (is<MemberExpression>(node)) { | 
					
						
							|  |  |  |         // NOTE: The value is in the accumulator, so we have to store that away first.
 | 
					
						
							|  |  |  |         auto value_reg = allocate_register(); | 
					
						
							|  |  |  |         emit<Bytecode::Op::Store>(value_reg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         auto& expression = static_cast<MemberExpression const&>(node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-02 19:26:31 +01:00
										 |  |  |         // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
 | 
					
						
							|  |  |  |         if (is<SuperExpression>(expression.object())) { | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  |             auto super_reference = TRY(emit_super_reference(expression)); | 
					
						
							| 
									
										
										
										
											2023-06-23 08:16:17 +02:00
										 |  |  |             emit<Bytecode::Op::Load>(value_reg); | 
					
						
							| 
									
										
										
										
											2023-07-02 19:26:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // 4. Return the Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }.
 | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  |             if (super_reference.referenced_name.has_value()) { | 
					
						
							| 
									
										
										
										
											2023-07-02 19:26:31 +01:00
										 |  |  |                 // 5. Let propertyKey be ? ToPropertyKey(propertyNameValue).
 | 
					
						
							|  |  |  |                 // FIXME: This does ToPropertyKey out of order, which is observable by Symbol.toPrimitive!
 | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  |                 emit<Bytecode::Op::PutByValueWithThis>(super_reference.base, *super_reference.referenced_name, super_reference.this_value); | 
					
						
							| 
									
										
										
										
											2023-07-02 19:26:31 +01:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 // 3. Let propertyKey be StringValue of IdentifierName.
 | 
					
						
							|  |  |  |                 auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); | 
					
						
							| 
									
										
										
										
											2023-07-06 17:02:06 -04:00
										 |  |  |                 emit<Bytecode::Op::PutByIdWithThis>(super_reference.base, super_reference.this_value, identifier_table_ref); | 
					
						
							| 
									
										
										
										
											2023-07-02 19:26:31 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-07-02 19:26:31 +01:00
										 |  |  |             TRY(expression.object().generate_bytecode(*this)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             auto object_reg = allocate_register(); | 
					
						
							|  |  |  |             emit<Bytecode::Op::Store>(object_reg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (expression.is_computed()) { | 
					
						
							|  |  |  |                 TRY(expression.property().generate_bytecode(*this)); | 
					
						
							|  |  |  |                 auto property_reg = allocate_register(); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::Store>(property_reg); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::Load>(value_reg); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::PutByValue>(object_reg, property_reg); | 
					
						
							|  |  |  |             } else if (expression.property().is_identifier()) { | 
					
						
							|  |  |  |                 emit<Bytecode::Op::Load>(value_reg); | 
					
						
							|  |  |  |                 auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::PutById>(object_reg, identifier_table_ref); | 
					
						
							|  |  |  |             } else if (expression.property().is_private_identifier()) { | 
					
						
							|  |  |  |                 emit<Bytecode::Op::Load>(value_reg); | 
					
						
							|  |  |  |                 auto identifier_table_ref = intern_identifier(verify_cast<PrivateIdentifier>(expression.property()).string()); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::PutPrivateById>(object_reg, identifier_table_ref); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return CodeGenerationError { | 
					
						
							|  |  |  |                     &expression, | 
					
						
							|  |  |  |                     "Unimplemented non-computed member expression"sv | 
					
						
							|  |  |  |                 }; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-07-02 19:26:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  |         return {}; | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-12 19:54:08 +03:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-18 20:18:19 +03:30
										 |  |  |     return CodeGenerationError { | 
					
						
							|  |  |  |         &node, | 
					
						
							|  |  |  |         "Unimplemented/invalid node used a reference"sv | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-10-25 15:16:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-27 19:50:09 +01:00
										 |  |  | CodeGenerationErrorOr<void> Generator::emit_delete_reference(JS::ASTNode const& node) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (is<Identifier>(node)) { | 
					
						
							|  |  |  |         auto& identifier = static_cast<Identifier const&>(node); | 
					
						
							| 
									
										
										
										
											2023-07-08 20:29:13 +02:00
										 |  |  |         if (identifier.is_local()) | 
					
						
							|  |  |  |             emit<Bytecode::Op::LoadImmediate>(Value(false)); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             emit<Bytecode::Op::DeleteVariable>(intern_identifier(identifier.string())); | 
					
						
							| 
									
										
										
										
											2022-03-27 19:50:09 +01:00
										 |  |  |         return {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (is<MemberExpression>(node)) { | 
					
						
							|  |  |  |         auto& expression = static_cast<MemberExpression const&>(node); | 
					
						
							| 
									
										
										
										
											2023-07-06 17:10:40 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
 | 
					
						
							|  |  |  |         if (is<SuperExpression>(expression.object())) { | 
					
						
							|  |  |  |             auto super_reference = TRY(emit_super_reference(expression)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (super_reference.referenced_name.has_value()) { | 
					
						
							|  |  |  |                 emit<Bytecode::Op::DeleteByValueWithThis>(super_reference.this_value, *super_reference.referenced_name); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); | 
					
						
							|  |  |  |                 emit<Bytecode::Op::DeleteByIdWithThis>(super_reference.this_value, identifier_table_ref); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-27 19:50:09 +01:00
										 |  |  |         TRY(expression.object().generate_bytecode(*this)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (expression.is_computed()) { | 
					
						
							|  |  |  |             auto object_reg = allocate_register(); | 
					
						
							|  |  |  |             emit<Bytecode::Op::Store>(object_reg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             TRY(expression.property().generate_bytecode(*this)); | 
					
						
							|  |  |  |             emit<Bytecode::Op::DeleteByValue>(object_reg); | 
					
						
							|  |  |  |         } else if (expression.property().is_identifier()) { | 
					
						
							|  |  |  |             auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); | 
					
						
							|  |  |  |             emit<Bytecode::Op::DeleteById>(identifier_table_ref); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             // NOTE: Trying to delete a private field generates a SyntaxError in the parser.
 | 
					
						
							|  |  |  |             return CodeGenerationError { | 
					
						
							|  |  |  |                 &expression, | 
					
						
							|  |  |  |                 "Unimplemented non-computed member expression"sv | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Though this will have no deletion effect, we still have to evaluate the node as it can have side effects.
 | 
					
						
							|  |  |  |     // For example: delete a(); delete ++c.b; etc.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation
 | 
					
						
							|  |  |  |     // 1. Let ref be the result of evaluating UnaryExpression.
 | 
					
						
							|  |  |  |     // 2. ReturnIfAbrupt(ref).
 | 
					
						
							|  |  |  |     TRY(node.generate_bytecode(*this)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 3. If ref is not a Reference Record, return true.
 | 
					
						
							|  |  |  |     emit<Bytecode::Op::LoadImmediate>(Value(true)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // NOTE: The rest of the steps are handled by Delete{Variable,ByValue,Id}.
 | 
					
						
							|  |  |  |     return {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 02:17:10 +02:00
										 |  |  | void Generator::emit_set_variable(JS::Identifier const& identifier, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Op::EnvironmentMode mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (identifier.is_local()) { | 
					
						
							|  |  |  |         emit<Bytecode::Op::SetLocal>(identifier.local_variable_index()); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         emit<Bytecode::Op::SetVariable>(intern_identifier(identifier.string()), initialization_mode, mode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-19 19:44:10 +12:00
										 |  |  | void Generator::generate_scoped_jump(JumpType type) | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     bool last_was_finally = false; | 
					
						
							|  |  |  |     for (size_t i = m_boundaries.size(); i > 0; --i) { | 
					
						
							|  |  |  |         auto boundary = m_boundaries[i - 1]; | 
					
						
							|  |  |  |         using enum BlockBoundaryType; | 
					
						
							|  |  |  |         switch (boundary) { | 
					
						
							|  |  |  |         case Break: | 
					
						
							| 
									
										
										
										
											2023-07-19 19:44:10 +12:00
										 |  |  |             if (type == JumpType::Break) { | 
					
						
							|  |  |  |                 emit<Op::Jump>().set_targets(nearest_breakable_scope(), {}); | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case Continue: | 
					
						
							|  |  |  |             if (type == JumpType::Continue) { | 
					
						
							|  |  |  |                 emit<Op::Jump>().set_targets(nearest_continuable_scope(), {}); | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  |         case Unwind: | 
					
						
							|  |  |  |             if (!last_was_finally) | 
					
						
							|  |  |  |                 emit<Bytecode::Op::LeaveUnwindContext>(); | 
					
						
							|  |  |  |             last_was_finally = false; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case LeaveLexicalEnvironment: | 
					
						
							| 
									
										
										
										
											2023-06-16 16:43:24 +02:00
										 |  |  |             emit<Bytecode::Op::LeaveLexicalEnvironment>(); | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case ReturnToFinally: { | 
					
						
							| 
									
										
										
										
											2023-07-19 19:44:10 +12:00
										 |  |  |             auto jump_type_name = type == JumpType::Break ? "break"sv : "continue"sv; | 
					
						
							|  |  |  |             auto& block = make_block(DeprecatedString::formatted("{}.{}", current_block().name(), jump_type_name)); | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  |             emit<Op::ScheduleJump>(Label { block }); | 
					
						
							|  |  |  |             switch_to_basic_block(block); | 
					
						
							|  |  |  |             last_was_finally = true; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  | void Generator::generate_labelled_jump(JumpType type, DeprecatedFlyString const& label) | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     size_t current_boundary = m_boundaries.size(); | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  |     bool last_was_finally = false; | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto const& jumpable_scopes = type == JumpType::Continue ? m_continuable_scopes : m_breakable_scopes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto const& jumpable_scope : jumpable_scopes.in_reverse()) { | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |         for (; current_boundary > 0; --current_boundary) { | 
					
						
							|  |  |  |             auto boundary = m_boundaries[current_boundary - 1]; | 
					
						
							|  |  |  |             if (boundary == BlockBoundaryType::Unwind) { | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  |                 if (!last_was_finally) | 
					
						
							|  |  |  |                     emit<Bytecode::Op::LeaveUnwindContext>(); | 
					
						
							|  |  |  |                 last_was_finally = false; | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |             } else if (boundary == BlockBoundaryType::LeaveLexicalEnvironment) { | 
					
						
							| 
									
										
										
										
											2023-06-16 16:43:24 +02:00
										 |  |  |                 emit<Bytecode::Op::LeaveLexicalEnvironment>(); | 
					
						
							| 
									
										
										
										
											2022-11-13 20:56:53 +01:00
										 |  |  |             } else if (boundary == BlockBoundaryType::ReturnToFinally) { | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  |                 auto jump_type_name = type == JumpType::Break ? "break"sv : "continue"sv; | 
					
						
							|  |  |  |                 auto& block = make_block(DeprecatedString::formatted("{}.{}", current_block().name(), jump_type_name)); | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  |                 emit<Op::ScheduleJump>(Label { block }); | 
					
						
							|  |  |  |                 switch_to_basic_block(block); | 
					
						
							|  |  |  |                 last_was_finally = true; | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  |             } else if ((type == JumpType::Continue && boundary == BlockBoundaryType::Continue) || (type == JumpType::Break && boundary == BlockBoundaryType::Break)) { | 
					
						
							|  |  |  |                 // Make sure we don't process this boundary twice if the current jumpable scope doesn't contain the target label.
 | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |                 --current_boundary; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  |         if (jumpable_scope.language_label_set.contains_slow(label)) { | 
					
						
							|  |  |  |             emit<Op::Jump>().set_targets(jumpable_scope.bytecode_target, {}); | 
					
						
							| 
									
										
										
										
											2022-11-25 16:15:34 +01:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  |     // We must have a jumpable scope available that contains the label, as this should be enforced by the parser.
 | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  |     VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  | void Generator::generate_break() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     generate_scoped_jump(JumpType::Break); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Generator::generate_break(DeprecatedFlyString const& break_label) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     generate_labelled_jump(JumpType::Break, break_label); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-25 16:35:39 +01:00
										 |  |  | void Generator::generate_continue() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-19 19:44:10 +12:00
										 |  |  |     generate_scoped_jump(JumpType::Continue); | 
					
						
							| 
									
										
										
										
											2022-11-25 16:35:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Generator::generate_continue(DeprecatedFlyString const& continue_label) | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-19 20:06:25 +12:00
										 |  |  |     generate_labelled_jump(JumpType::Continue, continue_label); | 
					
						
							| 
									
										
										
										
											2022-06-11 23:09:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 10:25:05 +02:00
										 |  |  | void Generator::push_home_object(Register register_) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_home_objects.append(register_); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Generator::pop_home_object() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_home_objects.take_last(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 18:17:13 +02:00
										 |  |  | void Generator::emit_new_function(FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name) | 
					
						
							| 
									
										
										
										
											2023-06-16 10:25:05 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_home_objects.is_empty()) | 
					
						
							| 
									
										
										
										
											2023-06-23 14:27:42 +02:00
										 |  |  |         emit<Op::NewFunction>(function_node, lhs_name); | 
					
						
							| 
									
										
										
										
											2023-06-16 10:25:05 +02:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2023-06-23 14:27:42 +02:00
										 |  |  |         emit<Op::NewFunction>(function_node, lhs_name, m_home_objects.last()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 18:17:13 +02:00
										 |  |  | CodeGenerationErrorOr<void> Generator::emit_named_evaluation_if_anonymous_function(Expression const& expression, Optional<IdentifierTableIndex> lhs_name) | 
					
						
							| 
									
										
										
										
											2023-06-23 14:27:42 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (is<FunctionExpression>(expression)) { | 
					
						
							|  |  |  |         auto const& function_expression = static_cast<FunctionExpression const&>(expression); | 
					
						
							|  |  |  |         if (!function_expression.has_name()) { | 
					
						
							|  |  |  |             TRY(function_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); | 
					
						
							|  |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (is<ClassExpression>(expression)) { | 
					
						
							|  |  |  |         auto const& class_expression = static_cast<ClassExpression const&>(expression); | 
					
						
							|  |  |  |         if (!class_expression.has_name()) { | 
					
						
							|  |  |  |             TRY(class_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); | 
					
						
							|  |  |  |             return {}; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TRY(expression.generate_bytecode(*this)); | 
					
						
							|  |  |  |     return {}; | 
					
						
							| 
									
										
										
										
											2023-06-16 10:25:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  | void Generator::emit_get_by_id(IdentifierTableIndex id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     emit<Op::GetById>(id, m_next_property_lookup_cache++); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Generator::emit_get_by_id_with_this(IdentifierTableIndex id, Register this_reg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     emit<Op::GetByIdWithThis>(id, this_reg, m_next_property_lookup_cache++); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } |