Skip to content

Commit

Permalink
Make Array includes() polyfill not enumerable (#7517)
Browse files Browse the repository at this point in the history
  • Loading branch information
aghassemi authored Feb 14, 2017
1 parent dc08518 commit 05d0f57
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/polyfills/array-includes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function includes(value, opt_fromIndex) {
*/
export function install(win) {
if (!win.Array.prototype.includes) {
win.Array.prototype.includes = includes;
win.Object.defineProperty(Array.prototype, 'includes', {
enumerable: false,
configurable: true,
writable: true,
value: includes,
});
}
}
7 changes: 6 additions & 1 deletion src/polyfills/document-contains.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ function documentContainsPolyfill(node) {
*/
export function install(win) {
if (!win.HTMLDocument.prototype.contains) {
win.HTMLDocument.prototype.contains = documentContainsPolyfill;
win.Object.defineProperty(win.HTMLDocument.prototype, 'contains', {
enumerable: false,
configurable: true,
writable: true,
value: documentContainsPolyfill,
});
}
}
7 changes: 6 additions & 1 deletion src/polyfills/domtokenlist-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ function domTokenListTogglePolyfill(token, opt_force) {
*/
export function install(win) {
if (isIe(win) && win.DOMTokenList) {
win.DOMTokenList.prototype.toggle = domTokenListTogglePolyfill;
win.Object.defineProperty(win.DOMTokenList.prototype, 'toggle', {
enumerable: false,
configurable: true,
writable: true,
value: domTokenListTogglePolyfill,
});
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/polyfills/math-sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export function sign(x) {
*/
export function install(win) {
if (!win.Math.sign) {
win.Math.sign = sign;
win.Object.defineProperty(win.Math, 'sign', {
enumerable: false,
configurable: true,
writable: true,
value: sign,
});
}
}
7 changes: 6 additions & 1 deletion src/polyfills/object-assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export function assign(target, var_args) {
*/
export function install(win) {
if (!win.Object.assign) {
win.Object.assign = assign;
win.Object.defineProperty(win.Object, 'assign', {
enumerable: false,
configurable: true,
writable: true,
value: assign,
});
}
}
2 changes: 2 additions & 0 deletions test/functional/test-polyfill-document-contains.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ describe('HTMLDocument.contains', () => {
HTMLDocument: class {
contains() {}
},
Object: window.Object,
};
nativeContains = fakeWinWithContains.HTMLDocument.prototype.contains;

fakeWinWithoutContains = {
HTMLDocument: class {
},
Object: window.Object,
};
install(fakeWinWithoutContains);
polyfillContains = fakeWinWithoutContains.HTMLDocument.prototype.contains;
Expand Down

0 comments on commit 05d0f57

Please sign in to comment.