0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-vm-low-stack-space.js
Anna Henningsen 4bd410bbbe
vm: don't abort process when stack space runs out
Make less assumptions about what objects will be available when
vm context creation or error message printing fail because V8
runs out of JS stack space.

Ref: https://github.com/nodejs/node/issues/6899
PR-URL: https://github.com/nodejs/node/pull/6907
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-24 17:03:02 +02:00

27 lines
517 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const vm = require('vm');
function a() {
try {
return a();
} catch (e) {
// Throw an exception as near to the recursion-based RangeError as possible.
return vm.runInThisContext('() => 42')();
}
}
assert.strictEqual(a(), 42);
function b() {
try {
return b();
} catch (e) {
// This writes a lot of noise to stderr, but it still works.
return vm.runInNewContext('() => 42')();
}
}
assert.strictEqual(b(), 42);