mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:12:45 +00:00 
			
		
		
		
	LibJS: Rename EnvironmentRecord::parent() => outer_environment()
This name matches the spec (corresponds to the [[OuterEnv]] slot.)
This commit is contained in:
		
							parent
							
								
									46f2c23030
								
							
						
					
					
						commit
						5edd259b0a
					
				
					 6 changed files with 30 additions and 29 deletions
				
			
		|  | @ -231,7 +231,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj | |||
|         //        and subsequently GetThisEnvironment() instead.
 | ||||
|         auto* function_environment = interpreter.current_environment(); | ||||
|         if (!function_environment->current_function()) | ||||
|             function_environment = static_cast<DeclarativeEnvironmentRecord*>(function_environment->parent()); | ||||
|             function_environment = static_cast<DeclarativeEnvironmentRecord*>(function_environment->outer_environment()); | ||||
| 
 | ||||
|         auto* super_constructor = function_environment->current_function()->prototype(); | ||||
|         // FIXME: Functions should track their constructor kind.
 | ||||
|  |  | |||
|  | @ -144,7 +144,7 @@ void Interpreter::exit_scope(const ScopeNode& scope_node) | |||
|     while (!m_scope_stack.is_empty()) { | ||||
|         auto popped_scope = m_scope_stack.take_last(); | ||||
|         if (popped_scope.pushed_environment) | ||||
|             vm().call_frame().environment_record = vm().call_frame().environment_record->parent(); | ||||
|             vm().call_frame().environment_record = vm().call_frame().environment_record->outer_environment(); | ||||
|         if (popped_scope.scope_node.ptr() == &scope_node) | ||||
|             break; | ||||
|     } | ||||
|  |  | |||
|  | @ -9,9 +9,9 @@ | |||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
| EnvironmentRecord::EnvironmentRecord(EnvironmentRecord* parent) | ||||
| EnvironmentRecord::EnvironmentRecord(EnvironmentRecord* outer_environment) | ||||
|     : Object(vm().environment_record_shape()) | ||||
|     , m_parent(parent) | ||||
|     , m_outer_environment(outer_environment) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -23,7 +23,7 @@ EnvironmentRecord::EnvironmentRecord(GlobalObjectTag tag) | |||
| void EnvironmentRecord::visit_edges(Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_parent); | ||||
|     visitor.visit(m_outer_environment); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -25,8 +25,9 @@ public: | |||
|     virtual bool has_this_binding() const = 0; | ||||
|     virtual Value get_this_binding(GlobalObject&) const = 0; | ||||
| 
 | ||||
|     EnvironmentRecord* parent() { return m_parent; } | ||||
|     EnvironmentRecord const* parent() const { return m_parent; } | ||||
|     // [[OuterEnv]]
 | ||||
|     EnvironmentRecord* outer_environment() { return m_outer_environment; } | ||||
|     EnvironmentRecord const* outer_environment() const { return m_outer_environment; } | ||||
| 
 | ||||
| protected: | ||||
|     explicit EnvironmentRecord(EnvironmentRecord* parent); | ||||
|  | @ -35,7 +36,7 @@ protected: | |||
|     virtual void visit_edges(Visitor&) override; | ||||
| 
 | ||||
| private: | ||||
|     EnvironmentRecord* m_parent { nullptr }; | ||||
|     EnvironmentRecord* m_outer_environment { nullptr }; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -41,12 +41,12 @@ bool ObjectEnvironmentRecord::delete_from_scope(FlyString const& name) | |||
| 
 | ||||
| bool ObjectEnvironmentRecord::has_this_binding() const | ||||
| { | ||||
|     return parent()->has_this_binding(); | ||||
|     return outer_environment()->has_this_binding(); | ||||
| } | ||||
| 
 | ||||
