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