Object-createSource-forceEnableAsmJS.js (3168B)
1 // |jit-test| --asmjs; skip-if: !wasmDebuggingEnabled() 2 3 gczeal(0); 4 5 const text = ` 6 function normalFunction() { 7 } 8 function asmJSModule(stdlib, foreign) { 9 "use asm"; 10 function asmJSFunction(x, y) { 11 x = x|0; 12 y = y|0; 13 return (x + y)|0; 14 } 15 return asmJSFunction; 16 } 17 `; 18 19 // Test the recompilation scenario. 20 for (const forceEnableAsmJS of [false, true]) { 21 const g = newGlobal({ newCompartment: true }); 22 23 g.evaluate(text, { 24 fileName: "test.js", 25 }); 26 27 const asmJSFunction = g.asmJSModule(globalThis, null); 28 assertEq(asmJSFunction(2, 3), 5); 29 30 const dbg = Debugger(); 31 const gdbg = dbg.addDebuggee(g); 32 33 gc(); 34 35 // The top-level script should be GC-ed. 36 const topLevelScriptObject = dbg.findScripts().find( 37 s => s.format == "js" && !s.isFunction); 38 assertEq(topLevelScriptObject, undefined); 39 40 // asmJSModule should be seen as WasmInstanceObject. 41 const asmJSModuleObject = dbg.findScripts().find( 42 s => s.format == "wasm"); 43 assertEq(!!asmJSModuleObject, true); 44 45 const source = gdbg.createSource({ 46 text, 47 url: "test.js", 48 startLine: 1, 49 forceEnableAsmJS, 50 }); 51 52 const asmJSModuleJSObject = dbg.findScripts().find( 53 s => s.format == "js" && s.displayName == "asmJSModule"); 54 if (forceEnableAsmJS) { 55 // If asm.js is force-enabled, createSource should enable the asm.js feature 56 // and the asmJSModule function should be compiled as a asm.js module again, 57 // and there shouldn't be BaseScript. 58 assertEq(asmJSModuleJSObject, undefined); 59 } else { 60 // If asm.js is not force-enabled, createSource should disable the asm.js 61 // feature, and the asmJSModule function should be compiled BaseScript. 62 assertEq(!!asmJSModuleJSObject, true); 63 } 64 } 65 66 // Test the initial compilation scenario. 67 for (const forceEnableAsmJS of [false, true]) { 68 const g = newGlobal({ newCompartment: true }); 69 70 const dbg = Debugger(); 71 const gdbg = dbg.addDebuggee(g); 72 73 const source = gdbg.createSource({ 74 text, 75 url: "test.js", 76 startLine: 1, 77 forceEnableAsmJS, 78 }); 79 80 const asmJSModuleJSObject = dbg.findScripts().find( 81 s => s.format == "js" && s.displayName == "asmJSModule"); 82 if (forceEnableAsmJS) { 83 // If asm.js is force-enabled, createSource should enable the asm.js feature 84 // and the asmJSModule function should be compiled as a asm.js module, and 85 // there shouldn't be BaseScript. 86 assertEq(asmJSModuleJSObject, undefined); 87 } else { 88 // If asm.js is not force-enabled, createSource should disable the asm.js 89 // feature, and the asmJSModule function should be compiled BaseScript. 90 // 91 // The asmJSModule script is not strongly held by anything, and it can be 92 // GCed at this point, depending on the GC timing. 93 // 94 // assertEq(!!asmJSModuleJSObject, true); 95 } 96 97 // If asm.js is not force-enabled, there shouldn't be WasmInstanceObject. 98 // 99 // Even if asm.js is force-enabled, the WasmInstanceObject is created only 100 // when the asmJSModule function is called, and there shouldn't be 101 // WasmInstanceObject yet. 102 const asmJSModuleObject = dbg.findScripts().find( 103 s => s.format == "wasm"); 104 assertEq(asmJSModuleObject, undefined); 105 }