Changeset 188018 in webkit


Ignore:
Timestamp:
Aug 5, 2015 9:01:00 PM (9 years ago)
Author:
rniwa@webkit.org
Message:

[ES6] Class parser does not allow methods named set and get.
https://bugs.webkit.org/show_bug.cgi?id=147150

Reviewed by Oliver Hunt.

Source/JavaScriptCore:

The bug was caused by parseClass assuming identifiers "get" and "set" could only appear
as the leading token for getter and setter methods. Fixed the bug by generalizing the code
so that we only treat them as such when it's followed by another token that could be a method name.

  • parser/Parser.cpp:

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

LayoutTests:

Added a regression test and rebaselined a test.

  • js/class-syntax-method-names-expected.txt: Added.
  • js/class-syntax-method-names.html: Added.
  • js/class-syntax-semicolon-expected.txt: Rebaselined as the error message got improved.
  • js/script-tests/class-syntax-method-names.js: Added.
  • js/script-tests/class-syntax-semicolon.js:
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r188017 r188018  
     12015-08-05  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        [ES6] Class parser does not allow methods named set and get.
     4        https://bugs.webkit.org/show_bug.cgi?id=147150
     5
     6        Reviewed by Oliver Hunt.
     7
     8        Added a regression test and rebaselined a test.
     9
     10        * js/class-syntax-method-names-expected.txt: Added.
     11        * js/class-syntax-method-names.html: Added.
     12        * js/class-syntax-semicolon-expected.txt: Rebaselined as the error message got improved.
     13        * js/script-tests/class-syntax-method-names.js: Added.
     14        * js/script-tests/class-syntax-semicolon.js:
     15
    1162015-08-05  Nikita Vasilyev  <nvasilyev@apple.com>
    217
  • trunk/LayoutTests/js/class-syntax-semicolon-expected.txt

    r183383 r188018  
    66PASS class A { foo;() { } } threw exception SyntaxError: Unexpected token ';'. Expected an opening '(' before a method's parameter list..
    77PASS class A { foo() ; { } } threw exception SyntaxError: Unexpected token ';'. Expected an opening '{' at the start of a method body..
    8 PASS class A { get ; foo() { } } threw exception SyntaxError: Unexpected token ';'.
     8PASS class A { get ; foo() { } } threw exception SyntaxError: Unexpected token ';'. Expected an opening '(' before a method's parameter list..
    99PASS class A { get foo;() { } } threw exception SyntaxError: Unexpected token ';'. Expected a parameter list for getter definition..
    1010PASS class A { get foo() ; { } } threw exception SyntaxError: Unexpected token ';'. Expected an opening '{' at the start of a getter body..
    11 PASS class A { set ; foo(x) { } } threw exception SyntaxError: Unexpected token ';'.
     11PASS class A { set ; foo(x) { } } threw exception SyntaxError: Unexpected token ';'. Expected an opening '(' before a method's parameter list..
    1212PASS class A { set foo;(x) { } } threw exception SyntaxError: Unexpected token ';'. Expected a parameter list for setter definition..
    1313PASS class A { set foo(x) ; { } } threw exception SyntaxError: Unexpected token ';'. Expected an opening '{' at the start of a setter body..
  • trunk/LayoutTests/js/script-tests/class-syntax-semicolon.js

    r183392 r188018  
    55shouldThrow("class A { foo;() { } }", "'SyntaxError: Unexpected token \\';\\'. Expected an opening \\'(\\' before a method\\'s parameter list.'");
    66shouldThrow("class A { foo() ; { } }", "'SyntaxError: Unexpected token \\\';\\'. Expected an opening \\'{\\' at the start of a method body.'");
    7 shouldThrow("class A { get ; foo() { } }", "'SyntaxError: Unexpected token \\';\\''");
     7shouldThrow("class A { get ; foo() { } }", "'SyntaxError: Unexpected token \\';\\'. Expected an opening \\'(\\' before a method\\'s parameter list.'");
    88shouldThrow("class A { get foo;() { } }", "'SyntaxError: Unexpected token \\\';\\'. Expected a parameter list for getter definition.'");
    99shouldThrow("class A { get foo() ; { } }", "'SyntaxError: Unexpected token \\\';\\'. Expected an opening \\'{\\' at the start of a getter body.'");
    10 shouldThrow("class A { set ; foo(x) { } }", "'SyntaxError: Unexpected token \\';\\''");
     10shouldThrow("class A { set ; foo(x) { } }", "'SyntaxError: Unexpected token \\';\\'. Expected an opening \\'(\\' before a method\\'s parameter list.'");
    1111shouldThrow("class A { set foo;(x) { } }", "'SyntaxError: Unexpected token \\\';\\'. Expected a parameter list for setter definition.'");
    1212shouldThrow("class A { set foo(x) ; { } }", "'SyntaxError: Unexpected token \\\';\\'. Expected an opening \\'{\\' at the start of a setter body.'");
  • trunk/Source/JavaScriptCore/ChangeLog

    r188002 r188018  
     12015-08-05  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        [ES6] Class parser does not allow methods named set and get.
     4        https://bugs.webkit.org/show_bug.cgi?id=147150
     5
     6        Reviewed by Oliver Hunt.
     7
     8        The bug was caused by parseClass assuming identifiers "get" and "set" could only appear
     9        as the leading token for getter and setter methods. Fixed the bug by generalizing the code
     10        so that we only treat them as such when it's followed by another token that could be a method name.
     11
     12        * parser/Parser.cpp:
     13        (JSC::Parser<LexerType>::parseClass):
     14
    1152015-08-05  Filip Pizlo  <fpizlo@apple.com>
    216
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r187890 r188018  
    19511951        case IDENT:
    19521952            ident = m_token.m_data.ident;
    1953             isGetter = *ident == propertyNames.get;
    1954             isSetter = *ident == propertyNames.set;
    19551953            ASSERT(ident);
     1954            next();
     1955            if (match(IDENT) || match(STRING) || match(DOUBLE) || match(INTEGER)) {
     1956                isGetter = *ident == propertyNames.get;
     1957                isSetter = *ident == propertyNames.set;
     1958            }
    19561959            break;
    19571960        case DOUBLE:
     
    19681971        const bool alwaysStrictInsideClass = true;
    19691972        if (isGetter || isSetter) {
    1970             nextExpectIdentifier(LexerFlagsIgnoreReservedWords);
    19711973            property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart,
    19721974                ConstructorKind::None, SuperBinding::Needed);
Note: See TracChangeset for help on using the changeset viewer.