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

Side by Side Diff: sdk/lib/json/json.dart

Issue 12190002: Revert "Use browsers JSON.parse for parsing JSON." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | tests/json/json_test.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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart.json; 5 library dart.json;
6 6
7 // JSON parsing and serialization. 7 // JSON parsing and serialization.
8 8
9 /** 9 /**
10 * Error thrown by JSON serialization if an object cannot be serialized. 10 * Error thrown by JSON serialization if an object cannot be serialized.
(...skipping 17 matching lines...) Expand all
28 if (cause != null) { 28 if (cause != null) {
29 return "Calling toJson method on object failed."; 29 return "Calling toJson method on object failed.";
30 } else { 30 } else {
31 return "Object toJson method returns non-serializable value."; 31 return "Object toJson method returns non-serializable value.";
32 } 32 }
33 } 33 }
34 } 34 }
35 35
36 36
37 /** 37 /**
38 * Parses [json] and builds the corresponding parsed JSON value. 38 * Parses [json] and build the corresponding parsed JSON value.
39 * 39 *
40 * Parsed JSON values are of the types [num], [String], [bool], [Null], 40 * Parsed JSON values are of the types [num], [String], [bool], [Null],
41 * [List]s of parsed JSON values or [Map]s from [String] to parsed 41 * [List]s of parsed JSON values or [Map]s from [String] to parsed
42 * JSON values. 42 * JSON values.
43 * 43 *
44 * The optional [reviver] function, if provided, is called once for each object 44 * The optional [revivier] function, if provided, is called once for each
45 * or list property parsed. The arguments are the property name ([String]) or 45 * object or list property parsed. The arguments are the property name
46 * list index ([int]), and the value is the parsed value. The return value of 46 * ([String]) or list index ([int]), and the value is the parsed value.
47 * the reviver will be used as the value of that property instead of the parsed 47 * The return value of the revivier will be used as the value of that property
48 * value. The top level value is passed to the reviver with the empty string as 48 * instead the parsed value.
49 * a key.
50 * 49 *
51 * Throws [FormatException] if the input is not valid JSON text. 50 * Throws [FormatException] if the input is not valid JSON text.
52 */ 51 */
53 external parse(String json, [reviver(var key, var value)]); 52 parse(String json, [reviver(var key, var value)]) {
54
55 _parse(String json, [reviver(var key, var value)]) {
56 BuildJsonListener listener; 53 BuildJsonListener listener;
57 if (reviver == null) { 54 if (reviver == null) {
58 listener = new BuildJsonListener(); 55 listener = new BuildJsonListener();
59 } else { 56 } else {
60 listener = new ReviverJsonListener(reviver); 57 listener = new ReviverJsonListener(reviver);
61 } 58 }
62 new JsonParser(json, listener).parse(); 59 new JsonParser(json, listener).parse();
63 return listener.result; 60 return listener.result;
64 } 61 }
65 62
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 first = false; 795 first = false;
799 }); 796 });
800 sb.add('}'); 797 sb.add('}');
801 seen.removeLast(); 798 seen.removeLast();
802 return true; 799 return true;
803 } else { 800 } else {
804 return false; 801 return false;
805 } 802 }
806 } 803 }
807 } 804 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | tests/json/json_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698