| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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: --allow-natives-syntax | 5 // Flags: --allow-natives-syntax |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 | 9 |
| 10 function checkPrototypeChain(object, constructors) { | 10 function checkPrototypeChain(object, constructors) { |
| 11 var proto = object.__proto__; | 11 var proto = object.__proto__; |
| 12 for (var i = 0; i < constructors.length; i++) { | 12 for (var i = 0; i < constructors.length; i++) { |
| 13 assertEquals(constructors[i].prototype, proto); | 13 assertEquals(constructors[i].prototype, proto); |
| 14 assertEquals(constructors[i], proto.constructor); | 14 assertEquals(constructors[i], proto.constructor); |
| 15 proto = proto.__proto__; | 15 proto = proto.__proto__; |
| 16 } | 16 } |
| 17 } | 17 } |
| 18 | 18 |
| 19 | 19 |
| 20 (function() { | 20 (function() { |
| 21 class A extends Function { |
| 22 constructor(...args) { |
| 23 assertTrue(%IsConstructCall()); |
| 24 super(...args); |
| 25 this.a = 42; |
| 26 } |
| 27 } |
| 28 |
| 29 var o = new A("this.foo = 153;"); |
| 30 assertTrue(o instanceof Object); |
| 31 assertTrue(o instanceof Function); |
| 32 assertTrue(o instanceof A); |
| 33 assertEquals("function", typeof o); |
| 34 checkPrototypeChain(o, [A, Function, Object]); |
| 35 assertEquals(42, o.a); |
| 36 var oo = new o(); |
| 37 assertEquals(153, oo.foo); |
| 38 |
| 39 var o1 = new A("return 312;"); |
| 40 assertTrue(%HaveSameMap(o, o1)); |
| 41 })(); |
| 42 |
| 43 |
| 44 (function() { |
| 21 class A extends Boolean { | 45 class A extends Boolean { |
| 22 constructor(...args) { | 46 constructor(...args) { |
| 23 assertTrue(%IsConstructCall()); | 47 assertTrue(%IsConstructCall()); |
| 24 super(...args); | 48 super(...args); |
| 25 this.a = 42; | 49 this.a = 42; |
| 26 } | 50 } |
| 27 } | 51 } |
| 28 | 52 |
| 29 var o = new A(true); | 53 var o = new A(true); |
| 30 assertTrue(o instanceof Object); | 54 assertTrue(o instanceof Object); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 assertEquals(0xbebafeca, o.getUint32(0, true)); | 311 assertEquals(0xbebafeca, o.getUint32(0, true)); |
| 288 assertEquals(42, o.a); | 312 assertEquals(42, o.a); |
| 289 | 313 |
| 290 var o1 = new A(buffer); | 314 var o1 = new A(buffer); |
| 291 assertTrue(%HaveSameMap(o, o1)); | 315 assertTrue(%HaveSameMap(o, o1)); |
| 292 | 316 |
| 293 })(); | 317 })(); |
| 294 | 318 |
| 295 | 319 |
| 296 (function() { | 320 (function() { |
| 321 // TODO(ishell): remove once GeneratorFunction is available. |
| 322 var GeneratorFunction = (function*() {}).__proto__.constructor; |
| 323 class A extends GeneratorFunction { |
| 324 constructor(...args) { |
| 325 assertTrue(%IsConstructCall()); |
| 326 super(...args); |
| 327 this.a = 42; |
| 328 } |
| 329 } |
| 330 var generator_func = new A("var index = 0; while (index < 5) { yield ++index;
}"); |
| 331 assertTrue(generator_func instanceof Object); |
| 332 assertTrue(generator_func instanceof Function); |
| 333 assertTrue(generator_func instanceof GeneratorFunction); |
| 334 assertTrue(generator_func instanceof A); |
| 335 assertEquals("function", typeof generator_func); |
| 336 checkPrototypeChain(generator_func, [A, GeneratorFunction, Function, Object]); |
| 337 assertEquals(42, generator_func.a); |
| 338 |
| 339 var o = new generator_func(); |
| 340 assertTrue(o instanceof Object); |
| 341 assertTrue(o instanceof generator_func); |
| 342 assertEquals("object", typeof o); |
| 343 |
| 344 assertPropertiesEqual({done: false, value: 1}, o.next()); |
| 345 assertPropertiesEqual({done: false, value: 2}, o.next()); |
| 346 assertPropertiesEqual({done: false, value: 3}, o.next()); |
| 347 assertPropertiesEqual({done: false, value: 4}, o.next()); |
| 348 assertPropertiesEqual({done: false, value: 5}, o.next()); |
| 349 assertPropertiesEqual({done: true, value: undefined}, o.next()); |
| 350 |
| 351 var generator_func1 = new A("return 0;"); |
| 352 assertTrue(%HaveSameMap(generator_func, generator_func1)); |
| 353 })(); |
| 354 |
| 355 |
| 356 (function() { |
| 297 class A extends Boolean { | 357 class A extends Boolean { |
| 298 constructor() { | 358 constructor() { |
| 299 assertTrue(%IsConstructCall()); | 359 assertTrue(%IsConstructCall()); |
| 300 super(true); | 360 super(true); |
| 301 this.a00 = 0 | 361 this.a00 = 0 |
| 302 this.a01 = 0 | 362 this.a01 = 0 |
| 303 this.a02 = 0 | 363 this.a02 = 0 |
| 304 this.a03 = 0 | 364 this.a03 = 0 |
| 305 this.a04 = 0 | 365 this.a04 = 0 |
| 306 this.a05 = 0 | 366 this.a05 = 0 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 (function() { | 456 (function() { |
| 397 class A extends null {} | 457 class A extends null {} |
| 398 assertThrows("new A"); | 458 assertThrows("new A"); |
| 399 })(); | 459 })(); |
| 400 | 460 |
| 401 | 461 |
| 402 (function() { | 462 (function() { |
| 403 class A extends Symbol {} | 463 class A extends Symbol {} |
| 404 assertThrows("new A"); | 464 assertThrows("new A"); |
| 405 })(); | 465 })(); |
| OLD | NEW |