Skip to content

Commit 05d0f57

Browse files
authored
Make Array includes() polyfill not enumerable (#7517)
1 parent dc08518 commit 05d0f57

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

src/polyfills/array-includes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ function includes(value, opt_fromIndex) {
4444
*/
4545
export function install(win) {
4646
if (!win.Array.prototype.includes) {
47-
win.Array.prototype.includes = includes;
47+
win.Object.defineProperty(Array.prototype, 'includes', {
48+
enumerable: false,
49+
configurable: true,
50+
writable: true,
51+
value: includes,
52+
});
4853
}
4954
}

src/polyfills/document-contains.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function documentContainsPolyfill(node) {
3737
*/
3838
export function install(win) {
3939
if (!win.HTMLDocument.prototype.contains) {
40-
win.HTMLDocument.prototype.contains = documentContainsPolyfill;
40+
win.Object.defineProperty(win.HTMLDocument.prototype, 'contains', {
41+
enumerable: false,
42+
configurable: true,
43+
writable: true,
44+
value: documentContainsPolyfill,
45+
});
4146
}
4247
}

src/polyfills/domtokenlist-toggle.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ function domTokenListTogglePolyfill(token, opt_force) {
4242
*/
4343
export function install(win) {
4444
if (isIe(win) && win.DOMTokenList) {
45-
win.DOMTokenList.prototype.toggle = domTokenListTogglePolyfill;
45+
win.Object.defineProperty(win.DOMTokenList.prototype, 'toggle', {
46+
enumerable: false,
47+
configurable: true,
48+
writable: true,
49+
value: domTokenListTogglePolyfill,
50+
});
4651
}
4752
}
4853

src/polyfills/math-sign.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export function sign(x) {
4040
*/
4141
export function install(win) {
4242
if (!win.Math.sign) {
43-
win.Math.sign = sign;
43+
win.Object.defineProperty(win.Math, 'sign', {
44+
enumerable: false,
45+
configurable: true,
46+
writable: true,
47+
value: sign,
48+
});
4449
}
4550
}

src/polyfills/object-assign.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export function assign(target, var_args) {
5050
*/
5151
export function install(win) {
5252
if (!win.Object.assign) {
53-
win.Object.assign = assign;
53+
win.Object.defineProperty(win.Object, 'assign', {
54+
enumerable: false,
55+
configurable: true,
56+
writable: true,
57+
value: assign,
58+
});
5459
}
5560
}

test/functional/test-polyfill-document-contains.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ describe('HTMLDocument.contains', () => {
3737
HTMLDocument: class {
3838
contains() {}
3939
},
40+
Object: window.Object,
4041
};
4142
nativeContains = fakeWinWithContains.HTMLDocument.prototype.contains;
4243

4344
fakeWinWithoutContains = {
4445
HTMLDocument: class {
4546
},
47+
Object: window.Object,
4648
};
4749
install(fakeWinWithoutContains);
4850
polyfillContains = fakeWinWithoutContains.HTMLDocument.prototype.contains;

0 commit comments

Comments
 (0)