2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2020 - 2022 ,  Linus  Groh  < linusg @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-22 01:24:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:52:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Lexer.h> 
  
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Parser.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/AbstractOperations.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-10-20 21:16:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/ECMAScriptFunctionObject.h> 
  
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Error.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/FunctionConstructor.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-06-27 21:48:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/FunctionObject.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-01-16 14:14:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/GeneratorPrototype.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-02-07 18:51:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/GlobalEnvironment.h> 
  
						 
					
						
							
								
									
										
										
										
											2020-04-18 13:18:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/GlobalObject.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Realm.h> 
  
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  JS  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 00:20:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								FunctionConstructor : : FunctionConstructor ( Realm &  realm )  
						 
					
						
							
								
									
										
										
										
											2022-09-14 19:10:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    :  NativeFunction ( realm . vm ( ) . names . Function . as_string ( ) ,  * realm . intrinsics ( ) . function_prototype ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2020-06-20 15:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 00:20:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  FunctionConstructor : : initialize ( Realm &  realm )  
						 
					
						
							
								
									
										
										
										
											2020-06-20 15:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2020-10-13 23:49:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  vm  =  this - > vm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 00:20:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    NativeFunction : : initialize ( realm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-19 00:38:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 20.2.2.2 Function.prototype, https://tc39.es/ecma262/#sec-function.prototype
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    define_direct_property ( vm . names . prototype ,  realm . intrinsics ( ) . function_prototype ( ) ,  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-19 00:38:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-06 02:15:08 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    define_direct_property ( vm . names . length ,  Value ( 1 ) ,  Attribute : : Configurable ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:52:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 20.2.1.1.1 CreateDynamicFunction ( constructor, newTarget, kind, args ), https://tc39.es/ecma262/#sec-createdynamicfunction
  
						 
					
						
							
								
									
										
										
										
											2022-08-21 20:38:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < ECMAScriptFunctionObject * >  FunctionConstructor : : create_dynamic_function ( VM &  vm ,  FunctionObject &  constructor ,  FunctionObject *  new_target ,  FunctionKind  kind ,  MarkedVector < Value >  const &  args )  
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 1. Let currentRealm be the current Realm Record.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 20:38:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  current_realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Perform ? HostEnsureCanCompileStrings(currentRealm).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    TRY ( vm . host_ensure_can_compile_strings ( current_realm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-10 00:57:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 3. If newTarget is undefined, set newTarget to constructor.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( new_target  = =  nullptr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        new_target  =  & constructor ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    StringView  prefix ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Object *  ( Intrinsics : : * fallback_prototype ) ( )  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( kind )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 4. If kind is normal, then
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    case  FunctionKind : : Normal : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let prefix be "function".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        prefix  =  " function " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Let exprSym be the grammar symbol FunctionExpression.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. Let bodySym be the grammar symbol FunctionBody[~Yield, ~Await].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Let parameterSym be the grammar symbol FormalParameters[~Yield, ~Await].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // e. Let fallbackProto be "%Function.prototype%".
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        fallback_prototype  =  & Intrinsics : : function_prototype ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 5. Else if kind is generator, then
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    case  FunctionKind : : Generator : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let prefix be "function*".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        prefix  =  " function* " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Let exprSym be the grammar symbol GeneratorExpression.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. Let bodySym be the grammar symbol GeneratorBody.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Let parameterSym be the grammar symbol FormalParameters[+Yield, ~Await].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // e. Let fallbackProto be "%GeneratorFunction.prototype%".
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        fallback_prototype  =  & Intrinsics : : generator_function_prototype ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 6. Else if kind is async, then
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    case  FunctionKind : : Async : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Let prefix be "async function".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        prefix  =  " async function " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Let exprSym be the grammar symbol AsyncFunctionExpression.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. Let bodySym be the grammar symbol AsyncFunctionBody.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Let parameterSym be the grammar symbol FormalParameters[~Yield, +Await].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // e. Let fallbackProto be "%AsyncFunction.prototype%".
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        fallback_prototype  =  & Intrinsics : : async_function_prototype ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 7. Else,
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    case  FunctionKind : : AsyncGenerator : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Assert: kind is asyncGenerator.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Let prefix be "async function*".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        prefix  =  " async function* " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. Let exprSym be the grammar symbol AsyncGeneratorExpression.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Let bodySym be the grammar symbol AsyncGeneratorBody.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // e. Let parameterSym be the grammar symbol FormalParameters[+Yield, +Await].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // f. Let fallbackProto be "%AsyncGeneratorFunction.prototype%".
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        fallback_prototype  =  & Intrinsics : : async_generator_function_prototype ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 8. Let argCount be the number of elements in args.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  arg_count  =  args . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 9. Let P be the empty String.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    DeprecatedString  parameters_string  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Optional < Value >  body_arg ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 10. If argCount = 0, let bodyArg be the empty String.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( arg_count  = =  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:17:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Optimization: Instead of creating a PrimitiveString here, we just check if body_arg is empty in step 16.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 11. Else if argCount = 1, let bodyArg be args[0].
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  if  ( arg_count  = =  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        body_arg  =  args [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 12. Else,
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // a. Assert: argCount > 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY ( arg_count  >  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // b. Let firstArg be args[0].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // c. Set P to ? ToString(firstArg).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // NOTE: Also done in the loop. We start at 0 instead and then join() with a comma.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // d. Let k be 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        size_t  k  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // e. Repeat, while k < argCount - 1,
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Vector < DeprecatedString >  parameters ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        for  ( ;  k  <  arg_count  -  1 ;  + + k )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // i. Let nextArg be args[k].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            auto  next_arg  =  args [ k ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // ii. Let nextArgString be ? ToString(nextArg).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // iii. Set P to the string-concatenation of P, "," (a comma), and nextArgString.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-13 10:29:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            parameters . append ( TRY ( next_arg . to_deprecated_string ( vm ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // iv. Set k to k + 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        parameters_string  =  DeprecatedString : : join ( ' , ' ,  parameters ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // f. Let bodyArg be args[k].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        body_arg  =  args [ k ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 13. Let bodyString be the string-concatenation of 0x000A (LINE FEED), ? ToString(bodyArg), and 0x000A (LINE FEED).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-13 10:29:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  body_string  =  DeprecatedString : : formatted ( " \n {} \n " ,  body_arg . has_value ( )  ?  TRY ( body_arg - > to_deprecated_string ( vm ) )  :  " " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 14. Let sourceString be the string-concatenation of prefix, " anonymous(", P, 0x000A (LINE FEED), ") {", bodyString, and "}".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 15. Let sourceText be StringToCodePoints(sourceString).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-04 18:02:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  source_text  =  DeprecatedString : : formatted ( " {} anonymous({} \n ) {{{}}} " ,  prefix ,  parameters_string ,  body_string ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    u8  parse_options  =  FunctionNodeParseOptions : : CheckForFunctionAndName ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( kind  = =  FunctionKind : : Async  | |  kind  = =  FunctionKind : : AsyncGenerator ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        parse_options  | =  FunctionNodeParseOptions : : IsAsyncFunction ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( kind  = =  FunctionKind : : Generator  | |  kind  = =  FunctionKind : : AsyncGenerator ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        parse_options  | =  FunctionNodeParseOptions : : IsGeneratorFunction ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 16. Let parameters be ParseText(StringToCodePoints(P), parameterSym).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    i32  function_length  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  parameters_parser  =  Parser  {  Lexer  {  parameters_string  }  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  parameters  =  parameters_parser . parse_formal_parameters ( function_length ,  parse_options ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 17. If parameters is a List of errors, throw a SyntaxError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( parameters_parser . has_errors ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  error  =  parameters_parser . errors ( ) [ 0 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 01:12:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  vm . throw_completion < SyntaxError > ( error . to_deprecated_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 18. Let body be ParseText(StringToCodePoints(bodyString), bodySym).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    bool  contains_direct_call_to_eval  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  body_parser  =  Parser  {  Lexer  {  body_string  }  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Set up some parser state to accept things like return await, and yield in the plain function body.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    body_parser . m_state . in_function_context  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ( parse_options  &  FunctionNodeParseOptions : : IsAsyncFunction )  ! =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        body_parser . m_state . await_expression_is_valid  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ( parse_options  &  FunctionNodeParseOptions : : IsGeneratorFunction )  ! =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        body_parser . m_state . in_generator_function_context  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ( void ) body_parser . parse_function_body ( parameters ,  kind ,  contains_direct_call_to_eval ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 19. If body is a List of errors, throw a SyntaxError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( body_parser . has_errors ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  error  =  body_parser . errors ( ) [ 0 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 01:12:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  vm . throw_completion < SyntaxError > ( error . to_deprecated_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 20. NOTE: The parameters and body are parsed separately to ensure that each is valid alone. For example, new Function("/*", "*/ ) {") is not legal.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 21. NOTE: If this step is reached, sourceText must have the syntax of exprSym (although the reverse implication does not hold). The purpose of the next two steps is to enforce any Early Error rules which apply to exprSym directly.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 22. Let expr be ParseText(sourceText, exprSym).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  source_parser  =  Parser  {  Lexer  {  source_text  }  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // This doesn't need any parse_options, it determines those & the function type based on the tokens that were found.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  expr  =  source_parser . parse_function_node < FunctionExpression > ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 23. If expr is a List of errors, throw a SyntaxError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( source_parser . has_errors ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  error  =  source_parser . errors ( ) [ 0 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 01:12:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  vm . throw_completion < SyntaxError > ( error . to_deprecated_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-27 18:45:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 24. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 19:24:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto *  prototype  =  TRY ( get_prototype_from_constructor ( vm ,  * new_target ,  fallback_prototype ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 25. Let realmF be the current Realm Record.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 00:20:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 26. Let env be realmF.[[GlobalEnv]].
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 00:20:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  environment  =  realm . global_environment ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 27. Let privateEnv be null.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 01:10:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PrivateEnvironment *  private_environment  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 28. Let F be OrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, env, privateEnv).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-13 20:49:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  function  =  ECMAScriptFunctionObject : : create ( realm ,  " anonymous " ,  * prototype ,  move ( source_text ) ,  expr - > body ( ) ,  expr - > parameters ( ) ,  expr - > function_length ( ) ,  & environment ,  private_environment ,  expr - > kind ( ) ,  expr - > is_strict_mode ( ) ,  expr - > might_need_arguments_object ( ) ,  contains_direct_call_to_eval ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // FIXME: Remove the name argument from create() and do this instead.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 29. Perform SetFunctionName(F, "anonymous").
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 30. If kind is generator, then
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( kind  = =  FunctionKind : : Generator )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Let prototype be OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        prototype  =  Object : : create ( realm ,  realm . intrinsics ( ) . generator_function_prototype_prototype ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        function - > define_direct_property ( vm . names . prototype ,  prototype ,  Attribute : : Writable ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 31. Else if kind is asyncGenerator, then
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  if  ( kind  = =  FunctionKind : : AsyncGenerator )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // a. Let prototype be OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        prototype  =  Object : : create ( realm ,  realm . intrinsics ( ) . async_generator_function_prototype_prototype ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 20:54:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-05 09:06:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        function - > define_direct_property ( vm . names . prototype ,  prototype ,  Attribute : : Writable ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 32. Else if kind is normal, perform MakeConstructor(F).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  if  ( kind  = =  FunctionKind : : Normal )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // FIXME: Implement MakeConstructor
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        prototype  =  Object : : create ( realm ,  realm . intrinsics ( ) . object_prototype ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        prototype - > define_direct_property ( vm . names . constructor ,  function ,  Attribute : : Writable  |  Attribute : : Configurable ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        function - > define_direct_property ( vm . names . prototype ,  prototype ,  Attribute : : Writable ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 33. NOTE: Functions whose kind is async are not constructible and do not have a [[Construct]] internal method or a "prototype" property.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 19:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 34. Return F.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-13 20:49:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  function . ptr ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:52:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 20.2.1.1 Function ( p1, p2, … , pn, body ), https://tc39.es/ecma262/#sec-function-p1-p2-pn-body
  
						 
					
						
							
								
									
										
										
										
											2021-10-20 21:16:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < Value >  FunctionConstructor : : call ( )  
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:52:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2021-10-20 21:16:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  TRY ( construct ( * this ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:52:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 20.2.1.1 Function ( p1, p2, … , pn, body ), https://tc39.es/ecma262/#sec-function-p1-p2-pn-body
  
						 
					
						
							
								
									
										
										
										
											2022-12-14 19:18:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ThrowCompletionOr < NonnullGCPtr < Object > >  FunctionConstructor : : construct ( FunctionObject &  new_target )  
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:52:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2021-10-20 21:16:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  vm  =  this - > vm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:52:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 1. Let C be the active function object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto *  constructor  =  vm . active_function_object ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-27 18:45:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 2. Let args be the argumentsList that was passed to this function by [[Call]] or [[Construct]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto &  args  =  vm . running_execution_context ( ) . arguments ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-27 18:45:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 17:26:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 3. Return ? CreateDynamicFunction(C, NewTarget, normal, args).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-14 19:18:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  * TRY ( create_dynamic_function ( vm ,  * constructor ,  & new_target ,  FunctionKind : : Normal ,  args ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-04 14:34:31 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}