Chromium Code Reviews| Index: test/mjsunit/harmony/super.js |
| diff --git a/test/mjsunit/harmony/super.js b/test/mjsunit/harmony/super.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9cd99a1e2ce1060c3f1e6fb0d579c293975c5c20 |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/super.js |
| @@ -0,0 +1,144 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +// Flags: --harmony-classes |
| + |
| + |
| +(function TestSuperKeyword() { |
| + function Base() { } |
| + function Derived() { |
| + this.derivedDataProperty = "xxx"; |
| + } |
| + Derived.prototype = Object.create(Base.prototype); |
| + |
| + function fBase() { return "Base " + this.toString(); } |
| + |
| + Base.prototype.f = fBase.toMethod(Base.prototype); |
| + |
| + function fDerived() { |
| + assertEquals("Base this is Derived", super.f()); |
| + assertEquals("128 from Base", super[128]()); |
| + assertEquals("128 from Derived", this[128]()); |
| + assertEquals(15, super.x); |
| + assertEquals(27, this.x); |
| + assertEquals(27, super[42]); |
| + assertEquals(33, this[42]); |
| + super.x = 5; |
| + assertEquals(5, Base.prototype.x); |
| + assertEquals(5, super.x); |
| + assertEquals(27, this.x); |
| + super[42] = 6; |
| + assertEquals(6, Base.prototype[42]); |
| + assertEquals(6, super[42]); |
| + assertEquals(33, this[42]); |
| + |
| + return "Derived" |
| + } |
| + |
| + Base.prototype.x = 15; |
| + Base.prototype[42] = 27; |
| + Base.prototype[128] = function() { return "128 from Base"; } |
| + Derived.prototype[128] = function() { return "128 from Derived"; } |
| + Base.prototype.toString = function() { return "this is Base"; }; |
| + Derived.prototype.toString = function() { return "this is Derived"; }; |
| + Derived.prototype.x = 27; |
| + Derived.prototype[42] = 33; |
| + Derived.prototype.f = fDerived.toMethod(Derived.prototype); |
| + |
| + assertEquals("Base this is Base", new Base().f()); |
| + assertEquals("Derived", new Derived().f()); |
| +}()); |
| + |
| +(function TestSuperKeywordNonMethod() { |
| + function f() { |
| + super.unknown(); |
| + } |
| + |
| + function g() { |
| + super['unknown'] = 5; |
| + } |
| + assertThrows(f, ReferenceError); |
| + assertThrows(g, ReferenceError); |
| +}()); |
| + |
| + |
| +(function TestGetter() { |
| + function Base() {} |
| + Base.prototype = { |
| + constructor: Base, |
| + get x() { |
| + return this._x; |
|
arv (Not doing code reviews)
2014/09/09 22:38:46
maybe assert that this === derived
var derived =
Dmitry Lomov (no reviews)
2014/09/15 12:31:12
Done.
|
| + }, |
| + _x: 'base' |
| + }; |
| + |
| + function Derived() {} |
| + Derived.__proto__ = Base; |
| + Derived.prototype = { |
| + __proto__: Base.prototype, |
| + constructor: Derived, |
| + _x: 'derived' |
| + }; |
| + Derived.prototype.testGetter = function() { |
| + return super.x; |
| + }.toMethod(Derived.prototype); |
|
arv (Not doing code reviews)
2014/09/09 22:38:46
wrong indentation
Dmitry Lomov (no reviews)
2014/09/15 12:31:12
Done.
|
| + assertEquals('derived', new Derived().testGetter()); |
| +}()); |
| + |
| +/* |
| + * TODO[dslomov]: named stores and keyed loads/stores not implemented yet. |
| +(function TestSetter() { |
| + function Base() {} |
| + Base.prototype = { |
| + constructor: Base, |
| + get x() { |
| + return this._x; |
| + }, |
| + set x(v) { |
| + this._x = v; |
| + }, |
| + _x: 'base' |
| + }; |
| + |
| + function Derived() {} |
| + Derived.__proto__ = Base; |
| + Derived.prototype = { |
| + __proto__: Base.prototype, |
| + constructor: Derived, |
| + _x: 'derived' |
| + }; |
| + Derived.prototype.testSetter = function() { |
| + super.x = 'foobar'; |
| + }.toMethod(Derived.prototype); |
| + var d = new Derived(); |
| + d.testSetter(); |
| + assertEquals('base', Base.prototype._x); |
| + assertEquals('foobar', d._x); |
| +}()); |
| + |
| + |
| +(function TestKeyedGetter() { |
| + function Base() {} |
| + Base.prototype = { |
| + constructor: Base, |
| + _x: 'base' |
| + }; |
| + |
| + Object.defineProperty(Base.prototype, '0', |
| + { get: function() { return this._x; } }); |
| + |
| + function Derived() {} |
| + Derived.__proto__ = Base; |
| + Derived.prototype = { |
| + __proto__: Base.prototype, |
| + constructor: Derived, |
| + _x: 'derived' |
| + }; |
| + Derived.prototype.testGetter = function() { |
| + return super[0]; |
| + }.toMethod(Derived.prototype); |
| + assertEquals('derived', new Derived()[0]); |
| + // assertEquals('derived', new Derived().testGetter()); |
| +}()); |
| +*/ |