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