Skip to content

Commit

Permalink
Ensure that strict mode reserved word binding throw an error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Aug 16, 2015
1 parent e6357f5 commit b5c6313
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 3 deletions.
11 changes: 8 additions & 3 deletions esprima.js
Expand Up @@ -3863,9 +3863,14 @@
tolerateError(Messages.InvalidLHSInAssignment);
}

// ECMA-262 11.13.1
if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
tolerateUnexpectedToken(token, Messages.StrictLHSAssignment);
// ECMA-262 12.1.1
if (strict && expr.type === Syntax.Identifier) {
if (isRestrictedWord(expr.name)) {
tolerateUnexpectedToken(token, Messages.StrictLHSAssignment);
}
if (isStrictModeReservedWord(expr.name)) {
tolerateUnexpectedToken(token, Messages.StrictReservedWord);
}
}

if (!match('=')) {
Expand Down
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
@@ -0,0 +1 @@
function hello() { "use strict"; implements = 1; }
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
@@ -0,0 +1 @@
function hello() { "use strict"; interface = 1; }
@@ -0,0 +1 @@
{"index":37,"lineNumber":1,"column":38,"message":"Error: Line 1: Unexpected token =","description":"Unexpected token ="}
1 change: 1 addition & 0 deletions test/fixtures/invalid-syntax/strict_assignment_let.js
@@ -0,0 +1 @@
function hello() { "use strict"; let = 1; }
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
1 change: 1 addition & 0 deletions test/fixtures/invalid-syntax/strict_assignment_package.js
@@ -0,0 +1 @@
function hello() { "use strict"; package = 1; }
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
1 change: 1 addition & 0 deletions test/fixtures/invalid-syntax/strict_assignment_private.js
@@ -0,0 +1 @@
function hello() { "use strict"; private = 1; }
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
@@ -0,0 +1 @@
function hello() { "use strict"; protected = 1; }
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
1 change: 1 addition & 0 deletions test/fixtures/invalid-syntax/strict_assignment_public.js
@@ -0,0 +1 @@
function hello() { "use strict"; public = 1; }
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
1 change: 1 addition & 0 deletions test/fixtures/invalid-syntax/strict_assignment_static.js
@@ -0,0 +1 @@
function hello() { "use strict"; static = 1; }
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Use of future reserved word in strict mode","description":"Use of future reserved word in strict mode"}
1 change: 1 addition & 0 deletions test/fixtures/invalid-syntax/strict_assignment_yield.js
@@ -0,0 +1 @@
function hello() { "use strict"; yield = 1; }

0 comments on commit b5c6313

Please sign in to comment.