Skip to content

Commit

Permalink
Duplicated proto should be checked only for PropertyDefinition with P…
Browse files Browse the repository at this point in the history
…ropertyName.

Other PropertyDefinition productions, such as MethodDefinition and
IdentifierReference, should be excluded from duplicated __proto_ checks.

Fixes jquery#1225
Closes jquerygh-1228
  • Loading branch information
ariya committed Jul 9, 2015
1 parent e4a35c8 commit 495b298
Show file tree
Hide file tree
Showing 43 changed files with 1,814 additions and 31 deletions.
27 changes: 10 additions & 17 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -2905,19 +2905,8 @@
return null;
}

function checkProto(key, computed, hasProto) {
if (computed === false && (key.type === Syntax.Identifier && key.name === '__proto__' ||
key.type === Syntax.Literal && key.value === '__proto__')) {
if (hasProto.value) {
tolerateError(Messages.DuplicateProtoProperty);
} else {
hasProto.value = true;
}
}
}

function parseObjectProperty(hasProto) {
var token = lookahead, node = new Node(), computed, key, maybeMethod, value;
var token = lookahead, node = new Node(), computed, key, maybeMethod, proto, value;

computed = match('[');
if (match('*')) {
Expand All @@ -2926,19 +2915,23 @@
key = parseObjectPropertyKey();
}
maybeMethod = tryParseMethodDefinition(token, key, computed, node);

if (maybeMethod) {
checkProto(maybeMethod.key, maybeMethod.computed, hasProto);
// finished
return maybeMethod;
}

if (!key) {
throwUnexpectedToken(lookahead);
}

// init property or short hand property.
checkProto(key, computed, hasProto);
// Check for duplicated __proto__
if (!computed) {
proto = (key.type === Syntax.Identifier && key.name === '__proto__') ||
(key.type === Syntax.Literal && key.value === '__proto__');
if (hasProto.value && proto) {
tolerateError(Messages.DuplicateProtoProperty);
}
hasProto.value |= proto;
}

if (match(':')) {
lex();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":48,"lineNumber":1,"column":49,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ get __proto(){}, "__proto__": null, __proto__: null, })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":31,"lineNumber":1,"column":32,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ __proto__: null, "__proto__": null })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":29,"lineNumber":1,"column":30,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ __proto__: null, __proto__ })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":29,"lineNumber":1,"column":30,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ __proto__: null, __proto__: null })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":31,"lineNumber":1,"column":32,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ "__proto__": null, __proto__: null })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":31,"lineNumber":1,"column":32,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ "__proto__": null, __proto__ })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":33,"lineNumber":1,"column":34,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ "__proto__": null, '__proto__': null })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":51,"lineNumber":1,"column":52,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ set __proto__(x){}, "__proto__": null, __proto__: null, })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":23,"lineNumber":1,"column":24,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ __proto__, __proto__: null })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":25,"lineNumber":1,"column":26,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ __proto__, "__proto__": null })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":23,"lineNumber":1,"column":24,"message":"Error: Line 1: Duplicate __proto__ fields are not allowed in object literals","description":"Duplicate __proto__ fields are not allowed in object literals"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ __proto__, __proto__ })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ __proto__: null, get __proto__(){}, set __proto__(x){} })
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
{
"range": [
0,
60
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 60
}
},
"type": "Program",
"body": [
{
"range": [
0,
60
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 60
}
},
"type": "ExpressionStatement",
"expression": {
"range": [
1,
59
],
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 59
}
},
"type": "ObjectExpression",
"properties": [
{
"range": [
3,
18
],
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 18
}
},
"type": "Property",
"key": {
"range": [
3,
12
],
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 12
}
},
"type": "Identifier",
"name": "__proto__"
},
"computed": false,
"value": {
"range": [
14,
18
],
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 18
}
},
"type": "Literal",
"value": null,
"raw": "null"
},
"kind": "init",
"method": false,
"shorthand": false
},
{
"range": [
20,
37
],
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 37
}
},
"type": "Property",
"key": {
"range": [
24,
33
],
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 33
}
},
"type": "Identifier",
"name": "__proto__"
},
"computed": false,
"value": {
"range": [
33,
37
],
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 37
}
},
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"body": {
"range": [
35,
37
],
"loc": {
"start": {
"line": 1,
"column": 35
},
"end": {
"line": 1,
"column": 37
}
},
"type": "BlockStatement",
"body": []
},
"generator": false,
"expression": false
},
"kind": "get",
"method": false,
"shorthand": false
},
{
"range": [
39,
57
],
"loc": {
"start": {
"line": 1,
"column": 39
},
"end": {
"line": 1,
"column": 57
}
},
"type": "Property",
"key": {
"range": [
43,
52
],
"loc": {
"start": {
"line": 1,
"column": 43
},
"end": {
"line": 1,
"column": 52
}
},
"type": "Identifier",
"name": "__proto__"
},
"computed": false,
"value": {
"range": [
52,
57
],
"loc": {
"start": {
"line": 1,
"column": 52
},
"end": {
"line": 1,
"column": 57
}
},
"type": "FunctionExpression",
"id": null,
"params": [
{
"range": [
53,
54
],
"loc": {
"start": {
"line": 1,
"column": 53
},
"end": {
"line": 1,
"column": 54
}
},
"type": "Identifier",
"name": "x"
}
],
"defaults": [],
"body": {
"range": [
55,
57
],
"loc": {
"start": {
"line": 1,
"column": 55
},
"end": {
"line": 1,
"column": 57
}
},
"type": "BlockStatement",
"body": []
},
"generator": false,
"expression": false
},
"kind": "set",
"method": false,
"shorthand": false
}
]
}
}
]
}
Loading

0 comments on commit 495b298

Please sign in to comment.