| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8d18aed commit 6151544
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1514,7 +1514,8 @@ bool IsExceptionDecorated(Environment* env, Local<Value> er) { | |||
| 1514 | 1514 | ||
| 1515 | 1515 | void AppendExceptionLine(Environment* env, | |
| 1516 | 1516 | Local<Value> er, | |
| 1517 | - Local<Message> message) { | ||
| 1517 | + Local<Message> message, | ||
| 1518 | + enum ErrorHandlingMode mode) { | ||
| 1518 | 1519 | if (message.IsEmpty()) | |
| 1519 | 1520 | return; | |
| 1520 | 1521 | ||
@@ -1601,20 +1602,26 @@ void AppendExceptionLine(Environment* env, | |||
| 1601 | 1602 | ||
| 1602 | 1603 | Local<String> arrow_str = String::NewFromUtf8(env->isolate(), arrow); | |
| 1603 | 1604 | ||
| 1604 | - if (!arrow_str.IsEmpty() && !err_obj.IsEmpty() && err_obj->IsNativeError()) { | ||
| 1605 | - err_obj->SetPrivate( | ||
| 1606 | - env->context(), | ||
| 1607 | - env->arrow_message_private_symbol(), | ||
| 1608 | - arrow_str); | ||
| 1605 | + const bool can_set_arrow = !arrow_str.IsEmpty() && !err_obj.IsEmpty(); | ||
| 1606 | + // If allocating arrow_str failed, print it out. There's not much else to do. | ||
| 1607 | + // If it's not an error, but something needs to be printed out because | ||
| 1608 | + // it's a fatal exception, also print it out from here. | ||
| 1609 | + // Otherwise, the arrow property will be attached to the object and handled | ||
| 1610 | + // by the caller. | ||
| 1611 | + if (!can_set_arrow || (mode == FATAL_ERROR && !err_obj->IsNativeError())) { | ||
| 1612 | + if (env->printed_error()) | ||
| 1613 | + return; | ||
| 1614 | + env->set_printed_error(true); | ||
| 1615 | + | ||
| 1616 | + uv_tty_reset_mode(); | ||
| 1617 | + PrintErrorString("\n%s", arrow); | ||
| 1609 | 1618 | return; | |
| 1610 | 1619 | } | |
| 1611 | 1620 | ||
| 1612 | - // Allocation failed, just print it out. | ||
| 1613 | - if (env->printed_error()) | ||
| 1614 | - return; | ||
| 1615 | - env->set_printed_error(true); | ||
| 1616 | - uv_tty_reset_mode(); | ||
| 1617 | - PrintErrorString("\n%s", arrow); | ||
| 1621 | + CHECK(err_obj->SetPrivate( | ||
| 1622 | + env->context(), | ||
| 1623 | + env->arrow_message_private_symbol(), | ||
| 1624 | + arrow_str).FromMaybe(false)); | ||
| 1618 | 1625 | } | |
| 1619 | 1626 | ||
| 1620 | 1627 | ||
@@ -1623,7 +1630,7 @@ static void ReportException(Environment* env, | |||
| 1623 | 1630 | Local<Message> message) { | |
| 1624 | 1631 | HandleScope scope(env->isolate()); | |
| 1625 | 1632 | ||
| 1626 | - AppendExceptionLine(env, er, message); | ||
| 1633 | + AppendExceptionLine(env, er, message, FATAL_ERROR); | ||
| 1627 | 1634 | ||
| 1628 | 1635 | Local<Value> trace_value; | |
| 1629 | 1636 | Local<Value> arrow; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -633,7 +633,7 @@ class ContextifyScript : public BaseObject { | |||
| 633 | 633 | if (IsExceptionDecorated(env, err_obj)) | |
| 634 | 634 | return; | |
| 635 | 635 | ||
| 636 | - AppendExceptionLine(env, exception, try_catch.Message()); | ||
| 636 | + AppendExceptionLine(env, exception, try_catch.Message(), CONTEXTIFY_ERROR); | ||
| 637 | 637 | Local<Value> stack = err_obj->Get(env->stack_string()); | |
| 638 | 638 | auto maybe_value = | |
| 639 | 639 | err_obj->GetPrivate( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,9 +142,11 @@ constexpr size_t arraysize(const T(&)[N]) { return N; } | |||
| 142 | 142 | ||
| 143 | 143 | bool IsExceptionDecorated(Environment* env, v8::Local<v8::Value> er); | |
| 144 | 144 | ||
| 145 | + enum ErrorHandlingMode { FATAL_ERROR, CONTEXTIFY_ERROR }; | ||
| 145 | 146 | void AppendExceptionLine(Environment* env, | |
| 146 | 147 | v8::Local<v8::Value> er, | |
| 147 | - v8::Local<v8::Message> message); | ||
| 148 | + v8::Local<v8::Message> message, | ||
| 149 | + enum ErrorHandlingMode mode); | ||
| 148 | 150 | ||
| 149 | 151 | NO_RETURN void FatalError(const char* location, const char* message); | |
| 150 | 152 | ||
| 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