Annex B defines an early error for duplicate PropertyName of __proto__, in object initializers,

but this does not apply to Object Assignment patterns

Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
Seonghyun Kim 2020-05-28 15:53:55 +09:00 committed by Hyukwoo Park
commit 389c6d8532
2 changed files with 14 additions and 9 deletions

View file

@ -1736,7 +1736,7 @@ public:
}
template <class ASTBuilder>
ASTNode parseObjectProperty(ASTBuilder& builder, bool& hasProto) //: Node.Property
ASTNode parseObjectProperty(ASTBuilder& builder, bool& propertyNameIs__proto__) //: Node.Property
{
ALLOC_TOKEN(token);
*token = this->lookahead;
@ -1815,12 +1815,8 @@ public:
if (this->match(PunctuatorKind::Colon) && !isAsync) {
// FIXME check !this->isParsingSingleFunction
isProto = !this->isParsingSingleFunction && builder.isPropertyKey(keyNode, "__proto__");
if (!computed && isProto) {
if (hasProto) {
this->throwError(Messages::DuplicateProtoProperty);
}
hasProto = true;
propertyNameIs__proto__ = true;
}
this->nextToken();
valueNode = this->inheritCoverGrammar(builder, &Parser::parseAssignmentExpression<ASTBuilder, true>);
@ -1898,12 +1894,16 @@ public:
MetaNode node = this->createNode();
ASTNodeList properties;
bool hasProto = false;
size_t __proto__Count = 0;
while (!this->match(RightBrace)) {
if (this->match(PeriodPeriodPeriod)) {
properties.append(this->allocator, this->parseSpreadElement<ASTBuilder, true>(builder));
} else {
properties.append(this->allocator, this->parseObjectProperty(builder, hasProto));
bool propertyNameIs__proto__ = false;
properties.append(this->allocator, this->parseObjectProperty(builder, propertyNameIs__proto__));
if (propertyNameIs__proto__) {
__proto__Count++;
}
}
if (!this->match(RightBrace)) {
this->expectCommaSeparator();
@ -1911,6 +1911,12 @@ public:
}
this->expect(RightBrace);
// Annex B defines an early error for duplicate PropertyName of `__proto__`, in object initializers,
// but this does not apply to Object Assignment patterns
if (!this->match(PunctuatorKind::Substitution) && __proto__Count >= 2) {
this->throwError(Messages::DuplicateProtoProperty);
}
return this->finalize(node, builder.createObjectExpressionNode(properties));
}

View file

@ -2357,7 +2357,6 @@
<test id="language/expressions/assignment/S11.13.1_A7_T3"><reason>TODO</reason></test>
<test id="language/expressions/assignment/destructuring/iterator-destructuring-property-reference-target-evaluation-order"><reason>TODO</reason></test>
<test id="language/expressions/assignment/destructuring/keyed-destructuring-property-reference-target-evaluation-order"><reason>TODO</reason></test>
<test id="language/expressions/assignment/destructuring/obj-prop-__proto__dup"><reason>TODO</reason></test>
<test id="language/expressions/async-generator/generator-created-after-decl-inst"><reason>TODO</reason></test>
<test id="language/expressions/bitwise-and/bigint"><reason>TODO</reason></test>
<test id="language/expressions/bitwise-and/bigint-and-number"><reason>TODO</reason></test>