incremental-encoder.js (1412B)
1 // |jit-test| skip-if: isLcovEnabled() 2 3 load(libdir + 'bytecode-cache.js'); 4 var test = ""; 5 6 // Check that without cloneSingleton, we can safely encode object literal which 7 // have mutations. 8 test = ` 9 var obj = { a: 1, b: 2 }; 10 obj.a++; 11 assertEq(obj.a, 2); 12 `; 13 evalWithCache(test, { 14 collectDelazifications: true, 15 assertEqResult : true 16 }); 17 18 19 // Encode lazy functions. 20 test = ` 21 function f() { return 1; }; 22 1; 23 `; 24 evalWithCache(test, { 25 collectDelazifications: true, 26 assertEqResult : true 27 }); 28 29 30 // Encode delazified functions. 31 test = ` 32 function f() { return 1; }; 33 f(); 34 `; 35 evalWithCache(test, { 36 collectDelazifications: true, 37 assertEqResult : true 38 }); 39 40 // Encode inner functions. 41 test = ` 42 function g() { 43 return function f() { return 1; }; 44 }; 45 g()(); 46 `; 47 evalWithCache(test, { 48 collectDelazifications: true, 49 assertEqResult : true 50 }); 51 52 // Extra zeal GCs can cause isRelazifiableFunction() to become true after we 53 // record its value by throwing away JIT code for the function. 54 gczeal(0); 55 56 // Relazified functions are encoded as non-lazy-script, when the encoding is 57 // incremental. 58 test = ` 59 assertEq(isLazyFunction(f), generation == 0 || generation == 3); 60 function f() { return isRelazifiableFunction(f); }; 61 expect = f(); 62 assertEq(isLazyFunction(f), false); 63 relazifyFunctions(f); 64 assertEq(isLazyFunction(f), expect); 65 `; 66 evalWithCache(test, { collectDelazifications: true });