[JSC] Do not use asArrayModes() with Structures because it discards TypedArray inform...
[WebKit-https.git] / JSTests / stress / call-non-calleable-constructors-as-function.js
1 var errors = "";
2 var numTests = 0;
3
4 function 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
27 test(Int8Array);
28 test(Uint8Array);
29 test(Uint8ClampedArray);
30 test(Int16Array);
31 test(Uint16Array);
32 test(Int32Array);
33 test(Uint32Array);
34 test(Float32Array);
35 test(Float64Array);
36
37 // https://tc39.github.io/ecma262/#sec-map-constructor
38 test(Map);
39 // https://tc39.github.io/ecma262/#sec-set-constructor
40 test(Set);
41 // https://tc39.github.io/ecma262/#sec-weakmap-constructor
42 test(WeakMap);
43 // https://tc39.github.io/ecma262/#sec-weakset-constructor
44 test(WeakSet);
45 // https://tc39.github.io/ecma262/#sec-arraybuffer-constructor
46 test(ArrayBuffer);
47 // https://tc39.github.io/ecma262/#sec-dataview-constructor
48 test(DataView);
49 // https://tc39.github.io/ecma262/#sec-promise-constructor
50 test(Promise);
51 // https://tc39.github.io/ecma262/#sec-proxy-constructor
52 test(Proxy);
53
54 let expectedNumTests = 34;
55 if (numTests != expectedNumTests) {
56     errors += "Not all tests were run: ran " + numTests + " out of " + expectedNumTests + " \n";
57 }
58 if (errors.length)
59     throw new Error(errors);