1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibJS: Implement create_dynamic_function() according to the spec

The three major changes are:

- Parsing parameters, the function body, and then the full assembled
  function source all separately. This is required by the spec, as
  function parameters and body must be valid each on their own, which
  cannot be guaranteed if we only ever parse the full function.
- Returning an ECMAScriptFunctionObject instead of a FunctionExpression
  that needs to be evaluated separately. This vastly simplifies the
  {Async,AsyncGenerator,Generator,}Function constructor implementations.
  Drop '_node' from the function name accordingly.
- The prototype is now determined via GetPrototypeFromConstructor and
  passed to OrdinaryFunctionCreate.
This commit is contained in:
Linus Groh 2022-01-15 17:26:06 +01:00
parent 13fe4e8c64
commit e8519156bc
9 changed files with 299 additions and 87 deletions

View file

@ -2473,13 +2473,13 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
if (function_kind == FunctionKind::Normal && match(TokenType::Async) && !next_token().trivia_contains_line_terminator()) {
function_kind = FunctionKind::Async;
consume(TokenType::Async);
parse_options = parse_options | FunctionNodeParseOptions::IsAsyncFunction;
parse_options |= FunctionNodeParseOptions::IsAsyncFunction;
}
consume(TokenType::Function);
if (match(TokenType::Asterisk)) {
function_kind = function_kind == FunctionKind::Normal ? FunctionKind::Generator : FunctionKind::AsyncGenerator;
consume(TokenType::Asterisk);
parse_options = parse_options | FunctionNodeParseOptions::IsGeneratorFunction;
parse_options |= FunctionNodeParseOptions::IsGeneratorFunction;
}
if (FunctionNodeType::must_have_name() || match_identifier())