| 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 class Constant implements Hashable { | 5 class Constant implements Hashable { |
| 6 const Constant(); | 6 const Constant(); |
| 7 | 7 |
| 8 bool isNull() => false; | 8 bool isNull() => false; |
| 9 bool isBool() => false; | 9 bool isBool() => false; |
| 10 bool isTrue() => false; | 10 bool isTrue() => false; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // Primitive constants don't have dependencies. | 49 // Primitive constants don't have dependencies. |
| 50 List<Constant> getDependencies() => const <Constant>[]; | 50 List<Constant> getDependencies() => const <Constant>[]; |
| 51 abstract DartString toDartString(); | 51 abstract DartString toDartString(); |
| 52 | 52 |
| 53 void _writeCanonicalizedJsCode(StringBuffer buffer, ConstantHandler handler) { | 53 void _writeCanonicalizedJsCode(StringBuffer buffer, ConstantHandler handler) { |
| 54 _writeJsCode(buffer, handler); | 54 _writeJsCode(buffer, handler); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 class NullConstant extends PrimitiveConstant { | 58 class NullConstant extends PrimitiveConstant { |
| 59 /** The value a Dart null is compiled to in JavaScript. */ |
| 60 static final String JsNull = "null"; |
| 61 |
| 59 factory NullConstant() => const NullConstant._internal(); | 62 factory NullConstant() => const NullConstant._internal(); |
| 60 const NullConstant._internal(); | 63 const NullConstant._internal(); |
| 61 bool isNull() => true; | 64 bool isNull() => true; |
| 62 get value() => null; | 65 get value() => null; |
| 63 | 66 |
| 64 void _writeJsCode(StringBuffer buffer, ConstantHandler handler) { | 67 void _writeJsCode(StringBuffer buffer, ConstantHandler handler) { |
| 65 buffer.add("(void 0)"); | 68 buffer.add(JsNull); |
| 66 } | 69 } |
| 67 | 70 |
| 68 // The magic constant has no meaning. It is just a random value. | 71 // The magic constant has no meaning. It is just a random value. |
| 69 int hashCode() => 785965825; | 72 int hashCode() => 785965825; |
| 70 DartString toDartString() => const LiteralDartString("null"); | 73 DartString toDartString() => const LiteralDartString("null"); |
| 71 } | 74 } |
| 72 | 75 |
| 73 class NumConstant extends PrimitiveConstant { | 76 class NumConstant extends PrimitiveConstant { |
| 74 abstract num get value(); | 77 abstract num get value(); |
| 75 const NumConstant(); | 78 const NumConstant(); |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 Constant fieldValue = fieldValues[field]; | 1166 Constant fieldValue = fieldValues[field]; |
| 1164 if (fieldValue === null) { | 1167 if (fieldValue === null) { |
| 1165 // Use the default value. | 1168 // Use the default value. |
| 1166 fieldValue = compiler.compileVariable(field); | 1169 fieldValue = compiler.compileVariable(field); |
| 1167 } | 1170 } |
| 1168 jsNewArguments.add(fieldValue); | 1171 jsNewArguments.add(fieldValue); |
| 1169 }); | 1172 }); |
| 1170 return jsNewArguments; | 1173 return jsNewArguments; |
| 1171 } | 1174 } |
| 1172 } | 1175 } |
| OLD | NEW |