2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2020 ,  Andreas  Kling  < kling @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2020 - 2022 ,  Linus  Groh  < linusg @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2022 ,  Luke  Wilde  < lukew @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-22 01:24:48 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-13 23:58:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <AK/ScopeGuard.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# include  <LibJS/AST.h> 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  <LibJS/Interpreter.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-22 12:44:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/AbstractOperations.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-24 22:40:38 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/ECMAScriptFunctionObject.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-01 12:24:46 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/FunctionEnvironment.h> 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/GlobalEnvironment.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-16 14:20:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/GlobalObject.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-27 12:37:27 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/Reference.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-02 19:32:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/Shape.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-16 14:20:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/Value.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								namespace  JS  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-12 12:33:54 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								NonnullOwnPtr < Interpreter >  Interpreter : : create_with_existing_realm ( Realm &  realm ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-27 17:24:14 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-22 19:00:49 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto &  vm  =  realm . vm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    DeferGC  defer_gc ( vm . heap ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto  interpreter  =  adopt_own ( * new  Interpreter ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-12 12:33:54 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    interpreter - > m_realm  =  make_handle ( & realm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-27 17:24:14 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  interpreter ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-20 19:24:44 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Interpreter : : Interpreter ( VM &  vm ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    :  m_vm ( vm ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// 16.1.6 ScriptEvaluation ( scriptRecord ), https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-09 18:48:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								ThrowCompletionOr < Value >  Interpreter : : run ( Script &  script_record ,  JS : : GCPtr < Environment >  lexical_environment_override ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-08 12:54:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto &  vm  =  this - > vm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-13 16:42:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-27 15:18:55 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    VM : : InterpreterExecutionScope  scope ( * this ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-09 21:13:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 1. Let globalEnv be scriptRecord.[[Realm]].[[GlobalEnv]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto &  global_environment  =  script_record . realm ( ) . global_environment ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 2. Let scriptContext be a new ECMAScript code execution context.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ExecutionContext  script_context ( vm . heap ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-11 21:32:37 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 3. Set the Function of scriptContext to null.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // NOTE: This was done during execution context construction.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 4. Set the Realm of scriptContext to scriptRecord.[[Realm]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    script_context . realm  =  & script_record . realm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-17 14:48:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 5. Set the ScriptOrModule of scriptContext to scriptRecord.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-05 14:31:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    script_context . script_or_module  =  NonnullGCPtr < Script > ( script_record ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 6. Set the VariableEnvironment of scriptContext to globalEnv.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    script_context . variable_environment  =  & global_environment ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 7. Set the LexicalEnvironment of scriptContext to globalEnv.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    script_context . lexical_environment  =  & global_environment ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-09 18:48:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // Non-standard: Override the lexical environment if requested.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( lexical_environment_override ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        script_context . lexical_environment  =  lexical_environment_override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 8. Set the PrivateEnvironment of scriptContext to null.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // NOTE: This isn't in the spec, but we require it.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    script_context . is_strict_mode  =  script_record . parse_node ( ) . is_strict_mode ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // FIXME: 9. Suspend the currently running execution context.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 10. Push scriptContext onto the execution context stack; scriptContext is now the running execution context.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 20:38:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    TRY ( vm . push_execution_context ( script_context ,  { } ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 01:13:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 11. Let script be scriptRecord.[[ECMAScriptCode]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto &  script  =  script_record . parse_node ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 12. Let result be Completion(GlobalDeclarationInstantiation(script, globalEnv)).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-15 10:37:42 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  instantiation_result  =  script . global_declaration_instantiation ( vm ,  global_environment ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    Completion  result  =  instantiation_result . is_throw_completion ( )  ?  instantiation_result . throw_completion ( )  :  normal_completion ( { } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 13. If result.[[Type]] is normal, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( result . type ( )  = =  Completion : : Type : : Normal )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 01:13:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // a. Set result to the result of evaluating script.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 19:28:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        result  =  script . execute ( * this ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 14. If result.[[Type]] is normal and result.[[Value]] is empty, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( result . type ( )  = =  Completion : : Type : : Normal  & &  ! result . value ( ) . has_value ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // a. Set result to NormalCompletion(undefined).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        result  =  normal_completion ( js_undefined ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // FIXME: 15. Suspend scriptContext and remove it from the execution context stack.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    vm . pop_execution_context ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 16. Assert: The execution context stack is not empty.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    VERIFY ( ! vm . execution_context_stack ( ) . is_empty ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // FIXME: 17. Resume the context that is now on the top of the execution context stack as the running execution context.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-24 18:21:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // At this point we may have already run any queued promise jobs via on_call_stack_emptied,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // in which case this is a no-op.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // FIXME: These three should be moved out of Interpreter::run and give the host an option to run these, as it's up to the host when these get run.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //        https://tc39.es/ecma262/#sec-jobs for jobs and https://tc39.es/ecma262/#_ref_3508 for ClearKeptObjects
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //        finish_execution_generation is particularly an issue for LibWeb, as the HTML spec wants to run it specifically after performing a microtask checkpoint.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //        The promise and registry cleanup queues don't cause LibWeb an issue, as LibWeb overrides the hooks that push onto these queues.
 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												LibJS: Add initial support for Promises
