feat(code size): make assertionsEnabled() statically computable by dart2js

Our existing implementation prevented dart2js from statically deducing the
return value. This fix does not yet result in better tree-shaking due to the
following dart2js bugs:

https://github.com/dart-lang/sdk/issues/24354
https://github.com/dart-lang/sdk/issues/24355

Closes #4198
This commit is contained in:
Yegor Jbanov 2015-09-15 12:11:26 -07:00 committed by Yegor
parent 06f0d6c046
commit 241632aaa1

View File

@ -243,17 +243,11 @@ bool isJsObject(o) {
return false; return false;
} }
var _assertionsEnabled = null;
bool assertionsEnabled() { bool assertionsEnabled() {
if (_assertionsEnabled == null) { // TODO(yjbanov): verify that this is inlined after https://github.com/dart-lang/sdk/issues/24355
try { bool k = false;
assert(false); assert((k = true));
_assertionsEnabled = false; return k;
} catch (e) {
_assertionsEnabled = true;
}
}
return _assertionsEnabled;
} }
// Can't be all uppercase as our transpiler would think it is a special directive... // Can't be all uppercase as our transpiler would think it is a special directive...