Debian Codegraph @

js/src/jit-test/tests/asm.js/testBug999790.js

raw
1 function CanBeConstructed(f) {
2 var caught = false;
3 try {
4 new f;
5 } catch (e) {
6 caught = true;
7 }
8 return !caught;
9 }
10
11 function IsConstructedFunction(f) {
12 return f.hasOwnProperty('length')
13 && f.hasOwnProperty('name')
14 && f.hasOwnProperty('prototype')
15 && f.prototype.hasOwnProperty('constructor')
16 && f.prototype.constructor === f;
17 }
18
19 function IsntConstructedFunction(f) {
20 return !f.hasOwnProperty('length')
21 && !f.hasOwnProperty('name')
22 && !f.hasOwnProperty('prototype')
23 }
24
25 var m = function() {
26 "use asm"
27 function g(){}
28 return g;
29 };
30 assertEq(CanBeConstructed(m), true, "asm.js modules can't be constructed");
31
32 var objM = new m;
33 assertEq(IsConstructedFunction(objM), true);
34
35 var g = m();
36 assertEq(CanBeConstructed(g), true, "asm.js functions can't be constructed");
37 // g is a ctor returning an primitive value, thus an empty object
38 assertEq(Object.getOwnPropertyNames(new g).length, 0);
39
40 var n = function() {
41 "use asm"
42 function g(){return 42.0}
43 function h(){return 42}
44 return {
45 g: g,
46 h: h
47 };
48 };
49 assertEq(CanBeConstructed(n), true, "asm.js modules can't be constructed");
50
51 var objN = new n;
52 // objN is an object with attributes g and h
53 assertEq(IsntConstructedFunction(objN), true);
54 assertEq(objN.hasOwnProperty('g'), true);
55 assertEq(objN.hasOwnProperty('h'), true);
56
57 assertEq(IsConstructedFunction(objN.g), true);
58 assertEq(IsConstructedFunction(objN.h), true);
59
60 var h = n().h;
61 assertEq(CanBeConstructed(h), true, "asm.js functions can't be constructed");
62 // h is a ctor returning an primitive value, thus an empty object
63 assertEq(Object.getOwnPropertyNames(new h).length, 0);
64
65 assertEq(typeof(function() {"use asm"; return {}}.prototype) !== 'undefined', true);