OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 throw new Error("Incomplete JSON"); | 115 throw new Error("Incomplete JSON"); |
116 this._json = this._json.slice(0, closingBracketIndex + 1); | 116 this._json = this._json.slice(0, closingBracketIndex + 1); |
117 this._snapshot.strings = JSON.parse(this._json); | 117 this._snapshot.strings = JSON.parse(this._json); |
118 }, | 118 }, |
119 | 119 |
120 /** | 120 /** |
121 * @param {string} chunk | 121 * @param {string} chunk |
122 */ | 122 */ |
123 write: function(chunk) | 123 write: function(chunk) |
124 { | 124 { |
125 this._json += chunk; | 125 if (this._json !== null) |
| 126 this._json += chunk; |
126 while (true) { | 127 while (true) { |
127 switch (this._state) { | 128 switch (this._state) { |
128 case "find-snapshot-info": { | 129 case "find-snapshot-info": { |
129 var snapshotToken = "\"snapshot\""; | 130 var snapshotToken = "\"snapshot\""; |
130 var snapshotTokenIndex = this._json.indexOf(snapshotToken); | 131 var snapshotTokenIndex = this._json.indexOf(snapshotToken); |
131 if (snapshotTokenIndex === -1) | 132 if (snapshotTokenIndex === -1) |
132 throw new Error("Snapshot token not found"); | 133 throw new Error("Snapshot token not found"); |
133 this._json = this._json.slice(snapshotTokenIndex + snapshotToken
.length + 1); | 134 |
| 135 var json = this._json.slice(snapshotTokenIndex + snapshotToken.l
ength + 1); |
134 this._state = "parse-snapshot-info"; | 136 this._state = "parse-snapshot-info"; |
135 this._progress.updateStatus("Loading snapshot info\u2026"); | 137 this._progress.updateStatus("Loading snapshot info\u2026"); |
136 break; | 138 this._json = null; // tokenizer takes over input. |
| 139 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTok
enizer(this._writeBalancedJSON.bind(this)); |
| 140 // Fall through with adjusted payload. |
| 141 chunk = json; |
137 } | 142 } |
138 case "parse-snapshot-info": { | 143 case "parse-snapshot-info": { |
139 var closingBracketIndex = WebInspector.TextUtils.findBalancedCur
lyBrackets(this._json); | 144 this._jsonTokenizer.write(chunk); |
140 if (closingBracketIndex === -1) | 145 if (this._jsonTokenizer) |
141 return; | 146 return; // no remainder to process. |
142 this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JS
ON.parse(this._json.slice(0, closingBracketIndex))); | |
143 this._json = this._json.slice(closingBracketIndex); | |
144 this._state = "find-nodes"; | |
145 break; | 147 break; |
146 } | 148 } |
147 case "find-nodes": { | 149 case "find-nodes": { |
148 var nodesToken = "\"nodes\""; | 150 var nodesToken = "\"nodes\""; |
149 var nodesTokenIndex = this._json.indexOf(nodesToken); | 151 var nodesTokenIndex = this._json.indexOf(nodesToken); |
150 if (nodesTokenIndex === -1) | 152 if (nodesTokenIndex === -1) |
151 return; | 153 return; |
152 var bracketIndex = this._json.indexOf("[", nodesTokenIndex); | 154 var bracketIndex = this._json.indexOf("[", nodesTokenIndex); |
153 if (bracketIndex === -1) | 155 if (bracketIndex === -1) |
154 return; | 156 return; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 if (bracketIndex === -1) | 260 if (bracketIndex === -1) |
259 return; | 261 return; |
260 this._json = this._json.slice(bracketIndex); | 262 this._json = this._json.slice(bracketIndex); |
261 this._state = "accumulate-strings"; | 263 this._state = "accumulate-strings"; |
262 break; | 264 break; |
263 } | 265 } |
264 case "accumulate-strings": | 266 case "accumulate-strings": |
265 return; | 267 return; |
266 } | 268 } |
267 } | 269 } |
| 270 }, |
| 271 |
| 272 /** |
| 273 * @param {string} data |
| 274 */ |
| 275 _writeBalancedJSON: function(data) |
| 276 { |
| 277 this._json = this._jsonTokenizer.remainder(); // tokenizer releases inp
ut. |
| 278 this._jsonTokenizer = null; |
| 279 this._state = "find-nodes"; |
| 280 this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse
(data)); |
268 } | 281 } |
269 }; | 282 } |
OLD | NEW |