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