Files
sdk/pkg/dev_compiler/test/codegen/expect/domtest.js
T
Olivier Chafik 04d4be0982 Less dart.notNull checks for local vars using flow-insensitive nullability inference.
Within some AST context (at library granularity, for convenience), we
collect all the assignments to local vars:
- Declaration with no initializer amounts to `null` assignment
- Assignment ops are expanded naively: `x++` yield an assigned value of
`x + 1`, etc

We detect "trivially nullable" variables (e.g. `var x;`, `x =
breaking.out;`) by spotting assigned values that are nullable under the
optimistic assumption that all known variables are non-nullable.

Then we build a nullability dependency graph in linear time: whenever
we see `x = y;`, we know that "y is nullable" implies "x is nullable".

Finally, we propagate "trivial nullabilities" through that graph: any
variable that wasn't reached is deemed not-nullable.

(this is similar to mark and sweep garbage collection, where the roots
are the "trivially nullable" variables; credits to leafpetersen@ for
linear solution)
2016-01-28 15:47:49 +00:00

21 lines
600 B
JavaScript

dart_library.library('domtest', null, /* Imports */[
'dart/_runtime',
'sunflower/dom',
'dart/core'
], /* Lazy imports */[
], function(exports, dart, dom, core) {
'use strict';
let dartx = dart.dartx;
function testNativeIndexers() {
let nodes = dom.document.querySelector('body').childNodes;
for (let i = 0; i < dart.notNull(nodes.length); i++) {
let old = nodes[i];
nodes[i] = dom.document.createElement('div');
core.print(dart.equals(nodes[i], old));
}
}
dart.fn(testNativeIndexers);
// Exports:
exports.testNativeIndexers = testNativeIndexers;
});