mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:12:43 +00:00 
			
		
		
		
	LibJS/JIT: Resolve the EnvironmentVariableCache pointers at JIT time
This commit is contained in:
		
							parent
							
								
									a616a682fe
								
							
						
					
					
						commit
						536b9c29e4
					
				
					 5 changed files with 17 additions and 13 deletions
				
			
		|  | @ -308,26 +308,25 @@ ThrowCompletionOr<void> put_by_value(VM& vm, Value base, Value property_key_valu | |||
|     return {}; | ||||
| } | ||||
| 
 | ||||
| ThrowCompletionOr<Value> get_variable(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, u32 cache_index) | ||||
| ThrowCompletionOr<Value> get_variable(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, EnvironmentVariableCache& cache) | ||||
| { | ||||
|     auto& vm = interpreter.vm(); | ||||
| 
 | ||||
|     auto& cached_environment_coordinate = interpreter.current_executable().environment_variable_caches[cache_index]; | ||||
|     if (cached_environment_coordinate.has_value()) { | ||||
|     if (cache.has_value()) { | ||||
|         auto environment = vm.running_execution_context().lexical_environment; | ||||
|         for (size_t i = 0; i < cached_environment_coordinate->hops; ++i) | ||||
|         for (size_t i = 0; i < cache->hops; ++i) | ||||
|             environment = environment->outer_environment(); | ||||
|         VERIFY(environment); | ||||
|         VERIFY(environment->is_declarative_environment()); | ||||
|         if (!environment->is_permanently_screwed_by_eval()) { | ||||
|             return TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, cached_environment_coordinate.value().index, vm.in_strict_mode())); | ||||
|             return TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, cache.value().index, vm.in_strict_mode())); | ||||
|         } | ||||
|         cached_environment_coordinate = {}; | ||||
|         cache = {}; | ||||
|     } | ||||
| 
 | ||||
|     auto reference = TRY(vm.resolve_binding(name)); | ||||
|     if (reference.environment_coordinate().has_value()) | ||||
|         cached_environment_coordinate = reference.environment_coordinate(); | ||||
|         cache = reference.environment_coordinate(); | ||||
|     return TRY(reference.get_value(vm)); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ ThrowCompletionOr<Value> typeof_variable(VM&, DeprecatedFlyString const&); | |||
| ThrowCompletionOr<void> set_variable(VM&, DeprecatedFlyString const&, Value, Op::EnvironmentMode, Op::SetVariable::InitializationMode); | ||||
| Value new_function(VM&, FunctionExpression const&, Optional<IdentifierTableIndex> const& lhs_name, Optional<Register> const& home_object); | ||||
| ThrowCompletionOr<void> put_by_value(VM&, Value base, Value property_key_value, Value value, Op::PropertyKind); | ||||
| ThrowCompletionOr<Value> get_variable(Bytecode::Interpreter&, DeprecatedFlyString const& name, u32 cache_index); | ||||
| ThrowCompletionOr<Value> get_variable(Bytecode::Interpreter&, DeprecatedFlyString const& name, EnvironmentVariableCache&); | ||||
| 
 | ||||
| struct CalleeAndThis { | ||||
|     Value callee; | ||||
|  |  | |||
|  | @ -33,6 +33,8 @@ struct GlobalVariableCache : public PropertyLookupCache { | |||
|     u64 environment_serial_number { 0 }; | ||||
| }; | ||||
| 
 | ||||
| using EnvironmentVariableCache = Optional<EnvironmentCoordinate>; | ||||
| 
 | ||||
| struct SourceRecord { | ||||
|     u32 source_start_offset {}; | ||||
|     u32 source_end_offset {}; | ||||
|  | @ -57,7 +59,7 @@ public: | |||
|     DeprecatedFlyString name; | ||||
|     Vector<PropertyLookupCache> property_lookup_caches; | ||||
|     Vector<GlobalVariableCache> global_variable_caches; | ||||
|     Vector<Optional<EnvironmentCoordinate>> environment_variable_caches; | ||||
|     Vector<EnvironmentVariableCache> environment_variable_caches; | ||||
|     Vector<NonnullOwnPtr<BasicBlock>> basic_blocks; | ||||
|     NonnullOwnPtr<StringTable> string_table; | ||||
|     NonnullOwnPtr<IdentifierTable> identifier_table; | ||||
|  |  | |||
|  | @ -683,7 +683,10 @@ ThrowCompletionOr<void> ConcatString::execute_impl(Bytecode::Interpreter& interp | |||
| 
 | ||||
| ThrowCompletionOr<void> GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const | ||||
| { | ||||
|     interpreter.accumulator() = TRY(get_variable(interpreter, interpreter.current_executable().get_identifier(m_identifier), m_cache_index)); | ||||
|     interpreter.accumulator() = TRY(get_variable( | ||||
|         interpreter, | ||||
|         interpreter.current_executable().get_identifier(m_identifier), | ||||
|         interpreter.current_executable().environment_variable_caches[m_cache_index])); | ||||
|     return {}; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling