|
1 |
| -import { isFunction, isUndefined } from '@rudderstack/analytics-js-common/utilities/checks'; |
| 1 | +import { isFunction } from '@rudderstack/analytics-js-common/utilities/checks'; |
2 | 2 |
|
3 | 3 | const isDatasetAvailable = (): boolean => {
|
4 |
| - const testElement = document.createElement('div'); |
| 4 | + const testElement = globalThis.document.createElement('div'); |
5 | 5 | testElement.setAttribute('data-a-b', 'c');
|
6 | 6 | return testElement.dataset ? testElement.dataset.aB === 'c' : false;
|
7 | 7 | };
|
8 | 8 |
|
9 | 9 | const legacyJSEngineRequiredPolyfills: Record<string, () => boolean> = {
|
10 |
| - URL: () => !isFunction(globalThis.URL) || !globalThis.URLSearchParams, |
11 |
| - MutationObserver: () => isUndefined(MutationObserver), |
12 |
| - Promise: () => isUndefined(Promise), |
13 |
| - 'Number.isNaN': () => !Number.isNaN, |
14 |
| - 'Number.isInteger': () => !Number.isInteger, |
15 |
| - 'Array.from': () => !Array.from, |
16 |
| - 'Array.prototype.find': () => !Array.prototype.find, |
17 |
| - 'Array.prototype.includes': () => !Array.prototype.includes, |
18 |
| - 'String.prototype.endsWith': () => !String.prototype.endsWith, |
19 |
| - 'String.prototype.startsWith': () => !String.prototype.startsWith, |
20 |
| - 'String.prototype.includes': () => !String.prototype.includes, |
21 |
| - 'Object.entries': () => !Object.entries, |
22 |
| - 'Object.values': () => !Object.values, |
23 |
| - 'Object.assign': () => typeof Object.assign !== 'function', |
| 10 | + // Ideally, we should separate the checks for URL and URLSearchParams but |
| 11 | + // the polyfill service serves them under the same feature name, "URL". |
| 12 | + URL: () => !isFunction(globalThis.URL) || !isFunction(globalThis.URLSearchParams), |
| 13 | + Promise: () => !isFunction(globalThis.Promise), |
| 14 | + 'Number.isNaN': () => !isFunction(globalThis.Number.isNaN), |
| 15 | + 'Number.isInteger': () => !isFunction(globalThis.Number.isInteger), |
| 16 | + 'Array.from': () => !isFunction(globalThis.Array.from), |
| 17 | + 'Array.prototype.find': () => !isFunction(globalThis.Array.prototype.find), |
| 18 | + 'Array.prototype.includes': () => !isFunction(globalThis.Array.prototype.includes), |
| 19 | + 'String.prototype.endsWith': () => !isFunction(globalThis.String.prototype.endsWith), |
| 20 | + 'String.prototype.startsWith': () => !isFunction(globalThis.String.prototype.startsWith), |
| 21 | + 'String.prototype.includes': () => !isFunction(globalThis.String.prototype.includes), |
| 22 | + 'String.prototype.replaceAll': () => !isFunction(globalThis.String.prototype.replaceAll), |
| 23 | + 'String.fromCodePoint': () => !isFunction(globalThis.String.fromCodePoint), |
| 24 | + 'Object.entries': () => !isFunction(globalThis.Object.entries), |
| 25 | + 'Object.values': () => !isFunction(globalThis.Object.values), |
| 26 | + 'Object.assign': () => !isFunction(globalThis.Object.assign), |
24 | 27 | 'Element.prototype.dataset': () => !isDatasetAvailable(),
|
25 |
| - 'String.prototype.replaceAll': () => !String.prototype.replaceAll, |
26 |
| - TextEncoder: () => isUndefined(TextEncoder) || isUndefined(TextDecoder), |
27 |
| - 'String.fromCodePoint': () => !String.fromCodePoint, |
| 28 | + // Ideally, we should separate the checks for TextEncoder and TextDecoder but |
| 29 | + // the polyfill service serves them under the same feature name, "TextEncoder". |
| 30 | + TextEncoder: () => !isFunction(globalThis.TextEncoder) || !isFunction(globalThis.TextDecoder), |
28 | 31 | requestAnimationFrame: () =>
|
29 | 32 | !isFunction(globalThis.requestAnimationFrame) || !isFunction(globalThis.cancelAnimationFrame),
|
30 | 33 | CustomEvent: () => !isFunction(globalThis.CustomEvent),
|
31 |
| - /* eslint-disable-next-line */ |
32 |
| - 'navigator.sendBeacon': () => !isFunction(navigator.sendBeacon), |
33 |
| - ArrayBuffer: () => !isFunction(Uint8Array), |
| 34 | + 'navigator.sendBeacon': () => !isFunction(globalThis.navigator.sendBeacon), |
| 35 | + // Note, the polyfill service serves both ArrayBuffer and Uint8Array under the same feature name, "ArrayBuffer". |
| 36 | + ArrayBuffer: () => !isFunction(globalThis.Uint8Array), |
34 | 37 | };
|
35 | 38 |
|
36 | 39 | const isLegacyJSEngine = (): boolean => {
|
|
0 commit comments