Chromium Code Reviews| Index: Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js |
| diff --git a/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js b/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js |
| index 8285fa8ccf5f2cd96e53bed43dbf46c16d8e2616..82b8f43b681af68cdb89bc96c785d609bae54ff4 100644 |
| --- a/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js |
| +++ b/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js |
| @@ -122,6 +122,12 @@ WebInspector.HeapSnapshotLoader.prototype = { |
| */ |
| write: function(chunk) |
| { |
| + if (this._state === "parse-snapshot-info") { |
|
alph
2015/03/01 11:30:13
looks like a hack to the state machine.
why not ju
pfeldman
2015/03/01 12:18:53
Done.
|
| + // Tokenizer takes over input. |
| + this._jsonTokenizer.write(chunk); |
| + return; |
| + } |
| + |
| this._json += chunk; |
| while (true) { |
| switch (this._state) { |
| @@ -130,18 +136,16 @@ WebInspector.HeapSnapshotLoader.prototype = { |
| var snapshotTokenIndex = this._json.indexOf(snapshotToken); |
| if (snapshotTokenIndex === -1) |
| throw new Error("Snapshot token not found"); |
| + |
| this._json = this._json.slice(snapshotTokenIndex + snapshotToken.length + 1); |
| this._state = "parse-snapshot-info"; |
| this._progress.updateStatus("Loading snapshot info\u2026"); |
| + this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this._writeBalancedJSON.bind(this)); |
| + this._jsonTokenizer.write(this._json); |
| break; |
| } |
| case "parse-snapshot-info": { |
| - var closingBracketIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(this._json); |
| - if (closingBracketIndex === -1) |
| - return; |
| - this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse(this._json.slice(0, closingBracketIndex))); |
| - this._json = this._json.slice(closingBracketIndex); |
| - this._state = "find-nodes"; |
| + console.assert(false, "This should nevet happen.") |
|
alph
2015/03/01 11:30:14
typo
pfeldman
2015/03/01 12:18:53
Done.
|
| break; |
| } |
| case "find-nodes": { |
| @@ -265,5 +269,16 @@ WebInspector.HeapSnapshotLoader.prototype = { |
| return; |
| } |
| } |
| + }, |
| + |
| + /** |
| + * @param {string} data |
| + */ |
| + _writeBalancedJSON: function(data) |
| + { |
| + this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse(data)); |
| + this._json = this._jsonTokenizer.remainder(); |
| + this._jsonTokenizer = null; |
| + this._state = "find-nodes"; |
| } |
| -}; |
| +} |