Commit 04c82084 authored by Tim van der Lippe's avatar Tim van der Lippe Committed by Commit Bot

Reland "Fix eslint and Closure compiler warnings"

This is a reland of c7f781ee

third_party/blink/web_tests/http/tests/devtools/extensions/extensions-panel.js
has been fixed

Original change's description:
> Fix eslint and Closure compiler warnings
>
> Some functions that were globally scoped were not properly type-checked.
> Adding these to the `externs.js` makes sure that these are now
> type-checked (just like `ls` has been up to this point).
>
> This is in preparation of an upcoming change to run `eslint` and Closure
> compiler in `module`-mode rather than script mode.
>
> Change-Id: Ic2d9dba24c7aae3c6024c3caeea2b042f401b3c5
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1748895
> Commit-Queue: Tim van der Lippe <tvanderlippe@google.com>
> Commit-Queue: Erik Luo <luoe@chromium.org>
> Reviewed-by: Erik Luo <luoe@chromium.org>
> Auto-Submit: Tim van der Lippe <tvanderlippe@google.com>
> Cr-Commit-Position: refs/heads/master@{#686839}

Change-Id: I26df62e5a315992d1b32e19671bee6f608550385
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1755904
Auto-Submit: Tim van der Lippe <tvanderlippe@google.com>
Commit-Queue: Erik Luo <luoe@chromium.org>
Reviewed-by: default avatarErik Luo <luoe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687253}
parent 0e9bff51
// Copyright (c) 2016 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
*/
class LighthousePort {
const LighthousePort = class {
/**
* @param {!string} eventName, 'message', 'close'
* @param {function(string|undefined)} cb
......@@ -20,7 +21,7 @@ class LighthousePort {
close() {
}
}
};
/**
* @implements {LighthousePort}
......
......@@ -325,18 +325,18 @@ Element.prototype.removeChildren = function() {
* @suppress {checkTypes}
* @suppressGlobalPropertiesCheck
*/
function createElement(tagName, customElementType) {
self.createElement = function(tagName, customElementType) {
return document.createElement(tagName, {is: customElementType});
}
};
/**
* @param {number|string} data
* @return {!Text}
* @suppressGlobalPropertiesCheck
*/
function createTextNode(data) {
self.createTextNode = function(data) {
return document.createTextNode(data);
}
};
/**
* @param {string} elementName
......@@ -359,9 +359,9 @@ Document.prototype.createElementWithClass = function(elementName, className, cus
* @return {!Element}
* @suppressGlobalPropertiesCheck
*/
function createElementWithClass(elementName, className, customElementType) {
self.createElementWithClass = function(elementName, className, customElementType) {
return document.createElementWithClass(elementName, className, customElementType);
}
};
/**
* @param {string} childType
......@@ -381,17 +381,17 @@ Document.prototype.createSVGElement = function(childType, className) {
* @return {!Element}
* @suppressGlobalPropertiesCheck
*/
function createSVGElement(childType, className) {
self.createSVGElement = function(childType, className) {
return document.createSVGElement(childType, className);
}
};
/**
* @return {!DocumentFragment}
* @suppressGlobalPropertiesCheck
*/
function createDocumentFragment() {
self.createDocumentFragment = function() {
return document.createDocumentFragment();
}
};
/**
* @param {string} elementName
......@@ -816,7 +816,7 @@ Node.prototype.getComponentRoot = function() {
*/
function onInvokeElement(element, callback) {
element.addEventListener('keydown', event => {
if (isEnterOrSpaceKey(event))
if (self.isEnterOrSpaceKey(event))
callback(event);
});
element.addEventListener('click', event => callback(event));
......@@ -826,26 +826,26 @@ function onInvokeElement(element, callback) {
* @param {!Event} event
* @return {boolean}
*/
function isEnterKey(event) {
self.isEnterKey = function(event) {
// Check if in IME.
return event.keyCode !== 229 && event.key === 'Enter';
}
};
/**
* @param {!Event} event
* @return {boolean}
*/
function isEnterOrSpaceKey(event) {
return isEnterKey(event) || event.key === ' ';
}
self.isEnterOrSpaceKey = function(event) {
return self.isEnterKey(event) || event.key === ' ';
};
/**
* @param {!Event} event
* @return {boolean}
*/
function isEscKey(event) {
self.isEscKey = function(event) {
return event.keyCode === 27;
}
};
// DevTools front-end still assumes that
// classList.toggle('a', undefined) works as
......
......@@ -812,11 +812,11 @@ function injectedExtensionAPI(extensionInfo, inspectedTabId, themeName, keysToFo
* @param {function(!Object, !Object)|undefined} testHook
* @return {string}
*/
function buildExtensionAPIInjectedScript(extensionInfo, inspectedTabId, themeName, keysToForward, testHook) {
self.buildExtensionAPIInjectedScript = function(extensionInfo, inspectedTabId, themeName, keysToForward, testHook) {
const argumentsJSON = [extensionInfo, inspectedTabId || null, themeName, keysToForward].map(_ => JSON.stringify(_)).join(',');
if (!testHook)
testHook = () => {};
return '(function(injectedScriptId){ ' + defineCommonExtensionSymbols.toString() + ';' +
'(' + injectedExtensionAPI.toString() + ')(' + argumentsJSON + ',' + testHook + ', injectedScriptId);' +
'})';
}
};
......@@ -7,7 +7,7 @@
* @suppress {accessControls}
*/
function extension_getRequestByUrl(urls, callback) {
self.extension_getRequestByUrl = function(urls, callback) {
function onHAR(response) {
const entries = response.entries;
......@@ -25,4 +25,4 @@ function extension_getRequestByUrl(urls, callback) {
}
webInspector.network.getHAR(onHAR);
}
};
......@@ -8,9 +8,8 @@
*/
const extensionsHost = 'devtools-extensions.oopif.test';
const extensionsOrigin = `http://${extensionsHost}:8000`;
Extensions.extensionServer._registerHandler('evaluateForTestInFrontEnd', onEvaluate);
Extensions.extensionsOrigin = `http://${extensionsHost}:8000`;
Extensions.extensionServer._extensionAPITestHook = function(extensionServerClient, coreAPI) {
window.webInspector = coreAPI;
window._extensionServerForTests = extensionServerClient;
......
......@@ -28,6 +28,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* eslint-disable no-unused-vars */
// Blink Web Facing API
/**
......@@ -187,7 +189,7 @@ Array.prototype.mergeOrdered = function(array, comparator) {};
*/
Int32Array.prototype.lowerBound = function(object, comparator, left, right) {};
// TODO(luoe): remove these BigInt types once closure supports them.
// TODO(luoe): remove these BigInt and ArrayLike types once closure supports them.
/**
* @param {number|string} value
*/
......@@ -196,6 +198,9 @@ const BigInt = function(value) {};
/** @typedef {*} */
const bigint = null;
/** @typedef {Array|NodeList|Arguments|{length: number}} */
let ArrayLike;
// File System API
/**
* @constructor
......@@ -865,6 +870,7 @@ Terminal.prototype = {
*/
Console.prototype.context = function(context) {};
// Globally defined functions
/**
* @param {!Array<string>|string} strings
......@@ -873,6 +879,139 @@ Console.prototype.context = function(context) {};
*/
const ls = function(strings, vararg) {};
/**
* @param {string} tagName
* @param {string=} customElementType
* @return {!Element}
*/
const createElement = function(tagName, customElementType) {};
/**
* @param {number|string} data
* @return {!Text}
*/
const createTextNode = function(data) {};
/**
* @param {string} elementName
* @param {string=} className
* @param {string=} customElementType
* @return {!Element}
*/
const createElementWithClass = function(elementName, className, customElementType) {};
/**
* @param {string} childType
* @param {string=} className
* @return {!Element}
*/
const createSVGElement = function(childType, className) {};
/**
* @return {!DocumentFragment}
*/
const createDocumentFragment = function() {};
/**
* @param {!Event} event
* @return {boolean}
*/
const isEnterKey = function(event) {};
/**
* @param {!Event} event
* @return {boolean}
*/
const isEnterOrSpaceKey = function(event) {};
/**
* @param {!Event} event
* @return {boolean}
*/
const isEscKey = function(event) {};
/**
* @param {!ExtensionDescriptor} extensionInfo
* @param {string} inspectedTabId
* @param {string} themeName
* @param {!Array<number>} keysToForward
* @param {function(!Object, !Object)|undefined} testHook
* @return {string}
*/
const buildExtensionAPIInjectedScript = function(extensionInfo, inspectedTabId, themeName, keysToForward, testHook) {};
/**
* @param {number} m
* @param {number} n
* @return {number}
*/
const mod = function(m, n) {};
/**
* @param {string} query
* @param {boolean} caseSensitive
* @param {boolean} isRegex
* @return {!RegExp}
*/
const createSearchRegex = function(query, caseSensitive, isRegex) {};
/**
* @param {string} query
* @param {string=} flags
* @return {!RegExp}
*/
const createPlainTextSearchRegex = function(query, flags) {};
/**
* @param {!RegExp} regex
* @param {string} content
* @return {number}
*/
const countRegexMatches = function(regex, content) {};
/**
* @param {number} spacesCount
* @return {string}
*/
const spacesPadding = function(spacesCount) {};
/**
* @param {number} value
* @param {number} symbolsCount
* @return {string}
*/
const numberToStringWithSpacesPadding = function(value, symbolsCount) {};
/**
* @param {string} url
* @return {!Promise.<string>}
*/
const loadXHR = function(url) {};
/**
* @param {*} value
*/
const suppressUnused = function(value) {};
/**
* TODO: move into its own module
* @param {function()} callback
*/
const runOnWindowLoad = function(callback) {};
/**
* @template T
* @param {function(new:T, ...)} constructorFunction
* @return {!T}
*/
const singleton = function(constructorFunction) {};
/**
* @param {?string} content
* @return {number}
*/
const base64ToSize = function(content) {};
/**
* @constructor
* @param {function(!Array<*>)} callback
......
......@@ -2168,7 +2168,7 @@ const HeapSnapshotMetainfo = class {
/**
* @unrestricted
*/
const HeapSnapshotHeader = class {
HeapSnapshotWorker.HeapSnapshotHeader = class {
constructor() {
// New format.
this.title = '';
......
......@@ -183,7 +183,7 @@ HeapSnapshotWorker.HeapSnapshotLoader = class {
this._jsonTokenizer = new TextUtils.TextUtils.BalancedJSONTokenizer(metaJSON => {
this._json = this._jsonTokenizer.remainder();
this._jsonTokenizer = null;
this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse(metaJSON));
this._snapshot.snapshot = /** @type {!HeapSnapshotWorker.HeapSnapshotHeader} */ (JSON.parse(metaJSON));
});
this._jsonTokenizer.write(json);
while (this._jsonTokenizer)
......
......@@ -27,17 +27,14 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @typedef {Array|NodeList|Arguments|{length: number}} */
let ArrayLike;
/**
* @param {number} m
* @param {number} n
* @return {number}
*/
function mod(m, n) {
self.mod = function(m, n) {
return ((m % n) + n) % n;
}
};
/**
* @param {string} string
......@@ -996,7 +993,7 @@ String.format = function(format, substitutions, formatters, initialValue, append
* @param {boolean} isRegex
* @return {!RegExp}
*/
function createSearchRegex(query, caseSensitive, isRegex) {
self.createSearchRegex = function(query, caseSensitive, isRegex) {
const regexFlags = caseSensitive ? 'g' : 'gi';
let regexObject;
......@@ -1009,17 +1006,17 @@ function createSearchRegex(query, caseSensitive, isRegex) {
}
if (!regexObject)
regexObject = createPlainTextSearchRegex(query, regexFlags);
regexObject = self.createPlainTextSearchRegex(query, regexFlags);
return regexObject;
}
};
/**
* @param {string} query
* @param {string=} flags
* @return {!RegExp}
*/
function createPlainTextSearchRegex(query, flags) {
self.createPlainTextSearchRegex = function(query, flags) {
// This should be kept the same as the one in StringUtil.cpp.
const regexSpecialCharacters = String.regexSpecialCharacters();
let regex = '';
......@@ -1030,14 +1027,14 @@ function createPlainTextSearchRegex(query, flags) {
regex += c;
}
return new RegExp(regex, flags || '');
}
};
/**
* @param {!RegExp} regex
* @param {string} content
* @return {number}
*/
function countRegexMatches(regex, content) {
self.countRegexMatches = function(regex, content) {
let text = content;
let result = 0;
let match;
......@@ -1047,26 +1044,26 @@ function countRegexMatches(regex, content) {
text = text.substring(match.index + 1);
}
return result;
}
};
/**
* @param {number} spacesCount
* @return {string}
*/
function spacesPadding(spacesCount) {
self.spacesPadding = function(spacesCount) {
return '\u00a0'.repeat(spacesCount);
}
};
/**
* @param {number} value
* @param {number} symbolsCount
* @return {string}
*/
function numberToStringWithSpacesPadding(value, symbolsCount) {
self.numberToStringWithSpacesPadding = function(value, symbolsCount) {
const numberString = value.toString();
const paddingLength = Math.max(0, symbolsCount - numberString.length);
return spacesPadding(paddingLength) + numberString;
}
return self.spacesPadding(paddingLength) + numberString;
};
/**
* @return {!Array.<T>}
......@@ -1251,7 +1248,7 @@ Multimap.prototype = {
* @param {string} url
* @return {!Promise.<string>}
*/
function loadXHR(url) {
self.loadXHR = function(url) {
return new Promise(load);
function load(successCallback, failureCallback) {
......@@ -1273,13 +1270,12 @@ function loadXHR(url) {
xhr.onreadystatechange = onReadyStateChanged;
xhr.send(null);
}
}
};
/**
* @param {*} value
*/
function suppressUnused(value) {
}
self.suppressUnused = function(value) {};
/**
* @param {function()} callback
......@@ -1364,9 +1360,8 @@ Map.prototype.diff = function(other, isEqual) {
/**
* TODO: move into its own module
* @param {function()} callback
* @suppressGlobalPropertiesCheck
*/
function runOnWindowLoad(callback) {
self.runOnWindowLoad = function(callback) {
/**
* @suppressGlobalPropertiesCheck
*/
......@@ -1379,7 +1374,7 @@ function runOnWindowLoad(callback) {
callback();
else
self.addEventListener('DOMContentLoaded', windowLoaded, false);
}
};
const _singletonSymbol = Symbol('singleton');
......@@ -1388,19 +1383,19 @@ const _singletonSymbol = Symbol('singleton');
* @param {function(new:T, ...)} constructorFunction
* @return {!T}
*/
function singleton(constructorFunction) {
self.singleton = function(constructorFunction) {
if (_singletonSymbol in constructorFunction)
return constructorFunction[_singletonSymbol];
const instance = new constructorFunction();
constructorFunction[_singletonSymbol] = instance;
return instance;
}
};
/**
* @param {?string} content
* @return {number}
*/
function base64ToSize(content) {
self.base64ToSize = function(content) {
if (!content)
return 0;
let size = content.length * 3 / 4;
......@@ -1409,4 +1404,4 @@ function base64ToSize(content) {
if (content.length > 1 && content[content.length - 2] === '=')
size--;
return size;
}
};
......@@ -8,32 +8,34 @@ ProductRegistry.instance = function() {
const extension = self.runtime.extension(ProductRegistry.Registry);
if (extension)
return extension.instance();
return Promise.resolve(self.singleton(ProductRegistry.RegistryStub));
// TODO(tvanderlippe): Remove type-cast once Closure compiler is updated to latest version.
return Promise.resolve(/** @type {!ProductRegistry.Registry} */ (self.singleton(ProductRegistry.RegistryStub)));
};
/**
* @interface
*/
ProductRegistry.Registry = function() {};
ProductRegistry.Registry.prototype = {
ProductRegistry.Registry = class {
/**
* @param {!Common.ParsedURL} parsedUrl
* @return {?string}
*/
nameForUrl: function(parsedUrl) {},
nameForUrl(parsedUrl) {
}
/**
* @param {!Common.ParsedURL} parsedUrl
* @return {?ProductRegistry.Registry.ProductEntry}
*/
entryForUrl: function(parsedUrl) {},
entryForUrl(parsedUrl) {
}
/**
* @param {!Common.ParsedURL} parsedUrl
* @return {?number}
*/
typeForUrl: function(parsedUrl) {}
typeForUrl(parsedUrl) {
}
};
/**
......
......@@ -198,7 +198,7 @@
extension_showPanel("extension");
function performSearch(query) {
UI.inspectorView.panel(extensionsOrigin + "TestPanelforsearch").then(panel => {
UI.inspectorView.panel(Extensions.extensionsOrigin + "TestPanelforsearch").then(panel => {
panel.searchableView().showSearchField();
panel.searchableView()._searchInputElement.value = query;
panel.searchableView()._performSearch(true, true);
......
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