Skip to content

Commit a57c8c4

Browse files
rel #23: disallow eval and arguments as CatchClause param
1 parent 08750bd commit a57c8c4

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This is a list of all esvalid validity tests other than `null` tests and type ch
5555

5656
* BreakStatement must have an IterationStatement or SwitchStatement as an ancestor
5757
* labelled BreakStatement must have a matching LabeledStatement ancestor
58+
* CatchClause `param` member must not be `eval` or `arguments` in strict mode
5859
* ContinueStatement must have an IterationStatement as an ancestor
5960
* labelled ContinueStatement must have a matching LabeledStatement ancestor
6061
* FunctionDeclaration `id` member must not be `eval` or `arguments` in strict mode

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ function errorsP(state) {
204204
case "CatchClause":
205205
if (!isExpression(node.param))
206206
errors.push(new E(node, "CatchClause `param` member must be an expression node"));
207+
else if (state.strict && node.param.type === "Identifier" && esutils.keyword.isRestrictedWord(node.param.name))
208+
errors.push(new E(node, "CatchClause `param` member must not be `eval` or `arguments` in strict mode"));
207209
if (node.body == null || node.body.type !== "BlockStatement")
208210
errors.push(new E(node, "CatchClause `body` member must be a BlockStatement node"));
209211
if (node.param != null)

test/strict.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ suite("strict mode", function() {
2727
validExpr(FE(exprStmt({type: "Literal", value: "use strict"})));
2828
});
2929

30+
test("CatchClause param must not be restricted in strict mode", function() {
31+
validStmt({type: "TryStatement", block: BLOCK, handler: {type: "CatchClause", param: {type: "Identifier", name: "eval"}, body: BLOCK}});
32+
validStmt({type: "TryStatement", block: BLOCK, handler: {type: "CatchClause", param: {type: "Identifier", name: "arguments"}, body: BLOCK}});
33+
validExpr(strictFE({type: "TryStatement", block: BLOCK, handler: {type: "CatchClause", param: {type: "Identifier", name: "x"}, body: BLOCK}}));
34+
invalidExpr(1, strictFE({type: "TryStatement", block: BLOCK, handler: {type: "CatchClause", param: {type: "Identifier", name: "eval"}, body: BLOCK}}));
35+
invalidExpr(1, strictFE({type: "TryStatement", block: BLOCK, handler: {type: "CatchClause", param: {type: "Identifier", name: "arguments"}, body: BLOCK}}));
36+
});
37+
3038
test("Function names must not be restricted in strict mode", function() {
3139
validExpr(strictFE(exprStmt({type: "FunctionExpression", id: null, params: [], body: BLOCK})));
3240
validExpr({type: "FunctionExpression", id: {type: "Identifier", name: "eval"}, params: [], body: BLOCK});

0 commit comments

Comments
 (0)