GeezerVison is showing github.com — report: get stack trace with cross origin contexts · jigfox/node@f7896d4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_errors.cc +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -513,6 +513,11 @@ void OOMErrorHandler(const char* location, bool is_heap_oom) { | 513 | 513 | } | 514 | 514 |
| 515 | 515 | if (report_on_fatalerror) { | | 516 | + // Trigger report with the isolate. Environment::GetCurrent may return | | 517 | + // nullptr here: | | 518 | + // - If the OOM is reported by a young generation space allocation, | | 519 | + // Isolate::GetCurrentContext returns an empty handle. | | 520 | + // - Otherwise, Isolate::GetCurrentContext returns a non-empty handle. | 516 | 521 | TriggerNodeReport(isolate, message, "OOMError", "", Local<Object>()); | 517 | 522 | } | 518 | 523 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_report.cc +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -470,8 +470,12 @@ static void PrintJavaScriptStack(JSONWriter* writer, | 470 | 470 | void* samples[MAX_FRAME_COUNT]; | 471 | 471 | isolate->GetStackSample(state, samples, MAX_FRAME_COUNT, &info); | 472 | 472 |
| | 473 | + constexpr StackTrace::StackTraceOptions stack_trace_options = | | 474 | + static_cast<StackTrace::StackTraceOptions>( | | 475 | + StackTrace::kDetailed | | | 476 | + StackTrace::kExposeFramesAcrossSecurityOrigins); | 473 | 477 | Local<StackTrace> stack = StackTrace::CurrentStackTrace( | 474 | | - isolate, MAX_FRAME_COUNT, StackTrace::kDetailed); | | 478 | + isolate, MAX_FRAME_COUNT, stack_trace_options); | 475 | 479 |
| 476 | 480 | if (stack->GetFrameCount() == 0) { | 477 | 481 | PrintEmptyJavaScriptStack(writer); | |
Collapse file Copy file name to clipboardExpand all lines: test/addons/report-api/binding.cc +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #include <node.h> | 2 | 2 | #include <v8.h> | 3 | 3 |
| | 4 | +using v8::Context; | 4 | 5 | using v8::FunctionCallbackInfo; | 5 | 6 | using v8::Isolate; | 6 | 7 | using v8::Local; | @@ -43,11 +44,37 @@ void TriggerReportNoEnv(const FunctionCallbackInfo<Value>& args) { | 43 | 44 | Local<Value>()); | 44 | 45 | } | 45 | 46 |
| | 47 | +void TriggerReportNoContext(const FunctionCallbackInfo<Value>& args) { | | 48 | + Isolate* isolate = args.GetIsolate(); | | 49 | + Local<Context> context = isolate->GetCurrentContext(); | | 50 | + context->Exit(); | | 51 | + | | 52 | + if (isolate->GetCurrentContext().IsEmpty()) { | | 53 | + node::TriggerNodeReport( | | 54 | + isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>()); | | 55 | + } | | 56 | + | | 57 | + // Restore current context to avoid crashing in Context::Scope in | | 58 | + // SpinEventLoop. | | 59 | + context->Enter(); | | 60 | +} | | 61 | + | | 62 | +void TriggerReportNewContext(const FunctionCallbackInfo<Value>& args) { | | 63 | + Isolate* isolate = args.GetIsolate(); | | 64 | + Local<Context> context = Context::New(isolate); | | 65 | + Context::Scope context_scope(context); | | 66 | + | | 67 | + node::TriggerNodeReport( | | 68 | + isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>()); | | 69 | +} | | 70 | + | 46 | 71 | void init(Local<Object> exports) { | 47 | 72 | NODE_SET_METHOD(exports, "triggerReport", TriggerReport); | 48 | 73 | NODE_SET_METHOD(exports, "triggerReportNoIsolate", TriggerReportNoIsolate); | 49 | 74 | NODE_SET_METHOD(exports, "triggerReportEnv", TriggerReportEnv); | 50 | 75 | NODE_SET_METHOD(exports, "triggerReportNoEnv", TriggerReportNoEnv); | | 76 | + NODE_SET_METHOD(exports, "triggerReportNoContext", TriggerReportNoContext); | | 77 | + NODE_SET_METHOD(exports, "triggerReportNewContext", TriggerReportNewContext); | 51 | 78 | } | 52 | 79 |
| 53 | 80 | NODE_MODULE(NODE_GYP_MODULE_NAME, init) |
Collapse file Copy file name to clipboardExpand all lines: test/addons/report-api/test.js +20-11Lines changed: 20 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ const tmpdir = require('../../common/tmpdir'); | 9 | 9 | const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`); | 10 | 10 | const addon = require(binding); | 11 | 11 |
| 12 | | -function myAddonMain(method, hasJavaScriptFrames) { | | 12 | +function myAddonMain(method, { hasIsolate, hasEnv }) { | 13 | 13 | tmpdir.refresh(); | 14 | 14 | process.report.directory = tmpdir.path; | 15 | 15 |
| @@ -19,26 +19,35 @@ function myAddonMain(method, hasJavaScriptFrames) { | 19 | 19 | assert.strictEqual(reports.length, 1); | 20 | 20 |
| 21 | 21 | const report = reports[0]; | 22 | | - helper.validate(report); | | 22 | + helper.validate(report, [ | | 23 | + ['header.event', 'FooMessage'], | | 24 | + ['header.trigger', 'BarTrigger'], | | 25 | + ]); | 23 | 26 |
| 24 | 27 | const content = require(report); | 25 | | - assert.strictEqual(content.header.event, 'FooMessage'); | 26 | | - assert.strictEqual(content.header.trigger, 'BarTrigger'); | 27 | 28 |
| 28 | 29 | // Check that the javascript stack is present. | 29 | | - if (hasJavaScriptFrames) { | | 30 | + if (hasIsolate) { | 30 | 31 | assert.strictEqual(content.javascriptStack.stack.findIndex((frame) => frame.match('myAddonMain')), 0); | 31 | 32 | } else { | 32 | 33 | assert.strictEqual(content.javascriptStack, undefined); | 33 | 34 | } | | 35 | + | | 36 | + if (hasEnv) { | | 37 | + assert.strictEqual(content.header.threadId, 0); | | 38 | + } else { | | 39 | + assert.strictEqual(content.header.threadId, null); | | 40 | + } | 34 | 41 | } | 35 | 42 |
| 36 | 43 | const methods = [ | 37 | | - ['triggerReport', true], | 38 | | - ['triggerReportNoIsolate', false], | 39 | | - ['triggerReportEnv', true], | 40 | | - ['triggerReportNoEnv', false], | | 44 | + ['triggerReport', true, true], | | 45 | + ['triggerReportNoIsolate', false, false], | | 46 | + ['triggerReportEnv', true, true], | | 47 | + ['triggerReportNoEnv', false, false], | | 48 | + ['triggerReportNoContext', true, false], | | 49 | + ['triggerReportNewContext', true, false], | 41 | 50 | ]; | 42 | | -for (const [method, hasJavaScriptFrames] of methods) { | 43 | | - myAddonMain(method, hasJavaScriptFrames); | | 51 | +for (const [method, hasIsolate, hasEnv] of methods) { | | 52 | + myAddonMain(method, { hasIsolate, hasEnv }); | 44 | 53 | } |
|