Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2576)

Unified Diff: test/mjsunit/harmony/classes.js

Issue 680993003: Classes: Add basic support for properties (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: git rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/classes.js
diff --git a/test/mjsunit/harmony/classes.js b/test/mjsunit/harmony/classes.js
index a83d483bd9a20945d383f1bda233875fb87b748c..3a22fd9b5427dcf74873f541744fcd65c42a7978 100644
--- a/test/mjsunit/harmony/classes.js
+++ b/test/mjsunit/harmony/classes.js
@@ -153,6 +153,240 @@
})();
+
+(function TestToString() {
+ class C {}
+ assertEquals('class C {}', C.toString());
+
+ class D { constructor() { 42; } }
+ assertEquals('class D { constructor() { 42; } }', D.toString());
+
+ class E { x() { 42; } }
+ assertEquals('class E { x() { 42; } }', E.toString());
+})();
+
+
+function assertMethodDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertTrue(descr.enumerable);
+ assertTrue(descr.writable);
+ assertEquals('function', typeof descr.value);
+}
+
+function assertGetterDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertTrue(descr.enumerable);
+ assertEquals('function', typeof descr.get);
+ assertEquals(undefined, descr.set);
+}
+
+
+function assertSetterDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertTrue(descr.enumerable);
+ assertEquals(undefined, descr.get);
+ assertEquals('function', typeof descr.set);
+}
+
+
+function assertAccessorDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertTrue(descr.enumerable);
+ assertEquals('function', typeof descr.get);
+ assertEquals('function', typeof descr.set);
+}
+
+
+(function TestMethods() {
+ class C {
+ method() { return 1; }
+ static staticMethod() { return 2; }
+ method2() { return 3; }
+ static staticMethod2() { return 4; }
+ }
+
+ assertMethodDescriptor(C.prototype, 'method');
+ assertMethodDescriptor(C.prototype, 'method2');
+ assertMethodDescriptor(C, 'staticMethod');
+ assertMethodDescriptor(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; }
+ }
+
+ assertGetterDescriptor(C.prototype, 'x');
+ assertGetterDescriptor(C.prototype, 'y');
+ assertGetterDescriptor(C, 'staticX');
+ assertGetterDescriptor(C, '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; }
+ }
+
+ assertSetterDescriptor(C.prototype, 'x');
+ assertSetterDescriptor(C.prototype, 'y');
+ assertSetterDescriptor(C, 'staticX');
+ assertSetterDescriptor(C, '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; }
+ }
+
+ assertAccessorDescriptor(C.prototype, 'x');
+ assertAccessorDescriptor(C, '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; }
+ }
+ assertMethodDescriptor(C.prototype, '__proto__');
+ assertEquals(1, new C().__proto__());
+})();
+
+
+(function TestProtoStatic() {
+ class C {
+ static __proto__() { return 1; }
+ }
+ assertMethodDescriptor(C, '__proto__');
+ assertEquals(1, C.__proto__());
+})();
+
+
+(function TestProtoAccessor() {
+ class C {
+ get __proto__() { return this._p; }
+ set __proto__(v) { this._p = v; }
+ }
+ assertAccessorDescriptor(C.prototype, '__proto__');
+ 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; }
+ }
+ assertAccessorDescriptor(C, '__proto__');
+ C._p = 1;
+ assertEquals(1, C.__proto__);
+ C.__proto__ = 2;
+ assertEquals(2, C.__proto__);
+})();
+
+
+(function TestSettersOnProto() {
+ function Base() {}
+ Base.prototype = {
+ set constructor(_) {
+ assertUnreachable();
+ },
+ set m(_) {
+ assertUnreachable();
+ }
+ };
+ Object.defineProperty(Base, 'staticM', {
+ set: function() {
+ assertUnreachable();
+ }
+ });
+
+ class C extends Base {
+ m() {
+ return 1;
+ }
+ static staticM() {
+ return 2;
+ }
+ }
+
+ assertEquals(1, new C().m());
+ assertEquals(2, C.staticM());
+})();
+
/* TODO(arv): Implement
(function TestNameBindingInConstructor() {
class C {
@@ -165,15 +399,3 @@
new C();
})();
*/
-
-
-(function TestToString() {
- class C {}
- assertEquals('class C {}', C.toString());
-
- class D { constructor() { 42; } }
- assertEquals('class D { constructor() { 42; } }', D.toString());
-
- class E { x() { 42; } }
- assertEquals('class E { x() { 42; } }', E.toString());
-})();
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698