propertyOptimize-3.js (1306B)
1 // Properties cleared in the middle of a single function constructor. 2 3 function foo(x, y) { 4 this.f = 0; 5 this.g = x + y; 6 this.h = 2; 7 } 8 9 var called = false; 10 var a = 0; 11 var b = {valueOf: function() { Object.defineProperty(Object.prototype, 'g', {set: function() { called = true }}) }}; 12 var c = new foo(a, b); 13 14 assertEq(called, true); 15 assertEq(c.g, undefined); 16 17 // Properties cleared in the middle of a constructor callee. 18 19 function foo2(x, y) { 20 this.a = 0; 21 this.b = 1; 22 bar2.call(this, x, y); 23 this.c = 2; 24 } 25 function bar2(x, y) { 26 this.d = x + y; 27 this.e = 3; 28 } 29 30 var called2 = false; 31 var xa = 0; 32 var xb = {valueOf: function() { Object.defineProperty(Object.prototype, 'e', {set: function() { called2 = true }}) }}; 33 var xc = new foo2(xa, xb); 34 35 assertEq(called2, true); 36 assertEq(xc.e, undefined); 37 assertEq(xc.c, 2); 38 39 // Properties cleared after a constructor callee. 40 41 function foo3() { 42 this.aa = 0; 43 this.bb = 1; 44 bar3.call(this); 45 this.cc = 2; 46 baz(); 47 xbar3.call(this); 48 this.dd = 3; 49 } 50 function bar3() { 51 this.ee = 4; 52 } 53 function xbar3() { 54 this.ff = 5; 55 } 56 function baz() { 57 eval("xbar3.call = function() { called3 = true }"); 58 } 59 60 var called3 = false; 61 var c3 = new foo3(); 62 assertEq(c3.cc, 2); 63 assertEq(c3.ee, 4); 64 assertEq(c3.ff, undefined); 65 assertEq(c3.dd, 3); 66 assertEq(called3, true);