objectfuse-global-state.js (1515B)
1 // |jit-test| --setpref=objectfuse_for_global=true 2 3 function markConstant(obj, key) { 4 assertEq(getObjectFuseState(obj).properties[key], "Untracked"); 5 // This relies on the fact that storing to an Untracked property marks it 6 // Constant. Use getOwnPropertyDescriptor to prevent interacting with JIT 7 // optimizations. 8 obj[key] = Object.getOwnPropertyDescriptor(obj, key).value; 9 } 10 function testGlobal() { 11 var g = newGlobal({sameCompartmentAs: this, useWindowProxy: false}); 12 addObjectFuse(g); 13 assertEq(getObjectFuseState(g).generation, 0); 14 15 // Ensure global variables are marked untracked or constant. 16 g.evaluate("var foo = 1; var bar; bar = function() {}; function baz() {};"); 17 var state = getObjectFuseState(g); 18 assertEq(state.properties.foo, "Constant"); 19 assertEq(state.properties.bar, "Constant"); 20 assertEq(state.properties.baz, "Untracked"); 21 22 // Shadowing a non-constant global on the lexical environment doesn't change 23 // the generation. 24 g.evaluate("let Object = {};"); 25 assertEq(getObjectFuseState(g).generation, 0); 26 27 // Shadowing a constant property does change the generation. 28 markConstant(g, "Function"); 29 g.evaluate("let Function = {};"); 30 assertEq(getObjectFuseState(g).generation, 1); 31 32 // Shadowing a no-longer-constant property must also change the generation because 33 // IC stubs may still have guards for this property. 34 g.Math = 1; 35 g.Math = 2; 36 g.evaluate("let Math = {};"); 37 assertEq(getObjectFuseState(g).generation, 2); 38 } 39 testGlobal(); 40 testGlobal();