Skip to content

Commit 0433d6f

Browse files
committed
merge updates from official devtools
2 parents 7bb1cac + e50c0f5 commit 0433d6f

File tree

11 files changed

+415
-383
lines changed

11 files changed

+415
-383
lines changed

resources/unpacked/devtools/front_end/object_ui/ObjectPropertiesSection.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,23 @@ ObjectUI.ObjectPropertiesSection = class extends UI.TreeOutlineInShadow {
185185
*/
186186
static valueElementForFunctionDescription(description, includePreview, defaultName) {
187187
var valueElement = createElementWithClass('span', 'object-value-function');
188-
var text = description ? description.replace(/^function [gs]et /, 'function ') : '';
188+
var text = '';
189+
if (description) {
190+
text = description.replace(/^function [gs]et /, 'function ')
191+
.replace(/^function [gs]et\(/, 'function\(')
192+
.replace(/^[gs]et /, '');
193+
}
189194
defaultName = defaultName || '';
190195

191196
// This set of best-effort regular expressions captures common function descriptions.
192197
// Ideally, some parser would provide prefix, arguments, function body text separately.
193-
var isAsync = text.startsWith('async function ');
194-
var isGenerator = text.startsWith('function* ');
198+
var asyncMatch = text.match(/^(async\s+function)/);
199+
var isGenerator = text.startsWith('function*');
195200
var isGeneratorShorthand = text.startsWith('*');
196-
var isBasic = !isGenerator && text.startsWith('function ');
201+
var isBasic = !isGenerator && text.startsWith('function');
197202
var isClass = text.startsWith('class ') || text.startsWith('class{');
198203
var firstArrowIndex = text.indexOf('=>');
199-
var isArrow = !isAsync && !isGenerator && !isBasic && !isClass && firstArrowIndex > 0;
204+
var isArrow = !asyncMatch && !isGenerator && !isBasic && !isClass && firstArrowIndex > 0;
200205

201206
var textAfterPrefix;
202207
if (isClass) {
@@ -206,8 +211,8 @@ ObjectUI.ObjectPropertiesSection = class extends UI.TreeOutlineInShadow {
206211
if (classNameMatch)
207212
className = classNameMatch[0].trim() || defaultName;
208213
addElements('class', textAfterPrefix, className);
209-
} else if (isAsync) {
210-
textAfterPrefix = text.substring('async function'.length);
214+
} else if (asyncMatch) {
215+
textAfterPrefix = text.substring(asyncMatch[1].length);
211216
addElements('async \u0192', textAfterPrefix, nameAndArguments(textAfterPrefix));
212217
} else if (isGenerator) {
213218
textAfterPrefix = text.substring('function*'.length);

resources/unpacked/devtools/front_end/persistence/IsolatedFileSystem.js

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -261,69 +261,67 @@ Persistence.IsolatedFileSystem = class {
261261

262262
/**
263263
* @param {string} path
264-
* @return {!Promise<?string>}
264+
* @return {!Promise<?Blob>}
265265
*/
266-
requestFileContentPromise(path) {
267-
var fulfill;
268-
var promise = new Promise(x => fulfill = x);
269-
this.requestFileContent(path, fulfill);
270-
return promise;
266+
requestFileBlob(path) {
267+
return new Promise(resolve => {
268+
this._domFileSystem.root.getFile(path, undefined, entry => {
269+
entry.file(resolve, errorHandler.bind(this));
270+
}, errorHandler.bind(this));
271+
272+
/**
273+
* @this {Persistence.IsolatedFileSystem}
274+
*/
275+
function errorHandler(error) {
276+
if (error.name === 'NotFoundError') {
277+
resolve(null);
278+
return;
279+
}
280+
281+
var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
282+
console.error(errorMessage + ' when getting content for file \'' + (this._path + '/' + path) + '\'');
283+
resolve(null);
284+
}
285+
});
271286
}
272287

273288
/**
274289
* @param {string} path
275-
* @param {function(?string)} callback
290+
* @return {!Promise<?string>}
276291
*/
277-
requestFileContent(path, callback) {
278-
this._domFileSystem.root.getFile(path, undefined, fileEntryLoaded.bind(this), errorHandler.bind(this));
279-
280-
/**
281-
* @param {!FileEntry} entry
282-
* @this {Persistence.IsolatedFileSystem}
283-
*/
284-
function fileEntryLoaded(entry) {
285-
entry.file(fileLoaded, errorHandler.bind(this));
292+
async requestFileContentPromise(path) {
293+
var blob = await this.requestFileBlob(path);
294+
if (!blob)
295+
return null;
296+
297+
var reader = new FileReader();
298+
var fileContentsLoadedPromise = new Promise(resolve => reader.onloadend = resolve);
299+
if (Persistence.IsolatedFileSystem.ImageExtensions.has(Common.ParsedURL.extractExtension(path)))
300+
reader.readAsDataURL(blob);
301+
else
302+
reader.readAsText(blob);
303+
await fileContentsLoadedPromise;
304+
if (reader.error) {
305+
console.error('Can\'t read file: ' + path + ': ' + reader.error);
306+
return null;
286307
}
287-
288-
/**
289-
* @param {!Blob} file
290-
*/
291-
function fileLoaded(file) {
292-
var reader = new FileReader();
293-
reader.onloadend = readerLoadEnd;
294-
if (Persistence.IsolatedFileSystem.ImageExtensions.has(Common.ParsedURL.extractExtension(path)))
295-
reader.readAsDataURL(file);
296-
else
297-
reader.readAsText(file);
308+
try {
309+
var result = reader.result;
310+
} catch (e) {
311+
result = null;
312+
console.error('Can\'t read file: ' + path + ': ' + e);
298313
}
314+
if (result === undefined)
315+
return null;
316+
return result;
317+
}
299318

300-
/**
301-
* @this {!FileReader}
302-
*/
303-
function readerLoadEnd() {
304-
/** @type {?string} */
305-
var string = null;
306-
try {
307-
string = /** @type {string} */ (this.result);
308-
} catch (e) {
309-
console.error('Can\'t read file: ' + path + ': ' + e);
310-
}
311-
callback(string);
312-
}
313-
314-
/**
315-
* @this {Persistence.IsolatedFileSystem}
316-
*/
317-
function errorHandler(error) {
318-
if (error.name === 'NotFoundError') {
319-
callback(null);
320-
return;
321-
}
322-
323-
var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
324-
console.error(errorMessage + ' when getting content for file \'' + (this._path + '/' + path) + '\'');
325-
callback(null);
326-
}
319+
/**
320+
* @param {string} path
321+
* @param {function(?string)} callback
322+
*/
323+
requestFileContent(path, callback) {
324+
this.requestFileContentPromise(path).then(callback);
327325
}
328326

329327
/**

0 commit comments

Comments
 (0)