Almost a year after first working on this, it's finally done: an
implementation of Promises for LibJS! :^)
The core functionality is working and closely following the spec [1].
I mostly took the pseudo code and transformed it into C++ - if you read
and understand it, you will know how the spec implements Promises; and
if you read the spec first, the code will look very familiar.
Implemented functions are:
- Promise() constructor
- Promise.prototype.then()
- Promise.prototype.catch()
- Promise.prototype.finally()
- Promise.resolve()
- Promise.reject()
For the tests I added a new function to test-js's global object,
runQueuedPromiseJobs(), which calls vm.run_queued_promise_jobs().
By design, queued jobs normally only run after the script was fully
executed, making it improssible to test handlers in individual test()
calls by default [2].
Subsequent commits include integrations into LibWeb and js(1) -
pretty-printing, running queued promise jobs when necessary.
This has an unusual amount of dbgln() statements, all hidden behind the
PROMISE_DEBUG flag - I'm leaving them in for now as they've been very
useful while debugging this, things can get quite complex with so many
asynchronously executed functions.
I've not extensively explored use of these APIs for promise-based
functionality in LibWeb (fetch(), Notification.requestPermission()
etc.), but we'll get there in due time.
[1]: https://tc39.es/ecma262/#sec-promise-objects
[2]: https://tc39.es/ecma262/#sec-jobs-and-job-queues
											 
										 
										
											2021-04-01 22:13:29 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    vm . run_queued_promise_jobs ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-12 17:32:54 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 22:16:17 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    vm . run_queued_finalization_registry_cleanup_jobs ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-12 17:32:54 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    vm . finish_execution_generation ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-08 21:28:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 18. Return ? result.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( result . is_abrupt ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        VERIFY ( result . type ( )  = =  Completion : : Type : : Throw ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  result . release_error ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-08 21:28:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    VERIFY ( result . value ( ) . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  * result . value ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 01:22:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								ThrowCompletionOr < Value >  Interpreter : : run ( SourceTextModule &  module ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-16 13:16:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 01:22:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // FIXME: This is not a entry point as defined in the spec, but is convenient.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //        To avoid work we use link_and_eval_module however that can already be
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //        dangerous if the vm loaded other modules.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto &  vm  =  this - > vm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    VM : : InterpreterExecutionScope  scope ( * this ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-15 12:36:57 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    TRY ( vm . link_and_eval_module ( Badge < JS : : Interpreter >  { } ,  module ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 01:22:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    vm . run_queued_promise_jobs ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    vm . run_queued_finalization_registry_cleanup_jobs ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  js_undefined ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-09 21:13:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-11 19:36:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Realm &  Interpreter : : realm ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  static_cast < Realm & > ( * m_realm . cell ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-01 20:58:27 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Realm  const &  Interpreter : : realm ( )  const 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-11 19:36:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-01 20:58:27 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  static_cast < Realm  const & > ( * m_realm . cell ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-11 19:36:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-07 19:42:11 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								}