| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7881b0f commit e5725c2
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -471,6 +471,11 @@ void OOMErrorHandler(const char* location, bool is_heap_oom) { | |||
| 471 | 471 | } | |
| 472 | 472 | ||
| 473 | 473 | if (report_on_fatalerror) { | |
| 474 | + // Trigger report with the isolate. Environment::GetCurrent may return | ||
| 475 | + // nullptr here: | ||
| 476 | + // - If the OOM is reported by a young generation space allocation, | ||
| 477 | + // Isolate::GetCurrentContext returns an empty handle. | ||
| 478 | + // - Otherwise, Isolate::GetCurrentContext returns a non-empty handle. | ||
| 474 | 479 | TriggerNodeReport(isolate, message, "OOMError", "", Local<Object>()); | |
| 475 | 480 | } | |
| 476 | 481 | ||
| 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); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 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) | |
| 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 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments