WebUI: Rename util to util_deprecated, incorporate legacy assert
This has the benefit of allowing us to check in module assert later, and makes util_deprecated.js dependency-free. Also check in modulized util.m.js to the repo. This is useful since util is no longer used via HTML imports, so developers have needed to manually include assert.js. In fact, most remaining uses of assert.js were only to satisfy util.js. Bug: 1173575 Change-Id: Ic0a042e4b8a08efa64841ca36442234106ae34d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3896993 Reviewed-by: Rohit Rao <rohitrao@chromium.org> Commit-Queue: Rohit Rao <rohitrao@chromium.org> Auto-Submit: Rebekah Potter <rbpotter@chromium.org> Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org> Reviewed-by: Tina Wang <tinazwang@chromium.org> Cr-Commit-Position: refs/heads/main@{#1048914}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4d20178cd5
commit
58ff9bbaba
chrome/browser
resources
chromeos
arc_graphics_tracing
arc_power_control
arc_support
cryptohome.htmldrive_internals.htmlmobile_setup_portal.htmlsupervised_user
supervised_user_error_page
components
management
resources
security_interstitials
core
ios/chrome/app/resources
ui/webui/resources
@@ -10,9 +10,7 @@ found in the LICENSE file.
|
||||
<meta charset=utf-8>
|
||||
<link rel="stylesheet" href="arc_tracing.css">
|
||||
<script src="chrome://resources/js/cr.js"></script>
|
||||
<script src="chrome://resources/js/cr/ui.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="arc_tracing_ui.js"></script>
|
||||
<script src="arc_graphics_tracing_ui.js"></script>
|
||||
<script src="arc_graphics_tracing.js"></script>
|
||||
|
@@ -10,9 +10,7 @@ found in the LICENSE file.
|
||||
<meta charset=utf-8>
|
||||
<link rel="stylesheet" href="arc_tracing.css">
|
||||
<script src="chrome://resources/js/cr.js"></script>
|
||||
<script src="chrome://resources/js/cr/ui.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="arc_tracing_ui.js"></script>
|
||||
<script src="arc_overview_tracing_ui.js"></script>
|
||||
<script src="arc_overview_tracing.js"></script>
|
||||
|
@@ -11,9 +11,7 @@ found in the LICENSE file.
|
||||
<link rel="stylesheet" href="arc_power_control.css">
|
||||
<link rel="stylesheet" href="arc_tracing.css">
|
||||
<script src="chrome://resources/js/cr.js"></script>
|
||||
<script src="chrome://resources/js/cr/ui.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="arc_tracing_ui.js"></script>
|
||||
<script src="arc_power_control.js"></script>
|
||||
<title>ARC power control</title>
|
||||
|
@@ -12,8 +12,7 @@
|
||||
<!-- TODO(crbug.com/1248474) - Remove during clean up -->
|
||||
<link rel="stylesheet" href="layout_style.css">
|
||||
<script src="chrome://resources/js/load_time_data.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="i18n_template_no_process.js"></script>
|
||||
<script src="chrome://resources/js/cr.js"></script>
|
||||
<script src="event_tracker.js"></script>
|
||||
|
@@ -4,8 +4,7 @@
|
||||
<title>About Cryptohome</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="chrome://cryptohome/cryptohome.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
@@ -5,8 +5,7 @@
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
|
||||
<link rel="stylesheet" href="drive_internals.css">
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="chrome://drive-internals/drive_internals.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
@@ -6,8 +6,7 @@
|
||||
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
|
||||
<link rel="stylesheet" href="mobile_setup.css"></link>
|
||||
<script src="chrome://resources/js/cr.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="chrome://resources/cr_components/chromeos/cellular_setup/webview_post_util.js">
|
||||
</script>
|
||||
<script src="mobile_setup_portal.js"></script>
|
||||
|
@@ -8,9 +8,7 @@
|
||||
<link href="https://fonts.googleapis.com/css?family=Google+Sans" rel="stylesheet">
|
||||
<link rel="stylesheet" href="../../../../../components/security_interstitials/core/common/resources/interstitial_core.css">
|
||||
<link rel="stylesheet" href="supervised_user_block_interstitial.css">
|
||||
<script src="../../../../../ui/webui/resources/js/cr.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/assert.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util_deprecated.js"></script>
|
||||
<script src="supervised_user_block_interstitial.js"></script>
|
||||
</head>
|
||||
<body class="supervised-user-block">
|
||||
|
@@ -8,8 +8,7 @@
|
||||
<link href="https://fonts.googleapis.com/css?family=Google+Sans" rel="stylesheet">
|
||||
<link rel="stylesheet" href="../../../../../components/security_interstitials/core/common/resources/interstitial_core.css">
|
||||
<link rel="stylesheet" href="supervised_user_block_interstitial_v2.css">
|
||||
<script src="../../../../../ui/webui/resources/js/assert.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util_deprecated.js"></script>
|
||||
<script src="supervised_user_block_interstitial.js"></script>
|
||||
</head>
|
||||
<body class="supervised-user-block">
|
||||
|
@@ -9,8 +9,7 @@
|
||||
<!-- TODO(crbug.com/487000): Remove this once injected by web. -->
|
||||
<script src="chrome://resources/js/ios/web_ui.js"></script>
|
||||
<script src="chrome://resources/js/load_time_data.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="strings.js"></script>
|
||||
<script src="management.js"></script>
|
||||
|
||||
|
@@ -18,8 +18,7 @@
|
||||
<link rel="stylesheet" href="interstitial_lookalikeurl.css">
|
||||
<link rel="stylesheet" href="interstitial_safebrowsing.css">
|
||||
<link rel="stylesheet" href="interstitial_ssl.css">
|
||||
<script src="../../../../../ui/webui/resources/js/assert.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util_deprecated.js"></script>
|
||||
<script src="captive_portal.js"></script>
|
||||
<script src="ssl.js"></script>
|
||||
<script src="extended_reporting.js"></script>
|
||||
|
@@ -9,8 +9,7 @@
|
||||
<title>$i18n{tabTitle}</title>
|
||||
<link rel="stylesheet" href="../../common/resources/interstitial_core.css">
|
||||
<link rel="stylesheet" href="interstitial_webview_quiet.css">
|
||||
<script src="../../../../../ui/webui/resources/js/assert.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util.js"></script>
|
||||
<script src="../../../../../ui/webui/resources/js/util_deprecated.js"></script>
|
||||
<script src="../../common/resources/interstitial_common.js"></script>
|
||||
<script src="interstitial_webview_quiet.js"></script>
|
||||
</head>
|
||||
|
@@ -14,7 +14,7 @@ js_type_check("closure_compile") {
|
||||
js_library("interstitial_common") {
|
||||
deps = [
|
||||
"//ui/webui/resources/js:load_time_data",
|
||||
"//ui/webui/resources/js:util",
|
||||
"//ui/webui/resources/js:util_deprecated",
|
||||
"//ui/webui/resources/js:webui_resource_test",
|
||||
]
|
||||
if (is_ios) {
|
||||
|
@@ -7,8 +7,7 @@
|
||||
<script src="chrome://resources/js/ios/web_ui.js"></script>
|
||||
|
||||
<script src="chrome://resources/js/load_time_data.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="strings.js"></script>
|
||||
<script src="inspect.js"></script>
|
||||
|
||||
|
@@ -9,8 +9,7 @@
|
||||
<link rel="stylesheet" href="omaha.css">
|
||||
<script src="chrome://resources/js/ios/web_ui.js"></script>
|
||||
<script src="chrome://resources/js/load_time_data.js"></script>
|
||||
<script src="chrome://resources/js/assert.js"></script>
|
||||
<script src="chrome://resources/js/util.js"></script>
|
||||
<script src="chrome://resources/js/util_deprecated.js"></script>
|
||||
<script src="chrome://omaha/omaha.js"></script>
|
||||
<script src="chrome://omaha/strings.js"></script>
|
||||
</head>
|
||||
|
@@ -16,10 +16,7 @@ generate_grd("build_grdp") {
|
||||
]
|
||||
|
||||
if (is_chromeos_ash) {
|
||||
input_files += [
|
||||
"promise_resolver.html",
|
||||
"util.html",
|
||||
]
|
||||
input_files += [ "promise_resolver.html" ]
|
||||
}
|
||||
|
||||
input_files_base_dir = rebase_path(".", "//")
|
||||
|
@@ -1,2 +0,0 @@
|
||||
<link rel="import" href="assert.html">
|
||||
<script src="../js/util.js"></script>
|
@@ -74,7 +74,8 @@ preprocess_if_expr("preprocess_src") {
|
||||
"test_loader_util.js",
|
||||
|
||||
# Used by security interstitials and ios inspect UI
|
||||
"util.js",
|
||||
"util_deprecated.js",
|
||||
"util.m.js",
|
||||
"webui_resource_test.js",
|
||||
"webview_manager.js",
|
||||
]
|
||||
@@ -112,7 +113,6 @@ preprocess_if_expr("preprocess_generated") {
|
||||
"assert.m.js",
|
||||
"load_time_data.js",
|
||||
"promise_resolver.m.js",
|
||||
"util.m.js",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ js_type_check("js_resources") {
|
||||
":cr",
|
||||
":load_time_data",
|
||||
":promise_resolver",
|
||||
":util",
|
||||
":util_deprecated",
|
||||
":webui_resource_test",
|
||||
]
|
||||
|
||||
@@ -165,9 +165,7 @@ js_library("promise_resolver") {
|
||||
deps = [ ":assert" ]
|
||||
}
|
||||
|
||||
js_library("util") {
|
||||
deps = [ ":cr" ]
|
||||
externs_list = [ "$externs_path/chrome_send.js" ]
|
||||
js_library("util_deprecated") {
|
||||
}
|
||||
|
||||
js_library("webview_manager") {
|
||||
@@ -183,7 +181,6 @@ js_modulizer("modulize") {
|
||||
input_files = [
|
||||
"assert.js",
|
||||
"promise_resolver.js",
|
||||
"util.js",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -266,11 +263,9 @@ js_library("static_types") {
|
||||
}
|
||||
|
||||
js_library("util.m") {
|
||||
sources = [ "$root_gen_dir/ui/webui/resources/js/util.m.js" ]
|
||||
deps = [
|
||||
":assert.m",
|
||||
":cr.m",
|
||||
]
|
||||
externs_list = [ "$externs_path/chrome_send.js" ]
|
||||
extra_deps = [ ":modulize" ]
|
||||
}
|
||||
|
@@ -2,15 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// #import {assertInstanceof} from './assert.m.js';
|
||||
// #import {dispatchSimpleEvent} from './cr.m.js';
|
||||
import {assertInstanceof} from './assert.m.js';
|
||||
import {dispatchSimpleEvent} from './cr.m.js';
|
||||
|
||||
/**
|
||||
* Alias for document.getElementById. Found elements must be HTMLElements.
|
||||
* @param {string} id The ID of the element to find.
|
||||
* @return {HTMLElement} The found element or null if not found.
|
||||
*/
|
||||
/* #export */ function $(id) {
|
||||
export function $(id) {
|
||||
// Disable getElementById restriction here, since we are instructing other
|
||||
// places to re-use the $() that is defined here.
|
||||
// eslint-disable-next-line no-restricted-properties
|
||||
@@ -22,7 +22,7 @@
|
||||
* @return {?Element} The currently focused element (including elements that are
|
||||
* behind a shadow root), or null if nothing is focused.
|
||||
*/
|
||||
/* #export */ function getDeepActiveElement() {
|
||||
export function getDeepActiveElement() {
|
||||
let a = document.activeElement;
|
||||
while (a && a.shadowRoot && a.shadowRoot.activeElement) {
|
||||
a = a.shadowRoot.activeElement;
|
||||
@@ -32,14 +32,14 @@
|
||||
|
||||
// <if expr="chromeos_ash">
|
||||
/**
|
||||
* DEPRECATED (if using Polymer): Use Polymer.IronA11yAnnouncer instead.
|
||||
* DEPRECATED (if using Polymer): Use IronA11yAnnouncer instead.
|
||||
* TODO(crbug.com/985410): Replace all existing usages and remove this function.
|
||||
* Add an accessible message to the page that will be announced to
|
||||
* users who have spoken feedback on, but will be invisible to all
|
||||
* other users. It's removed right away so it doesn't clutter the DOM.
|
||||
* @param {string} msg The text to be pronounced.
|
||||
*/
|
||||
/* #export */ function announceAccessibleMessage(msg) {
|
||||
export function announceAccessibleMessage(msg) {
|
||||
const element = document.createElement('div');
|
||||
element.setAttribute('aria-live', 'polite');
|
||||
element.style.position = 'fixed';
|
||||
@@ -61,7 +61,7 @@
|
||||
* @param {boolean=} includeShadowHosts
|
||||
* @return {Node} The found ancestor or null if not found.
|
||||
*/
|
||||
/* #export */ function findAncestor(node, predicate, includeShadowHosts) {
|
||||
export function findAncestor(node, predicate, includeShadowHosts) {
|
||||
while (node !== null) {
|
||||
if (predicate(node)) {
|
||||
break;
|
||||
@@ -76,7 +76,7 @@
|
||||
* Check the directionality of the page.
|
||||
* @return {boolean} True if Chrome is running an RTL UI.
|
||||
*/
|
||||
/* #export */ function isRTL() {
|
||||
export function isRTL() {
|
||||
return document.documentElement.dir === 'rtl';
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
* @param {string} id The identifier name.
|
||||
* @return {!HTMLElement} the Element.
|
||||
*/
|
||||
/* #export */ function getRequiredElement(id) {
|
||||
export function getRequiredElement(id) {
|
||||
return assertInstanceof(
|
||||
$(id), HTMLElement, 'Missing required element: ' + id);
|
||||
}
|
||||
@@ -100,7 +100,7 @@
|
||||
* @param {string} value The value of the param.
|
||||
* @return {string} The new URL.
|
||||
*/
|
||||
/* #export */ function appendParam(url, key, value) {
|
||||
export function appendParam(url, key, value) {
|
||||
const param = encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
||||
|
||||
if (url.indexOf('?') === -1) {
|
||||
@@ -115,7 +115,7 @@
|
||||
* @param {string} className The class name to use.
|
||||
* @return {Element} The created element.
|
||||
*/
|
||||
/* #export */ function createElementWithClassName(type, className) {
|
||||
export function createElementWithClassName(type, className) {
|
||||
const elm = document.createElement(type);
|
||||
elm.className = className;
|
||||
return elm;
|
||||
@@ -130,7 +130,7 @@
|
||||
* transitionend to happen. If not specified, it is fetched from |el|
|
||||
* using the transitionDuration style value.
|
||||
*/
|
||||
/* #export */ function ensureTransitionEndEvent(el, timeOut) {
|
||||
export function ensureTransitionEndEvent(el, timeOut) {
|
||||
if (timeOut === undefined) {
|
||||
const style = getComputedStyle(el);
|
||||
timeOut = parseFloat(style.transitionDuration) * 1000;
|
||||
@@ -146,7 +146,7 @@
|
||||
});
|
||||
window.setTimeout(function() {
|
||||
if (!fired) {
|
||||
cr.dispatchSimpleEvent(el, 'transitionend', true);
|
||||
dispatchSimpleEvent(el, 'transitionend', true);
|
||||
}
|
||||
}, timeOut);
|
||||
}
|
||||
@@ -156,7 +156,7 @@
|
||||
* @param {string} original The original string.
|
||||
* @return {string} The string with all the characters mentioned above replaced.
|
||||
*/
|
||||
/* #export */ function HTMLEscape(original) {
|
||||
export function HTMLEscape(original) {
|
||||
return original.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
@@ -169,7 +169,7 @@
|
||||
* @param {string} str The source string.
|
||||
* @return {string} The escaped string.
|
||||
*/
|
||||
/* #export */ function quoteString(str) {
|
||||
export function quoteString(str) {
|
||||
return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@
|
||||
* @param {function(!Event)} callback Called at most once. The
|
||||
* optional return value is passed on by the listener.
|
||||
*/
|
||||
/* #export */ function listenOnce(target, eventNames, callback) {
|
||||
export function listenOnce(target, eventNames, callback) {
|
||||
if (!Array.isArray(eventNames)) {
|
||||
eventNames = eventNames.split(/ +/);
|
||||
}
|
||||
@@ -203,7 +203,7 @@
|
||||
* @param {!Event} e
|
||||
* @return {boolean} Whether a modifier key was down when processing |e|.
|
||||
*/
|
||||
/* #export */ function hasKeyModifiers(e) {
|
||||
export function hasKeyModifiers(e) {
|
||||
return !!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey);
|
||||
}
|
||||
|
||||
@@ -211,8 +211,7 @@
|
||||
* @param {!Element} el
|
||||
* @return {boolean} Whether the element is interactive via text input.
|
||||
*/
|
||||
/* #export */ function isTextInputElement(el) {
|
||||
export function isTextInputElement(el) {
|
||||
return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA';
|
||||
}
|
||||
|
||||
/* #ignore */ console.warn('crbug/1173575, non-JS module files deprecated.');
|
122
ui/webui/resources/js/util_deprecated.js
Normal file
122
ui/webui/resources/js/util_deprecated.js
Normal file
@@ -0,0 +1,122 @@
|
||||
// Copyright 2012 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/* @filedescription Minimal utils and assertion support for places in the code
|
||||
* that are still not updated to JS modules. Do not use in new code; use the JS
|
||||
* modules (and more extensive) util.m.js, assert.m.js (for JS code), and
|
||||
* assert_ts.ts (for TS code) instead. */
|
||||
|
||||
/**
|
||||
* Note: This method is deprecated. Use the equivalent method in assert_ts.ts
|
||||
* instead.
|
||||
* Verify |condition| is truthy and return |condition| if so.
|
||||
* @template T
|
||||
* @param {T} condition A condition to check for truthiness. Note that this
|
||||
* may be used to test whether a value is defined or not, and we don't want
|
||||
* to force a cast to Boolean.
|
||||
* @param {string=} opt_message A message to show on failure.
|
||||
* @return {T} A non-null |condition|.
|
||||
* @closurePrimitive {asserts.truthy}
|
||||
* @suppress {reportUnknownTypes} because T is not sufficiently constrained.
|
||||
*/
|
||||
function assert(condition, opt_message) {
|
||||
if (!condition) {
|
||||
let message = 'Assertion failed';
|
||||
if (opt_message) {
|
||||
message = message + ': ' + opt_message;
|
||||
}
|
||||
const error = new Error(message);
|
||||
const global = function() {
|
||||
const thisOrSelf = this || self;
|
||||
/** @type {boolean} */
|
||||
thisOrSelf.traceAssertionsForTesting;
|
||||
return thisOrSelf;
|
||||
}();
|
||||
if (global.traceAssertionsForTesting) {
|
||||
console.warn(error.stack);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This method is deprecated. Use the equivalent method in assert_ts.ts
|
||||
* instead.
|
||||
* Call this from places in the code that should never be reached.
|
||||
*
|
||||
* For example, handling all the values of enum with a switch() like this:
|
||||
*
|
||||
* function getValueFromEnum(enum) {
|
||||
* switch (enum) {
|
||||
* case ENUM_FIRST_OF_TWO:
|
||||
* return first
|
||||
* case ENUM_LAST_OF_TWO:
|
||||
* return last;
|
||||
* }
|
||||
* assertNotReached();
|
||||
* return document;
|
||||
* }
|
||||
*
|
||||
* This code should only be hit in the case of serious programmer error or
|
||||
* unexpected input.
|
||||
*
|
||||
* @param {string=} message A message to show when this is hit.
|
||||
* @closurePrimitive {asserts.fail}
|
||||
*/
|
||||
function assertNotReached(message) {
|
||||
assert(false, message || 'Unreachable code hit');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} value The value to check.
|
||||
* @param {function(new: T, ...)} type A user-defined constructor.
|
||||
* @param {string=} message A message to show when this is hit.
|
||||
* @return {T}
|
||||
* @template T
|
||||
*/
|
||||
function assertInstanceof(value, type, message) {
|
||||
// We don't use assert immediately here so that we avoid constructing an error
|
||||
// message if we don't have to.
|
||||
if (!(value instanceof type)) {
|
||||
assertNotReached(
|
||||
message ||
|
||||
'Value ' + value + ' is not a[n] ' + (type.name || typeof type));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for document.getElementById. Found elements must be HTMLElements.
|
||||
* @param {string} id The ID of the element to find.
|
||||
* @return {HTMLElement} The found element or null if not found.
|
||||
*/
|
||||
function $(id) {
|
||||
// Disable getElementById restriction here, since we are instructing other
|
||||
// places to re-use the $() that is defined here.
|
||||
// eslint-disable-next-line no-restricted-properties
|
||||
const el = document.getElementById(id);
|
||||
return el ? assertInstanceof(el, HTMLElement) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first ancestor for which the {@code predicate} returns true.
|
||||
* @param {Node} node The node to check.
|
||||
* @param {function(Node):boolean} predicate The function that tests the
|
||||
* nodes.
|
||||
* @param {boolean=} includeShadowHosts
|
||||
* @return {Node} The found ancestor or null if not found.
|
||||
*/
|
||||
function findAncestor(node, predicate, includeShadowHosts) {
|
||||
while (node !== null) {
|
||||
if (predicate(node)) {
|
||||
break;
|
||||
}
|
||||
node = includeShadowHosts && node instanceof ShadowRoot ? node.host :
|
||||
node.parentNode;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
console.warn('crbug/1173575, non-JS module files deprecated.');
|
Reference in New Issue
Block a user