suppress false positives due to nested objects (#4597)

This commit is contained in:
Alex Lam S.L
2021-01-29 05:21:19 +00:00
committed by GitHub
parent d0bb147639
commit 35435d4bd3
2 changed files with 27 additions and 2 deletions

View File

@@ -98,6 +98,31 @@ log_global: {
expect_stdout: "[object global]" expect_stdout: "[object global]"
} }
log_nested: {
options = {
unused: true,
}
input: {
var o = { p: 42 };
for (var i = 0; i < 10; i++)
o = {
p: o,
q: function foo() {},
};
console.log(o);
}
expect: {
var o = { p: 42 };
for (var i = 0; i < 10; i++)
o = {
p: o,
q: function() {},
};
console.log(o);
}
expect_stdout: true
}
timers: { timers: {
options = { options = {
reduce_vars: true, reduce_vars: true,

View File

@@ -126,7 +126,7 @@ function setup(global, builtins, setup_log, setup_tty) {
if (arguments.length == 1 && typeof msg == "string") return log("%s", msg); if (arguments.length == 1 && typeof msg == "string") return log("%s", msg);
return log.apply(null, [].map.call(arguments, function(arg) { return log.apply(null, [].map.call(arguments, function(arg) {
return safe_log(arg, { return safe_log(arg, {
level: 3, level: 5,
original: [], original: [],
replaced: [], replaced: [],
}); });
@@ -189,7 +189,7 @@ function setup(global, builtins, setup_log, setup_tty) {
arg.constructor.toString(); arg.constructor.toString();
var index = cache.original.indexOf(arg); var index = cache.original.indexOf(arg);
if (index >= 0) return cache.replaced[index]; if (index >= 0) return cache.replaced[index];
if (--cache.level < 0) break; if (--cache.level < 0) return "[object Object]";
var value = {}; var value = {};
cache.original.push(arg); cache.original.push(arg);
cache.replaced.push(value); cache.replaced.push(value);