From 276b2416f26a67507586b2010136646dd394355b Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Mon, 19 Aug 2019 13:49:37 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Don=E2=80=99t=20compute=20unreachable=20out?= =?UTF-8?q?puts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/runtime.js | 2 +- src/variable.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime.js b/src/runtime.js index 19166bdf..96324eb3 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -112,7 +112,7 @@ function runtime_computeNow() { variable._indegree = 0; variable._outputs.forEach(variables.add, variables); } else { - variable._indegree = -1; + variable._indegree = NaN; variables.delete(variable); } }); diff --git a/src/variable.js b/src/variable.js index d2610296..5becd848 100644 --- a/src/variable.js +++ b/src/variable.js @@ -17,7 +17,7 @@ export default function Variable(type, module, observer) { _definition: {value: variable_undefined, writable: true}, _duplicate: {value: undefined, writable: true}, _duplicates: {value: undefined, writable: true}, - _indegree: {value: -1, writable: true}, // The number of computing inputs. + _indegree: {value: NaN, writable: true}, // The number of computing inputs. _inputs: {value: [], writable: true}, _invalidate: {value: noop, writable: true}, _module: {value: module}, From 36292784e523225a05dd3d7dadb36e2bb49e276c Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Mon, 19 Aug 2019 14:03:19 -0700 Subject: [PATCH 2/2] Add another test for reachability. --- test/variable/define-test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/variable/define-test.js b/test/variable/define-test.js index c8cd1ff8..ba15b905 100644 --- a/test/variable/define-test.js +++ b/test/variable/define-test.js @@ -350,6 +350,20 @@ tape("variable.define does not try to compute unreachable variables", async test test.equals(evaluated, false); }); +tape("variable.define does not try to compute unreachable variables that are outputs of reachable variables", async test => { + const runtime = new Runtime(); + const main = runtime.module(); + let evaluated = false; + const foo = main.variable(true).define("foo", [], () => 1); + const bar = main.variable(true).define("bar", [], () => 2); + const baz = main.variable().define("baz", ["foo", "bar"], (foo, bar) => evaluated = foo + bar); + await new Promise(setImmediate); + test.deepEqual(await valueof(foo), {value: 1}); + test.deepEqual(await valueof(bar), {value: 2}); + test.deepEqual(await valueof(baz), {value: undefined}); + test.equals(evaluated, false); +}); + tape("variable.define can reference whitelisted globals", async test => { const runtime = new Runtime(null, name => name === "magic" ? 21 : undefined); const module = runtime.module();