Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9dfdfe

Browse filesBrowse files
addaleaxMyles Borins
authored andcommitted
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 <info@bnoordhuis.nl>
1 parent 7d66752 commit b9dfdfe
Copy full SHA for b9dfdfe

File tree

Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed
Open diff view settings
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+5-1Lines changed: 5 additions & 1 deletion
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
Collapse file
+26Lines changed: 26 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.