Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: polyfill.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Use polyfill.js Created Oct. 10, 2017, 10:15 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « options.js ('k') | popup.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: polyfill.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/polyfill.js
@@ -0,0 +1,47 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+(function()
+{
+ // On Edge, the extension APIs are in the "browser" namespace, whereas on
+ // both Firefox and Chrome they're in the "chrome" namespace. Firefox has a
+ // "browser" namespace too, but it is slightly incompatible in that the
+ // implementation uses promises as a fallback in the absence of a callback
+ // parameter. Edge sometimes has a "chrome" namespace, but with no extension
+ // APIs.
+ //
+ // In order to make the same code run on all three platforms, we simply look
+ // for a "chrome" namespace with the extension APIs and assign it to the
+ // "browser" namespace.
+ if (typeof chrome != "undefined" && "extension" in chrome)
+ window.browser = chrome;
+
+ // Workaround since HTMLCollection, NodeList, StyleSheet and
+ // CSSRuleList didn't have iterator support before Chrome 51.
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=401699
+ let arrayIterator = Array.prototype[Symbol.iterator];
+ if (!(Symbol.iterator in HTMLCollection.prototype))
+ HTMLCollection.prototype[Symbol.iterator] = arrayIterator;
+ if (!(Symbol.iterator in NodeList.prototype))
+ NodeList.prototype[Symbol.iterator] = arrayIterator;
+ if (!(Symbol.iterator in StyleSheetList.prototype))
+ StyleSheetList.prototype[Symbol.iterator] = arrayIterator;
+ if (!(Symbol.iterator in CSSRuleList.prototype))
+ CSSRuleList.prototype[Symbol.iterator] = arrayIterator;
+}());
« no previous file with comments | « options.js ('k') | popup.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld