blob: bb14dbdabb6e961727329eed3c50a3fb6c7a9bb1 [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(function testNonConstructorStrict() {
6 "use strict";
7 assertThrows(function() {
8 return new Math.cos(...[1,2,3]);
9 }, TypeError);
10
11 assertThrows(function() {
12 var CallNull = null;
13 return new CallNull(...[1,2,3]);
14 }, TypeError);
15})();
16
17
18(function testNonConstructorSloppy() {
19 assertThrows(function() {
20 return new Math.cos(...[1,2,3]);
21 }, TypeError);
22
23 assertThrows(function() {
24 var CallNull = null;
25 return new CallNull(...[1,2,3]);
26 }, TypeError);
27})();
28
29
30(function testConstructStrict() {
31 "use strict";
32 function TestClass(a, b, c) {
33 this.wasCalled = true;
34 this.args = [a, b, c];
35 }
36 TestClass.prototype.method = function() {
37 return this.args;
38 }
39
40 assertInstanceof(new TestClass(...[1, 2, 3]), TestClass);
41 assertEquals([1, 2, 3], (new TestClass(...[1, 2, 3])).method());
42 assertEquals([1, 2, 3], (new TestClass(...[1, 2, 3])).args);
43 assertTrue((new TestClass(...[1, 2, 3])).wasCalled);
44})();
45
46
47(function testConstructSloppy() {
48 function TestClass(a, b, c) {
49 this.wasCalled = true;
50 this.args = [a, b, c];
51 }
52 TestClass.prototype.method = function() {
53 return this.args;
54 }
55
56 assertInstanceof(new TestClass(...[1, 2, 3]), TestClass);
57 assertEquals([1, 2, 3], (new TestClass(...[1, 2, 3])).method());
58 assertEquals([1, 2, 3], (new TestClass(...[1, 2, 3])).args);
59 assertTrue((new TestClass(...[1, 2, 3])).wasCalled);
60})();