2020-07-03 14:36:58 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-22 16:53:07 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2020 ,  Matthew  Olsson  < mattco @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-13 15:26:41 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2020 - 2023 ,  Linus  Groh  < linusg @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-03 14:36:58 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-22 01:24:48 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-03 14:36:58 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-07 13:06:40 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/ArrayBuffer.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-18 18:45:12 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibTest/JavaScriptTestRunner.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-03 14:36:58 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-18 18:45:12 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TEST_ROOT ( " Userland/Libraries/LibJS/Tests " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-03 14:36:58 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_PROGRAM_FLAG ( test262_parser_tests ,  " Run test262 parser tests " ,  " test262-parser-tests " ,  0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-18 18:45:12 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_GLOBAL_FUNCTION ( is_strict_mode ,  isStrictMode ,  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-05 10:47:40 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-04 13:54:44 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  JS : : Value ( vm . in_strict_mode ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-05 10:47:40 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-18 18:45:12 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_GLOBAL_FUNCTION ( can_parse_source ,  canParseSource ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-11 22:12:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-13 10:29:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  source  =  TRY ( vm . argument ( 0 ) . to_deprecated_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-11 22:12:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  parser  =  JS : : Parser ( JS : : Lexer ( source ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-02 11:00:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ( void ) parser . parse_program ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-11 22:12:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  JS : : Value ( ! parser . has_errors ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-18 18:45:12 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_GLOBAL_FUNCTION ( run_queued_promise_jobs ,  runQueuedPromiseJobs ) 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												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 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  JS : : js_undefined ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-09 20:10:47 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_GLOBAL_FUNCTION ( get_weak_set_size ,  getWeakSetSize ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-13 15:26:41 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  object  =  TRY ( vm . argument ( 0 ) . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! is < JS : : WeakSet > ( * object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  vm . throw_completion < JS : : TypeError > ( JS : : ErrorType : : NotAnObjectOfType ,  " WeakSet " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-13 15:26:41 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto &  weak_set  =  static_cast < JS : : WeakSet & > ( * object ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  JS : : Value ( weak_set . values ( ) . size ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-09 20:10:47 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-12 05:37:09 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_GLOBAL_FUNCTION ( get_weak_map_size ,  getWeakMapSize ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-13 15:26:41 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  object  =  TRY ( vm . argument ( 0 ) . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! is < JS : : WeakMap > ( * object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  vm . throw_completion < JS : : TypeError > ( JS : : ErrorType : : NotAnObjectOfType ,  " WeakMap " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-13 15:26:41 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto &  weak_map  =  static_cast < JS : : WeakMap & > ( * object ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  JS : : Value ( weak_map . values ( ) . size ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-12 05:37:09 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-07 17:14:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_GLOBAL_FUNCTION ( mark_as_garbage ,  markAsGarbage ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto  argument  =  vm . argument ( 0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-20 01:58:04 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! argument . is_string ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-12 21:54:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  vm . throw_completion < JS : : TypeError > ( JS : : ErrorType : : NotAString ,  TRY_OR_THROW_OOM ( vm ,  argument . to_string_without_side_effects ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-07 17:14:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto &  variable_name  =  argument . as_string ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // In native functions we don't have a lexical environment so get the outer via the execution stack.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto  outer_environment  =  vm . execution_context_stack ( ) . last_matching ( [ & ] ( auto &  execution_context )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  execution_context - > lexical_environment  ! =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-20 01:58:04 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! outer_environment . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  vm . throw_completion < JS : : ReferenceError > ( JS : : ErrorType : : UnknownIdentifier ,  TRY ( variable_name . deprecated_string ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-07 17:14:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  reference  =  TRY ( vm . resolve_binding ( TRY ( variable_name . deprecated_string ( ) ) ,  outer_environment . value ( ) - > lexical_environment ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-18 16:31:50 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 15:39:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  value  =  TRY ( reference . get_value ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-07 17:14:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 23:08:12 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! can_be_held_weakly ( value ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  vm . throw_completion < JS : : TypeError > ( JS : : ErrorType : : CannotBeHeldWeakly ,  DeprecatedString : : formatted ( " Variable with name {} " ,  TRY ( variable_name . deprecated_string ( ) ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-07 17:14:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 23:08:12 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    vm . heap ( ) . uproot_cell ( & value . as_cell ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 15:39:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    TRY ( reference . delete_ ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-07 17:14:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  JS : : js_undefined ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-07 13:06:40 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_GLOBAL_FUNCTION ( detach_array_buffer ,  detachArrayBuffer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto  array_buffer  =  vm . argument ( 0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! array_buffer . is_object ( )  | |  ! is < JS : : ArrayBuffer > ( array_buffer . as_object ( ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  vm . throw_completion < JS : : TypeError > ( JS : : ErrorType : : NotAnObjectOfType ,  " ArrayBuffer " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-07 13:06:40 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto &  array_buffer_object  =  static_cast < JS : : ArrayBuffer & > ( array_buffer . as_object ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 17:25:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    TRY ( JS : : detach_array_buffer ( vm ,  array_buffer_object ,  vm . argument ( 1 ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  JS : : js_null ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-07 13:06:40 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TESTJS_RUN_FILE_FUNCTION ( DeprecatedString  const &  test_file ,  JS : : Interpreter &  interpreter ,  JS : : ExecutionContext & ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! test262_parser_tests ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  Test : : JS : : RunFileHookResult : : RunAsNormal ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-27 12:57:35 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  start_time  =  Test : : get_time_in_ms ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    LexicalPath  path ( test_file ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-11 00:55:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  dirname  =  path . dirname ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    enum  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        Early , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        Fail , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        Pass , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ExplicitPass , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  expectation  {  Pass  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-11 17:32:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( dirname . ends_with ( " early " sv ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        expectation  =  Early ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-11 17:32:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    else  if  ( dirname . ends_with ( " fail " sv ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        expectation  =  Fail ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-11 17:32:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    else  if  ( dirname . ends_with ( " pass-explicit " sv ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        expectation  =  ExplicitPass ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-11 17:32:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    else  if  ( dirname . ends_with ( " pass " sv ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        expectation  =  Pass ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  Test : : JS : : RunFileHookResult : : SkipFile ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-11 17:32:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  program_type  =  path . basename ( ) . ends_with ( " .module.js " sv )  ?  JS : : Program : : Type : : Module  :  JS : : Program : : Type : : Script ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-14 20:58:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    bool  parse_succeeded  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( program_type  = =  JS : : Program : : Type : : Module ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        parse_succeeded  =  ! Test : : JS : : parse_module ( test_file ,  interpreter . realm ( ) ) . is_error ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        parse_succeeded  =  ! Test : : JS : : parse_script ( test_file ,  interpreter . realm ( ) ) . is_error ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-14 17:30:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    bool  test_passed  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    DeprecatedString  message ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    DeprecatedString  expectation_string ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    switch  ( expectation )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    case  Early : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    case  Fail : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        expectation_string  =  " File should not parse " ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-14 20:58:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        test_passed  =  ! parse_succeeded ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! test_passed ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            message  =  " Expected the file to fail parsing, but it did not " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    case  Pass : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    case  ExplicitPass : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        expectation_string  =  " File should parse " ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-14 20:58:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        test_passed  =  parse_succeeded ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! test_passed ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            message  =  " Expected the file to parse, but it did not " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto  test_result  =  test_passed  ?  Test : : Result : : Pass  :  Test : : Result : : Fail ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-08 07:09:41 +03:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  test_path  =  LexicalPath : : relative_path ( test_file ,  Test : : JS : : g_test_root ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto  duration_ms  =  Test : : get_time_in_ms ( )  -  start_time ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  Test : : JS : : JSFileResult  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-08 07:09:41 +03:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        test_path , 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        { } , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-08 07:09:41 +03:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        duration_ms , 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        test_result , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-08 07:09:41 +03:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        {  Test : : Suite  {  test_path ,  " Parse file " ,  test_result ,  {  {  expectation_string ,  test_result ,  message ,  static_cast < u64 > ( duration_ms )  *  1000u  }  }  }  } 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-30 10:35:44 +04:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}