Ignore:
Timestamp:
May 20, 2015, 9:54:09 AM (10 years ago)
Author:
[email protected]
Message:

ES6: Should not allow duplicate basic proto properties in Object Literals
https://bugs.webkit.org/show_bug.cgi?id=145138

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2015-05-20
Reviewed by Darin Adler.

Source/JavaScriptCore:

Implement ES6 Annex B.3.1, which disallows duplicate basic proto
properties in object literals. This doesn't affect computed properties,
shorthand properties, or getters/setters all of which avoid setting
the actual prototype of the object anyway.

  • interpreter/Interpreter.cpp:

(JSC::eval):
Remove out of date comment. Duplicate property names are allowed
now in ES6, they were not in ES5 strict mode.

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::getName):
(JSC::ASTBuilder::getType):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::getName):
Add back getName to get the property name depending on the tree builder.
Also tighten up the parameter types.

  • runtime/LiteralParser.cpp:

(JSC::LiteralParser<CharType>::parse):
In quick JSON literal parsing for eval, we actually need to evaluate
the proto property assignment, instead of just building up a list
of direct properties. Only do this when not doing a strict JSON parse.

  • parser/Nodes.h:

Add "Shorthand" to the list of PropertyNode types to allow it to
be distinguished without relying on other information.

  • parser/Parser.h:
  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseProperty):
Add the Shorthand type when parsing a shorthand property.

(JSC::Parser<LexerType>::shouldCheckPropertyForUnderscoreProtoDuplicate):
(JSC::Parser<LexerType>::parseObjectLiteral):
(JSC::Parser<LexerType>::parseStrictObjectLiteral):
Check for duplicate proto properties, and throw a SyntaxError
if that was the case.

LayoutTests:

  • js/dom/JSON-parse-expected.txt:
  • js/resources/JSON-parse.js:

Update expected results for JSON parsing using eval() versus JSON.parse.
In eval, an object literal with a "proto" property modifies the prototype.
In JSON.parse, all properties are direct/own properties, no matter their name,
so "proto" does not get special treatment.

  • js/eval-json-proto-expected.txt: Added.
  • js/eval-json-proto.html: Added.
  • js/script-tests/eval-json-proto.js: Added.

Direct test for LiteralParser behavior, in both eval and JSON.parse.

  • js/object-literal-duplicate-properties-expected.txt:
  • js/script-tests/object-literal-duplicate-properties.js:

(runProtoTestShouldThrow):
(runProtoTestShouldNotThrow):
Test for all cases of acceptable and unacceptable proto duplicate
properties in literals.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/SyntaxChecker.h

    r184337 r184640  
    294294    void assignmentStackAppend(int, int, int, int, int, Operator) { }
    295295    int createAssignment(const JSTokenLocation&, int, int, int, int, int) { RELEASE_ASSERT_NOT_REACHED(); return AssignmentExpr; }
     296    const Identifier* getName(const Property& property) const { return property.name; }
    296297    PropertyNode::Type getType(const Property& property) const { return property.type; }
    297298    bool isResolve(ExpressionType expr) const { return expr == ResolveExpr || expr == ResolveEvalExpr; }
Note: See TracChangeset for help on using the changeset viewer.