clearImmediate not polyfilled when setImmediate is polyfilled earlier
Closed this issue · 3 comments
waxidiotic commented
If another script on a page polyfills only setImmediate and not clearImmediate, when this polyfill runs, it only checks for setImmediate and if that exists, it does not polyfill clearImmediate.
// setimmediate attaches itself to the global object
require("setimmediate");
// On some exotic environments, it's not clear which object `setimmeidate` was
// able to install onto. Search each possibility in the same order as the
// `setimmediate` library.
exports.setImmediate = (typeof self !== "undefined" && self.setImmediate) ||
(typeof global !== "undefined" && global.setImmediate) ||
(this && this.setImmediate);
exports.clearImmediate = (typeof self !== "undefined" && self.clearImmediate) ||
(typeof global !== "undefined" && global.clearImmediate) ||
(this && this.clearImmediate);
This causes libraries compiled with webpack to not load properly and throw an exception when clearImmediate is undefined
.
From jwplayer/jwplayer:
/*!***************************************************!*\
!*** ./node_modules/setimmediate/setImmediate.js ***!
\***************************************************/
/*! dynamic exports provided */
/*! all exports used */
/*! ModuleConcatenation bailout: Module is not an ECMAScript module */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
"use strict";
if (global.setImmediate) {
return;
}
robwalch commented
@waxidiotic we can close this. I've opened a PR in setImmediate that handles this issue: YuzuJS/setImmediate#71
jryans commented
Interesting! My first impression is that a fix in setImmediate
is the right place for this, and it appears one has now been filed. For now, I'll close this, but please reopen if the situation changes.