load-nonsyntactic.js (1445B)
1 var nonSyntacticEnvironment = { field: 10 }; 2 3 var source = ` 4 function f() { 5 function g() { 6 function h() { 7 // Load out of non syntactic environment. 8 return field; 9 } 10 return h(); 11 } 12 return g(); 13 } 14 15 f()` 16 17 function check(before, after) { 18 var code = cacheEntry(source); 19 var res = evaluate(code, before); 20 assertEq(res, 10); 21 res = evaluate(code, after); 22 assertEq(res, 10); 23 } 24 25 26 check({ envChainObject: nonSyntacticEnvironment, saveBytecodeWithDelazifications: true, }, 27 { envChainObject: nonSyntacticEnvironment, loadBytecode: true }) 28 29 30 try { 31 var global = newGlobal(); 32 global.field = 10; 33 check({ envChainObject: nonSyntacticEnvironment, saveBytecodeWithDelazifications: true, }, 34 { global: global, loadBytecode: true }) 35 36 // Should have thrown 37 assertEq(false, true) 38 } catch (e) { 39 assertEq(/Incompatible cache contents/.test(e.message), true); 40 } 41 42 try { 43 check({ global: global, saveBytecodeWithDelazifications: true }, 44 { envChainObject: nonSyntacticEnvironment, loadBytecode: true }) 45 46 // Should have thrown 47 assertEq(false, true) 48 } catch (e) { 49 assertEq(/Incompatible cache contents/.test(e.message), true); 50 } 51 52 53 var nonSyntacticEnvironmentTwo = { field: 10 }; 54 check({ envChainObject: nonSyntacticEnvironment, saveBytecodeWithDelazifications: true, }, 55 { envChainObject: nonSyntacticEnvironmentTwo, loadBytecode: true })