Skip to content

Commit 13174e5

Browse files
committed
Add another test for reachability.
1 parent b86e7e9 commit 13174e5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/variable/define-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,20 @@ tape("variable.define does not try to compute unreachable variables", async test
320320
test.equals(evaluated, false);
321321
});
322322

323+
tape("variable.define does not try to compute unreachable variables that are outputs of reachable variables", async test => {
324+
const runtime = new Runtime();
325+
const main = runtime.module();
326+
let evaluated = false;
327+
const foo = main.variable(true).define("foo", [], () => 1);
328+
const bar = main.variable(true).define("bar", [], () => 2);
329+
const baz = main.variable().define("baz", ["foo", "bar"], (foo, bar) => evaluated = foo + bar);
330+
await new Promise(setImmediate);
331+
test.deepEqual(await valueof(foo), {value: 1});
332+
test.deepEqual(await valueof(bar), {value: 2});
333+
test.deepEqual(await valueof(baz), {value: undefined});
334+
test.equals(evaluated, false);
335+
});
336+
323337
tape("variable.define can reference whitelisted globals", async test => {
324338
const runtime = new Runtime(null, name => name === "magic" ? 21 : undefined);
325339
const module = runtime.module();

0 commit comments

Comments
 (0)