Skip to content

Commit 04223ff

Browse files
committed
report: disable js stack when no context is entered
There are no guarantees that the JS stack can be generated when no context is entered.
1 parent 9bdd172 commit 04223ff

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/node_report.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,9 @@ static void PrintEmptyJavaScriptStack(JSONWriter* writer) {
452452
static void PrintJavaScriptStack(JSONWriter* writer,
453453
Isolate* isolate,
454454
const char* trigger) {
455-
// Can not capture the stacktrace when the isolate is in a OOM state.
456-
if (!strcmp(trigger, "OOMError")) {
455+
// Can not capture the stacktrace when the isolate is in a OOM state or no
456+
// context is entered.
457+
if (!strcmp(trigger, "OOMError") || !isolate->InContext()) {
457458
PrintEmptyJavaScriptStack(writer);
458459
return;
459460
}

test/addons/report-api/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const tmpdir = require('../../common/tmpdir');
99
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
1010
const addon = require(binding);
1111

12-
function myAddonMain(method, { hasIsolate, hasEnv }) {
12+
function myAddonMain(method, { hasContext, hasEnv }) {
1313
tmpdir.refresh();
1414
process.report.directory = tmpdir.path;
1515

@@ -27,7 +27,7 @@ function myAddonMain(method, { hasIsolate, hasEnv }) {
2727
const content = require(report);
2828

2929
// Check that the javascript stack is present.
30-
if (hasIsolate) {
30+
if (hasContext) {
3131
assert.strictEqual(content.javascriptStack.stack.findIndex((frame) => frame.match('myAddonMain')), 0);
3232
} else {
3333
assert.strictEqual(content.javascriptStack, undefined);
@@ -45,9 +45,9 @@ const methods = [
4545
['triggerReportNoIsolate', false, false],
4646
['triggerReportEnv', true, true],
4747
['triggerReportNoEnv', false, false],
48-
['triggerReportNoContext', true, false],
48+
['triggerReportNoContext', false, false],
4949
['triggerReportNewContext', true, false],
5050
];
51-
for (const [method, hasIsolate, hasEnv] of methods) {
52-
myAddonMain(method, { hasIsolate, hasEnv });
51+
for (const [method, hasContext, hasEnv] of methods) {
52+
myAddonMain(method, { hasContext, hasEnv });
5353
}

0 commit comments

Comments
 (0)