Skip to content

Commit efb28f7

Browse files
committed
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 tc39/proposal-explicit-resource-management#248 Bug: 42203506 Change-Id: Ia056b161f4ea28a0f3ba4e3e420f1718195274a4 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6594471 Commit-Queue: Shu-yu Guo <[email protected]> Reviewed-by: Rezvan Mahdavi Hezaveh <[email protected]> Cr-Commit-Position: refs/heads/main@{#100531} Refs: v8/v8@249de88 PR-URL: #58561 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 8347ef6 commit efb28f7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.16',
41+
'v8_embedder_string': '-node.17',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/parsing/parser-base.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,15 +1178,16 @@ class ParserBase {
11781178
scope()->scope_type() == REPL_MODE_SCOPE) &&
11791179
!scope()->is_nonlinear());
11801180
}
1181-
bool IsNextUsingKeyword(Token::Value token_after_using, bool is_await_using) {
1181+
bool IsNextUsingKeyword(bool is_await_using) {
11821182
// using and await using declarations in for-of statements must be followed
1183-
// by a non-pattern ForBinding. In the case of synchronous `using`, `of` is
1184-
// disallowed as well with a negative lookahead.
1183+
// by a non-pattern ForBinding.
11851184
//
11861185
// `of`: for ( [lookahead ≠ using of] ForDeclaration[?Yield, ?Await, +Using]
11871186
// of AssignmentExpression[+In, ?Yield, ?Await] )
11881187
//
11891188
// If `using` is not considered a keyword, it is parsed as an identifier.
1189+
Token::Value token_after_using =
1190+
is_await_using ? PeekAheadAhead() : PeekAhead();
11901191
if (v8_flags.js_explicit_resource_management) {
11911192
switch (token_after_using) {
11921193
case Token::kIdentifier:
@@ -1201,7 +1202,16 @@ class ParserBase {
12011202
case Token::kAsync:
12021203
return true;
12031204
case Token::kOf:
1204-
return is_await_using;
1205+
if (is_await_using) {
1206+
return true;
1207+
} else {
1208+
// In the case of synchronous `using`, `of` is disallowed as well
1209+
// with a negative lookahead for for-of loops. But, cursedly,
1210+
// `using of` is allowed as the initializer of C-style for loops,
1211+
// e.g. `for (using of = null;;)` parses.
1212+
Token::Value token_after_of = PeekAheadAhead();
1213+
return token_after_of == Token::kAssign;
1214+
}
12051215
case Token::kFutureStrictReservedWord:
12061216
case Token::kEscapedStrictReservedWord:
12071217
return is_sloppy(language_mode());
@@ -1220,12 +1230,12 @@ class ParserBase {
12201230
// LineTerminator here] ForBinding[?Yield, +Await, ~Pattern]
12211231
return ((peek() == Token::kUsing &&
12221232
!scanner()->HasLineTerminatorAfterNext() &&
1223-
IsNextUsingKeyword(PeekAhead(), /* is_await_using */ false)) ||
1233+
IsNextUsingKeyword(/* is_await_using */ false)) ||
12241234
(is_await_allowed() && peek() == Token::kAwait &&
12251235
!scanner()->HasLineTerminatorAfterNext() &&
12261236
PeekAhead() == Token::kUsing &&
12271237
!scanner()->HasLineTerminatorAfterNextNext() &&
1228-
IsNextUsingKeyword(PeekAheadAhead(), /* is_await_using */ true)));
1238+
IsNextUsingKeyword(/* is_await_using */ true)));
12291239
}
12301240
const PendingCompilationErrorHandler* pending_error_handler() const {
12311241
return pending_error_handler_;

deps/v8/test/mjsunit/harmony/for-using-of-await-using-of.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,6 @@ const reservedWords =
9393
for (using using of[]) {}
9494
for (using async of []) {}
9595
for (using foo of []) {}
96+
// Cursedly, `using of` is a valid binding form in C-style for loops.
97+
for (using of = null;;) break;
9698
})();

0 commit comments

Comments
 (0)