Skip to content

Commit b9dfdfe

Browse files
addaleaxMyles Borins
authored and
Myles Borins
committed
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: #6899 PR-URL: #6907 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 7d66752 commit b9dfdfe

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/node_contextify.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ class ContextifyContext {
205205

206206
Local<Context> ctx = Context::New(env->isolate(), nullptr, object_template);
207207

208-
CHECK(!ctx.IsEmpty());
208+
if (ctx.IsEmpty()) {
209+
env->ThrowError("Could not instantiate context");
210+
return Local<Context>();
211+
}
212+
209213
ctx->SetSecurityToken(env->context()->GetSecurityToken());
210214

211215
// We need to tie the lifetime of the sandbox object with the lifetime of
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const vm = require('vm');
5+
6+
function a() {
7+
try {
8+
return a();
9+
} catch (e) {
10+
// Throw an exception as near to the recursion-based RangeError as possible.
11+
return vm.runInThisContext('() => 42')();
12+
}
13+
}
14+
15+
assert.strictEqual(a(), 42);
16+
17+
function b() {
18+
try {
19+
return b();
20+
} catch (e) {
21+
// This writes a lot of noise to stderr, but it still works.
22+
return vm.runInNewContext('() => 42')();
23+
}
24+
}
25+
26+
assert.strictEqual(b(), 42);

0 commit comments

Comments
 (0)