Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report: disable js stack when no context is entered #48495

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static void PrintJavaScriptErrorStack(JSONWriter* writer,
Isolate* isolate,
Local<Value> error,
const char* trigger);
static void PrintEmptyJavaScriptStack(JSONWriter* writer);
static void PrintJavaScriptStack(JSONWriter* writer,
Isolate* isolate,
const char* trigger);
Expand Down Expand Up @@ -184,6 +185,10 @@ static void WriteNodeReport(Isolate* isolate,

// Report V8 Heap and Garbage Collector information
PrintGCStatistics(&writer, isolate);
} else {
writer.json_objectstart("javascriptStack");
PrintEmptyJavaScriptStack(&writer);
writer.json_objectend(); // the end of 'javascriptStack'
}

// Report native stack backtrace
Expand Down Expand Up @@ -452,8 +457,9 @@ static void PrintEmptyJavaScriptStack(JSONWriter* writer) {
static void PrintJavaScriptStack(JSONWriter* writer,
Isolate* isolate,
const char* trigger) {
// Can not capture the stacktrace when the isolate is in a OOM state.
if (!strcmp(trigger, "OOMError")) {
// Can not capture the stacktrace when the isolate is in a OOM state or no
// context is entered.
if (!strcmp(trigger, "OOMError") || !isolate->InContext()) {
PrintEmptyJavaScriptStack(writer);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions test/addons/report-api/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const tmpdir = require('../../common/tmpdir');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
const addon = require(binding);

function myAddonMain(method, { hasIsolate, hasEnv }) {
function myAddonMain(method, { hasContext, hasEnv }) {
tmpdir.refresh();
process.report.directory = tmpdir.path;

Expand All @@ -27,10 +27,10 @@ function myAddonMain(method, { hasIsolate, hasEnv }) {
const content = require(report);

// Check that the javascript stack is present.
if (hasIsolate) {
if (hasContext) {
assert.strictEqual(content.javascriptStack.stack.findIndex((frame) => frame.match('myAddonMain')), 0);
} else {
assert.strictEqual(content.javascriptStack, undefined);
assert.strictEqual(content.javascriptStack.message, 'No stack.');
}

if (hasEnv) {
Expand All @@ -45,9 +45,9 @@ const methods = [
['triggerReportNoIsolate', false, false],
['triggerReportEnv', true, true],
['triggerReportNoEnv', false, false],
['triggerReportNoContext', true, false],
['triggerReportNoContext', false, false],
['triggerReportNewContext', true, false],
];
for (const [method, hasIsolate, hasEnv] of methods) {
myAddonMain(method, { hasIsolate, hasEnv });
for (const [method, hasContext, hasEnv] of methods) {
myAddonMain(method, { hasContext, hasEnv });
}
8 changes: 4 additions & 4 deletions test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ function validateContent(report, fields = []) {

function _validateContent(report, fields = []) {
const isWindows = process.platform === 'win32';
const isJavaScriptThreadReport = report.javascriptStack != null;
const isJavaScriptThreadReport = report.javascriptHeap != null;

// Verify that all sections are present as own properties of the report.
const sections = ['header', 'nativeStack', 'libuv', 'environmentVariables',
'sharedObjects', 'resourceUsage', 'workers'];
const sections = ['header', 'nativeStack', 'javascriptStack', 'libuv',
'environmentVariables', 'sharedObjects', 'resourceUsage', 'workers'];
if (!isWindows)
sections.push('userLimits');

if (report.uvthreadResourceUsage)
sections.push('uvthreadResourceUsage');

if (isJavaScriptThreadReport)
sections.push('javascriptStack', 'javascriptHeap');
sections.push('javascriptHeap');

checkForUnknownFields(report, sections);
sections.forEach((section) => {
Expand Down