mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
LibJS: Disallow NumericLiteral immediately followed by Identifier
From the spec: https://tc39.es/ecma262/#sec-literals-numeric-literals The SourceCharacter immediately following a NumericLiteral must not be an IdentifierStart or DecimalDigit. For example: 3in is an error and not the two input elements 3 and in.
This commit is contained in:
parent
80bb22788f
commit
f8ae6fa713
Notes:
sideshowbarker
2024-07-19 01:47:08 +09:00
Author: https://github.com/linusg
Commit: f8ae6fa713
Pull-request: https://github.com/SerenityOS/serenity/pull/3821
Reviewed-by: https://github.com/emanuele6
2 changed files with 4 additions and 0 deletions
|
@ -1827,6 +1827,8 @@ Token Parser::consume_and_validate_numeric_literal()
|
|||
auto token = consume(TokenType::NumericLiteral);
|
||||
if (m_parser_state.m_strict_mode && is_unprefixed_octal_number(token.value()))
|
||||
syntax_error("Unprefixed octal number not allowed in strict mode", literal_start_line, literal_start_column);
|
||||
if (match_identifier_name() && m_parser_state.m_current_token.trivia().is_empty())
|
||||
syntax_error("Numeric literal must not be immediately followed by identifier");
|
||||
return token;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,4 +46,6 @@ test("invalid numeric literals", () => {
|
|||
expect("0b").not.toEval();
|
||||
expect("0o").not.toEval();
|
||||
expect("'use strict'; 0755").not.toEval();
|
||||
expect("1in[]").not.toEval();
|
||||
expect("2instanceof foo").not.toEval();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue