test_oom_comprehensive.js (1652B)
1 // |jit-test| --setpref=experimental.capture_oom_stack_trace=true; skip-if: !this.hasOwnProperty("getLastOOMStackTrace") 2 3 function assertCapturesOOMStackTrace(f, lineNo) { 4 // Clear any existing trace 5 var initialTrace = getLastOOMStackTrace(); 6 assertEq(initialTrace, null); 7 8 try { 9 f(); 10 assertEq(true, false, "Expected an OOM exception"); 11 } catch (e) { 12 print("✓ Exception caught: " + e); 13 14 // Check for captured stack trace 15 var finalTrace = getLastOOMStackTrace(); 16 assertEq(finalTrace !== null, true, "Expected a stack trace after OOM"); 17 18 print(finalTrace); 19 20 // Detailed analysis 21 var lines = finalTrace.split('\n'); 22 let re = new RegExp("#0.*test_oom_comprehensive\.js:" + lineNo) 23 assertEq(re.test(lines[0]), true, "Missing innermost frame"); 24 } 25 } 26 27 // Interpreter captures innermost frame 28 assertCapturesOOMStackTrace(function () { 29 function deepFunction() { 30 function evenDeeper() { 31 throwOutOfMemory(); 32 } 33 evenDeeper(); 34 } 35 deepFunction(); 36 }, 31); 37 38 if (getJitCompilerOptions()['baseline.enable']){ 39 // JITs capture innermost frame 40 assertCapturesOOMStackTrace(function () { 41 function deepFunction(shouldOOM) { 42 function evenDeeper() { 43 if (shouldOOM) { 44 assertEq(inJit(), true, "Should be JIT-compiled"); 45 throwOutOfMemory(); 46 } 47 } 48 evenDeeper(); 49 } 50 const MAX = 150; 51 for (let i = 0; i < MAX; i++) { 52 deepFunction(i >= MAX - 1); 53 } 54 }, 45); 55 }