Chromium Code Reviews| Index: test/mjsunit/harmony/super.js |
| diff --git a/test/mjsunit/harmony/super.js b/test/mjsunit/harmony/super.js |
| index 89fb4b1c1689ef60c1c6aec3813d4b09170d728b..809ba1071d71670dec0015709e07939987405fb6 100644 |
| --- a/test/mjsunit/harmony/super.js |
| +++ b/test/mjsunit/harmony/super.js |
| @@ -18,6 +18,8 @@ |
| function fDerived() { |
| assertEquals("Base this is Derived", super.f()); |
| + var a = super.x; |
| + assertEquals(15, a); |
| assertEquals(15, super.x); |
| assertEquals(27, this.x); |
| @@ -34,6 +36,7 @@ |
| assertEquals("Derived", new Derived().f()); |
| }()); |
| + |
| (function TestSuperKeywordNonMethod() { |
| function f() { |
| super.unknown(); |
| @@ -65,12 +68,17 @@ |
| Derived.prototype.testGetter = function() { |
| return super.x; |
| }.toMethod(Derived.prototype); |
| + Derived.prototype.testGetterStrict = function() { |
| + 'use strict'; |
| + return super.x; |
| + }.toMethod(Derived.prototype); |
| derived = new Derived(); |
| assertEquals('derived', derived.testGetter()); |
| + derived = new Derived(); |
| + assertEquals('derived', derived.testGetterStrict()); |
| }()); |
| -/* |
| - * TODO[dslomov]: named stores and keyed loads/stores not implemented yet. |
| + |
| (function TestSetter() { |
| function Base() {} |
| Base.prototype = { |
| @@ -92,36 +100,135 @@ |
| _x: 'derived' |
| }; |
| Derived.prototype.testSetter = function() { |
| - super.x = 'foobar'; |
| - }.toMethod(Derived.prototype); |
| + assertEquals('foobar', super.x = 'foobar'); |
| + assertEquals('foobarabc', super.x += 'abc'); |
| + }.toMethod(Derived.prototype); |
| var d = new Derived(); |
| d.testSetter(); |
| assertEquals('base', Base.prototype._x); |
| - assertEquals('foobar', d._x); |
| + assertEquals('foobarabc', d._x); |
| + d._x = ''; |
| + Derived.prototype.testSetterStrict = function() { |
| + 'use strict'; |
| + assertEquals('foobar', super.x = 'foobar'); |
| + assertEquals('foobarabc', super.x += 'abc'); |
| + }.toMethod(Derived.prototype); |
| + d.testSetterStrict(); |
| + assertEquals('base', Base.prototype._x); |
| + assertEquals('foobarabc', d._x); |
| }()); |
| -(function TestKeyedGetter() { |
| +(function TestAccessorsOnPrimitives() { |
| + var getCalled = false; |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
Tip: These kinds of tests are always better writte
|
| + var setCalled = false; |
| function Base() {} |
| Base.prototype = { |
| constructor: Base, |
| - _x: 'base' |
| + get x() { |
| + getCalled = true; |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
getCalls++;
|
| + return 1; |
| + }, |
| + set x(v) { |
| + setCalled = true; |
| + return v; |
| + }, |
| }; |
| - 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()); |
| + Derived.prototype.testSetter = function() { |
| + assertTrue(42 == this); |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
If this is sloppy, should we not get a wrapper her
|
| + getCalled = false; |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
getCalls = 0;
|
| + setCalled = false; |
| + assertEquals(1, super.x); |
| + assertTrue(getCalled); |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
assertEquals(1, getCalls);
|
| + assertFalse(setCalled); |
| + |
| + setCalled = false; |
| + getCalled = false; |
| + assertEquals(5, super.x = 5); |
| + assertFalse(getCalled); |
| + assertTrue(setCalled); |
| + |
| + getCalled = false; |
| + setCalled = false; |
| + assertEquals(6, super.x += 5); |
| + assertTrue(getCalled); |
| + assertTrue(setCalled); |
| + }.toMethod(Derived.prototype); |
| + |
| + Derived.prototype.testSetterStrict = function() { |
| + 'use strict'; |
| + assertTrue(42 == this); |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
=== and/or add typeof assert.
|
| + getCalled = false; |
| + setCalled = false; |
| + assertEquals(1, super.x); |
| + assertTrue(getCalled); |
| + assertFalse(setCalled); |
| + |
| + setCalled = false; |
| + getCalled = false; |
| + assertEquals(5, super.x = 5); |
| + assertFalse(getCalled); |
| + assertTrue(setCalled); |
| + |
| + getCalled = false; |
| + setCalled = false; |
| + assertEquals(6, super.x += 5); |
| + assertTrue(getCalled); |
| + assertTrue(setCalled); |
| + }.toMethod(Derived.prototype); |
| + |
| + Derived.prototype.testSetter.call(42); |
| + Derived.prototype.testSetterStrict.call(42); |
| + |
| + function DerivedFromString() {} |
| + DerivedFromString.prototype = Object.create(String.prototype); |
| + |
| + function f() { |
| + 'use strict'; |
| + assertTrue(42 == this); |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
here as well. == is just too lenient to use for th
|
| + assertEquals(String.prototype.toString, super.toString); |
| + var except = false; |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
assertThrows cannot be used here but the following
|
| + try { |
| + super.toString(); |
| + } catch(e) { except = true; } |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
ws after catch (like if, for, while, etc)
|
| + assertTrue(except); |
| + } |
| + f.toMethod(DerivedFromString.prototype).call(42); |
| +}()); |
| + |
| + |
| +(function TestSetterFailures() { |
| + function Base() {} |
| + function Derived() {} |
| + Derived.prototype = { __proto__ : Base.prototype }; |
| + Derived.prototype.mSloppy = function () { |
| + super.x = 10; |
| + assertEquals(undefined, super.x); |
| + }.toMethod(Derived.prototype); |
| + |
| + Derived.prototype.mStrict = function () { |
| + "use strict"; |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
Don't mix and match quotes. Stick to '
|
| + super.x = 10; |
| + }.toMethod(Derived.prototype); |
| + var d = new Derived(); |
| + d.mSloppy(); |
| + assertEquals(undefined, d.x); |
| + var d1 = new Derived(); |
| + assertThrows(function() { d.mStrict(); }, ReferenceError); |
| + assertEquals(undefined, d.x); |
| +}()); |
| + |
| + |
| +(function TestUnsupportedCases() { |
| + function f1(x) { return super[x]; } |
| + var o = {} |
|
arv (Not doing code reviews)
2014/09/29 14:37:27
;
|
| + assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); |
| + function f2() { super.x++; } |
| + assertThrows(function(){f2.toMethod(o)();}, ReferenceError); |
| }()); |
| -*/ |