File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -31,27 +31,32 @@ const defaultOptions = {
31
31
*/
32
32
export function polyfill ( options ) {
33
33
const opts = { ...defaultOptions , ...options } ;
34
+ let root = null ;
35
+ try {
36
+ root = window || global ;
37
+ } catch ( e ) {
38
+ root = global ;
39
+ }
34
40
if ( opts . isomorphicFetch ) {
35
41
const Tough = require ( 'tough-cookie' ) ;
36
42
const Store = new Tough . MemoryCookieStore ( ) ;
37
43
const cookieJar = new Tough . CookieJar ( Store ) ;
38
44
const fetch = require ( 'fetch-cookie' ) ( require ( 'isomorphic-fetch' ) , cookieJar ) ;
39
- global . fetch = fetch ;
40
- global . cookieJar = cookieJar ;
45
+ root . fetch = fetch ;
46
+ root . cookieJar = cookieJar ;
41
47
require ( 'whatwg-fetch' ) ;
42
48
}
43
49
44
50
if ( opts . fetch && ! opts . isomorphicFetch ) {
45
51
require ( 'whatwg-fetch' ) ;
46
- global . fetchMock = require ( 'fetch-mock' ) ;
52
+ root . fetchMock = require ( 'fetch-mock' ) ;
47
53
}
48
54
49
- if ( opts . localStorage && ! global . localStorage ) {
50
- global . localStorage = require ( 'localStorage' ) ;
55
+ if ( root . localStorage && ! root . localStorage ) {
56
+ root . localStorage = require ( 'localStorage' ) ;
51
57
}
52
58
53
59
if ( opts . media ) {
54
- const root = window || global ;
55
60
root . matchMedia = root . matchMedia
56
61
|| function ( ) {
57
62
return {
You can’t perform that action at this time.
0 commit comments