polyfill-service
Version:
A polyfill combinator
1 lines • 8.8 kB
JSON
{"browsers":{"chrome":"*","firefox":"*","opera":"*","safari":"*","ie":"* - 9","ios_saf":"*","ios_chr":"*","android":"*","op_mob":"*","ie_mob":"<10","firefox_mob":"*","bb":"*","op_mini":"*"},"docs":"https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate","repo":"https://github.com/YuzuJS/setImmediate","baseDir":"setImmediate","hasTests":false,"rawSource":"\n// setImmediate\n(function (global, undefined) {\n \"use strict\";\n\n if (global.setImmediate) {\n return;\n }\n\n var nextHandle = 1; // Spec says greater than zero\n var tasksByHandle = {};\n var currentlyRunningATask = false;\n var doc = global.document;\n var setImmediate;\n\n function addFromSetImmediateArguments(args) {\n tasksByHandle[nextHandle] = partiallyApplied.apply(undefined, args);\n return nextHandle++;\n }\n\n // This function accepts the same arguments as setImmediate, but\n // returns a function that requires no arguments.\n function partiallyApplied(handler) {\n var args = [].slice.call(arguments, 1);\n return function() {\n if (typeof handler === \"function\") {\n handler.apply(undefined, args);\n } else {\n (new Function(\"\" + handler))();\n }\n };\n }\n\n function runIfPresent(handle) {\n // From the spec: \"Wait until any invocations of this algorithm started before this one have completed.\"\n // So if we're currently running a task, we'll need to delay this invocation.\n if (currentlyRunningATask) {\n // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a\n // \"too much recursion\" error.\n setTimeout(partiallyApplied(runIfPresent, handle), 0);\n } else {\n var task = tasksByHandle[handle];\n if (task) {\n currentlyRunningATask = true;\n try {\n task();\n } finally {\n clearImmediate(handle);\n currentlyRunningATask = false;\n }\n }\n }\n }\n\n function clearImmediate(handle) {\n delete tasksByHandle[handle];\n }\n\n function installNextTickImplementation() {\n setImmediate = function() {\n var handle = addFromSetImmediateArguments(arguments);\n process.nextTick(partiallyApplied(runIfPresent, handle));\n return handle;\n };\n }\n\n function canUsePostMessage() {\n // The test against `importScripts` prevents this implementation from being installed inside a web worker,\n // where `global.postMessage` means something completely different and can't be used for this purpose.\n if (global.postMessage && !global.importScripts) {\n var postMessageIsAsynchronous = true;\n var oldOnMessage = global.onmessage;\n global.onmessage = function() {\n postMessageIsAsynchronous = false;\n };\n global.postMessage(\"\", \"*\");\n global.onmessage = oldOnMessage;\n return postMessageIsAsynchronous;\n }\n }\n\n function installPostMessageImplementation() {\n // Installs an event handler on `global` for the `message` event: see\n // * https://developer.mozilla.org/en/DOM/window.postMessage\n // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages\n\n var messagePrefix = \"setImmediate$\" + Math.random() + \"$\";\n var onGlobalMessage = function(event) {\n if (event.source === global &&\n typeof event.data === \"string\" &&\n event.data.indexOf(messagePrefix) === 0) {\n runIfPresent(+event.data.slice(messagePrefix.length));\n }\n };\n\n if (global.addEventListener) {\n global.addEventListener(\"message\", onGlobalMessage, false);\n } else {\n global.attachEvent(\"onmessage\", onGlobalMessage);\n }\n\n setImmediate = function() {\n var handle = addFromSetImmediateArguments(arguments);\n global.postMessage(messagePrefix + handle, \"*\");\n return handle;\n };\n }\n\n function installMessageChannelImplementation() {\n var channel = new MessageChannel();\n channel.port1.onmessage = function(event) {\n var handle = event.data;\n runIfPresent(handle);\n };\n\n setImmediate = function() {\n var handle = addFromSetImmediateArguments(arguments);\n channel.port2.postMessage(handle);\n return handle;\n };\n }\n\n function installReadyStateChangeImplementation() {\n var html = doc.documentElement;\n setImmediate = function() {\n var handle = addFromSetImmediateArguments(arguments);\n // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted\n // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.\n var script = doc.createElement(\"script\");\n script.onreadystatechange = function () {\n runIfPresent(handle);\n script.onreadystatechange = null;\n html.removeChild(script);\n script = null;\n };\n html.appendChild(script);\n return handle;\n };\n }\n\n function installSetTimeoutImplementation() {\n setImmediate = function() {\n var handle = addFromSetImmediateArguments(arguments);\n setTimeout(partiallyApplied(runIfPresent, handle), 0);\n return handle;\n };\n }\n\n // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.\n var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);\n attachTo = attachTo && attachTo.setTimeout ? attachTo : global;\n\n // Don't get fooled by e.g. browserify environments.\n if ({}.toString.call(global.process) === \"[object process]\") {\n // For Node.js before 0.9\n installNextTickImplementation();\n\n } else if (canUsePostMessage()) {\n // For non-IE10 modern browsers\n installPostMessageImplementation();\n\n } else if (global.MessageChannel) {\n // For web workers, where supported\n installMessageChannelImplementation();\n\n } else if (doc && \"onreadystatechange\" in doc.createElement(\"script\")) {\n // For IE 6–8\n installReadyStateChangeImplementation();\n\n } else {\n // For older browsers\n installSetTimeoutImplementation();\n }\n\n attachTo.setImmediate = setImmediate;\n attachTo.clearImmediate = clearImmediate;\n}(typeof self === \"undefined\" ? typeof global === \"undefined\" ? this : global : self));\n","minSource":"!function(e,t){\"use strict\";function n(e){return p[m]=a.apply(t,e),m++}function a(e){var n=[].slice.call(arguments,1);return function(){\"function\"==typeof e?e.apply(t,n):new Function(\"\"+e)()}}function o(e){if(g)setTimeout(a(o,e),0);else{var t=p[e];if(t){g=!0;try{t()}finally{s(e),g=!1}}}}function s(e){delete p[e]}function r(){d=function(){var e=n(arguments);return process.nextTick(a(o,e)),e}}function i(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage(\"\",\"*\"),e.onmessage=n,t}}function c(){var t=\"setImmediate$\"+Math.random()+\"$\",a=function(n){n.source===e&&\"string\"==typeof n.data&&0===n.data.indexOf(t)&&o(+n.data.slice(t.length))};e.addEventListener?e.addEventListener(\"message\",a,!1):e.attachEvent(\"onmessage\",a),d=function(){var a=n(arguments);return e.postMessage(t+a,\"*\"),a}}function u(){var e=new MessageChannel;e.port1.onmessage=function(e){var t=e.data;o(t)},d=function(){var t=n(arguments);return e.port2.postMessage(t),t}}function f(){var e=v.documentElement;d=function(){var t=n(arguments),a=v.createElement(\"script\");return a.onreadystatechange=function(){o(t),a.onreadystatechange=null,e.removeChild(a),a=null},e.appendChild(a),t}}function l(){d=function(){var e=n(arguments);return setTimeout(a(o,e),0),e}}if(!e.setImmediate){var d,m=1,p={},g=!1,v=e.document,y=Object.getPrototypeOf&&Object.getPrototypeOf(e);y=y&&y.setTimeout?y:e,\"[object process]\"==={}.toString.call(e.process)?r():i()?c():e.MessageChannel?u():v&&\"onreadystatechange\"in v.createElement(\"script\")?f():l(),y.setImmediate=d,y.clearImmediate=s}}(\"undefined\"==typeof self?\"undefined\"==typeof global?this:global:self);","detectSource":"'setImmediate' in window"}