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

Side by Side Diff: test/dart_codegen/expect/convert/json.dart

Issue 1096583002: Reifier hookup (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: Address comments Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « test/dart_codegen/expect/collection/splay_tree.dart ('k') | test/dart_codegen/expect/d/d.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of dart.convert; 1 part of dart.convert;
2 class JsonUnsupportedObjectError extends Error {final unsupportedObject; 2 class JsonUnsupportedObjectError extends Error {final unsupportedObject;
3 final cause; 3 final cause;
4 JsonUnsupportedObjectError(this.unsupportedObject, { 4 JsonUnsupportedObjectError(this.unsupportedObject, {
5 this.cause} 5 this.cause}
6 ); 6 );
7 String toString() { 7 String toString() {
8 if (cause != null) { 8 if (cause != null) {
9 return "Converting object to an encodable object failed."; 9 return "Converting object to an encodable object failed.";
10 } 10 }
(...skipping 19 matching lines...) Expand all
30 ) { 30 ) {
31 if (reviver == null) reviver = _reviver; 31 if (reviver == null) reviver = _reviver;
32 if (reviver == null) return decoder.convert(source); 32 if (reviver == null) return decoder.convert(source);
33 return new JsonDecoder(reviver).convert(source); 33 return new JsonDecoder(reviver).convert(source);
34 } 34 }
35 String encode(Object value, { 35 String encode(Object value, {
36 toEncodable(var object)} 36 toEncodable(var object)}
37 ) { 37 ) {
38 if (toEncodable == null) toEncodable = _toEncodable; 38 if (toEncodable == null) toEncodable = _toEncodable;
39 if (toEncodable == null) return encoder.convert(value); 39 if (toEncodable == null) return encoder.convert(value);
40 return new JsonEncoder(DEVC$RT.cast(toEncodable, __t8, __t6, "CompositeCast", " ""line 142, column 28 of dart:convert/json.dart: """, toEncodable is __t6, false )).convert(value); 40 return new JsonEncoder(DEVC$RT.cast(toEncodable, __CastType8, __CastType6, "Com positeCast", """line 142, column 28 of dart:convert/json.dart: """, toEncodable is __CastType6, false)).convert(value);
41 } 41 }
42 JsonEncoder get encoder { 42 JsonEncoder get encoder {
43 if (_toEncodable == null) return const JsonEncoder(); 43 if (_toEncodable == null) return const JsonEncoder();
44 return new JsonEncoder(DEVC$RT.cast(_toEncodable, _ToEncodable, __t6, "Composit eCast", """line 147, column 28 of dart:convert/json.dart: """, _toEncodable is _ _t6, false)); 44 return new JsonEncoder(DEVC$RT.cast(_toEncodable, _ToEncodable, __CastType6, "C ompositeCast", """line 147, column 28 of dart:convert/json.dart: """, _toEncodab le is __CastType6, false));
45 } 45 }
46 JsonDecoder get decoder { 46 JsonDecoder get decoder {
47 if (_reviver == null) return const JsonDecoder(); 47 if (_reviver == null) return const JsonDecoder();
48 return new JsonDecoder(_reviver); 48 return new JsonDecoder(_reviver);
49 } 49 }
50 } 50 }
51 class JsonEncoder extends Converter<Object, String> {final String indent; 51 class JsonEncoder extends Converter<Object, String> {final String indent;
52 final Function _toEncodable; 52 final Function _toEncodable;
53 const JsonEncoder([Object toEncodable(Object nonSerializable)]) : this.indent = null, this._toEncodable = toEncodable; 53 const JsonEncoder([Object toEncodable(Object nonSerializable)]) : this.indent = null, this._toEncodable = toEncodable;
54 const JsonEncoder.withIndent(this.indent, [Object toEncodable(Object nonSeriali zable)]) : this._toEncodable = toEncodable; 54 const JsonEncoder.withIndent(this.indent, [Object toEncodable(Object nonSeriali zable)]) : this._toEncodable = toEncodable;
55 String convert(Object object) => _JsonStringStringifier.stringify(object, DEVC$ RT.cast(_toEncodable, Function, __t8, "ImplicitCast", """line 243, column 48 of dart:convert/json.dart: """, _toEncodable is __t8, true), indent); 55 String convert(Object object) => _JsonStringStringifier.stringify(object, DEVC$ RT.cast(_toEncodable, Function, __CastType8, "ImplicitCast", """line 243, column 48 of dart:convert/json.dart: """, _toEncodable is __CastType8, true), indent);
56 ChunkedConversionSink<Object> startChunkedConversion(Sink<String> sink) { 56 ChunkedConversionSink<Object> startChunkedConversion(Sink<String> sink) {
57 if (sink is! StringConversionSink) { 57 if (sink is! StringConversionSink) {
58 sink = new StringConversionSink.from(sink); 58 sink = new StringConversionSink.from(sink);
59 } 59 }
60 else if (sink is _Utf8EncoderSink) { 60 else if (sink is _Utf8EncoderSink) {
61 return new _JsonUtf8EncoderSink(sink._sink, _toEncodable, JsonUtf8Encoder._utf8E ncode(indent), JsonUtf8Encoder.DEFAULT_BUFFER_SIZE); 61 return new _JsonUtf8EncoderSink(sink._sink, _toEncodable, JsonUtf8Encoder._utf8E ncode(indent), JsonUtf8Encoder.DEFAULT_BUFFER_SIZE);
62 } 62 }
63 return new _JsonEncoderSink(DEVC$RT.cast(sink, DEVC$RT.type((Sink<String> _) { 63 return new _JsonEncoderSink(DEVC$RT.cast(sink, DEVC$RT.type((Sink<String> _) {
64 } 64 }
65 ), StringConversionSink, "ImplicitCast", """line 262, column 33 of dart:convert/ json.dart: """, sink is StringConversionSink, true), _toEncodable, indent); 65 ), StringConversionSink, "ImplicitCast", """line 262, column 33 of dart:convert/ json.dart: """, sink is StringConversionSink, true), _toEncodable, indent);
66 } 66 }
67 Stream<String> bind(Stream<Object> stream) => ((__x10) => DEVC$RT.cast(__x10, D EVC$RT.type((DDC$async$.Stream<dynamic> _) { 67 Stream<String> bind(Stream<Object> stream) => ((__x10) => DEVC$RT.cast(__x10, D EVC$RT.type((DDC$async$.Stream<dynamic> _) {
68 } 68 }
69 ), DEVC$RT.type((DDC$async$.Stream<String> _) { 69 ), DEVC$RT.type((DDC$async$.Stream<String> _) {
70 } 70 }
71 ), "CompositeCast", """line 266, column 49 of dart:convert/json.dart: """, __x10 is DDC$async$.Stream<String>, false))(super.bind(stream)); 71 ), "CompositeCast", """line 266, column 49 of dart:convert/json.dart: """, __x10 is DDC$async$.Stream<String>, false))(super.bind(stream));
72 Converter<Object, dynamic> fuse(Converter<String, dynamic> other) { 72 Converter<Object, dynamic> fuse(Converter<String, dynamic> other) {
73 if (other is Utf8Encoder) { 73 if (other is Utf8Encoder) {
74 return new JsonUtf8Encoder(indent, DEVC$RT.cast(_toEncodable, Function, __t11, " CompositeCast", """line 270, column 42 of dart:convert/json.dart: """, _toEncoda ble is __t11, false)); 74 return new JsonUtf8Encoder(indent, DEVC$RT.cast(_toEncodable, Function, __CastTy pe11, "CompositeCast", """line 270, column 42 of dart:convert/json.dart: """, _t oEncodable is __CastType11, false));
75 } 75 }
76 return super.fuse(other); 76 return super.fuse(other);
77 } 77 }
78 } 78 }
79 class JsonUtf8Encoder extends Converter<Object, List<int>> {static const int DE FAULT_BUFFER_SIZE = 256; 79 class JsonUtf8Encoder extends Converter<Object, List<int>> {static const int DE FAULT_BUFFER_SIZE = 256;
80 final List<int> _indent; 80 final List<int> _indent;
81 final Function _toEncodable; 81 final Function _toEncodable;
82 final int _bufferSize; 82 final int _bufferSize;
83 JsonUtf8Encoder([String indent, toEncodable(Object object), int bufferSize = DE FAULT_BUFFER_SIZE]) : _indent = _utf8Encode(indent), _toEncodable = toEncodable, _bufferSize = bufferSize; 83 JsonUtf8Encoder([String indent, toEncodable(Object object), int bufferSize = DE FAULT_BUFFER_SIZE]) : _indent = _utf8Encode(indent), _toEncodable = toEncodable, _bufferSize = bufferSize;
84 static List<int> _utf8Encode(String string) { 84 static List<int> _utf8Encode(String string) {
85 if (string == null) return null; 85 if (string == null) return null;
86 if (string.isEmpty) return new Uint8List(0); 86 if (string.isEmpty) return new Uint8List(0);
87 checkAscii: { 87 checkAscii: {
88 for (int i = 0; i < string.length; i++) { 88 for (int i = 0; i < string.length; i++) {
89 if (string.codeUnitAt(i) >= 0x80) break checkAscii; 89 if (string.codeUnitAt(i) >= 0x80) break checkAscii;
90 } 90 }
91 return string.codeUnits; 91 return string.codeUnits;
92 } 92 }
93 return UTF8.encode(string); 93 return UTF8.encode(string);
94 } 94 }
95 List<int> convert(Object object) { 95 List<int> convert(Object object) {
96 List<List<int>> bytes = <List<int>> []; 96 List<List<int>> bytes = <List<int>> [];
97 void addChunk(Uint8List chunk, int start, int end) { 97 void addChunk(Uint8List chunk, int start, int end) {
98 if (start > 0 || end < chunk.length) { 98 if (start > 0 || end < chunk.length) {
99 int length = end - start; 99 int length = end - start;
100 chunk = new Uint8List.view(chunk.buffer, chunk.offsetInBytes + start, length); 100 chunk = new Uint8List.view(chunk.buffer, chunk.offsetInBytes + start, length);
101 } 101 }
102 bytes.add(chunk); 102 bytes.add(chunk);
103 } 103 }
104 _JsonUtf8Stringifier.stringify(object, _indent, DEVC$RT.cast(_toEncodable, Func tion, __t11, "CompositeCast", """line 352, column 36 of dart:convert/json.dart: """, _toEncodable is __t11, false), _bufferSize, addChunk); 104 _JsonUtf8Stringifier.stringify(object, _indent, DEVC$RT.cast(_toEncodable, Func tion, __CastType11, "CompositeCast", """line 352, column 36 of dart:convert/json .dart: """, _toEncodable is __CastType11, false), _bufferSize, addChunk);
105 if (bytes.length == 1) return bytes[0]; 105 if (bytes.length == 1) return bytes[0];
106 int length = 0; 106 int length = 0;
107 for (int i = 0; i < bytes.length; i++) { 107 for (int i = 0; i < bytes.length; i++) {
108 length += bytes[i].length; 108 length += bytes[i].length;
109 } 109 }
110 Uint8List result = new Uint8List(length); 110 Uint8List result = new Uint8List(length);
111 for (int i = 0, offset = 0; i < bytes.length; i++) { 111 for (int i = 0, offset = 0; i < bytes.length; i++) {
112 var byteList = bytes[i]; 112 var byteList = bytes[i];
113 int end = offset + byteList.length; 113 int end = offset + byteList.length;
114 result.setRange(offset, end, byteList); 114 result.setRange(offset, end, byteList);
(...skipping 26 matching lines...) Expand all
141 final Function _toEncodable; 141 final Function _toEncodable;
142 final StringConversionSink _sink; 142 final StringConversionSink _sink;
143 bool _isDone = false; 143 bool _isDone = false;
144 _JsonEncoderSink(this._sink, this._toEncodable, this._indent); 144 _JsonEncoderSink(this._sink, this._toEncodable, this._indent);
145 void add(Object o) { 145 void add(Object o) {
146 if (_isDone) { 146 if (_isDone) {
147 throw new StateError("Only one call to add allowed"); 147 throw new StateError("Only one call to add allowed");
148 } 148 }
149 _isDone = true; 149 _isDone = true;
150 ClosableStringSink stringSink = _sink.asStringSink(); 150 ClosableStringSink stringSink = _sink.asStringSink();
151 _JsonStringStringifier.printOn(o, stringSink, DEVC$RT.cast(_toEncodable, Functi on, __t8, "ImplicitCast", """line 425, column 51 of dart:convert/json.dart: """, _toEncodable is __t8, true), _indent); 151 _JsonStringStringifier.printOn(o, stringSink, DEVC$RT.cast(_toEncodable, Functi on, __CastType8, "ImplicitCast", """line 425, column 51 of dart:convert/json.dar t: """, _toEncodable is __CastType8, true), _indent);
152 stringSink.close(); 152 stringSink.close();
153 } 153 }
154 void close() { 154 void close() {
155 } 155 }
156 } 156 }
157 class _JsonUtf8EncoderSink extends ChunkedConversionSink<Object> {final ByteCon versionSink _sink; 157 class _JsonUtf8EncoderSink extends ChunkedConversionSink<Object> {final ByteCon versionSink _sink;
158 final List<int> _indent; 158 final List<int> _indent;
159 final Function _toEncodable; 159 final Function _toEncodable;
160 final int _bufferSize; 160 final int _bufferSize;
161 bool _isDone = false; 161 bool _isDone = false;
162 _JsonUtf8EncoderSink(this._sink, this._toEncodable, this._indent, this._bufferS ize); 162 _JsonUtf8EncoderSink(this._sink, this._toEncodable, this._indent, this._bufferS ize);
163 void _addChunk(Uint8List chunk, int start, int end) { 163 void _addChunk(Uint8List chunk, int start, int end) {
164 _sink.addSlice(chunk, start, end, false); 164 _sink.addSlice(chunk, start, end, false);
165 } 165 }
166 void add(Object object) { 166 void add(Object object) {
167 if (_isDone) { 167 if (_isDone) {
168 throw new StateError("Only one call to add allowed"); 168 throw new StateError("Only one call to add allowed");
169 } 169 }
170 _isDone = true; 170 _isDone = true;
171 _JsonUtf8Stringifier.stringify(object, _indent, DEVC$RT.cast(_toEncodable, Func tion, __t11, "CompositeCast", """line 455, column 53 of dart:convert/json.dart: """, _toEncodable is __t11, false), _bufferSize, _addChunk); 171 _JsonUtf8Stringifier.stringify(object, _indent, DEVC$RT.cast(_toEncodable, Func tion, __CastType11, "CompositeCast", """line 455, column 53 of dart:convert/json .dart: """, _toEncodable is __CastType11, false), _bufferSize, _addChunk);
172 _sink.close(); 172 _sink.close();
173 } 173 }
174 void close() { 174 void close() {
175 if (!_isDone) { 175 if (!_isDone) {
176 _isDone = true; 176 _isDone = true;
177 _sink.close(); 177 _sink.close();
178 } 178 }
179 } 179 }
180 } 180 }
181 class JsonDecoder extends Converter<String, Object> {final _Reviver _reviver; 181 class JsonDecoder extends Converter<String, Object> {final _Reviver _reviver;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 386 }
387 ); 387 );
388 writeString('\n'); 388 writeString('\n');
389 _indentLevel--; 389 _indentLevel--;
390 writeIndentation(_indentLevel); 390 writeIndentation(_indentLevel);
391 writeString('}'); 391 writeString('}');
392 } 392 }
393 } 393 }
394 } 394 }
395 class _JsonStringStringifier extends _JsonStringifier {final StringSink _sink; 395 class _JsonStringStringifier extends _JsonStringifier {final StringSink _sink;
396 _JsonStringStringifier(this._sink, _toEncodable) : super(DEVC$RT.cast(_toEncoda ble, dynamic, __t6, "CompositeCast", """line 798, column 60 of dart:convert/json .dart: """, _toEncodable is __t6, false)); 396 _JsonStringStringifier(this._sink, _toEncodable) : super(DEVC$RT.cast(_toEncoda ble, dynamic, __CastType6, "CompositeCast", """line 798, column 60 of dart:conve rt/json.dart: """, _toEncodable is __CastType6, false));
397 static String stringify(object, toEncodable(object), String indent) { 397 static String stringify(object, toEncodable(object), String indent) {
398 StringBuffer output = new StringBuffer(); 398 StringBuffer output = new StringBuffer();
399 printOn(object, output, toEncodable, indent); 399 printOn(object, output, toEncodable, indent);
400 return output.toString(); 400 return output.toString();
401 } 401 }
402 static void printOn(object, StringSink output, toEncodable(object), String inde nt) { 402 static void printOn(object, StringSink output, toEncodable(object), String inde nt) {
403 var stringifier; 403 var stringifier;
404 if (indent == null) { 404 if (indent == null) {
405 stringifier = new _JsonStringStringifier(output, toEncodable); 405 stringifier = new _JsonStringStringifier(output, toEncodable);
406 } 406 }
(...skipping 18 matching lines...) Expand all
425 class _JsonStringStringifierPretty extends _JsonStringStringifier with _JsonPre ttyPrintMixin {final String _indent; 425 class _JsonStringStringifierPretty extends _JsonStringStringifier with _JsonPre ttyPrintMixin {final String _indent;
426 _JsonStringStringifierPretty(StringSink sink, Function toEncodable, this._inden t) : super(sink, toEncodable); 426 _JsonStringStringifierPretty(StringSink sink, Function toEncodable, this._inden t) : super(sink, toEncodable);
427 void writeIndentation(int count) { 427 void writeIndentation(int count) {
428 for (int i = 0; i < count; i++) writeString(_indent); 428 for (int i = 0; i < count; i++) writeString(_indent);
429 } 429 }
430 } 430 }
431 class _JsonUtf8Stringifier extends _JsonStringifier {final int bufferSize; 431 class _JsonUtf8Stringifier extends _JsonStringifier {final int bufferSize;
432 final Function addChunk; 432 final Function addChunk;
433 Uint8List buffer; 433 Uint8List buffer;
434 int index = 0; 434 int index = 0;
435 _JsonUtf8Stringifier(toEncodable, int bufferSize, this.addChunk) : super(DEVC$R T.cast(toEncodable, dynamic, __t6, "CompositeCast", """line 874, column 15 of da rt:convert/json.dart: """, toEncodable is __t6, false)), this.bufferSize = buffe rSize, buffer = new Uint8List(bufferSize); 435 _JsonUtf8Stringifier(toEncodable, int bufferSize, this.addChunk) : super(DEVC$R T.cast(toEncodable, dynamic, __CastType6, "CompositeCast", """line 874, column 1 5 of dart:convert/json.dart: """, toEncodable is __CastType6, false)), this.buff erSize = bufferSize, buffer = new Uint8List(bufferSize);
436 static void stringify(Object object, List<int> indent, toEncodableFunction(Obje ct o), int bufferSize, void addChunk(Uint8List chunk, int start, int end)) { 436 static void stringify(Object object, List<int> indent, toEncodableFunction(Obje ct o), int bufferSize, void addChunk(Uint8List chunk, int start, int end)) {
437 _JsonUtf8Stringifier stringifier; 437 _JsonUtf8Stringifier stringifier;
438 if (indent != null) { 438 if (indent != null) {
439 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent, buffer Size, addChunk); 439 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent, buffer Size, addChunk);
440 } 440 }
441 else { 441 else {
442 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize, addChunk ); 442 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize, addChunk );
443 } 443 }
444 stringifier.writeObject(object); 444 stringifier.writeObject(object);
445 stringifier.flush(); 445 stringifier.flush();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 index = end; 536 index = end;
537 } 537 }
538 else { 538 else {
539 for (int i = 0; i < indentLength; i++) { 539 for (int i = 0; i < indentLength; i++) {
540 writeByte(indent[i]); 540 writeByte(indent[i]);
541 } 541 }
542 } 542 }
543 } 543 }
544 } 544 }
545 } 545 }
546 typedef Object __t6(Object __u7); 546 typedef Object __CastType6(Object __u7);
547 typedef dynamic __t8(dynamic __u9); 547 typedef dynamic __CastType8(dynamic __u9);
548 typedef dynamic __t11(Object __u12); 548 typedef dynamic __CastType11(Object __u12);
OLDNEW
« no previous file with comments | « test/dart_codegen/expect/collection/splay_tree.dart ('k') | test/dart_codegen/expect/d/d.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698