zloirock / core-js

Standard Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$.global is inaccessible after changing domain on IE 8

imsun opened this issue · comments

var global = typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
module.exports = global;
if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef

In $.global.js, self is used as global. But on IE 8 if you changed document.domain, the elder self will be refused to access.

// i.e.
var global = require('./$.global');
document.domain = 'foo.bar'

// no log on IE 8
global.console.log('Accessible!')

What's worse is that the loader will cache $.global module, so if you changed domain after the first time you load it, it won't work any longer.

You can propose more correct way global detection?

Maybe you could detect if the script is executing in a web worker, and use window if not.