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

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/convert_patch.dart

Issue 649113005: Make JSON parsing work as a chunked conversion sink. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also add an UTF-8 base JSON parser, without intermediate string representations. Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Patch file for dart:convert library. 5 // Patch file for dart:convert library.
6 6
7 import 'dart:_js_helper' show patch; 7 import 'dart:_js_helper' show patch;
8 import 'dart:_foreign_helper' show JS; 8 import 'dart:_foreign_helper' show JS;
9 import 'dart:_interceptors' show JSExtendableArray; 9 import 'dart:_interceptors' show JSExtendableArray;
10 import 'dart:_internal' show MappedIterable; 10 import 'dart:_internal' show MappedIterable;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 => JS('', '#[#]', object, key); 330 => JS('', '#[#]', object, key);
331 static _setProperty(object, String key, value) 331 static _setProperty(object, String key, value)
332 => JS('', '#[#]=#', object, key, value); 332 => JS('', '#[#]=#', object, key, value);
333 static List _getPropertyNames(object) 333 static List _getPropertyNames(object)
334 => JS('JSExtendableArray', 'Object.keys(#)', object); 334 => JS('JSExtendableArray', 'Object.keys(#)', object);
335 static bool _isUnprocessed(object) 335 static bool _isUnprocessed(object)
336 => JS('bool', 'typeof(#)=="undefined"', object); 336 => JS('bool', 'typeof(#)=="undefined"', object);
337 static _newJavaScriptObject() 337 static _newJavaScriptObject()
338 => JS('=Object', 'Object.create(null)'); 338 => JS('=Object', 'Object.create(null)');
339 } 339 }
340
341 @patch class JsonDecoder {
342 @patch
343 StringConversionSink startChunkedConversion(Sink<Object> sink) {
344 return new _JsonDecoderSink(_reviver, sink);
345 }
346 }
347
348 /**
349 * Implements the chunked conversion from a JSON string to its corresponding
350 * object.
351 *
352 * The sink only creates one object, but its input can be chunked.
353 */
354 // TODO(floitsch): don't accumulate everything before starting to decode.
355 class _JsonDecoderSink extends _StringSinkConversionSink {
356 final _Reviver _reviver;
357 final Sink<Object> _sink;
358
359 _JsonDecoderSink(this._reviver, this._sink)
360 : super(new StringBuffer());
361
362 void close() {
363 super.close();
364 StringBuffer buffer = _stringSink;
365 String accumulated = buffer.toString();
366 buffer.clear();
367 Object decoded = _parseJson(accumulated, _reviver);
368 _sink.add(decoded);
369 _sink.close();
370 }
371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698