Index: sdk/lib/_internal/compiler/js_lib/convert_patch.dart |
diff --git a/sdk/lib/_internal/compiler/js_lib/convert_patch.dart b/sdk/lib/_internal/compiler/js_lib/convert_patch.dart |
index dd7244d10deba02ebe3b06800a77a3d368136321..2686ca6cdb3eb8f14436833e9244979775e88d02 100644 |
--- a/sdk/lib/_internal/compiler/js_lib/convert_patch.dart |
+++ b/sdk/lib/_internal/compiler/js_lib/convert_patch.dart |
@@ -337,3 +337,35 @@ class _JsonMap implements LinkedHashMap { |
static _newJavaScriptObject() |
=> JS('=Object', 'Object.create(null)'); |
} |
+ |
+@patch class JsonDecoder { |
+ @patch |
+ StringConversionSink startChunkedConversion(Sink<Object> sink) { |
+ return new _JsonDecoderSink(_reviver, sink); |
+ } |
+} |
+ |
+/** |
+ * Implements the chunked conversion from a JSON string to its corresponding |
+ * object. |
+ * |
+ * The sink only creates one object, but its input can be chunked. |
+ */ |
+// TODO(floitsch): don't accumulate everything before starting to decode. |
+class _JsonDecoderSink extends _StringSinkConversionSink { |
+ final _Reviver _reviver; |
+ final Sink<Object> _sink; |
+ |
+ _JsonDecoderSink(this._reviver, this._sink) |
+ : super(new StringBuffer()); |
+ |
+ void close() { |
+ super.close(); |
+ StringBuffer buffer = _stringSink; |
+ String accumulated = buffer.toString(); |
+ buffer.clear(); |
+ Object decoded = _parseJson(accumulated, _reviver); |
+ _sink.add(decoded); |
+ _sink.close(); |
+ } |
+} |