blob: e921b7e4b21b88ab838ae7dc468499984252f922 [file] [log] [blame]
mark.lam@apple.com20736fa2016-02-23 19:41:56 +00001var errors = "";
2var numTests = 0;
3
4function test(type) {
5 var didThrow = false;
6 try {
7 var bad = type(10);
8 } catch(e) {
9 didThrow = true;
10 }
11
12 if (!didThrow) {
13 errors += ("bad result: calling " + type.name + " as a function did not throw\n");
14 }
15 numTests++;
16
17 if (typeof type !== "function")
18 errors += ("bad result: typeof " + type.name + " is not function. Was " + (typeof type) + "\n");
19 numTests++;
20}
21
22// According to the spec, the constructors of the following types "are not intended to be
23// called as a function and will throw an exception". However, as constructors, their
24// type should be "function".
25
26// https://tc39.github.io/ecma262/#sec-typedarray-constructors
27test(Int8Array);
28test(Uint8Array);
29test(Uint8ClampedArray);
30test(Int16Array);
31test(Uint16Array);
32test(Int32Array);
33test(Uint32Array);
34test(Float32Array);
35test(Float64Array);
36
37// https://tc39.github.io/ecma262/#sec-map-constructor
38test(Map);
39// https://tc39.github.io/ecma262/#sec-set-constructor
40test(Set);
41// https://tc39.github.io/ecma262/#sec-weakmap-constructor
42test(WeakMap);
43// https://tc39.github.io/ecma262/#sec-weakset-constructor
44test(WeakSet);
45// https://tc39.github.io/ecma262/#sec-arraybuffer-constructor
46test(ArrayBuffer);
47// https://tc39.github.io/ecma262/#sec-dataview-constructor
48test(DataView);
49// https://tc39.github.io/ecma262/#sec-promise-constructor
50test(Promise);
51// https://tc39.github.io/ecma262/#sec-proxy-constructor
52test(Proxy);
53
54let expectedNumTests = 34;
55if (numTests != expectedNumTests) {
56 errors += "Not all tests were run: ran " + numTests + " out of " + expectedNumTests + " \n";
57}
58if (errors.length)
59 throw new Error(errors);