PageSourceSearch

https://app.screenclip.com/npm.setimmediate.c90049cf7d58b14ea0af.js

js screenclip.com collected 2026-09-24 09:07:09 UTC 6,786 bytes, 197 lines download raw bytes

vendor: 6,124 bytes, lines 1-176
1(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[41],{
2
3/***/ "YBdB":
4/***/ (function(module, exports, __webpack_require__) {
5
6/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
7    "use strict";
8
9    if (global.setImmediate) {
10        return;
11    }
12
13    var nextHandle = 1; // Spec says greater than zero
14    var tasksByHandle = {};
15    var currentlyRunningATask = false;
16    var doc = global.document;
17    var registerImmediate;
18
19    function setImmediate(callback) {
20      // Callback can either be a function or a string
21      if (typeof callback !== "function") {
22        callback = new Function("" + callback);
23      }
24      // Copy function arguments
25      var args = new Array(arguments.length - 1);
26      for (var i = 0; i < args.length; i++) {
27          args[i] = arguments[i + 1];
28      }
29      // Store and register the task
30      var task = { callback: callback, args: args };
31      tasksByHandle[nextHandle] = task;
32      registerImmediate(nextHandle);
33      return nextHandle++;
34    }
35
36    function clearImmediate(handle) {
37        delete tasksByHandle[handle];
38    }
39
40    function run(task) {
41        var callback = task.callback;
42        var args = task.args;
43        switch (args.length) {
44        case 0:
45            callback();
46            break;
47        case 1:
48            callback(args[0]);
49            break;
50        case 2:
51            callback(args[0], args[1]);
52            break;
53        case 3:
54            callback(args[0], args[1], args[2]);
55            break;
56        default:
57            callback.apply(undefined, args);
58            break;
59        }
60    }
61
62    function runIfPresent(handle) {
63        // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
64        // So if we're currently running a task, we'll need to delay this invocation.
65        if (currentlyRunningATask) {
66            // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
67            // "too much recursion" error.
68            setTimeout(runIfPresent, 0, handle);
69        } else {
70            var task = tasksByHandle[handle];
71            if (task) {
72                currentlyRunningATask = true;
73                try {
74                    run(task);
75                } finally {
76                    clearImmediate(handle);
77                    currentlyRunningATask = false;
78                }
79            }
80        }
81    }
82
83    function installNextTickImplementation() {
84        registerImmediate = function(handle) {
85            process.nextTick(function () { runIfPresent(handle); });
86        };
87    }
88
89    function canUsePostMessage() {
90        // The test against `importScripts` prevents this implementation from being installed inside a web worker,
91        // where `global.postMessage` means something completely different and can't be used for this purpose.
92        if (global.postMessage && !global.importScripts) {
93            var postMessageIsAsynchronous = true;
94            var oldOnMessage = global.onmessage;
95            global.onmessage = function() {
96                postMessageIsAsynchronous = false;
97            };
98            global.postMessage("", "*");
99            global.onmessage = oldOnMessage;
100            return postMessageIsAsynchronous;
101        }
102    }
103
104    function installPostMessageImplementation() {
105        // Installs an event handler on `global` for the `message` event: see
106        // * https://developer.mozilla.org/en/DOM/window.postMessage
107        // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
108
109        var messagePrefix = "setImmediate$" + Math.random() + "$";
110        var onGlobalMessage = function(event) {
111            if (event.source === global &&
112                typeof event.data === "string" &&
113                event.data.indexOf(messagePrefix) === 0) {
114                runIfPresent(+event.data.slice(messagePrefix.length));
115            }
116        };
117
118        if (global.addEventListener) {
119            global.addEventListener("message", onGlobalMessage, false);
120        } else {
121            global.attachEvent("onmessage", onGlobalMessage);
122        }
123
124        registerImmediate = function(handle) {
125            global.postMessage(messagePrefix + handle, "*");
126        };
127    }
128
129    function installMessageChannelImplementation() {
130        var channel = new MessageChannel();
131        channel.port1.onmessage = function(event) {
132            var handle = event.data;
133            runIfPresent(handle);
134        };
135
136        registerImmediate = function(handle) {
137            channel.port2.postMessage(handle);
138        };
139    }
140
141    function installReadyStateChangeImplementation() {
142        var html = doc.documentElement;
143        registerImmediate = function(handle) {
144            // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
145            // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
146            var script = doc.createElement("script");
147            script.onreadystatechange = function () {
148                runIfPresent(handle);
149                script.onreadystatechange = null;
150                html.removeChild(script);
151                script = null;
152            };
153            html.appendChild(script);
154        };
155    }
156
157    function installSetTimeoutImplementation() {
158        registerImmediate = function(handle) {
159            setTimeout(runIfPresent, 0, handle);
160        };
161    }
162
163    // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
164    var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
165    attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
166
167    // Don't get fooled by e.g. browserify environments.
168    if ({}.toString.call(global.process) === "[object process]") {
169        // For Node.js before 0.9
170        installNextTickImplementation();
171
172    } else if (canUsePostMessage()) {
173        // For non-IE10 modern browsers
174        installPostMessageImplementation();
175
176    }
176 else if (global.MessageChannel) {
177        // For web workers, where supported
178        installMessageChannelImplementation();
179
180    } else if (doc && "onreadystatechange" in doc.createElement("script")) {
181        // For IE 6–8
182        installReadyStateChangeImplementation();
183
184    } else {
185        // For older browsers
186        installSetTimeoutImplementation();
187    }
188
189    attachTo.setImmediate = setImmediate;
190    attachTo.clearImmediate = clearImmediate;
191}(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
192
193/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__("yLpj"), __webpack_require__("8oxB")))
194
195/***/ })
196
197}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.