| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7dbb0d0 commit 8557597
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1439,7 +1439,8 @@ ssize_t DecodeWrite(Isolate* isolate, | |||
| 1439 | 1439 | ||
| 1440 | 1440 | void AppendExceptionLine(Environment* env, | |
| 1441 | 1441 | Local<Value> er, | |
| 1442 | - Local<Message> message) { | ||
| 1442 | + Local<Message> message, | ||
| 1443 | + enum ErrorHandlingMode mode) { | ||
| 1443 | 1444 | if (message.IsEmpty()) | |
| 1444 | 1445 | return; | |
| 1445 | 1446 | ||
@@ -1521,19 +1522,23 @@ void AppendExceptionLine(Environment* env, | |||
| 1521 | 1522 | ||
| 1522 | 1523 | Local<String> arrow_str = String::NewFromUtf8(env->isolate(), arrow); | |
| 1523 | 1524 | ||
| 1524 | - // Allocation failed, just print it out | ||
| 1525 | - if (arrow_str.IsEmpty() || err_obj.IsEmpty() || !err_obj->IsNativeError()) | ||
| 1526 | - goto print; | ||
| 1527 | - | ||
| 1528 | - err_obj->SetHiddenValue(env->arrow_message_string(), arrow_str); | ||
| 1529 | - return; | ||
| 1525 | + const bool can_set_arrow = !arrow_str.IsEmpty() && !err_obj.IsEmpty(); | ||
| 1526 | + // If allocating arrow_str failed, print it out. There's not much else to do. | ||
| 1527 | + // If it's not an error, but something needs to be printed out because | ||
| 1528 | + // it's a fatal exception, also print it out from here. | ||
| 1529 | + // Otherwise, the arrow property will be attached to the object and handled | ||
| 1530 | + // by the caller. | ||
| 1531 | + if (!can_set_arrow || (mode == FATAL_ERROR && !err_obj->IsNativeError())) { | ||
| 1532 | + if (env->printed_error()) | ||
| 1533 | + return; | ||
| 1534 | + env->set_printed_error(true); | ||
| 1530 | 1535 | ||
| 1531 | - print: | ||
| 1532 | - if (env->printed_error()) | ||
| 1536 | + uv_tty_reset_mode(); | ||
| 1537 | + PrintErrorString("\n%s", arrow); | ||
| 1533 | 1538 | return; | |
| 1534 | - env->set_printed_error(true); | ||
| 1535 | - uv_tty_reset_mode(); | ||
| 1536 | - PrintErrorString("\n%s", arrow); | ||
| 1539 | + } | ||
| 1540 | + | ||
| 1541 | + err_obj->SetHiddenValue(env->arrow_message_string(), arrow_str); | ||
| 1537 | 1542 | } | |
| 1538 | 1543 | ||
| 1539 | 1544 | ||
@@ -1542,7 +1547,7 @@ static void ReportException(Environment* env, | |||
| 1542 | 1547 | Local<Message> message) { | |
| 1543 | 1548 | HandleScope scope(env->isolate()); | |
| 1544 | 1549 | ||
| 1545 | - AppendExceptionLine(env, er, message); | ||
| 1550 | + AppendExceptionLine(env, er, message, FATAL_ERROR); | ||
| 1546 | 1551 | ||
| 1547 | 1552 | Local<Value> trace_value; | |
| 1548 | 1553 | Local<Value> arrow; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,9 +126,11 @@ constexpr size_t arraysize(const T(&)[N]) { return N; } | |||
| 126 | 126 | # define NO_RETURN | |
| 127 | 127 | #endif | |
| 128 | 128 | ||
| 129 | + enum ErrorHandlingMode { FATAL_ERROR, CONTEXTIFY_ERROR }; | ||
| 129 | 130 | void AppendExceptionLine(Environment* env, | |
| 130 | 131 | v8::Local<v8::Value> er, | |
| 131 | - v8::Local<v8::Message> message); | ||
| 132 | + v8::Local<v8::Message> message, | ||
| 133 | + enum ErrorHandlingMode mode = CONTEXTIFY_ERROR); | ||
| 132 | 134 | ||
| 133 | 135 | NO_RETURN void FatalError(const char* location, const char* message); | |
| 134 | 136 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const vm = require('vm'); | ||
| 4 | + | ||
| 5 | + console.error('beginning'); | ||
| 6 | + | ||
| 7 | + // Regression test for https://github.com/nodejs/node/issues/7397: | ||
| 8 | + // vm.runInThisContext() should not print out anything to stderr by itself. | ||
| 9 | + try { | ||
| 10 | + vm.runInThisContext(`throw ({ | ||
| 11 | + name: 'MyCustomError', | ||
| 12 | + message: 'This is a custom message' | ||
| 13 | + })`, { filename: 'test.vm' }); | ||
| 14 | + } catch (e) { | ||
| 15 | + console.error('received error', e.name); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + console.error('end'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + beginning | ||
| 2 | + received error MyCustomError | ||
| 3 | + end | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments