Title: [250098] trunk
- Revision
- 250098
- Author
- [email protected]
- Date
- 2019-09-19 11:45:12 -0700 (Thu, 19 Sep 2019)
Log Message
Syntax checker should report duplicate __proto__ properties
https://bugs.webkit.org/show_bug.cgi?id=201897
<rdar://problem/53201788>
Reviewed by Mark Lam.
JSTests:
* stress/syntax-checker-duplicate-underscore-proto.js: Added.
(catch):
Source/_javascript_Core:
Currently we have two ways of parsing object literals:
- parseObjectLiteral: this is called in sloppy mode, and as an optimization for syntax checking,
it doesn't allocate string literals while parsing properties. It does still allocate identifiers,
but it won't store them in the Property object that it creates for each parsed property. This
method backtracks and calls parseObjectStrictLiteral if it finds any getters or setters.
- parseObjectStrictLiteral: this is called in strict mode, or when the object contains getters/setters
as stated above. This will always allocate string literals as well as identifiers and store them in
the Property object, even during syntax checking.
>From looking at the history, it seems that there was a distinction between these two methods:
parseStrictObjectLiteral was introduced in r62848 and contained an extra check for duplicate
getters/setters or properties defined as both getters/setters and constants. That distinction
was removed and the only distinction that remained was whether we build strings and store the
strings and properties as part of the Property object created by SyntaxChecker::createProperty.
However, this optimization is no longer valid, since we need to throw a SyntaxError for duplicate
__proto__ properties in object literals even in sloppy mode, which means that we do need to build
the strings and identifiers and store them as part of the Property objects.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseObjectLiteral):
(JSC::Parser<LexerType>::parsePrimaryExpression):
(JSC::Parser<LexerType>::parseStrictObjectLiteral): Deleted.
* parser/Parser.h:
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (250097 => 250098)
--- trunk/JSTests/ChangeLog 2019-09-19 18:28:19 UTC (rev 250097)
+++ trunk/JSTests/ChangeLog 2019-09-19 18:45:12 UTC (rev 250098)
@@ -1,3 +1,14 @@
+2019-09-19 Tadeu Zagallo <[email protected]>
+
+ Syntax checker should report duplicate __proto__ properties
+ https://bugs.webkit.org/show_bug.cgi?id=201897
+ <rdar://problem/53201788>
+
+ Reviewed by Mark Lam.
+
+ * stress/syntax-checker-duplicate-underscore-proto.js: Added.
+ (catch):
+
2019-09-18 Saam Barati <[email protected]>
TOCTOU bug in havingABadTime related assertion in DFGSpeculativeJIT
Added: trunk/JSTests/stress/syntax-checker-duplicate-underscore-proto.js (0 => 250098)
--- trunk/JSTests/stress/syntax-checker-duplicate-underscore-proto.js (rev 0)
+++ trunk/JSTests/stress/syntax-checker-duplicate-underscore-proto.js 2019-09-19 18:45:12 UTC (rev 250098)
@@ -0,0 +1,8 @@
+try {
+ eval("(function() { ({ x: 1, y: 1, z: 1, __proto__: 1, __proto__: 1 }) })");
+ eval("(function() { ({ x: 1, y: 1, z: 1, '__proto__': 1, '__proto__': 1 }) })");
+ throw new Error('Should have thrown a SyntaxError');
+} catch (error) {
+ if (!(error instanceof SyntaxError) && error.message !== 'Attempted to redefine __proto__ property.')
+ throw new Error(`Unexpected error: ${error.message}`);
+}
Modified: trunk/Source/_javascript_Core/ChangeLog (250097 => 250098)
--- trunk/Source/_javascript_Core/ChangeLog 2019-09-19 18:28:19 UTC (rev 250097)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-09-19 18:45:12 UTC (rev 250098)
@@ -1,3 +1,35 @@
+2019-09-19 Tadeu Zagallo <[email protected]>
+
+ Syntax checker should report duplicate __proto__ properties
+ https://bugs.webkit.org/show_bug.cgi?id=201897
+ <rdar://problem/53201788>
+
+ Reviewed by Mark Lam.
+
+ Currently we have two ways of parsing object literals:
+ - parseObjectLiteral: this is called in sloppy mode, and as an optimization for syntax checking,
+ it doesn't allocate string literals while parsing properties. It does still allocate identifiers,
+ but it won't store them in the Property object that it creates for each parsed property. This
+ method backtracks and calls parseObjectStrictLiteral if it finds any getters or setters.
+ - parseObjectStrictLiteral: this is called in strict mode, or when the object contains getters/setters
+ as stated above. This will always allocate string literals as well as identifiers and store them in
+ the Property object, even during syntax checking.
+
+ From looking at the history, it seems that there was a distinction between these two methods:
+ parseStrictObjectLiteral was introduced in r62848 and contained an extra check for duplicate
+ getters/setters or properties defined as both getters/setters and constants. That distinction
+ was removed and the only distinction that remained was whether we build strings and store the
+ strings and properties as part of the Property object created by SyntaxChecker::createProperty.
+ However, this optimization is no longer valid, since we need to throw a SyntaxError for duplicate
+ __proto__ properties in object literals even in sloppy mode, which means that we do need to build
+ the strings and identifiers and store them as part of the Property objects.
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseObjectLiteral):
+ (JSC::Parser<LexerType>::parsePrimaryExpression):
+ (JSC::Parser<LexerType>::parseStrictObjectLiteral): Deleted.
+ * parser/Parser.h:
+
2019-09-19 Mark Lam <[email protected]>
Remove a now unnecessary hack to work around static const needing external linkage.
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (250097 => 250098)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2019-09-19 18:28:19 UTC (rev 250097)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2019-09-19 18:45:12 UTC (rev 250098)
@@ -4204,62 +4204,6 @@
template <typename LexerType>
template <class TreeBuilder> TreeExpression Parser<LexerType>::parseObjectLiteral(TreeBuilder& context)
{
- SavePoint savePoint = createSavePoint();
- consumeOrFailWithFlags(OPENBRACE, TreeBuilder::DontBuildStrings, "Expected opening '{' at the start of an object literal");
-
- int oldNonLHSCount = m_parserState.nonLHSCount;
-
- JSTokenLocation location(tokenLocation());
- if (match(CLOSEBRACE)) {
- next();
- return context.createObjectLiteral(location);
- }
-
- TreeProperty property = parseProperty(context, false);
- failIfFalse(property, "Cannot parse object literal property");
-
- if (context.getType(property) & (PropertyNode::Getter | PropertyNode::Setter)) {
- restoreSavePoint(savePoint);
- return parseStrictObjectLiteral(context);
- }
-
- bool seenUnderscoreProto = false;
- if (shouldCheckPropertyForUnderscoreProtoDuplicate(context, property))
- seenUnderscoreProto = *context.getName(property) == m_vm.propertyNames->underscoreProto;
-
- TreePropertyList propertyList = context.createPropertyList(location, property);
- TreePropertyList tail = propertyList;
- while (match(COMMA)) {
- next(TreeBuilder::DontBuildStrings);
- if (match(CLOSEBRACE))
- break;
- JSTokenLocation propertyLocation(tokenLocation());
- property = parseProperty(context, false);
- failIfFalse(property, "Cannot parse object literal property");
- if (context.getType(property) & (PropertyNode::Getter | PropertyNode::Setter)) {
- restoreSavePoint(savePoint);
- return parseStrictObjectLiteral(context);
- }
- if (shouldCheckPropertyForUnderscoreProtoDuplicate(context, property)) {
- if (*context.getName(property) == m_vm.propertyNames->underscoreProto) {
- semanticFailIfTrue(seenUnderscoreProto, "Attempted to redefine __proto__ property");
- seenUnderscoreProto = true;
- }
- }
- tail = context.createPropertyList(propertyLocation, property, tail);
- }
-
- location = tokenLocation();
- handleProductionOrFail2(CLOSEBRACE, "}", "end", "object literal");
-
- m_parserState.nonLHSCount = oldNonLHSCount;
-
- return context.createObjectLiteral(location, propertyList);
-}
-
-template <typename LexerType>
-template <class TreeBuilder> TreeExpression Parser<LexerType>::parseStrictObjectLiteral(TreeBuilder& context)
-{
consumeOrFail(OPENBRACE, "Expected opening '{' at the start of an object literal");
int oldNonLHSCount = m_parserState.nonLHSCount;
@@ -4499,8 +4443,6 @@
case CLASSTOKEN:
return parseClassExpression(context);
case OPENBRACE:
- if (strictMode())
- return parseStrictObjectLiteral(context);
return parseObjectLiteral(context);
case OPENBRACKET:
return parseArrayLiteral(context);
Modified: trunk/Source/_javascript_Core/parser/Parser.h (250097 => 250098)
--- trunk/Source/_javascript_Core/parser/Parser.h 2019-09-19 18:28:19 UTC (rev 250097)
+++ trunk/Source/_javascript_Core/parser/Parser.h 2019-09-19 18:45:12 UTC (rev 250098)
@@ -1615,7 +1615,6 @@
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parsePrimaryExpression(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseArrayLiteral(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseObjectLiteral(TreeBuilder&);
- template <class TreeBuilder> NEVER_INLINE TreeExpression parseStrictObjectLiteral(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeClassExpression parseClassExpression(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseFunctionExpression(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseAsyncFunctionExpression(TreeBuilder&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes