From 261767039202e3afc8155f87c018241b65ce798b Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 30 Jun 2018 22:54:56 +0100 Subject: [PATCH] dep.js: Add optional debugging blather. Set `DEP.DEBUG' true for a firehose. --- dep.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/dep.js b/dep.js index f9a9a18..989e871 100644 --- a/dep.js +++ b/dep.js @@ -25,6 +25,19 @@ var DEP = { }; (function () { /*----- Utility functions and classes -------------------------------------*/ +DEP.DEBUG = false; +function blather(msg) { + /* Report MSG to the log if we're debugging. */ + if (DEP.DEBUG) console.log(";; " + msg); +} +function show(what, value) { + /* Report that WHAT has the value VALUE, if we're debugging; and, + * regardless, return VALUE. + */ + blather(what + " = " + value); + return value; +} + function dolist(list, func) { /* Apply FUNC to each element of LIST, discarding the results. * @@ -203,9 +216,11 @@ function Dep(value, maybefunc) { this._dependencies = { }; // Set of objects we depend on. // If we have a recomputation function then exercise it. + blather("new dep " + me); if (func !== null) { with_frozen(function () { PENDING.push(me); + blather("push new dep " + me); }); } } @@ -268,6 +283,7 @@ Dep.prototype = { * function which doesn't handle propagation or anything like that. */ + blather("_update " + this + ": " + value); if (value === BAD ? this._value === BAD : (this._value !== BAD && @@ -293,8 +309,9 @@ Dep.prototype = { this._dependencies = { }; return try_finally(function () { EVALUATING = me; - return orelse(function () { return me._value_function(); }, - function () { return BAD; }); + return show("_new_value for " + me, + orelse(function () { return me._value_function(); }, + function () { return show("ret", BAD); })); }, function() { EVALUATING = old; }); @@ -402,6 +419,7 @@ Dep.prototype = { } } val = this._value; + blather("value " + this + ": " + val); if (val === BAD) throw BAD; return val; }, @@ -471,6 +489,7 @@ function recompute_pending() { var d, f; var old_state = STATE; STATE = 'recomputing'; + blather("STATE <- :recomputing"); try_finally(function () { while (PENDING.length) { d = PENDING.shift(); @@ -487,8 +506,10 @@ function recompute_pending() { while (PENDING.length) { d = PENDING.shift(); d._value = BAD; + blather("recompute_pending mark " + d); } STATE = old_state; + blather("STATE <- :" + old_state); }); } @@ -519,6 +540,7 @@ function with_frozen(body, delay) { old_pending = PENDING; old_state = STATE; STATE = "frozen"; + blather("STATE <- :frozen"); try_finally(function () { DELAYED = []; PENDING = []; @@ -534,6 +556,7 @@ function with_frozen(body, delay) { DELAYED = old_delayed; PENDING = old_pending; STATE = old_state; + blather("STATE <- :" + old_state); }); break; } -- 2.11.0