Commit 75a39ca7 authored by Paul Lewis's avatar Paul Lewis Committed by Commit Bot

Reland "[DevTools]: Moves common to ES modules"

This reverts commit 25a9b3bd.

Reason for revert: Memory snapshots work again

Original change's description:
> Revert "[DevTools]: Moves common to ES modules"
>
> This reverts commit e0645533.
>
> Reason for revert: Memory tool fails to take heap snapshots with this
> error: https://imgur.com/hzR9Eqw
>
> Original change's description:
> > [DevTools]: Moves common to ES modules
> >
> > This CL converts the contents of the common/ folder over to ES modules
> > from the current custom module system. It includes statements in each
> > file that will pollute the global namespace, allowing the non-ESM code
> > to continue working as before.
> >
> > Bug: 1006759
> > Change-Id: Ib591e49155000381f85999a5da6c467ad0160996
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1816563
> > Reviewed-by: Yang Guo <yangguo@chromium.org>
> > Commit-Queue: Paul Lewis <aerotwist@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#699728}
>
>
> Change-Id: Ic0d526780451e8bb4de538f11c85859a3badfb0f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 1006759
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825463
> Commit-Queue: Yang Guo <yangguo@chromium.org>
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#699835}

Bug: 1006759
Change-Id: I48c7e84262bb295e5830cac8a79a274226df046c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825420
Commit-Queue: Paul Lewis <aerotwist@chromium.org>
Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699981}
parent 481a9326
......@@ -139,25 +139,7 @@ all_devtools_files = [
"front_end/color_picker/module.json",
"front_end/color_picker/spectrum.css",
"front_end/color_picker/Spectrum.js",
"front_end/common/CharacterIdMap.js",
"front_end/common/Color.js",
"front_end/common/Console.js",
"front_end/common/ContentProvider.js",
"front_end/common/module.json",
"front_end/common/ModuleExtensionInterfaces.js",
"front_end/common/Object.js",
"front_end/common/OutputStream.js",
"front_end/common/ParsedURL.js",
"front_end/common/Progress.js",
"front_end/common/ResourceType.js",
"front_end/common/SegmentedRange.js",
"front_end/common/Settings.js",
"front_end/common/StaticContentProvider.js",
"front_end/common/TextDictionary.js",
"front_end/common/Throttler.js",
"front_end/common/Trie.js",
"front_end/common/UIString.js",
"front_end/common/Worker.js",
"front_end/components/DockController.js",
"front_end/components/ImagePreview.js",
"front_end/components/imagePreview.css",
......@@ -961,6 +943,32 @@ all_devtools_modules = [
"front_end/root.js",
"front_end/ui/ARIAUtils.js",
"front_end/ui/ui.js",
"front_end/common/common.js",
"front_end/common/App.js",
"front_end/common/AppProvider.js",
"front_end/common/CharacterIdMap.js",
"front_end/common/Color.js",
"front_end/common/ContentProvider.js",
"front_end/common/EventTarget.js",
"front_end/common/JavaScriptMetaData.js",
"front_end/common/Linkifier.js",
"front_end/common/Object.js",
"front_end/common/Console.js",
"front_end/common/ParsedURL.js",
"front_end/common/Progress.js",
"front_end/common/QueryParamHandler.js",
"front_end/common/ResourceType.js",
"front_end/common/Revealer.js",
"front_end/common/Runnable.js",
"front_end/common/SegmentedRange.js",
"front_end/common/Settings.js",
"front_end/common/StaticContentProvider.js",
"front_end/common/StringOutputStream.js",
"front_end/common/TextDictionary.js",
"front_end/common/Throttler.js",
"front_end/common/Trie.js",
"front_end/common/UIString.js",
"front_end/common/Worker.js",
]
devtools_test_files = [
......@@ -1158,6 +1166,32 @@ copied_devtools_modules = [
"$resources_out_dir/root.js",
"$resources_out_dir/ui/ARIAUtils.js",
"$resources_out_dir/ui/ui.js",
"$resources_out_dir/common/common.js",
"$resources_out_dir/common/App.js",
"$resources_out_dir/common/AppProvider.js",
"$resources_out_dir/common/CharacterIdMap.js",
"$resources_out_dir/common/Color.js",
"$resources_out_dir/common/ContentProvider.js",
"$resources_out_dir/common/EventTarget.js",
"$resources_out_dir/common/JavaScriptMetaData.js",
"$resources_out_dir/common/Linkifier.js",
"$resources_out_dir/common/Object.js",
"$resources_out_dir/common/Console.js",
"$resources_out_dir/common/ParsedURL.js",
"$resources_out_dir/common/Progress.js",
"$resources_out_dir/common/QueryParamHandler.js",
"$resources_out_dir/common/ResourceType.js",
"$resources_out_dir/common/Revealer.js",
"$resources_out_dir/common/Runnable.js",
"$resources_out_dir/common/SegmentedRange.js",
"$resources_out_dir/common/Settings.js",
"$resources_out_dir/common/StaticContentProvider.js",
"$resources_out_dir/common/StringOutputStream.js",
"$resources_out_dir/common/TextDictionary.js",
"$resources_out_dir/common/Throttler.js",
"$resources_out_dir/common/Trie.js",
"$resources_out_dir/common/UIString.js",
"$resources_out_dir/common/Worker.js",
]
generated_applications = [
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @interface
*/
export default class App {
/**
* @param {!Document} document
*/
presentUI(document) {
}
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.App = App;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @interface
*/
export default class AppProvider {
/**
* @return {!Common.App}
*/
createApp() {
}
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.AppProvider = AppProvider;
......@@ -5,7 +5,7 @@
* @template T
* @unrestricted
*/
Common.CharacterIdMap = class {
export default class CharacterIdMap {
constructor() {
/** @type {!Map<T, string>} */
this._elementToCharacter = new Map();
......@@ -40,4 +40,13 @@ Common.CharacterIdMap = class {
return null;
return object;
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @constructor
*/
Common.CharacterIdMap = CharacterIdMap;
......@@ -4,7 +4,7 @@
/**
* @unrestricted
*/
Common.Console = class extends Common.Object {
export default class Console extends Common.Object {
constructor() {
super();
/** @type {!Array.<!Common.Console.Message>} */
......@@ -61,17 +61,17 @@ Common.Console = class extends Common.Object {
showPromise() {
return Common.Revealer.reveal(this);
}
};
}
/** @enum {symbol} */
Common.Console.Events = {
export const Events = {
MessageAdded: Symbol('messageAdded')
};
/**
* @enum {string}
*/
Common.Console.MessageLevel = {
export const MessageLevel = {
Info: 'info',
Warning: 'warning',
Error: 'error'
......@@ -80,7 +80,7 @@ Common.Console.MessageLevel = {
/**
* @unrestricted
*/
Common.Console.Message = class {
export class Message {
/**
* @param {string} text
* @param {!Common.Console.MessageLevel} level
......@@ -93,6 +93,28 @@ Common.Console.Message = class {
this.timestamp = (typeof timestamp === 'number') ? timestamp : Date.now();
this.show = show;
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
Common.console = new Console();
Common.console = new Common.Console();
/**
* @constructor
*/
Common.Console = Console;
/** @enum {symbol} */
Common.Console.Events = Events;
/**
* @enum {string}
*/
Common.Console.MessageLevel = MessageLevel;
/**
* @constructor
*/
Common.Console.Message = Message;
......@@ -30,28 +30,30 @@
/**
* @interface
*/
Common.ContentProvider = function() {};
Common.ContentProvider.prototype = {
export default class ContentProvider {
/**
* @return {string}
*/
contentURL() {},
contentURL() {
}
/**
* @return {!Common.ResourceType}
*/
contentType() {},
contentType() {
}
/**
* @return {!Promise<boolean>}
*/
contentEncoded() {},
contentEncoded() {
}
/**
* @return {!Promise<string>}
*/
requestContent() {},
requestContent() {
}
/**
* @param {string} query
......@@ -60,12 +62,12 @@ Common.ContentProvider.prototype = {
* @return {!Promise<!Array<!Common.ContentProvider.SearchMatch>>}
*/
searchInContent(query, caseSensitive, isRegex) {}
};
}
/**
* @unrestricted
*/
Common.ContentProvider.SearchMatch = class {
export class SearchMatch {
/**
* @param {number} lineNumber
* @param {string} lineContent
......@@ -74,7 +76,7 @@ Common.ContentProvider.SearchMatch = class {
this.lineNumber = lineNumber;
this.lineContent = lineContent;
}
};
}
/**
* @param {string} content
......@@ -83,7 +85,7 @@ Common.ContentProvider.SearchMatch = class {
* @param {boolean} isRegex
* @return {!Array.<!Common.ContentProvider.SearchMatch>}
*/
Common.ContentProvider.performSearchInContent = function(content, query, caseSensitive, isRegex) {
export const performSearchInContent = function(content, query, caseSensitive, isRegex) {
const regex = createSearchRegex(query, caseSensitive, isRegex);
const text = new TextUtils.Text(content);
......@@ -104,7 +106,7 @@ Common.ContentProvider.performSearchInContent = function(content, query, caseSen
* @param {?string=} charset
* @return {?string}
*/
Common.ContentProvider.contentAsDataURL = function(content, mimeType, contentEncoded, charset) {
export const contentAsDataURL = function(content, mimeType, contentEncoded, charset) {
const maxDataUrlSize = 1024 * 1024;
if (content === null || content.length > maxDataUrlSize)
return null;
......@@ -112,3 +114,19 @@ Common.ContentProvider.contentAsDataURL = function(content, mimeType, contentEnc
return 'data:' + mimeType + (charset ? ';charset=' + charset : '') + (contentEncoded ? ';base64' : '') + ',' +
content;
};
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.ContentProvider = ContentProvider;
/**
* @constructor
*/
Common.ContentProvider.SearchMatch = SearchMatch;
Common.ContentProvider.performSearchInContent = performSearchInContent;
Common.ContentProvider.contentAsDataURL = contentAsDataURL;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @param {!Array<!Common.EventTarget.EventDescriptor>} eventList
*/
export function removeEventListeners(eventList) {
for (const eventInfo of eventList)
eventInfo.eventTarget.removeEventListener(eventInfo.eventType, eventInfo.listener, eventInfo.thisObject);
// Do not hold references on unused event descriptors.
eventList.splice(0);
}
/**
* @interface
*/
export default class EventTarget {
/**
* @param {symbol} eventType
* @param {function(!Common.Event)} listener
* @param {!Object=} thisObject
* @return {!Common.EventTarget.EventDescriptor}
*/
addEventListener(eventType, listener, thisObject) {
}
/**
* @param {symbol} eventType
* @return {!Promise<*>}
*/
once(eventType) {
}
/**
* @param {string|symbol} eventType
* @param {function(!Common.Event)} listener
* @param {!Object=} thisObject
*/
removeEventListener(eventType, listener, thisObject) {
}
/**
* @param {symbol} eventType
* @return {boolean}
*/
hasEventListeners(eventType) {
}
/**
* @param {symbol} eventType
* @param {*=} eventData
*/
dispatchEventToListeners(eventType, eventData) {
}
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @typedef {!{data: *}}
*/
Common.Event;
/**
* @interface
*/
Common.EventTarget = EventTarget;
EventTarget.removeEventListeners = removeEventListeners;
/**
* @typedef {!{eventTarget: !Common.EventTarget, eventType: (string|symbol), thisObject: (!Object|undefined), listener: function(!Common.Event)}}
*/
Common.EventTarget.EventDescriptor;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @interface
*/
export default class JavaScriptMetadata {
/**
* @param {string} name
* @return {?Array<!Array<string>>}
*/
signaturesForNativeFunction(name) {
}
/**
* @param {string} name
* @param {string} receiverClassName
* @return {?Array<!Array<string>>}
*/
signaturesForInstanceMethod(name, receiverClassName) {
}
/**
* @param {string} name
* @param {string} receiverConstructorName
* @return {?Array<!Array<string>>}
*/
signaturesForStaticMethod(name, receiverConstructorName) {
}
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.JavaScriptMetadata = JavaScriptMetadata;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @interface
*/
export default class Linkifier {
/**
* @param {!Object} object
* @param {!Common.Linkifier.Options=} options
* @return {!Node}
*/
linkify(object, options) {
}
}
/**
* @param {?Object} object
* @param {!Common.Linkifier.Options=} options
* @return {!Promise<!Node>}
*/
export function linkify(object, options) {
if (!object)
return Promise.reject(new Error('Can\'t linkify ' + object));
return self.runtime.extension(Common.Linkifier, object)
.instance()
.then(linkifier => linkifier.linkify(object, options));
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.Linkifier = Linkifier;
Common.Linkifier.linkify = linkify;
/** @typedef {{tooltip: (string|undefined), preventKeyboardFocus: (boolean|undefined)}} */
Common.Linkifier.Options;
......@@ -27,7 +27,7 @@
* @implements {Common.EventTarget}
* @unrestricted
*/
Common.Object = class {
export default class ObjectWrapper {
constructor() {
/** @type {(!Map<string|symbol, !Array<!Common.Object._listenerCallbackTuple>>|undefined)} */
this._listeners;
......@@ -115,69 +115,18 @@ Common.Object = class {
listeners[i].listener.call(listeners[i].thisObject, event);
}
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @typedef {!{data: *}}
* @constructor
*/
Common.Event;
Common.Object = ObjectWrapper;
/**
* @typedef {!{thisObject: (!Object|undefined), listener: function(!Common.Event), disposed: (boolean|undefined)}}
*/
Common.Object._listenerCallbackTuple;
/**
* @interface
*/
Common.EventTarget = function() {};
/**
* @typedef {!{eventTarget: !Common.EventTarget, eventType: (string|symbol), thisObject: (!Object|undefined), listener: function(!Common.Event)}}
*/
Common.EventTarget.EventDescriptor;
/**
* @param {!Array<!Common.EventTarget.EventDescriptor>} eventList
*/
Common.EventTarget.removeEventListeners = function(eventList) {
for (const eventInfo of eventList)
eventInfo.eventTarget.removeEventListener(eventInfo.eventType, eventInfo.listener, eventInfo.thisObject);
// Do not hold references on unused event descriptors.
eventList.splice(0);
};
Common.EventTarget.prototype = {
/**
* @param {symbol} eventType
* @param {function(!Common.Event)} listener
* @param {!Object=} thisObject
* @return {!Common.EventTarget.EventDescriptor}
*/
addEventListener(eventType, listener, thisObject) {},
/**
* @param {symbol} eventType
* @return {!Promise<*>}
*/
once(eventType) {},
/**
* @param {string|symbol} eventType
* @param {function(!Common.Event)} listener
* @param {!Object=} thisObject
*/
removeEventListener(eventType, listener, thisObject) {},
/**
* @param {symbol} eventType
* @return {boolean}
*/
hasEventListeners(eventType) {},
/**
* @param {symbol} eventType
* @param {*=} eventData
*/
dispatchEventToListeners(eventType, eventData) {},
};
......@@ -29,7 +29,7 @@
/**
* @unrestricted
*/
Common.ParsedURL = class {
export default class ParsedURL {
/**
* @param {string} url
*/
......@@ -388,8 +388,7 @@ Common.ParsedURL = class {
return this.url.substring(this.scheme.length + 3);
return this.url;
}
};
}
/**
* @return {?Common.ParsedURL}
......@@ -400,3 +399,12 @@ String.prototype.asParsedURL = function() {
return parsedURL;
return null;
};
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @constructor
*/
Common.ParsedURL = ParsedURL;
......@@ -27,47 +27,51 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @interface
*/
Common.Progress = function() {};
Common.Progress.prototype = {
export default class Progress {
/**
* @param {number} totalWork
*/
setTotalWork(totalWork) {},
setTotalWork(totalWork) {
}
/**
* @param {string} title
*/
setTitle(title) {},
setTitle(title) {
}
/**
* @param {number} worked
* @param {string=} title
*/
setWorked(worked, title) {},
setWorked(worked, title) {
}
/**
* @param {number=} worked
*/
worked(worked) {},
worked(worked) {
}
done() {},
done() {
}
/**
* @return {boolean}
*/
isCanceled() {
return false;
},
};
}
}
/**
* @unrestricted
*/
Common.CompositeProgress = class {
export class CompositeProgress {
/**
* @param {!Common.Progress} parent
*/
......@@ -107,13 +111,13 @@ Common.CompositeProgress = class {
}
this._parent.setWorked(done / totalWeights);
}
};
}
/**
* @implements {Common.Progress}
* @unrestricted
*/
Common.SubProgress = class {
export class SubProgress {
/**
* @param {!Common.CompositeProgress} composite
* @param {number=} weight
......@@ -176,13 +180,13 @@ Common.SubProgress = class {
worked(worked) {
this.setWorked(this._worked + (worked || 1));
}
};
}
/**
* @implements {Common.Progress}
* @unrestricted
*/
Common.ProgressProxy = class {
export class ProgressProxy {
/**
* @param {?Common.Progress} delegate
* @param {function()=} doneCallback
......@@ -246,4 +250,28 @@ Common.ProgressProxy = class {
if (this._delegate)
this._delegate.worked(worked);
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.Progress = Progress;
/**
* @constructor
*/
Common.CompositeProgress = CompositeProgress;
/**
* @constructor
*/
Common.SubProgress = SubProgress;
/**
* @constructor
*/
Common.ProgressProxy = ProgressProxy;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @interface
*/
export default class QueryParamHandler {
/**
* @param {string} value
*/
handleQueryParam(value) {
}
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.QueryParamHandler = QueryParamHandler;
......@@ -5,14 +5,22 @@
/**
* @interface
*/
Common.Revealer = function() {};
export default class Revealer {
/**
* @param {!Object} object
* @param {boolean=} omitFocus
* @return {!Promise}
*/
reveal(object, omitFocus) {
}
}
/**
* @param {?Object} revealable
* @param {boolean=} omitFocus
* @return {!Promise.<undefined>}
*/
Common.Revealer.reveal = function(revealable, omitFocus) {
export const reveal = function(revealable, omitFocus) {
if (!revealable)
return Promise.reject(new Error('Can\'t reveal ' + revealable));
return self.runtime.allInstances(Common.Revealer, revealable).then(reveal);
......@@ -33,123 +41,20 @@ Common.Revealer.reveal = function(revealable, omitFocus) {
* @param {?Object} revealable
* @return {?string}
*/
Common.Revealer.revealDestination = function(revealable) {
export const revealDestination = function(revealable) {
const extension = self.runtime.extension(Common.Revealer, revealable);
if (!extension)
return null;
return extension.descriptor()['destination'];
};
Common.Revealer.prototype = {
/**
* @param {!Object} object
* @param {boolean=} omitFocus
* @return {!Promise}
*/
reveal(object, omitFocus) {}
};
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.App = function() {};
Common.App.prototype = {
/**
* @param {!Document} document
*/
presentUI(document) {}
};
/**
* @interface
*/
Common.AppProvider = function() {};
Common.AppProvider.prototype = {
/**
* @return {!Common.App}
*/
createApp() {}
};
/**
* @interface
*/
Common.QueryParamHandler = function() {};
Common.QueryParamHandler.prototype = {
/**
* @param {string} value
*/
handleQueryParam(value) {}
};
/**
* @interface
*/
Common.Runnable = function() {};
Common.Runnable.prototype = {
/**
* @return {!Promise}
*/
run() {}
};
/**
* @interface
*/
Common.Linkifier = function() {};
Common.Linkifier.prototype = {
/**
* @param {!Object} object
* @param {!Common.Linkifier.Options=} options
* @return {!Node}
*/
linkify(object, options) {}
};
/**
* @param {?Object} object
* @param {!Common.Linkifier.Options=} options
* @return {!Promise<!Node>}
*/
Common.Linkifier.linkify = function(object, options) {
if (!object)
return Promise.reject(new Error('Can\'t linkify ' + object));
return self.runtime.extension(Common.Linkifier, object)
.instance()
.then(linkifier => linkifier.linkify(object, options));
};
/** @typedef {{tooltip: (string|undefined), preventKeyboardFocus: (boolean|undefined)}} */
Common.Linkifier.Options;
/**
* @interface
*/
Common.JavaScriptMetadata = function() {};
Common.JavaScriptMetadata.prototype = {
/**
* @param {string} name
* @return {?Array<!Array<string>>}
*/
signaturesForNativeFunction(name) {},
/**
* @param {string} name
* @param {string} receiverClassName
* @return {?Array<!Array<string>>}
*/
signaturesForInstanceMethod(name, receiverClassName) {},
/**
* @param {string} name
* @param {string} receiverConstructorName
* @return {?Array<!Array<string>>}
*/
signaturesForStaticMethod(name, receiverConstructorName) {}
};
Common.Revealer = Revealer;
Common.Revealer.reveal = reveal;
Common.Revealer.revealDestination = revealDestination;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @interface
*/
export default class Runnable {
/**
* @return {!Promise}
*/
run() {
}
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.Runnable = Runnable;
......@@ -4,7 +4,7 @@
/**
* @unrestricted
*/
Common.Segment = class {
export class Segment {
/**
* @param {number} begin
* @param {number} end
......@@ -25,12 +25,12 @@ Common.Segment = class {
intersects(that) {
return this.begin < that.end && that.begin < this.end;
}
};
}
/**
* @unrestricted
*/
Common.SegmentedRange = class {
export default class SegmentedRange {
/**
* @param {(function(!Common.Segment, !Common.Segment): ?Common.Segment)=} mergeCallback
*/
......@@ -108,4 +108,18 @@ Common.SegmentedRange = class {
merged.end = Math.max(first.end, second.end);
return merged;
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @constructor
*/
Common.Segment = Segment;
/**
* @constructor
*/
Common.SegmentedRange = SegmentedRange;
......@@ -31,7 +31,7 @@
/**
* @unrestricted
*/
Common.Settings = class {
export default class Settings {
/**
* @param {!Common.SettingsStorage} globalStorage
* @param {!Common.SettingsStorage} localStorage
......@@ -164,12 +164,12 @@ Common.Settings = class {
}
return this._globalStorage;
}
};
}
/**
* @unrestricted
*/
Common.SettingsStorage = class {
export class SettingsStorage {
/**
* @param {!Object} object
* @param {function(string, string)=} setCallback
......@@ -244,13 +244,13 @@ Common.SettingsStorage = class {
for (let i = 0; i < 10 && i < keys.length; ++i)
Common.console.log('Setting: \'' + keys[i] + '\', size: ' + sizes[keys[i]]);
}
};
}
/**
* @template V
* @unrestricted
*/
Common.Setting = class {
export class Setting {
/**
* @param {!Common.Settings} settings
* @param {string} name
......@@ -376,12 +376,12 @@ Common.Setting = class {
Common.console.error(errorMessage);
this._storage._dumpSizes();
}
};
}
/**
* @unrestricted
*/
Common.RegExpSetting = class extends Common.Setting {
export class RegExpSetting extends Setting {
/**
* @param {!Common.Settings} settings
* @param {string} name
......@@ -448,12 +448,12 @@ Common.RegExpSetting = class extends Common.Setting {
}
return this._regex;
}
};
}
/**
* @unrestricted
*/
Common.VersionController = class {
export class VersionController {
updateVersion() {
const localStorageVersion =
window.localStorage ? window.localStorage[Common.VersionController._currentVersionName] : 0;
......@@ -877,20 +877,12 @@ Common.VersionController = class {
if (breakpointsSetting.get().length > maxBreakpointsCount)
breakpointsSetting.set([]);
}
};
Common.VersionController._currentVersionName = 'inspectorVersion';
Common.VersionController.currentVersion = 28;
/**
* @type {!Common.Settings}
*/
Common.settings;
}
/**
* @enum {symbol}
*/
Common.SettingStorageType = {
export const SettingStorageType = {
Global: Symbol('Global'),
Local: Symbol('Local'),
Session: Symbol('Session')
......@@ -900,14 +892,58 @@ Common.SettingStorageType = {
* @param {string} settingName
* @return {!Common.Setting}
*/
Common.moduleSetting = function(settingName) {
export function moduleSetting(settingName) {
return Common.settings.moduleSetting(settingName);
};
}
/**
* @param {string} settingName
* @return {!Common.Setting}
*/
Common.settingForTest = function(settingName) {
export function settingForTest(settingName) {
return Common.settings.settingForTest(settingName);
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @constructor
*/
Common.Settings = Settings;
/**
* @constructor
*/
Common.SettingsStorage = SettingsStorage;
/**
* @constructor
*/
Common.Setting = Setting;
/**
* @constructor
*/
Common.RegExpSetting = RegExpSetting;
Common.settingForTest = settingForTest;
/**
* @constructor
*/
Common.VersionController = VersionController;
Common.moduleSetting = moduleSetting;
/**
* @enum {symbol}
*/
Common.SettingStorageType = SettingStorageType;
Common.VersionController._currentVersionName = 'inspectorVersion';
Common.VersionController.currentVersion = 28;
/**
* @type {!Common.Settings}
*/
Common.settings;
......@@ -5,7 +5,7 @@
* @implements {Common.ContentProvider}
* @unrestricted
*/
Common.StaticContentProvider = class {
export default class StaticContentProvider {
/**
* @param {string} contentURL
* @param {!Common.ResourceType} contentType
......@@ -71,4 +71,13 @@ Common.StaticContentProvider = class {
const content = await this._lazyContent();
return content ? Common.ContentProvider.performSearchInContent(content, query, caseSensitive, isRegex) : [];
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @constructor
*/
Common.StaticContentProvider = StaticContentProvider;
......@@ -5,25 +5,25 @@
/**
* @interface
*/
Common.OutputStream = function() {};
Common.OutputStream.prototype = {
export class OutputStream {
/**
* @param {string} data
* @return {!Promise}
*/
write(data) {},
async write(data) {
}
/**
* @return {!Promise}
*/
close() {}
};
async close() {
}
}
/**
* @implements {Common.OutputStream}
*/
Common.StringOutputStream = class {
export default class StringOutputStream {
constructor() {
this._data = '';
}
......@@ -40,7 +40,7 @@ Common.StringOutputStream = class {
/**
* @override
*/
close() {
async close() {
}
/**
......@@ -49,4 +49,14 @@ Common.StringOutputStream = class {
data() {
return this._data;
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @interface
*/
Common.OutputStream = OutputStream;
Common.StringOutputStream = StringOutputStream;
......@@ -31,7 +31,7 @@
/**
* @unrestricted
*/
Common.TextDictionary = class {
export default class TextDictionary {
constructor() {
/** @type {!Map<string, number>} */
this._words = new Map();
......@@ -92,4 +92,10 @@ Common.TextDictionary = class {
this._words.clear();
this._index.clear();
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
Common.TextDictionary = TextDictionary;
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @unrestricted
*/
Common.Throttler = class {
export default class Throttler {
/**
* @param {number} timeout
*/
......@@ -108,7 +109,13 @@ Common.Throttler = class {
_getTime() {
return window.performance.now();
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
Common.Throttler = Throttler;
/** @typedef {function(!Error=)} */
Common.Throttler.FinishCallback;
......@@ -4,7 +4,7 @@
/**
* @unrestricted
*/
Common.Trie = class {
export default class Trie {
constructor() {
this.clear();
}
......@@ -132,4 +132,10 @@ Common.Trie = class {
/** @type {!Array<number>} */
this._freeNodes = [];
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
Common.Trie = Trie;
......@@ -29,57 +29,55 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
self['Common'] = self['Common'] || {};
/**
* @param {string} string
* @param {...*} vararg
* @return {string}
*/
Common.UIString = function(string, vararg) {
export default function UIString(string, vararg) {
return String.vsprintf(Common.localize(string), Array.prototype.slice.call(arguments, 1));
};
}
/**
* @param {string} string
* @param {?ArrayLike} values
* @return {string}
*/
Common.serializeUIString = function(string, values = []) {
export function serializeUIString(string, values = []) {
const messageParts = [string];
const serializedMessage = {messageParts, values};
return JSON.stringify(serializedMessage);
};
}
/**
* @param {string} serializedMessage
* @return {*}
*/
Common.deserializeUIString = function(serializedMessage) {
export function deserializeUIString(serializedMessage) {
if (!serializedMessage)
return {};
return JSON.parse(serializedMessage);
};
}
/**
* @param {string} string
* @return {string}
*/
Common.localize = function(string) {
export function localize(string) {
return string;
};
}
/**
* @unrestricted
*/
Common.UIStringFormat = class {
export class UIStringFormat {
/**
* @param {string} format
*/
constructor(format) {
/** @type {string} */
this._localizedFormat = Common.localize(format);
this._localizedFormat = localize(format);
/** @type {!Array.<!Object>} */
this._tokenizedFormat = String.tokenizeFormatString(this._localizedFormat, String.standardFormatters);
}
......@@ -104,10 +102,7 @@ Common.UIStringFormat = class {
this._tokenizedFormat)
.formattedResult;
}
};
/** @type {!WeakMap<!Array<string>, string>} */
Common._substitutionStrings = new WeakMap();
}
/**
* @param {!Array<string>|string} strings
......@@ -124,3 +119,20 @@ self.ls = function(strings, vararg) {
}
return Common.UIString(substitutionString, ...Array.prototype.slice.call(arguments, 1));
};
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @constructor
*/
Common.UIStringFormat = UIStringFormat;
Common.UIString = UIString;
Common.serializeUIString = serializeUIString;
Common.deserializeUIString = deserializeUIString;
Common.localize = localize;
/** @type {!WeakMap<!Array<string>, string>} */
Common._substitutionStrings = new WeakMap();
......@@ -31,7 +31,7 @@
/**
* @unrestricted
*/
Common.Worker = class {
export default class WorkerWrapper {
/**
* @param {string} appName
*/
......@@ -91,4 +91,13 @@ Common.Worker = class {
set onerror(listener) {
this._workerPromise.then(worker => worker.onerror = listener);
}
};
}
/* Legacy exported object */
self.Common = self.Common || {};
Common = Common || {};
/**
* @constructor
*/
Common.Worker = WorkerWrapper;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import './EventTarget.js';
import './Object.js';
// Do not reorder these imports as it breaks dependencies.
import * as App from './App.js';
import * as AppProvider from './AppProvider.js';
import * as CharacterIdMap from './CharacterIdMap.js';
import * as Color from './Color.js';
import * as Console from './Console.js';
import * as ContentProvider from './ContentProvider.js';
import * as EventTarget from './EventTarget.js';
import * as JavaScriptMetaData from './JavaScriptMetaData.js';
import * as Linkifier from './Linkifier.js';
import * as Object from './Object.js';
import * as ParsedURL from './ParsedURL.js';
import * as Progress from './Progress.js';
import * as QueryParamHandler from './QueryParamHandler.js';
import * as ResourceType from './ResourceType.js';
import * as Revealer from './Revealer.js';
import * as Runnable from './Runnable.js';
import * as SegmentedRange from './SegmentedRange.js';
import * as Settings from './Settings.js';
import * as StaticContentProvider from './StaticContentProvider.js';
import * as StringOutputStream from './StringOutputStream.js';
import * as TextDictionary from './TextDictionary.js';
import * as Throttler from './Throttler.js';
import * as Trie from './Trie.js';
import * as UIString from './UIString.js';
import * as Worker from './Worker.js';
export {
App,
AppProvider,
CharacterIdMap,
Color,
Console,
ContentProvider,
EventTarget,
JavaScriptMetaData,
Linkifier,
Object,
ParsedURL,
Progress,
QueryParamHandler,
ResourceType,
Revealer,
Runnable,
SegmentedRange,
Settings,
StaticContentProvider,
StringOutputStream,
TextDictionary,
Throttler,
Trie,
UIString,
Worker,
};
......@@ -3,10 +3,12 @@
"text_utils",
"platform"
],
"scripts": [
"modules": [
"common.js",
"EventTarget.js",
"Object.js",
"Worker.js",
"TextDictionary.js",
"Object.js",
"Color.js",
"Console.js",
"ContentProvider.js",
......@@ -15,12 +17,20 @@
"ResourceType.js",
"Settings.js",
"StaticContentProvider.js",
"OutputStream.js",
"SegmentedRange.js",
"Throttler.js",
"Trie.js",
"UIString.js",
"ModuleExtensionInterfaces.js",
"Revealer.js",
"App.js",
"AppProvider.js",
"JavaScriptMetaData.js",
"Linkifier.js",
"QueryParamHandler.js",
"Revealer.js",
"Runnable.js",
"StringOutputStream.js",
"CharacterIdMap.js"
]
],
"scripts": []
}
......@@ -2,6 +2,64 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Release build has Runtime.js bundled.
if (!self.Runtime)
self.importScripts('Runtime.js');
// Due to a lack of ESM within workers the functionality required by the
// worker is duplicated here from Common. When ESM lands in Workers, this code
// can be replaced with the ESM equivalent.
// TODO(https://crbug.com/680046) Remove the dupe code below.
const _substitutionStrings = new WeakMap();
/**
* @param {string} string
* @param {?ArrayLike} values
* @return {string}
*/
function serializeUIString(string, values = []) {
const messageParts = [string];
const serializedMessage = {messageParts, values};
return JSON.stringify(serializedMessage);
}
/**
* @param {string} serializedMessage
* @return {*}
*/
function deserializeUIString(serializedMessage) {
if (!serializedMessage)
return {};
return JSON.parse(serializedMessage);
}
function localize(string) {
return string;
}
function UIString(string, vararg) {
return String.vsprintf(localize(string), Array.prototype.slice.call(arguments, 1));
}
/**
* @param {!Array<string>|string} strings
* @param {...*} vararg
* @return {string}
*/
self.ls = function(strings, vararg) {
if (typeof strings === 'string')
return strings;
let substitutionString = _substitutionStrings.get(strings);
if (!substitutionString) {
substitutionString = strings.join('%s');
_substitutionStrings.set(strings, substitutionString);
}
return UIString(substitutionString, ...Array.prototype.slice.call(arguments, 1));
};
self.serializeUIString = serializeUIString;
self.deserializeUIString = deserializeUIString;
Runtime.startWorker('heap_snapshot_worker');
......@@ -756,7 +756,7 @@ HeapSnapshotWorker.HeapSnapshotProgress = class {
* @param {string} status
*/
updateStatus(status) {
this._sendUpdateEvent(Common.serializeUIString(status));
this._sendUpdateEvent(self.serializeUIString(status));
}
/**
......@@ -766,7 +766,7 @@ HeapSnapshotWorker.HeapSnapshotProgress = class {
*/
updateProgress(title, value, total) {
const percentValue = ((total ? (value / total) : 0) * 100).toFixed(0);
this._sendUpdateEvent(Common.serializeUIString(title, [percentValue]));
this._sendUpdateEvent(self.serializeUIString(title, [percentValue]));
}
/**
......
......@@ -71,4 +71,4 @@ JavaScriptMetadata.JavaScriptMetadata = class {
* receiver: (string|undefined),
* }>}
*/
JavaScriptMetadata.NativeFunctions;
\ No newline at end of file
JavaScriptMetadata.NativeFunctions;
......@@ -28,7 +28,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @typedef {string} */
/**
* @typedef {string}
* @suppress {checkTypes}
*/
Protocol.Error = Symbol('Protocol.Error');
/**
......
......@@ -2,4 +2,5 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import './common/common.js';
import './ui/ui.js';
......@@ -279,9 +279,9 @@ def prepare_closure_frontend_compile(temp_devtools_path, descriptors, namespace_
'--externs',
namespace_externs_path,
'--js',
RUNTIME_FILE,
'--js',
ROOT_MODULE_FILE,
'--js',
RUNTIME_FILE,
]
all_files = descriptors.all_compiled_files()
......@@ -318,7 +318,6 @@ def generate_namespace_externs(modules_by_name):
namespace_externs_file = tempfile.NamedTemporaryFile(mode='wt', delete=False)
try:
for namespace in namespaces:
namespace_externs_file.write('/** @const */\n')
namespace_externs_file.write('var %s = {};\n' % namespace)
finally:
namespace_externs_file.close()
......
......@@ -140,6 +140,22 @@ var TestRunner = class {
return eval(`${source}\n//# sourceURL=${url}`);
};
async loadScriptModule(path) {
const source = await this._fetch(this._testBaseURL + path);
return new Promise((resolve, reject) => {
const src = URL.createObjectURL(new Blob([source], { type: 'application/javascript' }));
const script = Object.assign(document.createElement('script'), {
src,
type: 'module',
onerror: reject,
onload: resolve
});
document.head.appendChild(script);
})
};
browserP() {
return this._browserSession.protocol;
}
......
......@@ -6,12 +6,23 @@
// This script is supposed to be evaluated in inspector-protocol/heap-profiler tests
// and the relative paths below are relative to that location.
await testRunner.loadScript('../../../../blink/renderer/devtools/front_end/platform/utilities.js');
await testRunner.loadScript('../../../../blink/renderer/devtools/front_end/common/UIString.js');
await testRunner.loadScript('../../../../blink/renderer/devtools/front_end/heap_snapshot_model/HeapSnapshotModel.js');
await testRunner.loadScript('../../../../blink/renderer/devtools/front_end/heap_snapshot_worker/HeapSnapshot.js');
await testRunner.loadScript('../../../../blink/renderer/devtools/front_end/text_utils/TextUtils.js');
await testRunner.loadScript('../../../../blink/renderer/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js');
await testRunner.loadScriptModule(
'../../../../blink/renderer/devtools/front_end/platform/utilities.js');
await testRunner.loadScriptModule(
'../../../../blink/renderer/devtools/front_end/common/UIString.js');
await testRunner.loadScriptModule(
'../../../../blink/renderer/devtools/front_end/heap_snapshot_model/HeapSnapshotModel.js');
await testRunner.loadScriptModule(
'../../../../blink/renderer/devtools/front_end/heap_snapshot_worker/HeapSnapshot.js');
await testRunner.loadScriptModule(
'../../../../blink/renderer/devtools/front_end/text_utils/TextUtils.js');
await testRunner.loadScriptModule(
'../../../../blink/renderer/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js');
// Expose the (de)serialize code from Common because the worker expects it on self.
// TODO(https://crbug.com/680046) Remove the dupe code below.
self.serializeUIString = Common.serializeUIString;
self.deserializeUIString = Common.deserializeUIString;
async function takeHeapSnapshotInternal(command) {
var loader = new HeapSnapshotWorker.HeapSnapshotLoader();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment