mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:32:46 +00:00 
			
		
		
		
	LibJS/Bytecode: Move NewClass impl to CommonImplementations
This commit is contained in:
		
							parent
							
								
									ddce5e03c2
								
							
						
					
					
						commit
						f9fbb8cff2
					
				
					 3 changed files with 24 additions and 19 deletions
				
			
		|  | @ -449,4 +449,26 @@ ThrowCompletionOr<void> create_variable(VM& vm, DeprecatedFlyString const& name, | |||
|     return verify_cast<GlobalEnvironment>(vm.variable_environment())->create_global_var_binding(name, false); | ||||
| } | ||||
| 
 | ||||
| ThrowCompletionOr<ECMAScriptFunctionObject*> new_class(VM& vm, ClassExpression const& class_expression, Optional<IdentifierTableIndex> const& lhs_name) | ||||
| { | ||||
|     auto& interpreter = vm.bytecode_interpreter(); | ||||
|     auto name = class_expression.name(); | ||||
|     auto super_class = interpreter.accumulator(); | ||||
| 
 | ||||
|     // NOTE: NewClass expects classEnv to be active lexical environment
 | ||||
|     auto* class_environment = vm.lexical_environment(); | ||||
|     vm.running_execution_context().lexical_environment = interpreter.saved_lexical_environment_stack().take_last(); | ||||
| 
 | ||||
|     DeprecatedFlyString binding_name; | ||||
|     DeprecatedFlyString class_name; | ||||
|     if (!class_expression.has_name() && lhs_name.has_value()) { | ||||
|         class_name = interpreter.current_executable().get_identifier(lhs_name.value()); | ||||
|     } else { | ||||
|         binding_name = name; | ||||
|         class_name = name.is_null() ? ""sv : name; | ||||
|     } | ||||
| 
 | ||||
|     return TRY(class_expression.create_class_constructor(vm, class_environment, vm.lexical_environment(), super_class, binding_name, class_name)); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -33,5 +33,6 @@ ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode:: | |||
| Value new_regexp(VM&, ParsedRegex const&, DeprecatedString const& pattern, DeprecatedString const& flags); | ||||
| MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter&); | ||||
| ThrowCompletionOr<void> create_variable(VM&, DeprecatedFlyString const& name, Op::EnvironmentMode, bool is_global, bool is_immutable, bool is_strict); | ||||
| ThrowCompletionOr<ECMAScriptFunctionObject*> new_class(VM&, ClassExpression const&, Optional<IdentifierTableIndex> const& lhs_name); | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -1443,25 +1443,7 @@ ThrowCompletionOr<void> IteratorResultValue::execute_impl(Bytecode::Interpreter& | |||
| 
 | ||||
| ThrowCompletionOr<void> NewClass::execute_impl(Bytecode::Interpreter& interpreter) const | ||||
| { | ||||
|     auto& vm = interpreter.vm(); | ||||
|     auto name = m_class_expression.name(); | ||||
|     auto super_class = interpreter.accumulator(); | ||||
| 
 | ||||
|     // NOTE: NewClass expects classEnv to be active lexical environment
 | ||||
|     auto class_environment = vm.lexical_environment(); | ||||
|     vm.running_execution_context().lexical_environment = interpreter.saved_lexical_environment_stack().take_last(); | ||||
| 
 | ||||
|     DeprecatedFlyString binding_name; | ||||
|     DeprecatedFlyString class_name; | ||||
|     if (!m_class_expression.has_name() && m_lhs_name.has_value()) { | ||||
|         class_name = interpreter.current_executable().get_identifier(m_lhs_name.value()); | ||||
|     } else { | ||||
|         binding_name = name; | ||||
|         class_name = name.is_null() ? ""sv : name; | ||||
|     } | ||||
| 
 | ||||
|     interpreter.accumulator() = TRY(m_class_expression.create_class_constructor(vm, class_environment, vm.lexical_environment(), super_class, binding_name, class_name)); | ||||
| 
 | ||||
|     interpreter.accumulator() = TRY(new_class(interpreter.vm(), m_class_expression, m_lhs_name)); | ||||
|     return {}; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Simon Wanner
						Simon Wanner