is-constructing.js (1153B)
1 var isConstructing = getSelfHostedValue("IsConstructing"); 2 3 function testBasic() { 4 var f = function(expected) { 5 with(this) {}; // Don't inline. 6 assertEq(isConstructing(), expected); 7 }; 8 for (var i=0; i<40; i++) { 9 f(false); 10 new f(true); 11 } 12 } 13 testBasic(); 14 15 function testGeneric() { 16 var f1 = function(expected) { 17 with(this) {}; 18 assertEq(isConstructing(), expected); 19 }; 20 var f2 = function(expected) { 21 assertEq(isConstructing(), expected); 22 } 23 var funs = [f1, f2]; 24 for (var i=0; i<40; i++) { 25 var f = funs[i % 2]; 26 f(false); 27 new f(true); 28 } 29 } 30 testGeneric(); 31 32 function testArgsRectifier() { 33 var f = function(x) { 34 with(this) {}; 35 assertEq(isConstructing(), true); 36 }; 37 for (var i=0; i<40; i++) 38 new f(); 39 } 40 testArgsRectifier(); 41 42 function testBailout() { 43 var f1 = function(x, expected) { 44 if (x > 20) { 45 bailout(); 46 assertEq(isConstructing(), expected); 47 } 48 }; 49 var f2 = function(x) { 50 return new f1(x, true); 51 }; 52 var f3 = function(x) { 53 return f1(x, false); 54 }; 55 for (var i=0; i<40; i++) { 56 f2(i); 57 f3(i); 58 } 59 for (var i=0; i<40; i++) 60 f1(i, false); 61 } 62 testBailout();