Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | |
| 6 | class Base {} |
| 7 | |
| 8 | class DerivedWithReturn extends Base { |
| 9 | constructor(x) { |
| 10 | super(); |
| 11 | return x; |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | assertThrows(function() { |
| 16 | new DerivedWithReturn(null); |
| 17 | }, TypeError); |
| 18 | assertThrows(function() { |
| 19 | new DerivedWithReturn(42); |
| 20 | }, TypeError); |
| 21 | assertThrows(function() { |
| 22 | new DerivedWithReturn(true); |
| 23 | }, TypeError); |
| 24 | assertThrows(function() { |
| 25 | new DerivedWithReturn('hi'); |
| 26 | }, TypeError); |
| 27 | assertThrows(function() { |
| 28 | new DerivedWithReturn(Symbol()); |
| 29 | }, TypeError); |
| 30 | |
| 31 | |
| 32 | assertInstanceof(new DerivedWithReturn(undefined), DerivedWithReturn); |
| 33 | function f() {} |
| 34 | assertInstanceof(new DerivedWithReturn(new f()), f); |
| 35 | assertInstanceof(new DerivedWithReturn(/re/), RegExp); |
| 36 | |
| 37 | |
| 38 | class DerivedWithReturnNoSuper extends Base { |
| 39 | constructor(x) { |
| 40 | return x; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | |
| 45 | assertThrows(function() { |
| 46 | new DerivedWithReturnNoSuper(null); |
| 47 | }, TypeError); |
| 48 | assertThrows(function() { |
| 49 | new DerivedWithReturnNoSuper(42); |
| 50 | }, TypeError); |
| 51 | assertThrows(function() { |
| 52 | new DerivedWithReturnNoSuper(true); |
| 53 | }, TypeError); |
| 54 | assertThrows(function() { |
| 55 | new DerivedWithReturnNoSuper('hi'); |
| 56 | }, TypeError); |
| 57 | assertThrows(function() { |
| 58 | new DerivedWithReturnNoSuper(Symbol()); |
| 59 | }, TypeError); |
| 60 | assertThrows(function() { |
| 61 | new DerivedWithReturnNoSuper(undefined); |
| 62 | }, ReferenceError); |
| 63 | |
| 64 | |
| 65 | function f2() {} |
| 66 | assertInstanceof(new DerivedWithReturnNoSuper(new f2()), f2); |
| 67 | assertInstanceof(new DerivedWithReturnNoSuper(/re/), RegExp); |
| 68 | |
| 69 | |
| 70 | class DerivedReturn extends Base { |
| 71 | constructor() { |
| 72 | super(); |
| 73 | return; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | assertInstanceof(new DerivedReturn(), DerivedReturn); |
| 78 | |
| 79 | |
| 80 | |
| 81 | class DerivedReturnThis extends Base { |
| 82 | constructor() { |
| 83 | super(); |
| 84 | return this; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | assertInstanceof(new DerivedReturnThis(), DerivedReturnThis); |