| 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() { | |
| 45 class A extends Boolean { | 21 class A extends Boolean { |
| 46 constructor(...args) { | 22 constructor(...args) { |
| 47 assertTrue(%IsConstructCall()); | 23 assertTrue(%IsConstructCall()); |
| 48 super(...args); | 24 super(...args); |
| 49 this.a = 42; | 25 this.a = 42; |
| 50 } | 26 } |
| 51 } | 27 } |
| 52 | 28 |
| 53 var o = new A(true); | 29 var o = new A(true); |
| 54 assertTrue(o instanceof Object); | 30 assertTrue(o instanceof Object); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 assertEquals(0xcafebabe, o.getUint32(0, false)); | 286 assertEquals(0xcafebabe, o.getUint32(0, false)); |
| 311 assertEquals(0xbebafeca, o.getUint32(0, true)); | 287 assertEquals(0xbebafeca, o.getUint32(0, true)); |
| 312 assertEquals(42, o.a); | 288 assertEquals(42, o.a); |
| 313 | 289 |
| 314 var o1 = new A(buffer); | 290 var o1 = new A(buffer); |
| 315 assertTrue(%HaveSameMap(o, o1)); | 291 assertTrue(%HaveSameMap(o, o1)); |
| 316 | 292 |
| 317 })(); | 293 })(); |
| 318 | 294 |
| 319 | 295 |
| 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() { | 296 (function() { |
| 357 class A extends Boolean { | 297 class A extends Boolean { |
| 358 constructor() { | 298 constructor() { |
| 359 assertTrue(%IsConstructCall()); | 299 assertTrue(%IsConstructCall()); |
| 360 super(true); | 300 super(true); |
| 361 this.a00 = 0 | 301 this.a00 = 0 |
| 362 this.a01 = 0 | 302 this.a01 = 0 |
| 363 this.a02 = 0 | 303 this.a02 = 0 |
| 364 this.a03 = 0 | 304 this.a03 = 0 |
| 365 this.a04 = 0 | 305 this.a04 = 0 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 (function() { | 396 (function() { |
| 457 class A extends null {} | 397 class A extends null {} |
| 458 assertThrows("new A"); | 398 assertThrows("new A"); |
| 459 })(); | 399 })(); |
| 460 | 400 |
| 461 | 401 |
| 462 (function() { | 402 (function() { |
| 463 class A extends Symbol {} | 403 class A extends Symbol {} |
| 464 assertThrows("new A"); | 404 assertThrows("new A"); |
| 465 })(); | 405 })(); |
| OLD | NEW |