summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2018-01-27 20:20:00 +0200
committerKevin Mitchell <kevmitch@gmail.com>2018-04-07 16:02:19 -0700
commit84aa9e71469f666c552aa9f797da16d3c9676f53 (patch)
treea40386d1e467a951069bacf6b2737943aff70258
parent9a47023c444df488ff51c8f86fbd1b1b93e99a9b (diff)
downloadmpv-84aa9e71469f666c552aa9f797da16d3c9676f53.tar.bz2
mpv-84aa9e71469f666c552aa9f797da16d3c9676f53.tar.xz
js: dump(..): fix incorrect <VISITED> with array argument
When dump's argument is an array, it was displaying <VISITED> for all the array's object elements (objects, arrays, etc), regardless if they're actually visited or not. The reason is that we try to stringify twice: once normally which may throw (on cycles), and a second time while excluding visited items which is indicated by binding the replacer to an empty array - in which we hold the visited items, where the replacer tests if its 'this' is an array or not and acts accordingly. However, its "this" may also be an array even if we don't bind it to one, because its "normal" this is the main stringified object, so the test of Array.isArray(this) is true when the top object is an array, and the object items are indeed are in it - so the replacer considers them visited. Fix by binding to null on the first attempt such that "this" is an array only when we want it to test for visited items and not when the argument itself is an array.
-rw-r--r--player/javascript/defaults.js2
1 files changed, 1 insertions, 1 deletions
diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js
index 281008fd07..96bac2126f 100644
--- a/player/javascript/defaults.js
+++ b/player/javascript/defaults.js
@@ -537,7 +537,7 @@ function replacer(k, v) {
function obj2str(v) {
try { // can process objects more than once, but throws on cycles
- return JSON.stringify(v, replacer, 2);
+ return JSON.stringify(v, replacer.bind(null), 2);
} catch (e) { // simple safe: exclude visited objects, even if not cyclic
return JSON.stringify(v, replacer.bind([]), 2);
}