Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
14 changes: 14 additions & 0 deletions test/variable/define-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down