Skip to content

Commit bdcc037

Browse files
legendecasRafaelGSS
authored andcommitted
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. PR-URL: #48495Fixes: nodejs/node-v8#250 Refs: https://chromium-review.googlesource.com/c/v8/v8/+/4582948 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
1 parent 52de27b commit bdcc037

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎src/node_report.cc‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static void PrintJavaScriptErrorStack(JSONWriter* writer,
6666
Isolate* isolate,
6767
Local<Value> error,
6868
constchar* trigger);
69+
staticvoidPrintEmptyJavaScriptStack(JSONWriter* writer);
6970
staticvoidPrintJavaScriptStack(JSONWriter* writer,
7071
Isolate* isolate,
7172
constchar* trigger);
@@ -184,6 +185,10 @@ static void WriteNodeReport(Isolate* isolate,
184185

185186
// Report V8 Heap and Garbage Collector information
186187
PrintGCStatistics(&writer, isolate);
188+
} else {
189+
writer.json_objectstart("javascriptStack");
190+
PrintEmptyJavaScriptStack(&writer);
191+
writer.json_objectend(); // the end of 'javascriptStack'
187192
}
188193

189194
// Report native stack backtrace
@@ -452,8 +457,9 @@ static void PrintEmptyJavaScriptStack(JSONWriter* writer) {
452457
staticvoidPrintJavaScriptStack(JSONWriter* writer,
453458
Isolate* isolate,
454459
constchar* trigger) {
455-
// Can not capture the stacktrace when the isolate is in a OOM state.
456-
if (!strcmp(trigger, "OOMError")) {
460+
// Can not capture the stacktrace when the isolate is in a OOM state or no
461+
// context is entered.
462+
if (!strcmp(trigger, "OOMError") || !isolate->InContext()) {
457463
PrintEmptyJavaScriptStack(writer);
458464
return;
459465
}

‎test/addons/report-api/test.js‎

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

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

@@ -27,10 +27,10 @@ function myAddonMain(method, { hasIsolate, hasEnv }) {
2727
constcontent=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{
33-
assert.strictEqual(content.javascriptStack,undefined);
33+
assert.strictEqual(content.javascriptStack.message,'No stack.');
3434
}
3535

3636
if(hasEnv){
@@ -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]ofmethods){
52-
myAddonMain(method,{hasIsolate, hasEnv });
51+
for(const[method,hasContext,hasEnv]ofmethods){
52+
myAddonMain(method,{hasContext, hasEnv });
5353
}

‎test/common/report.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ function validateContent(report, fields = []) {
5555

5656
function_validateContent(report,fields=[]){
5757
constisWindows=process.platform==='win32';
58-
constisJavaScriptThreadReport=report.javascriptStack!=null;
58+
constisJavaScriptThreadReport=report.javascriptHeap!=null;
5959

6060
// Verify that all sections are present as own properties of the report.
61-
constsections=['header','nativeStack','libuv','environmentVariables',
62-
'sharedObjects','resourceUsage','workers'];
61+
constsections=['header','nativeStack','javascriptStack','libuv',
62+
'environmentVariables','sharedObjects','resourceUsage','workers'];
6363
if(!isWindows)
6464
sections.push('userLimits');
6565

6666
if(report.uvthreadResourceUsage)
6767
sections.push('uvthreadResourceUsage');
6868

6969
if(isJavaScriptThreadReport)
70-
sections.push('javascriptStack','javascriptHeap');
70+
sections.push('javascriptHeap');
7171

7272
checkForUnknownFields(report,sections);
7373
sections.forEach((section)=>{

0 commit comments

Comments
 (0)