Changeset 266322 in webkit for trunk/Source/JavaScriptCore


Ignore:
Timestamp:
Aug 29, 2020, 12:11:42 AM (5 years ago)
Author:
[email protected]
Message:

[JSC] super property with new should be accepted
https://bugs.webkit.org/show_bug.cgi?id=215966

Reviewed by Ross Kirsling.

JSTests:

  • stress/super-and-new.js: Added.

(testSyntaxError):
(shouldBe):
(test.A):
(test.A.prototype.get hey):
(test.A.prototype.get hey2):
(test.A.prototype.super):
(test.B.get super):

Source/JavaScriptCore:

While we should reject new super / new super(), we should accept new super.property.
https://tc39.es/ecma262/#prod-SuperProperty is a child production of https://tc39.es/ecma262/#prod-MemberExpression,
unlike https://tc39.es/ecma262/#prod-SuperCall. So new should accept SuperProperty (e.g. super.xxx).

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseMemberExpression):

LayoutTests:

  • js/class-syntax-super-expected.txt:
  • js/script-tests/class-syntax-super.js:
Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r266318 r266322  
     12020-08-28  Yusuke Suzuki  <[email protected]>
     2
     3        [JSC] super property with new should be accepted
     4        https://bugs.webkit.org/show_bug.cgi?id=215966
     5
     6        Reviewed by Ross Kirsling.
     7
     8        While we should reject `new super` / `new super()`, we should accept `new super.property`.
     9        https://tc39.es/ecma262/#prod-SuperProperty is a child production of https://tc39.es/ecma262/#prod-MemberExpression,
     10        unlike https://tc39.es/ecma262/#prod-SuperCall. So `new` should accept SuperProperty (e.g. `super.xxx`).
     11
     12        * parser/Parser.cpp:
     13        (JSC::Parser<LexerType>::parseMemberExpression):
     14
    1152020-08-28  Yusuke Suzuki  <[email protected]>
    216
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r266318 r266322  
    48444844    bool previousBaseWasSuper = false;
    48454845    bool baseIsImport = match(IMPORT);
    4846     semanticFailIfTrue(baseIsSuper && newCount, "Cannot use new with ", getToken());
    48474846
    48484847    bool baseIsNewTarget = false;
     
    49764975                if (newCount) {
    49774976                    newCount--;
     4977                    semanticFailIfTrue(baseIsSuper, "Cannot use new with super call");
    49784978                    JSTextPosition expressionEnd = lastTokenEndPosition();
    49794979                    TreeArguments arguments = parseArguments(context);
     
    50725072    } while (match(QUESTIONDOT));
    50735073
    5074     semanticFailIfTrue(baseIsSuper, "super is not valid in this context");
     5074    semanticFailIfTrue(baseIsSuper, newCount ? "Cannot use new with super call" : "super is not valid in this context");
    50755075    while (newCount--)
    50765076        base = context.createNewExpr(location, base, expressionStart, lastTokenEndPosition());
Note: See TracChangeset for help on using the changeset viewer.