Skip to content

Commit

Permalink
Merge pull request #287 from tabarra/patch-1
Browse files Browse the repository at this point in the history
prevent circular reference error in console.dir()
  • Loading branch information
blattersturm authored Oct 24, 2019
2 parents c789eeb + 75de15f commit 9aef84c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion data/shared/citizen/scripting/v8/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,16 @@

case Array.isArray(arg):
case arg.toString() === "[object Object]":
return JSON.stringify(arg, null, 2);
let cache = [];
let out = JSON.stringify(arg, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) return;
cache.push(value);
}
return value;
}, 2);
cache = null;
return out;

case arg.toString() === "[object Error]" || arg instanceof Error:
return arg.stack || Error.prototype.toString.call(arg);
Expand Down

0 comments on commit 9aef84c

Please sign in to comment.