1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:47:46 +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

@ -13,31 +13,46 @@ function anonymous(
test("LINE FEED is a line terminator", () => {
expect(() => {
Function("\n\n@");
}).toThrowWithMessage(SyntaxError, "line: 5, column: 1");
}).toThrowWithMessage(
SyntaxError,
"Unexpected token Invalid. Expected CurlyClose (line: 4, column: 1)"
);
});
test("CARRIAGE RETURN is a line terminator", () => {
expect(() => {
Function("\r\r@");
}).toThrowWithMessage(SyntaxError, "line: 5, column: 1");
}).toThrowWithMessage(
SyntaxError,
"Unexpected token Invalid. Expected CurlyClose (line: 4, column: 1)"
);
});
test("LINE SEPARATOR is a line terminator", () => {
expect(() => {
Function("@");
}).toThrowWithMessage(SyntaxError, "line: 5, column: 1");
}).toThrowWithMessage(
SyntaxError,
"Unexpected token Invalid. Expected CurlyClose (line: 4, column: 1)"
);
});
test("PARAGRAPH SEPARATOR is a line terminator", () => {
expect(() => {
Function("@");
}).toThrowWithMessage(SyntaxError, "line: 5, column: 1");
}).toThrowWithMessage(
SyntaxError,
"Unexpected token Invalid. Expected CurlyClose (line: 4, column: 1)"
);
});
test("CR LF is counted as only one line terminator", () => {
expect(() => {
Function("\r\n\r\n@");
}).toThrowWithMessage(SyntaxError, "line: 5, column: 1");
}).toThrowWithMessage(
SyntaxError,
"Unexpected token Invalid. Expected CurlyClose (line: 4, column: 1)"
);
});
test("LF/CR are not allowed in string literal", () => {
@ -55,7 +70,10 @@ test("LS/PS are allowed in string literal", () => {
test("line terminators can be mixed (but please don't)", () => {
expect(() => {
Function("\r\r\n\n\r@");
}).toThrowWithMessage(SyntaxError, "line: 9, column: 1");
}).toThrowWithMessage(
SyntaxError,
"Unexpected token Invalid. Expected CurlyClose (line: 8, column: 1)"
);
});
test("all line terminators are valid for line continuations", () => {