From e8519156bcb1d142a5a43cfcd8891c48015297fc Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 15 Jan 2022 17:26:06 +0100 Subject: 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. --- .../LibJS/Tests/parser-line-terminators.js | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'Userland/Libraries/LibJS/Tests/parser-line-terminators.js') diff --git a/Userland/Libraries/LibJS/Tests/parser-line-terminators.js b/Userland/Libraries/LibJS/Tests/parser-line-terminators.js index 9b75eb4af0..63c7009f18 100644 --- a/Userland/Libraries/LibJS/Tests/parser-line-terminators.js +++ b/Userland/Libraries/LibJS/Tests/parser-line-terminators.js @@ -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", () => { -- cgit v1.2.3