From 1d0452117a83044c5b1a687de2f2d42968939b4e Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Wed, 25 Aug 2021 10:14:01 -0500 Subject: [PATCH] Add closure-library externs for csp, and our own hack file for elemental2 --- .../browser/cspviolationobserver_externs.js | 86 +++++++++++++++++++ externs/browser/elemental2-1.1.0-hack.js | 54 ++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 externs/browser/cspviolationobserver_externs.js create mode 100644 externs/browser/elemental2-1.1.0-hack.js diff --git a/externs/browser/cspviolationobserver_externs.js b/externs/browser/cspviolationobserver_externs.js new file mode 100644 index 00000000000..77ce701059f --- /dev/null +++ b/externs/browser/cspviolationobserver_externs.js @@ -0,0 +1,86 @@ +/** + * @license + * Copyright The Closure Library Authors. + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * @fileoverview Externs used by cspviolationobserver.js that are not available + * in the open-source Closure compiler release. This file should be deleted + * once w3c_reporting_observer.js is available in open-source externs. + * + * @externs + */ + +// TODO(user): Remove this file once w3c_reporting_observer.js is +// available in the open-source Closure compiler. + +/** + * https://w3c.github.io/reporting/#interface-reporting-observer + * @constructor + * @param {!ReportingObserverCallback} callback + * @param {!ReportingObserverOptions} opts + */ +function ReportingObserver2(callback, opts) {} +/** @return {void} */ +ReportingObserver2.prototype.observe = function() {}; +/** @return {void} */ +ReportingObserver2.prototype.disconnect = function() {}; +/** @return {!Array} */ +ReportingObserver2.prototype.takeRecords = function() {}; + +/** + * @typedef {ReportingObserver2|ReportingObserver} + * @suppress {duplicate} + */ +var ReportingObserver; + + +/** + * @typedef {!function(!Array, !ReportingObserver): void} + * @suppress {duplicate} + */ +var ReportingObserverCallback; + + +/** + * @constructor + */ +function ReportingObserverOptions2() {} +/** @type {undefined|!Array} */ +ReportingObserverOptions2.prototype.types; +/** @type {boolean} */ +ReportingObserverOptions2.prototype.buffered; + +/** + * @typedef {ReportingObserverOptions2|ReportingObserverOptions} + * @suppress {duplicate} + */ +var ReportingObserverOptions; + + +/** + * @constructor + * @suppress {duplicate} + */ +function Report2() {} +/** @type {string} */ Report2.prototype.type; +/** @type {string} */ Report2.prototype.url; +/** @type {?ReportBody} */ Report2.prototype.body; + +/** + * @typedef {Report2|Report} + * @suppress {duplicate} + */ +var Report; + + +/** + * @constructor + */ +function ReportBody2() {} + +/** + * @typedef {ReportBody2|ReportBody2} + * @suppress {duplicate} + */ +var ReportBody; diff --git a/externs/browser/elemental2-1.1.0-hack.js b/externs/browser/elemental2-1.1.0-hack.js new file mode 100644 index 00000000000..d8abbfaf674 --- /dev/null +++ b/externs/browser/elemental2-1.1.0-hack.js @@ -0,0 +1,54 @@ +/** + * @fileoverview Describes types present in elemental2 1.1.0 that are not in closure-compiler, since they aren't + * real browser types. Presently this only contains the `WebWorker` type which never existed as a browser type, + * but showed up in closure-compiler as a typo or early draft or something. As long as elemental2 1.1.0 is + * supported, we must keep this file in our closure-compiler fork. + * + * TODO Remove this once elemental2 1.1.0 is considered to be unsupported by j2cl - this day may not come soon, + * if ever, as it is a "stable" release. + * + * @externs + */ + +/** + * @see http://dev.w3.org/html5/workers/ + * @constructor + * @implements {EventTarget} + */ +function WebWorker() {} + +/** @override */ +WebWorker.prototype.addEventListener = function(type, listener, opt_options) {}; + +/** @override */ +WebWorker.prototype.removeEventListener = function( + type, listener, opt_options) {}; + +/** @override */ +WebWorker.prototype.dispatchEvent = function(evt) {}; + +/** + * Stops the worker process + * @return {undefined} + */ +WebWorker.prototype.terminate = function() {}; + +/** + * Posts a message to the worker thread. + * @param {string} message + * @return {undefined} + */ +WebWorker.prototype.postMessage = function(message) {}; + +/** + * Sent when the worker thread posts a message to its creator. + * @type {?function(!MessageEvent<*>): void} + */ +WebWorker.prototype.onmessage; + +/** + * Sent when the worker thread encounters an error. + * @type {?function(!ErrorEvent): void} + */ +WebWorker.prototype.onerror; +