| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --harmony | 5 // Flags: --harmony |
| 6 | 6 |
| 7 (function TestBasics() { | 7 (function TestBasics() { |
| 8 var C = class C {} | 8 var C = class C {} |
| 9 assertEquals(typeof C, 'function'); | 9 assertEquals(typeof C, 'function'); |
| 10 assertEquals(C.__proto__, Function.prototype); | 10 assertEquals(C.__proto__, Function.prototype); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 (function TestToString() { | 170 (function TestToString() { |
| 171 class C {} | 171 class C {} |
| 172 assertEquals('class C {}', C.toString()); | 172 assertEquals('class C {}', C.toString()); |
| 173 | 173 |
| 174 class D { constructor() { 42; } } | 174 class D { constructor() { 42; } } |
| 175 assertEquals('class D { constructor() { 42; } }', D.toString()); | 175 assertEquals('class D { constructor() { 42; } }', D.toString()); |
| 176 | 176 |
| 177 class E { x() { 42; } } | 177 class E { x() { 42; } } |
| 178 assertEquals('class E { x() { 42; } }', E.toString()); | 178 assertEquals('class E { x() { 42; } }', E.toString()); |
| 179 })(); | 179 })(); |
| 180 |
| 181 |
| 182 (function TestMethods() { |
| 183 class C { |
| 184 method() { return 1; } |
| 185 static staticMethod() { return 2; } |
| 186 method2() { return 3; } |
| 187 static staticMethod2() { return 4; } |
| 188 } |
| 189 |
| 190 assertEquals('function', typeof C.prototype.method); |
| 191 assertEquals('function', typeof C.prototype.method2); |
| 192 assertEquals('function', typeof C.staticMethod); |
| 193 assertEquals('function', typeof C.staticMethod2); |
| 194 |
| 195 assertEquals(1, new C().method()); |
| 196 assertEquals(2, C.staticMethod()); |
| 197 assertEquals(3, new C().method2()); |
| 198 assertEquals(4, C.staticMethod2()); |
| 199 })(); |
| 200 |
| 201 |
| 202 (function TestGetters() { |
| 203 class C { |
| 204 get x() { return 1; } |
| 205 static get staticX() { return 2; } |
| 206 get y() { return 3; } |
| 207 static get staticY() { return 4; } |
| 208 } |
| 209 |
| 210 assertTrue(C.prototype.hasOwnProperty('x')); |
| 211 assertTrue(C.hasOwnProperty('staticX')); |
| 212 assertTrue(C.prototype.hasOwnProperty('y')); |
| 213 assertTrue(C.hasOwnProperty('staticY')); |
| 214 |
| 215 assertEquals(1, new C().x); |
| 216 assertEquals(2, C.staticX); |
| 217 assertEquals(3, new C().y); |
| 218 assertEquals(4, C.staticY); |
| 219 })(); |
| 220 |
| 221 |
| 222 |
| 223 (function TestSetters() { |
| 224 var x, staticX, y, staticY; |
| 225 class C { |
| 226 set x(v) { x = v; } |
| 227 static set staticX(v) { staticX = v; } |
| 228 set y(v) { y = v; } |
| 229 static set staticY(v) { staticY = v; } |
| 230 } |
| 231 |
| 232 assertTrue(C.prototype.hasOwnProperty('x')); |
| 233 assertTrue(C.hasOwnProperty('staticX')); |
| 234 assertTrue(C.prototype.hasOwnProperty('y')); |
| 235 assertTrue(C.hasOwnProperty('staticY')); |
| 236 |
| 237 assertEquals(1, new C().x = 1); |
| 238 assertEquals(1, x); |
| 239 assertEquals(2, C.staticX = 2); |
| 240 assertEquals(2, staticX); |
| 241 assertEquals(3, new C().y = 3); |
| 242 assertEquals(3, y); |
| 243 assertEquals(4, C.staticY = 4); |
| 244 assertEquals(4, staticY); |
| 245 })(); |
| 246 |
| 247 |
| 248 (function TestAccessors() { |
| 249 class C { |
| 250 // constructor(x) { |
| 251 // this._x = x; |
| 252 // } |
| 253 |
| 254 get x() { return this._x; } |
| 255 set x(v) { this._x = v; } |
| 256 |
| 257 // static get staticX() { return this._x; } |
| 258 // static set staticX(v) { this._x = v; } |
| 259 } |
| 260 |
| 261 // assertTrue(C.prototype.hasOwnProperty('x')); |
| 262 // assertTrue(C.hasOwnProperty('staticX')); |
| 263 |
| 264 // var c = new C(1); |
| 265 // c._x = 1; |
| 266 // assertEquals(1, c.x); |
| 267 |
| 268 })(); |
| OLD | NEW |