Changeset 190847 in webkit


Ignore:
Timestamp:
Oct 11, 2015 11:46:52 AM (9 years ago)
Author:
Yusuke Suzuki
Message:

ES6 classes: When a class extends B, super() invokes B.prototype.constructor() instead of B()
https://bugs.webkit.org/show_bug.cgi?id=149001

Reviewed by Saam Barati.

Source/JavaScriptCore:

This patch matches the super() call in the constructor to the latest spec.
Before this patch, when calling super(), it loads callee.[[HomeObject]].__proto__.constructor
as a super constructor. But after this patch, it loads callee.__proto__ as a super constructor.
This behavior corresponds to the section 12.3.5.2[1].

[1]: http://www.ecma-international.org/ecma-262/6.0/#sec-getsuperconstructor

  • bytecompiler/NodesCodegen.cpp:

(JSC::SuperNode::emitBytecode):

  • tests/stress/super-call-does-not-look-up-constructor.js: Added.

(shouldBe):
(B):
(C):
(B.prototype):

LayoutTests:

An error message becomes changed.

  • js/class-syntax-call-expected.txt:
  • js/class-syntax-extends-expected.txt:
  • js/class-syntax-super-expected.txt:
  • js/script-tests/class-syntax-call.js:
  • js/script-tests/class-syntax-extends.js:
  • js/script-tests/class-syntax-super.js:
Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190840 r190847  
     12015-10-11  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        ES6 classes: When a class extends B, super() invokes B.prototype.constructor() instead of B()
     4        https://bugs.webkit.org/show_bug.cgi?id=149001
     5
     6        Reviewed by Saam Barati.
     7
     8        An error message becomes changed.
     9
     10        * js/class-syntax-call-expected.txt:
     11        * js/class-syntax-extends-expected.txt:
     12        * js/class-syntax-super-expected.txt:
     13        * js/script-tests/class-syntax-call.js:
     14        * js/script-tests/class-syntax-extends.js:
     15        * js/script-tests/class-syntax-super.js:
     16
    1172015-10-10  Antti Koivisto  <antti@apple.com>
    218
  • trunk/LayoutTests/js/class-syntax-call-expected.txt

    r187680 r190847  
    1010PASS new (class { constructor() {} })()
    1111PASS (class { constructor() {} })():::"TypeError: Cannot call a class constructor"
    12 PASS new (class extends null { constructor() { super() } })():::"TypeError: undefined is not an object (evaluating 'super()')"
     12PASS new (class extends null { constructor() { super() } })():::"TypeError: function is not a constructor (evaluating 'super()')"
    1313PASS (class extends null { constructor() { super() } })():::"TypeError: Cannot call a class constructor"
    1414PASS successfullyParsed is true
  • trunk/LayoutTests/js/class-syntax-extends-expected.txt

    r187680 r190847  
    5959PASS class x {}; new (class extends null { constructor () { return new x; } }) instanceof x
    6060PASS new (class extends null { constructor () { this; } }):::ReferenceError: Cannot access uninitialized variable.
    61 PASS new (class extends null { constructor () { super(); } }):::TypeError: undefined is not an object (evaluating 'super()')
     61PASS new (class extends null { constructor () { super(); } }):::TypeError: function is not a constructor (evaluating 'super()')
    6262PASS x = {}; new (class extends null { constructor () { return x } }):::x
    6363PASS y = 12; new (class extends null { constructor () { return y; } }):::TypeError: Cannot return a non-object type in the constructor of a derived class.
  • trunk/LayoutTests/js/class-syntax-super-expected.txt

    r187680 r190847  
    3030PASS new (class extends Base { constructor() { return 1; } }):::TypeError: Cannot return a non-object type in the constructor of a derived class.
    3131PASS new (class extends null { constructor() { return undefined } }):::ReferenceError: Cannot access uninitialized variable.
    32 PASS new (class extends null { constructor() { super(); return undefined } }):::TypeError: undefined is not an object (evaluating 'super()')
     32PASS new (class extends null { constructor() { super(); return undefined } }):::TypeError: function is not a constructor (evaluating 'super()')
    3333PASS x = { }; new (class extends null { constructor() { return x } });:::x
    3434PASS x instanceof Object
    3535PASS new (class extends null { constructor() { } }):::ReferenceError: Cannot access uninitialized variable.
    3636PASS new (class extends null { constructor() { return 1; } }):::TypeError: Cannot return a non-object type in the constructor of a derived class.
    37 PASS new (class extends null { constructor() { super() } }):::TypeError: undefined is not an object (evaluating 'super()')
     37PASS new (class extends null { constructor() { super() } }):::TypeError: function is not a constructor (evaluating 'super()')
    3838PASS new (class { constructor() { super() } }):::SyntaxError: Cannot call super() in a base class constructor.
    3939PASS function x() { super(); }:::SyntaxError: Cannot call super() outside of a class constructor.
  • trunk/LayoutTests/js/script-tests/class-syntax-call.js

    r187680 r190847  
    3838shouldNotThrow('new (class { constructor() {} })()');
    3939shouldThrow('(class { constructor() {} })()', '"TypeError: Cannot call a class constructor"');
    40 shouldThrow('new (class extends null { constructor() { super() } })()', '"TypeError: undefined is not an object (evaluating \'super()\')"');
     40shouldThrow('new (class extends null { constructor() { super() } })()', '"TypeError: function is not a constructor (evaluating \'super()\')"');
    4141shouldThrow('(class extends null { constructor() { super() } })()', '"TypeError: Cannot call a class constructor"');
    4242
  • trunk/LayoutTests/js/script-tests/class-syntax-extends.js

    r187680 r190847  
    117117shouldBeTrue ('class x {}; new (class extends null { constructor () { return new x; } }) instanceof x');
    118118shouldThrow('new (class extends null { constructor () { this; } })', '"ReferenceError: Cannot access uninitialized variable."');
    119 shouldThrow('new (class extends null { constructor () { super(); } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');
     119shouldThrow('new (class extends null { constructor () { super(); } })', '"TypeError: function is not a constructor (evaluating \'super()\')"');
    120120shouldBe('x = {}; new (class extends null { constructor () { return x } })', 'x');
    121121shouldThrow('y = 12; new (class extends null { constructor () { return y; } })', '"TypeError: Cannot return a non-object type in the constructor of a derived class."');
  • trunk/LayoutTests/js/script-tests/class-syntax-super.js

    r187680 r190847  
    104104shouldThrow('new (class extends Base { constructor() { return 1; } })', '"TypeError: Cannot return a non-object type in the constructor of a derived class."');
    105105shouldThrow('new (class extends null { constructor() { return undefined } })');
    106 shouldThrow('new (class extends null { constructor() { super(); return undefined } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');
     106shouldThrow('new (class extends null { constructor() { super(); return undefined } })', '"TypeError: function is not a constructor (evaluating \'super()\')"');
    107107shouldBe('x = { }; new (class extends null { constructor() { return x } });', 'x');
    108108shouldBeTrue('x instanceof Object');
    109109shouldThrow('new (class extends null { constructor() { } })', '"ReferenceError: Cannot access uninitialized variable."');
    110110shouldThrow('new (class extends null { constructor() { return 1; } })', '"TypeError: Cannot return a non-object type in the constructor of a derived class."');
    111 shouldThrow('new (class extends null { constructor() { super() } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');
     111shouldThrow('new (class extends null { constructor() { super() } })', '"TypeError: function is not a constructor (evaluating \'super()\')"');
    112112shouldThrow('new (class { constructor() { super() } })', '"SyntaxError: Cannot call super() in a base class constructor."');
    113113shouldThrow('function x() { super(); }', '"SyntaxError: Cannot call super() outside of a class constructor."');
  • trunk/Source/JavaScriptCore/ChangeLog

    r190843 r190847  
     12015-10-11  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        ES6 classes: When a class extends B, super() invokes B.prototype.constructor() instead of B()
     4        https://bugs.webkit.org/show_bug.cgi?id=149001
     5
     6        Reviewed by Saam Barati.
     7
     8        This patch matches the `super()` call in the constructor to the latest spec.
     9        Before this patch, when calling `super()`, it loads `callee.[[HomeObject]].__proto__.constructor`
     10        as a super constructor. But after this patch, it loads `callee.__proto__` as a super constructor.
     11        This behavior corresponds to the section 12.3.5.2[1].
     12
     13        [1]: http://www.ecma-international.org/ecma-262/6.0/#sec-getsuperconstructor
     14
     15        * bytecompiler/NodesCodegen.cpp:
     16        (JSC::SuperNode::emitBytecode):
     17        * tests/stress/super-call-does-not-look-up-constructor.js: Added.
     18        (shouldBe):
     19        (B):
     20        (C):
     21        (B.prototype):
     22
    1232015-10-10  Andreas Kling  <akling@apple.com>
    224
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r190014 r190847  
    168168    callee.setIndex(JSStack::Callee);
    169169
    170     RefPtr<RegisterID> homeObject = generator.emitGetById(generator.newTemporary(), &callee, generator.propertyNames().homeObjectPrivateName);
    171     RefPtr<RegisterID> protoParent = generator.emitGetById(generator.newTemporary(), homeObject.get(), generator.propertyNames().underscoreProto);
    172     return generator.emitGetById(generator.finalDestination(dst), protoParent.get(), generator.propertyNames().constructor);
     170    return generator.emitGetById(generator.finalDestination(dst), &callee, generator.propertyNames().underscoreProto);
    173171}
    174172
Note: See TracChangeset for help on using the changeset viewer.