11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// This test ensures that an out of memory error exits with code 134 on Windows
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciif (!common.isWindows) return common.skip('Windows-only');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst assert = require('assert');
91cb0ef41Sopenharmony_ciconst { exec } = require('child_process');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciif (process.argv[2] === 'heapBomb') {
121cb0ef41Sopenharmony_ci  // Heap bomb, imitates a memory leak quickly
131cb0ef41Sopenharmony_ci  const fn = (nM) => [...Array(nM)].map((i) => fn(nM * 2));
141cb0ef41Sopenharmony_ci  fn(2);
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// Run child in tmpdir to avoid report files in repo
181cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
191cb0ef41Sopenharmony_citmpdir.refresh();
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// --max-old-space-size=3 is the min 'old space' in V8, explodes fast
221cb0ef41Sopenharmony_ciconst cmd = `"${process.execPath}" --max-old-space-size=30 "${__filename}"`;
231cb0ef41Sopenharmony_ciexec(`${cmd} heapBomb`, { cwd: tmpdir.path }, common.mustCall((err, stdout, stderr) => {
241cb0ef41Sopenharmony_ci  const msg = `Wrong exit code of ${err.code}! Expected 134 for abort`;
251cb0ef41Sopenharmony_ci  // Note: common.nodeProcessAborted() is not asserted here because it
261cb0ef41Sopenharmony_ci  // returns true on 134 as well as 0x80000003 (V8's base::OS::Abort)
271cb0ef41Sopenharmony_ci  assert.strictEqual(err.code, 134, msg);
281cb0ef41Sopenharmony_ci}));
29