Skip to content

Commit c8f8295

Browse files
rmahdavnodejs-github-bot
authored andcommitted
deps: V8: cherry-pick 044b9b6f589d
Original commit message: [explicit-resource-management] disallow using in switch cases This CL disallows `using` and `await using` in switch cases. This was a normative change that got consensus in TC39 meetings: rbuckton/ecma262#14 Bug: 409478039 Change-Id: I077e75d7d0d632c8b34150cfc76e4903984d6091 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6500234 Reviewed-by: Shu-yu Guo <[email protected]> Commit-Queue: Rezvan Mahdavi Hezaveh <[email protected]> Cr-Commit-Position: refs/heads/main@{#100037} Refs: v8/v8@044b9b6 PR-URL: #58230 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 12e0b51 commit c8f8295

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
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.13',
41+
'v8_embedder_string': '-node.14',
4242

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

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,16 +1165,18 @@ class ParserBase {
11651165
}
11661166
bool is_using_allowed() const {
11671167
// UsingDeclaration and AwaitUsingDeclaration are Syntax Errors if the goal
1168-
// symbol is Script. UsingDeclaration and AwaitUsingDeclaration are not
1169-
// contained, either directly or indirectly, within a Block, CaseBlock,
1170-
// ForStatement, ForInOfStatement, FunctionBody, GeneratorBody,
1168+
// symbol is Script. UsingDeclaration and AwaitUsingDeclaration are Syntax
1169+
// Errors if they are not contained, either directly or indirectly, within a
1170+
// Block, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody,
11711171
// AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or
1172-
// ClassBody. Unless the current scope's ScopeType is ScriptScope, the
1172+
// ClassBody. They are disallowed in 'bare' switch cases.
1173+
// Unless the current scope's ScopeType is ScriptScope, the
11731174
// current position is directly or indirectly within one of the productions
11741175
// listed above since they open a new scope.
1175-
return ((scope()->scope_type() != SCRIPT_SCOPE &&
1176-
scope()->scope_type() != EVAL_SCOPE) ||
1177-
scope()->scope_type() == REPL_MODE_SCOPE);
1176+
return (((scope()->scope_type() != SCRIPT_SCOPE &&
1177+
scope()->scope_type() != EVAL_SCOPE) ||
1178+
scope()->scope_type() == REPL_MODE_SCOPE) &&
1179+
!scope()->is_nonlinear());
11781180
}
11791181
bool IsNextUsingKeyword(Token::Value token_after_using, bool is_await_using) {
11801182
// using and await using declarations in for-of statements must be followed

deps/v8/test/test262/test262.status

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,10 @@
12771277
# May OOM fatally
12781278
'staging/sm/regress/regress-610026': [SKIP],
12791279

1280+
# https://github.com/rbuckton/ecma262/pull/14
1281+
'staging/explicit-resource-management/await-using-in-switch-case-block': [SKIP],
1282+
'staging/explicit-resource-management/call-dispose-methods': [SKIP],
1283+
12801284
############################ SLOW TESTS #############################
12811285

12821286
'annexB/built-ins/RegExp/RegExp-leading-escape-BMP': [PASS, SLOW],

deps/v8/test/unittests/parser/decls-unittest.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,24 @@ TEST_F(DeclsTest, TestUsing) {
10821082
EXPECT_ERROR);
10831083
context.Check("{var using; \n using = 42;}", EXPECT_RESULT,
10841084
Number::New(isolate(), 42));
1085+
context.Check(
1086+
"let label = \"1\"; \n switch (label) { \n case 1: \n let y = 2; \n"
1087+
"using x = { \n "
1088+
" value: 1, \n "
1089+
" [Symbol.dispose]() { \n "
1090+
" return 42; \n "
1091+
" } \n "
1092+
" }; }",
1093+
EXPECT_ERROR);
1094+
context.Check(
1095+
"let label = \"1\"; \n switch (label) { \n case 1: {\n let y = 2; \n"
1096+
"using x = { \n "
1097+
" value: 1, \n "
1098+
" [Symbol.dispose]() { \n "
1099+
" return 42; \n "
1100+
" } \n "
1101+
" }; } }",
1102+
EXPECT_RESULT, Undefined(isolate()));
10851103
}
10861104
}
10871105

@@ -1144,6 +1162,17 @@ TEST_F(DeclsTest, TestAwaitUsing) {
11441162
" } } \n "
11451163
" f(); ",
11461164
EXPECT_ERROR);
1165+
context.Check(
1166+
"async function f() {let label = \"1\"; \n switch (label){ \n case 1: "
1167+
"\n let y = 2;"
1168+
"\n await using x = { \n "
1169+
" value: 1, \n "
1170+
" [Symbol.asyncDispose]() { \n "
1171+
" classStaticBlockBodyValues.push(42); \n "
1172+
" } \n "
1173+
" }; \n }"
1174+
"} \n f();",
1175+
EXPECT_ERROR);
11471176
}
11481177
}
11491178

0 commit comments

Comments
 (0)