mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 21:35:34 +00:00

Ensure that the debug context has an Environment assigned in case a fatal error is raised. The fatal exception handler in node.cc is not equipped to deal with contexts that don't have one and can't easily be taught that due to a deficiency in the V8 API: there is no way for the embedder to tell if the data index is in use. Fixes: https://github.com/iojs/io.js/issues/1190 PR-URL: https://github.com/iojs/io.js/pull/1229 Reviewed-By: Fedor Indutny <fedor@indutny.com>
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
var common = require('../common');
|
|
var assert = require('assert');
|
|
var vm = require('vm');
|
|
var spawn = require('child_process').spawn;
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext('*');
|
|
}, /SyntaxError/);
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext({ toString: assert.fail });
|
|
}, /AssertionError/);
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext('throw URIError("BAM")');
|
|
}, /URIError/);
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext('(function(f) { f(f) })(function(f) { f(f) })');
|
|
}, /RangeError/);
|
|
|
|
assert.equal(typeof(vm.runInDebugContext('this')), 'object');
|
|
assert.equal(typeof(vm.runInDebugContext('Debug')), 'object');
|
|
|
|
assert.strictEqual(vm.runInDebugContext(), undefined);
|
|
assert.strictEqual(vm.runInDebugContext(0), 0);
|
|
assert.strictEqual(vm.runInDebugContext(null), null);
|
|
assert.strictEqual(vm.runInDebugContext(undefined), undefined);
|
|
|
|
// See https://github.com/iojs/io.js/issues/1190, fatal errors should not
|
|
// crash the process.
|
|
var script = common.fixturesDir + '/vm-run-in-debug-context.js';
|
|
var proc = spawn(process.execPath, [script]);
|
|
var data = [];
|
|
proc.stdout.on('data', assert.fail);
|
|
proc.stderr.on('data', data.push.bind(data));
|
|
proc.once('exit', common.mustCall(function(exitCode, signalCode) {
|
|
assert.equal(exitCode, 1);
|
|
assert.equal(signalCode, null);
|
|
var haystack = Buffer.concat(data).toString('utf8');
|
|
assert(/SyntaxError: Unexpected token \*/.test(haystack));
|
|
}));
|
|
|
|
var proc = spawn(process.execPath, [script, 'handle-fatal-exception']);
|
|
proc.stdout.on('data', assert.fail);
|
|
proc.stderr.on('data', assert.fail);
|
|
proc.once('exit', common.mustCall(function(exitCode, signalCode) {
|
|
assert.equal(exitCode, 42);
|
|
assert.equal(signalCode, null);
|
|
}));
|