Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2037)

Unified Diff: pkg/compiler/lib/src/serialization/json_serializer.dart

Issue 2250643002: Support encoding of NaN, infinity and negative infinity. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/serialization/serialization.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/serialization/json_serializer.dart
diff --git a/pkg/compiler/lib/src/serialization/json_serializer.dart b/pkg/compiler/lib/src/serialization/json_serializer.dart
index 52e9f9604d6d82e33d714c57e9a4e877deb696e1..ba995bde28babd1f15a71b45549438c199707d20 100644
--- a/pkg/compiler/lib/src/serialization/json_serializer.dart
+++ b/pkg/compiler/lib/src/serialization/json_serializer.dart
@@ -15,8 +15,13 @@ class JsonSerializationEncoder implements SerializationEncoder {
const JsonSerializationEncoder();
String encode(ObjectValue objectValue) {
- return new JsonEncoder.withIndent(' ')
- .convert(const JsonValueEncoder().convert(objectValue));
+ try {
+ return new JsonEncoder.withIndent(' ')
+ .convert(const JsonValueEncoder().convert(objectValue));
+ } on JsonUnsupportedObjectError catch (e) {
+ throw 'Error encoding `${e.unsupportedObject}` '
+ '(${e.unsupportedObject.runtimeType})';
+ }
}
}
@@ -48,7 +53,19 @@ class JsonValueEncoder implements ValueVisitor {
visitConstant(ConstantValue value, arg) => visit(value.id);
@override
- double visitDouble(DoubleValue value, arg) => value.value;
+ visitDouble(DoubleValue value, arg) {
+ double d = value.value;
+ if (d.isNaN) {
+ return 'NaN';
+ } else if (d.isInfinite) {
+ if (d.isNegative) {
+ return '-Infinity';
+ } else {
+ return 'Infinity';
+ }
+ }
+ return d;
+ }
@override
visitElement(ElementValue value, arg) => visit(value.id);
« no previous file with comments | « no previous file | pkg/compiler/lib/src/serialization/serialization.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698