| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Flags: --harmony-classes |
| 6 |
| 7 |
| 8 (function TestSuperKeyword() { |
| 9 function Base() { } |
| 10 function Derived() { } |
| 11 Derived.prototype = Object.create(Base.prototype); |
| 12 |
| 13 function fBase() { return "Base " + this.toString(); } |
| 14 |
| 15 Base.prototype.f = fBase.toMethod(Base.prototype); |
| 16 |
| 17 function fDerived() { |
| 18 assertEquals("Base this is Derived", super.f()); |
| 19 assertEquals("128 from Base", super[128]()); |
| 20 assertEquals("128 from Derived", this[128]()); |
| 21 assertEquals(15, super.x); |
| 22 assertEquals(27, this.x); |
| 23 assertEquals(27, super[42]); |
| 24 assertEquals(33, this[42]); |
| 25 super.x = 5; |
| 26 assertEquals(5, Base.prototype.x); |
| 27 assertEquals(5, super.x); |
| 28 assertEquals(27, this.x); |
| 29 super[42] = 6; |
| 30 assertEquals(6, Base.prototype[42]); |
| 31 assertEquals(6, super[42]); |
| 32 assertEquals(33, this[42]); |
| 33 |
| 34 return "Derived" |
| 35 } |
| 36 |
| 37 Base.prototype.x = 15; |
| 38 Base.prototype[42] = 27; |
| 39 Base.prototype[128] = function() { return "128 from Base"; } |
| 40 Derived.prototype[128] = function() { return "128 from Derived"; } |
| 41 Base.prototype.toString = function() { return "this is Base"; }; |
| 42 Derived.prototype.toString = function() { return "this is Derived"; }; |
| 43 Derived.prototype.x = 27; |
| 44 Derived.prototype[42] = 33; |
| 45 Derived.prototype.f = fDerived.toMethod(Derived.prototype); |
| 46 |
| 47 assertEquals("Base this is Base", new Base().f()); |
| 48 assertEquals("Derived", new Derived().f()); |
| 49 }()); |
| 50 |
| 51 (function TestSuperKeywordNonMethod() { |
| 52 function f() { |
| 53 super.unknown(); |
| 54 } |
| 55 |
| 56 function g() { |
| 57 super['unknown'] = 5; |
| 58 } |
| 59 assertThrows(f, ReferenceError); |
| 60 assertThrows(g, ReferenceError); |
| 61 }()); |
| OLD | NEW |