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

Side by Side Diff: Source/devtools/front_end/sources/ScriptFormatter.js

Issue 685203003: DevTools: Get rid of synchronous XHRs in the frontend code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Annotate code, fix tests Created 6 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 * @param {string} mimeType 98 * @param {string} mimeType
99 * @param {string} content 99 * @param {string} content
100 * @param {function(string, !WebInspector.FormatterSourceMapping)} callback 100 * @param {function(string, !WebInspector.FormatterSourceMapping)} callback
101 */ 101 */
102 formatContent: function(mimeType, content, callback) 102 formatContent: function(mimeType, content, callback)
103 { 103 {
104 content = content.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uF EFF/, ''); 104 content = content.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uF EFF/, '');
105 const method = "format"; 105 const method = "format";
106 var parameters = { mimeType: mimeType, content: content, indentString: W ebInspector.settings.textEditorIndent.get() }; 106 var parameters = { mimeType: mimeType, content: content, indentString: W ebInspector.settings.textEditorIndent.get() };
107 this._tasks.push({ data: parameters, callback: callback }); 107 this._tasks.push({ data: parameters, callback: callback });
108 this._worker.postMessage({ method: method, params: parameters }); 108 this._worker().postMessage({ method: method, params: parameters });
109 }, 109 },
110 110
111 _didFormatContent: function(event) 111 _didFormatContent: function(event)
112 { 112 {
113 var task = this._tasks.shift(); 113 var task = this._tasks.shift();
114 var originalContent = task.data.content; 114 var originalContent = task.data.content;
115 var formattedContent = event.data.content; 115 var formattedContent = event.data.content;
116 var mapping = event.data["mapping"]; 116 var mapping = event.data["mapping"];
117 var sourceMapping = new WebInspector.FormatterSourceMappingImpl(original Content.lineEndings(), formattedContent.lineEndings(), mapping); 117 var sourceMapping = new WebInspector.FormatterSourceMappingImpl(original Content.lineEndings(), formattedContent.lineEndings(), mapping);
118 task.callback(formattedContent, sourceMapping); 118 task.callback(formattedContent, sourceMapping);
119 }, 119 },
120 120
121 /** 121 /**
122 * @return {!Worker} 122 * @return {!WorkerRuntime.Worker}
123 */ 123 */
124 get _worker() 124 _worker: function()
125 { 125 {
126 if (!this._cachedWorker) { 126 if (!this._cachedWorker) {
127 this._cachedWorker = Runtime.startWorker("script_formatter_worker"); 127 this._cachedWorker = new WorkerRuntime.Worker("script_formatter_work er");
128 this._cachedWorker.onmessage = /** @type {function(this:Worker)} */ (this._didFormatContent.bind(this)); 128 this._cachedWorker.onmessage = /** @type {function(this:Worker)} */ (this._didFormatContent.bind(this));
129 } 129 }
130 return this._cachedWorker; 130 return this._cachedWorker;
131 } 131 }
132 } 132 }
133 133
134 /** 134 /**
135 * @constructor 135 * @constructor
136 * @implements {WebInspector.Formatter} 136 * @implements {WebInspector.Formatter}
137 */ 137 */
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 */ 261 */
262 _convertPosition: function(positions1, positions2, position) 262 _convertPosition: function(positions1, positions2, position)
263 { 263 {
264 var index = positions1.upperBound(position) - 1; 264 var index = positions1.upperBound(position) - 1;
265 var convertedPosition = positions2[index] + position - positions1[index] ; 265 var convertedPosition = positions2[index] + position - positions1[index] ;
266 if (index < positions2.length - 1 && convertedPosition > positions2[inde x + 1]) 266 if (index < positions2.length - 1 && convertedPosition > positions2[inde x + 1])
267 convertedPosition = positions2[index + 1]; 267 convertedPosition = positions2[index + 1];
268 return convertedPosition; 268 return convertedPosition;
269 } 269 }
270 } 270 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sources/FilteredItemSelectionDialog.js ('k') | Source/devtools/front_end/ui/View.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698