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>
This commit is contained in:
Anna Henningsen authored and Myles Borins committed 2016-07-12 10:59:42 -07:00
1 parent 7d66752f1f
commit b9dfdfe1d3
2 files changed
+31 -1

No files matched your search

+5 -1
View File
@@ -205,7 +205,11 @@ class ContextifyContext {
Local<Context> ctx = Context::New(env->isolate(), nullptr, object_template);
CHECK(!ctx.IsEmpty());
if (ctx.IsEmpty()) {
env->ThrowError("Could not instantiate context");
return Local<Context>();
}
ctx->SetSecurityToken(env->context()->GetSecurityToken());
// We need to tie the lifetime of the sandbox object with the lifetime of
+26
View File
@@ -0,0 +1,26 @@
'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);