| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); | 7 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); |
| 8 | 8 |
| 9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); | 9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); |
| 10 | 10 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 int primitiveValue = constant.primitiveValue; | 98 int primitiveValue = constant.primitiveValue; |
| 99 // Since we are in JavaScript we can shorten long integers to their shorter | 99 // Since we are in JavaScript we can shorten long integers to their shorter |
| 100 // exponential representation, for example: "1e4" is shorter than "10000". | 100 // exponential representation, for example: "1e4" is shorter than "10000". |
| 101 // | 101 // |
| 102 // Note that this shortening apparently loses precision for big numbers | 102 // Note that this shortening apparently loses precision for big numbers |
| 103 // (like 1234567890123456789012345 which becomes 12345678901234568e8). | 103 // (like 1234567890123456789012345 which becomes 12345678901234568e8). |
| 104 // However, since JavaScript engines represent all numbers as doubles, these | 104 // However, since JavaScript engines represent all numbers as doubles, these |
| 105 // digits are lost anyway. | 105 // digits are lost anyway. |
| 106 String representation = primitiveValue.toString(); | 106 String representation = primitiveValue.toString(); |
| 107 String alternative = null; | 107 String alternative = null; |
| 108 int cutoff = compiler.enableMinification ? 10000 : 1e10.toInt(); | 108 int cutoff = compiler.options.enableMinification ? 10000 : 1e10.toInt(); |
| 109 if (primitiveValue.abs() >= cutoff) { | 109 if (primitiveValue.abs() >= cutoff) { |
| 110 alternative = _shortenExponentialRepresentation( | 110 alternative = _shortenExponentialRepresentation( |
| 111 primitiveValue.toStringAsExponential()); | 111 primitiveValue.toStringAsExponential()); |
| 112 } | 112 } |
| 113 if (alternative != null && alternative.length < representation.length) { | 113 if (alternative != null && alternative.length < representation.length) { |
| 114 representation = alternative; | 114 representation = alternative; |
| 115 } | 115 } |
| 116 return new jsAst.LiteralNumber(representation); | 116 return new jsAst.LiteralNumber(representation); |
| 117 } | 117 } |
| 118 | 118 |
| 119 @override | 119 @override |
| 120 jsAst.Expression visitDouble(DoubleConstantValue constant, [_]) { | 120 jsAst.Expression visitDouble(DoubleConstantValue constant, [_]) { |
| 121 double value = constant.primitiveValue; | 121 double value = constant.primitiveValue; |
| 122 if (value.isNaN) { | 122 if (value.isNaN) { |
| 123 return js("0/0"); | 123 return js("0/0"); |
| 124 } else if (value == double.INFINITY) { | 124 } else if (value == double.INFINITY) { |
| 125 return js("1/0"); | 125 return js("1/0"); |
| 126 } else if (value == -double.INFINITY) { | 126 } else if (value == -double.INFINITY) { |
| 127 return js("-1/0"); | 127 return js("-1/0"); |
| 128 } else { | 128 } else { |
| 129 String shortened = _shortenExponentialRepresentation("$value"); | 129 String shortened = _shortenExponentialRepresentation("$value"); |
| 130 return new jsAst.LiteralNumber(shortened); | 130 return new jsAst.LiteralNumber(shortened); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 @override | 134 @override |
| 135 jsAst.Expression visitBool(BoolConstantValue constant, [_]) { | 135 jsAst.Expression visitBool(BoolConstantValue constant, [_]) { |
| 136 if (compiler.enableMinification) { | 136 if (compiler.options.enableMinification) { |
| 137 if (constant.isTrue) { | 137 if (constant.isTrue) { |
| 138 // Use !0 for true. | 138 // Use !0 for true. |
| 139 return js("!0"); | 139 return js("!0"); |
| 140 } else { | 140 } else { |
| 141 // Use !1 for false. | 141 // Use !1 for false. |
| 142 return js("!1"); | 142 return js("!1"); |
| 143 } | 143 } |
| 144 } else { | 144 } else { |
| 145 return constant.isTrue ? js('true') : js('false'); | 145 return constant.isTrue ? js('true') : js('false'); |
| 146 } | 146 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 [value, argumentList]); | 319 [value, argumentList]); |
| 320 } | 320 } |
| 321 return value; | 321 return value; |
| 322 } | 322 } |
| 323 | 323 |
| 324 @override | 324 @override |
| 325 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { | 325 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { |
| 326 return constantReferenceGenerator(constant.referenced); | 326 return constantReferenceGenerator(constant.referenced); |
| 327 } | 327 } |
| 328 } | 328 } |
| OLD | NEW |