| Value ObjectEnvironmentRecord::get_this_binding(GlobalObject& global_object) const | ||||
| { | ||||
|     return parent()->get_this_binding(global_object); | ||||
|     return outer_environment()->get_this_binding(global_object); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -135,10 +135,10 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o | |||
| { | ||||
|     Optional<Variable> possible_match; | ||||
|     if (!specific_scope && m_call_stack.size()) { | ||||
|         for (auto* scope = current_scope(); scope; scope = scope->parent()) { | ||||
|             possible_match = scope->get_from_scope(name); | ||||
|         for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) { | ||||
|             possible_match = environment_record->get_from_scope(name); | ||||
|             if (possible_match.has_value()) { | ||||
|                 specific_scope = scope; | ||||
|                 specific_scope = environment_record; | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | @ -167,10 +167,10 @@ bool VM::delete_variable(FlyString const& name) | |||
|     EnvironmentRecord* specific_scope = nullptr; | ||||
|     Optional<Variable> possible_match; | ||||
|     if (!m_call_stack.is_empty()) { | ||||
|         for (auto* scope = current_scope(); scope; scope = scope->parent()) { | ||||
|             possible_match = scope->get_from_scope(name); | ||||
|         for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) { | ||||
|             possible_match = environment_record->get_from_scope(name); | ||||
|             if (possible_match.has_value()) { | ||||
|                 specific_scope = scope; | ||||
|                 specific_scope = environment_record; | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | @ -376,8 +376,8 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object) | |||
|             return call_frame().arguments_object; | ||||
|         } | ||||
| 
 | ||||
|         for (auto* scope = current_scope(); scope; scope = scope->parent()) { | ||||
|             auto possible_match = scope->get_from_scope(name); | ||||
|         for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) { | ||||
|             auto possible_match = environment_record->get_from_scope(name); | ||||
|             if (exception()) | ||||
|                 return {}; | ||||
|             if (possible_match.has_value()) | ||||
|  | @ -393,10 +393,10 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object) | |||
| Reference VM::get_reference(const FlyString& name) | ||||
| { | ||||
|     if (m_call_stack.size()) { | ||||
|         for (auto* scope = current_scope(); scope; scope = scope->parent()) { | ||||
|             if (is<GlobalObject>(scope)) | ||||
|         for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) { | ||||
|             if (is<GlobalObject>(environment_record)) | ||||
|                 break; | ||||
|             auto possible_match = scope->get_from_scope(name); | ||||
|             auto possible_match = environment_record->get_from_scope(name); | ||||
|             if (possible_match.has_value()) | ||||
|                 return { Reference::LocalVariable, name }; | ||||
|         } | ||||
|  | @ -508,9 +508,9 @@ Value VM::resolve_this_binding(GlobalObject& global_object) const | |||
| const EnvironmentRecord* VM::find_this_scope() const | ||||
| { | ||||
|     // We will always return because the Global environment will always be reached, which has a |this| binding.
 | ||||
|     for (auto* scope = current_scope(); scope; scope = scope->parent()) { | ||||
|         if (scope->has_this_binding()) | ||||
|             return scope; | ||||
|     for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) { | ||||
|         if (environment_record->has_this_binding()) | ||||
|             return environment_record; | ||||
|     } | ||||
|     VERIFY_NOT_REACHED(); | ||||
| } | ||||
|  | @ -624,11 +624,11 @@ void VM::dump_backtrace() const | |||
| 
 | ||||
| void VM::dump_scope_chain() const | ||||
| { | ||||
|     for (auto* scope = current_scope(); scope; scope = scope->parent()) { | ||||
|         dbgln("+> {} ({:p})", scope->class_name(), scope); | ||||
|         if (is<DeclarativeEnvironmentRecord>(*scope)) { | ||||
|             auto& environment_record = static_cast<DeclarativeEnvironmentRecord const&>(*scope); | ||||
|             for (auto& variable : environment_record.variables()) { | ||||
|     for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) { | ||||
|         dbgln("+> {} ({:p})", environment_record->class_name(), environment_record); | ||||
|         if (is<DeclarativeEnvironmentRecord>(*environment_record)) { | ||||
|             auto& declarative_environment_record = static_cast<DeclarativeEnvironmentRecord const&>(*environment_record); | ||||
|             for (auto& variable : declarative_environment_record.variables()) { | ||||
|                 dbgln("    {}", variable.key); | ||||
|             } | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling