Skip to content

Commit a057e32

Browse files
author
Benjamin Pasero
committed
ext host - improve printing of circular objects
1 parent 121bb10 commit a057e32

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/bootstrap.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ if (!!process.send && process.env.PIPE_LOGGING === 'true') {
7676
res = JSON.stringify(argsArray, function (key, value) {
7777

7878
// Objects get special treatment to prevent circles
79-
if (value && Object.prototype.toString.call(value) === '[object Object]') {
79+
if (isObject(value) || Array.isArray(value)) {
8080
if (seen.indexOf(value) !== -1) {
81-
return Object.create(null); // prevent circular references!
81+
return '[Circular]';
8282
}
8383

8484
seen.push(value);
@@ -105,6 +105,14 @@ if (!!process.send && process.env.PIPE_LOGGING === 'true') {
105105
}
106106
}
107107

108+
function isObject(obj) {
109+
return typeof obj === 'object'
110+
&& obj !== null
111+
&& !Array.isArray(obj)
112+
&& !(obj instanceof RegExp)
113+
&& !(obj instanceof Date);
114+
}
115+
108116
// Pass console logging to the outside so that we have it in the main side if told so
109117
if (process.env.VERBOSE_LOGGING === 'true') {
110118
console.log = function () { safeSend({ type: '__$console', severity: 'log', arguments: safeToArray(arguments) }); };

0 commit comments

Comments
 (0)