Index: test/mjsunit/harmony/classes.js |
diff --git a/test/mjsunit/harmony/classes.js b/test/mjsunit/harmony/classes.js |
index a83d483bd9a20945d383f1bda233875fb87b748c..6ceb3ed53b33c14de8c4508a6f2f08a1ff3ea3da 100644 |
--- a/test/mjsunit/harmony/classes.js |
+++ b/test/mjsunit/harmony/classes.js |
@@ -177,3 +177,179 @@ |
class E { x() { 42; } } |
assertEquals('class E { x() { 42; } }', E.toString()); |
})(); |
+ |
Dmitry Lomov (no reviews)
2014/10/27 21:37:14
Additional tests:
1. Test that 'DefineProperty' i
arv (Not doing code reviews)
2014/10/27 22:20:53
I thought I tested that but I guess my tests where
Dmitry Lomov (no reviews)
2014/10/28 10:34:08
Acknowledged.
|
+ |
+(function TestMethods() { |
+ class C { |
+ method() { return 1; } |
+ static staticMethod() { return 2; } |
+ method2() { return 3; } |
+ static staticMethod2() { return 4; } |
+ } |
+ |
+ assertEquals('function', typeof C.prototype.method); |
+ assertEquals('function', typeof C.prototype.method2); |
+ assertEquals('function', typeof C.staticMethod); |
+ assertEquals('function', typeof C.staticMethod2); |
+ |
+ assertEquals(1, new C().method()); |
+ assertEquals(2, C.staticMethod()); |
+ assertEquals(3, new C().method2()); |
+ assertEquals(4, C.staticMethod2()); |
+})(); |
+ |
+ |
+(function TestGetters() { |
+ class C { |
+ get x() { return 1; } |
+ static get staticX() { return 2; } |
+ get y() { return 3; } |
+ static get staticY() { return 4; } |
+ } |
+ |
+ assertTrue(C.prototype.hasOwnProperty('x')); |
+ assertTrue(C.hasOwnProperty('staticX')); |
+ assertTrue(C.prototype.hasOwnProperty('y')); |
+ assertTrue(C.hasOwnProperty('staticY')); |
+ |
+ assertEquals(1, new C().x); |
+ assertEquals(2, C.staticX); |
+ assertEquals(3, new C().y); |
+ assertEquals(4, C.staticY); |
+})(); |
+ |
+ |
+ |
+(function TestSetters() { |
+ var x, staticX, y, staticY; |
+ class C { |
+ set x(v) { x = v; } |
+ static set staticX(v) { staticX = v; } |
+ set y(v) { y = v; } |
+ static set staticY(v) { staticY = v; } |
+ } |
+ |
+ assertTrue(C.prototype.hasOwnProperty('x')); |
+ assertTrue(C.hasOwnProperty('staticX')); |
+ assertTrue(C.prototype.hasOwnProperty('y')); |
+ assertTrue(C.hasOwnProperty('staticY')); |
+ |
+ assertEquals(1, new C().x = 1); |
+ assertEquals(1, x); |
+ assertEquals(2, C.staticX = 2); |
+ assertEquals(2, staticX); |
+ assertEquals(3, new C().y = 3); |
+ assertEquals(3, y); |
+ assertEquals(4, C.staticY = 4); |
+ assertEquals(4, staticY); |
+})(); |
+ |
+ |
+(function TestSideEffectsInPropertyDefine() { |
+ function B() {} |
+ B.prototype = { |
+ constructor: B, |
+ set m(v) { |
+ throw Error(); |
+ } |
+ }; |
+ |
+ class C extends B { |
+ m() { return 1; } |
+ } |
+ |
+ assertEquals(1, new C().m()); |
+})(); |
+ |
+ |
+(function TestAccessors() { |
+ class C { |
+ constructor(x) { |
+ this._x = x; |
+ } |
+ |
+ get x() { return this._x; } |
+ set x(v) { this._x = v; } |
+ |
+ static get staticX() { return this._x; } |
+ static set staticX(v) { this._x = v; } |
+ } |
+ |
+ assertTrue(C.prototype.hasOwnProperty('x')); |
+ assertTrue(C.hasOwnProperty('staticX')); |
+ |
+ var c = new C(1); |
+ c._x = 1; |
+ assertEquals(1, c.x); |
+ c.x = 2; |
+ assertEquals(2, c._x); |
+ |
+ C._x = 3; |
+ assertEquals(3, C.staticX); |
+ C._x = 4; |
+ assertEquals(4, C.staticX ); |
+})(); |
+ |
+ |
+(function TestProto() { |
+ class C { |
+ __proto__() { return 1; } |
+ } |
+ var descr = Object.getOwnPropertyDescriptor(C.prototype, '__proto__'); |
+ assertTrue(descr.configurable); |
+ assertTrue(descr.enumerable); |
+ assertTrue(descr.writable); |
+ assertEquals('function', typeof descr.value); |
+ assertEquals(1, descr.value()); |
+ assertEquals(1, C.prototype.__proto__()); |
+ assertEquals(1, new C().__proto__()); |
+})(); |
+ |
+ |
+(function TestProtoStatic() { |
+ class C { |
+ static __proto__() { return 1; } |
+ } |
+ var descr = Object.getOwnPropertyDescriptor(C, '__proto__'); |
+ assertTrue(descr.configurable); |
+ assertTrue(descr.enumerable); |
+ assertTrue(descr.writable); |
+ assertEquals('function', typeof descr.value); |
+ assertEquals(1, descr.value()); |
+ assertEquals(1, C.__proto__()); |
+})(); |
+ |
+ |
+(function TestProtoAccessor() { |
+ class C { |
+ get __proto__() { return this._p; } |
+ set __proto__(v) { this._p = v; } |
+ } |
+ var descr = Object.getOwnPropertyDescriptor(C.prototype, '__proto__'); |
+ assertTrue(descr.configurable); |
+ assertTrue(descr.enumerable); |
+ assertEquals('function', typeof descr.get); |
+ assertEquals('function', typeof descr.set); |
+ var c = new C(); |
+ c._p = 1; |
+ assertEquals(1, c.__proto__); |
+ c.__proto__ = 2; |
+ assertEquals(2, c.__proto__); |
+})(); |
+ |
+ |
+(function TestStaticProtoAccessor() { |
+ class C { |
+ static get __proto__() { return this._p; } |
+ static set __proto__(v) { this._p = v; } |
+ } |
+ var descr = Object.getOwnPropertyDescriptor(C, '__proto__'); |
+ assertTrue(descr.configurable); |
+ assertTrue(descr.enumerable); |
+ assertEquals('function', typeof descr.get); |
+ assertEquals('function', typeof descr.set); |
+ C._p = 1; |
+ assertEquals(1, C.__proto__); |
+ C.__proto__ = 2; |
+ assertEquals(2, C.__proto__); |
+})(); |