OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.serialization; | 5 library dart2js.serialization; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/resolution.dart'; | 8 import '../common/resolution.dart'; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 throw new StateError("Ints value '$key' not found in $_map."); | 533 throw new StateError("Ints value '$key' not found in $_map."); |
534 } | 534 } |
535 return list; | 535 return list; |
536 } | 536 } |
537 | 537 |
538 /// Returns the [double] value associated with [key] in the decoded object. | 538 /// Returns the [double] value associated with [key] in the decoded object. |
539 /// | 539 /// |
540 /// If no value is associated with [key], then if [isOptional] is `true`, | 540 /// If no value is associated with [key], then if [isOptional] is `true`, |
541 /// [defaultValue] is returned, otherwise an exception is thrown. | 541 /// [defaultValue] is returned, otherwise an exception is thrown. |
542 double getDouble(K key, {bool isOptional: false, double defaultValue}) { | 542 double getDouble(K key, {bool isOptional: false, double defaultValue}) { |
543 double value = _map[_getKeyValue(key)]; | 543 var value = _map[_getKeyValue(key)]; |
544 if (value == null) { | 544 if (value == null) { |
545 if (isOptional || defaultValue != null) { | 545 if (isOptional || defaultValue != null) { |
546 return defaultValue; | 546 return defaultValue; |
547 } | 547 } |
548 throw new StateError("double value '$key' not found in $_map."); | 548 throw new StateError("double value '$key' not found in $_map."); |
549 } | 549 } |
| 550 // Support alternative encoding of NaN and +/- infinity for JSON. |
| 551 if (value == 'NaN') { |
| 552 return double.NAN; |
| 553 } else if (value == '-Infinity') { |
| 554 return double.NEGATIVE_INFINITY; |
| 555 } else if (value == 'Infinity') { |
| 556 return double.INFINITY; |
| 557 } |
550 return value; | 558 return value; |
551 } | 559 } |
552 | 560 |
553 /// Returns an [ObjectDecoder] for the map value associated with [key] in the | 561 /// Returns an [ObjectDecoder] for the map value associated with [key] in the |
554 /// decoded object. | 562 /// decoded object. |
555 /// | 563 /// |
556 /// If no value is associated with [key], then if [isOptional] is `true`, | 564 /// If no value is associated with [key], then if [isOptional] is `true`, |
557 /// `null` is returned, otherwise an exception is thrown. | 565 /// `null` is returned, otherwise an exception is thrown. |
558 ObjectDecoder getObject(K key, {bool isOptional: false}) { | 566 ObjectDecoder getObject(K key, {bool isOptional: false}) { |
559 Map map = _map[_getKeyValue(key)]; | 567 Map map = _map[_getKeyValue(key)]; |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 | 1137 |
1130 /// Returns the value used to store [key] as a property in the encoding an | 1138 /// Returns the value used to store [key] as a property in the encoding an |
1131 /// [ObjectValue]. | 1139 /// [ObjectValue]. |
1132 /// | 1140 /// |
1133 /// Different encodings have different restrictions and capabilities as how | 1141 /// Different encodings have different restrictions and capabilities as how |
1134 /// to store a [Key] value. For instance: A JSON encoding needs to convert | 1142 /// to store a [Key] value. For instance: A JSON encoding needs to convert |
1135 /// [Key] to a [String] to store it in a JSON object; a Dart encoding can | 1143 /// [Key] to a [String] to store it in a JSON object; a Dart encoding can |
1136 /// choose to store a [Key] as an [int] or as the [Key] itself. | 1144 /// choose to store a [Key] as an [int] or as the [Key] itself. |
1137 getObjectPropertyValue(Key key); | 1145 getObjectPropertyValue(Key key); |
1138 } | 1146 } |
OLD | NEW |