diff --git a/src/node.cc b/src/node.cc index d8681292aad36a..bf544c470d9472 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1511,8 +1511,10 @@ static void ReportException(Environment* env, name.IsEmpty() || name->IsUndefined()) { // Not an error object. Just print as-is. - node::Utf8Value message(env->isolate(), er); - PrintErrorString("%s\n", *message); + String::Utf8Value message(er); + + PrintErrorString("%s\n", *message ? *message : + ""); } else { node::Utf8Value name_string(env->isolate(), name); node::Utf8Value message_string(env->isolate(), message); diff --git a/test/fixtures/throws_error7.js b/test/fixtures/throws_error7.js new file mode 100644 index 00000000000000..f730bc6def1ba9 --- /dev/null +++ b/test/fixtures/throws_error7.js @@ -0,0 +1,5 @@ +throw { + toString: function() { + throw this; + } +}; diff --git a/test/parallel/test-error-reporting.js b/test/parallel/test-error-reporting.js index 88ef5d306e3e37..b5b70eeb3b2add 100644 --- a/test/parallel/test-error-reporting.js +++ b/test/parallel/test-error-reporting.js @@ -24,8 +24,6 @@ function errExec(script, callback) { // Count the tests exits++; - - console.log('.'); }); } @@ -64,6 +62,11 @@ errExec('throws_error6.js', function(err, stdout, stderr) { assert.ok(/SyntaxError/.test(stderr)); }); +// Object that throws in toString() doesn't print garbage +errExec('throws_error7.js', function(err, stdout, stderr) { + assert.ok(/