deps: V8: cherry-pick 249de887a8d3

Original commit message:

    [explicit-resource-management] Fix parsing for (using of=null;;)

    Apparently `using of` is allowed in the initializer position of C-style
    for loops.

    See https://github.com/tc39/proposal-explicit-resource-management/issues/248

    Bug: 42203506
    Change-Id: Ia056b161f4ea28a0f3ba4e3e420f1718195274a4
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6594471
    Commit-Queue: Shu-yu Guo <syg@chromium.org>
    Reviewed-by: Rezvan Mahdavi Hezaveh <rezvan@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#100531}

Refs: 249de887a8
PR-URL: https://github.com/nodejs/node/pull/58561
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Michaël Zasso 2025-06-05 09:51:08 +02:00 committed by GitHub
parent 9e35ddca44
commit d327cbea9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View File

@ -38,7 +38,7 @@
# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.12',
'v8_embedder_string': '-node.13',
##### V8 defaults for Node.js #####

View File

@ -1178,15 +1178,16 @@ class ParserBase {
scope()->scope_type() == REPL_MODE_SCOPE) &&
!scope()->is_nonlinear());
}
bool IsNextUsingKeyword(Token::Value token_after_using, bool is_await_using) {
bool IsNextUsingKeyword(bool is_await_using) {
// using and await using declarations in for-of statements must be followed
// by a non-pattern ForBinding. In the case of synchronous `using`, `of` is
// disallowed as well with a negative lookahead.
// by a non-pattern ForBinding.
//
// `of`: for ( [lookahead ≠ using of] ForDeclaration[?Yield, ?Await, +Using]
// of AssignmentExpression[+In, ?Yield, ?Await] )
//
// If `using` is not considered a keyword, it is parsed as an identifier.
Token::Value token_after_using =
is_await_using ? PeekAheadAhead() : PeekAhead();
if (v8_flags.js_explicit_resource_management) {
switch (token_after_using) {
case Token::kIdentifier:
@ -1201,7 +1202,16 @@ class ParserBase {
case Token::kAsync:
return true;
case Token::kOf:
return is_await_using;
if (is_await_using) {
return true;
} else {
// In the case of synchronous `using`, `of` is disallowed as well
// with a negative lookahead for for-of loops. But, cursedly,
// `using of` is allowed as the initializer of C-style for loops,
// e.g. `for (using of = null;;)` parses.
Token::Value token_after_of = PeekAheadAhead();
return token_after_of == Token::kAssign;
}
case Token::kFutureStrictReservedWord:
case Token::kEscapedStrictReservedWord:
return is_sloppy(language_mode());
@ -1220,12 +1230,12 @@ class ParserBase {
// LineTerminator here] ForBinding[?Yield, +Await, ~Pattern]
return ((peek() == Token::kUsing &&
!scanner()->HasLineTerminatorAfterNext() &&
IsNextUsingKeyword(PeekAhead(), /* is_await_using */ false)) ||
IsNextUsingKeyword(/* is_await_using */ false)) ||
(is_await_allowed() && peek() == Token::kAwait &&
!scanner()->HasLineTerminatorAfterNext() &&
PeekAhead() == Token::kUsing &&
!scanner()->HasLineTerminatorAfterNextNext() &&
IsNextUsingKeyword(PeekAheadAhead(), /* is_await_using */ true)));
IsNextUsingKeyword(/* is_await_using */ true)));
}
const PendingCompilationErrorHandler* pending_error_handler() const {
return pending_error_handler_;

View File

@ -93,4 +93,6 @@ const reservedWords =
for (using using of[]) {}
for (using async of []) {}
for (using foo of []) {}
// Cursedly, `using of` is a valid binding form in C-style for loops.
for (using of = null;;) break;
})();