Skip to content

Commit 1a6eee4

Browse files
Nick Santoshns
authored andcommitted
Tests for strict mode parsing or getter and setters.
Fixes issue 598 Committed by John Lenz ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=26392288 Conflicts: src/org/mozilla/javascript/Parser.java
1 parent 323f151 commit 1a6eee4

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/org/mozilla/javascript/Parser.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,7 +3078,7 @@ private ArrayComprehensionLoop arrayComprehensionLoop()
30783078
}
30793079
}
30803080

3081-
private AstNode generatorExpression(AstNode result, int pos)
3081+
private AstNode generatorExpression(AstNode result, int pos)
30823082
throws IOException
30833083
{
30843084
return generatorExpression(result, pos, false);
@@ -3168,18 +3168,28 @@ private GeneratorExpressionLoop generatorExpressionLoop()
31683168
}
31693169
}
31703170

3171+
private static final int PROP_ENTRY = 1;
3172+
private static final int GET_ENTRY = 2;
3173+
private static final int SET_ENTRY = 4;
3174+
31713175
private ObjectLiteral objectLiteral()
31723176
throws IOException
31733177
{
31743178
int pos = ts.tokenBeg, lineno = ts.lineno;
31753179
int afterComma = -1;
31763180
List<ObjectProperty> elems = new ArrayList<ObjectProperty>();
3177-
Set<String> propertyNames = new HashSet<String>();
3181+
Set<String> getterNames = null;
3182+
Set<String> setterNames = null;
3183+
if (this.inUseStrictDirective) {
3184+
getterNames = new HashSet<String>();
3185+
setterNames = new HashSet<String>();
3186+
}
31783187
Comment objJsdocNode = getAndResetJsDoc();
31793188

31803189
commaLoop:
31813190
for (;;) {
31823191
String propertyName = null;
3192+
int entryKind = PROP_ENTRY;
31833193
int tt = peekToken();
31843194
Comment jsdocNode = getAndResetJsDoc();
31853195
switch(tt) {
@@ -3230,11 +3240,29 @@ private ObjectLiteral objectLiteral()
32303240
break;
32313241
}
32323242

3233-
if (this.inUseStrictDirective) {
3234-
if (propertyNames.contains(propertyName)) {
3235-
addError("msg.dup.obj.lit.prop.strict", propertyName);
3243+
if (this.inUseStrictDirective && propertyName != null) {
3244+
switch (entryKind) {
3245+
case PROP_ENTRY:
3246+
if (getterNames.contains(propertyName)
3247+
|| setterNames.contains(propertyName)) {
3248+
addError("msg.dup.obj.lit.prop.strict", propertyName);
3249+
}
3250+
getterNames.add(propertyName);
3251+
setterNames.add(propertyName);
3252+
break;
3253+
case GET_ENTRY:
3254+
if (getterNames.contains(propertyName)) {
3255+
addError("msg.dup.obj.lit.prop.strict", propertyName);
3256+
}
3257+
getterNames.add(propertyName);
3258+
break;
3259+
case SET_ENTRY:
3260+
if (setterNames.contains(propertyName)) {
3261+
addError("msg.dup.obj.lit.prop.strict", propertyName);
3262+
}
3263+
setterNames.add(propertyName);
3264+
break;
32363265
}
3237-
propertyNames.add(propertyName);
32383266
}
32393267

32403268
// Eat any dangling jsdoc in the property.

0 commit comments

Comments
 (0)