1'use strict'; 2const common = require('../common'); 3 4// This test ensures that an out of memory error exits with code 134 on Windows 5 6if (!common.isWindows) return common.skip('Windows-only'); 7 8const assert = require('assert'); 9const { exec } = require('child_process'); 10 11if (process.argv[2] === 'heapBomb') { 12 // Heap bomb, imitates a memory leak quickly 13 const fn = (nM) => [...Array(nM)].map((i) => fn(nM * 2)); 14 fn(2); 15} 16 17// Run child in tmpdir to avoid report files in repo 18const tmpdir = require('../common/tmpdir'); 19tmpdir.refresh(); 20 21// --max-old-space-size=3 is the min 'old space' in V8, explodes fast 22const cmd = `"${process.execPath}" --max-old-space-size=30 "${__filename}"`; 23exec(`${cmd} heapBomb`, { cwd: tmpdir.path }, common.mustCall((err, stdout, stderr) => { 24 const msg = `Wrong exit code of ${err.code}! Expected 134 for abort`; 25 // Note: common.nodeProcessAborted() is not asserted here because it 26 // returns true on 134 as well as 0x80000003 (V8's base::OS::Abort) 27 assert.strictEqual(err.code, 134, msg); 28})); 29