From 64cd5bf3a5affccb4cc8eec2f26b6dbb3155d714 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 4 Feb 2019 21:33:38 -0800 Subject: [PATCH] refactor: deprecate ServiceWorker APIs (#16732) --- lib/browser/api/web-contents.js | 2 ++ lib/common/api/deprecate.js | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index ee32a55a5cdfc..82b16299b1a84 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -379,6 +379,8 @@ WebContents.prototype._init = function () { this.setMaxListeners(0) this.capturePage = deprecate.promisify(this.capturePage) + this.hasServiceWorker = deprecate.function(this.hasServiceWorker) + this.unregisterServiceWorker = deprecate.function(this.unregisterServiceWorker) // Dispatch IPC messages to the ipc module. this.on('-ipc-message', function (event, [channel, ...args]) { diff --git a/lib/common/api/deprecate.js b/lib/common/api/deprecate.js index 42218003f78c2..ef92a635d549c 100644 --- a/lib/common/api/deprecate.js +++ b/lib/common/api/deprecate.js @@ -69,6 +69,16 @@ const deprecate = { }) }, + function: (fn, newName) => { + // if newName is left blank, a removal warning will be displayed + const warn = warnOnce(fn.name, newName) + + return function () { + if (!process.noDeprecation) warn() + return fn.apply(this, arguments) + } + }, + promisify: (fn) => { const fnName = fn.name || 'function' const oldName = `${fnName} with callbacks`