source: trip-planner-front/node_modules/core-js/internals/task.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1var global = require('../internals/global');
2var fails = require('../internals/fails');
3var bind = require('../internals/function-bind-context');
4var html = require('../internals/html');
5var createElement = require('../internals/document-create-element');
6var IS_IOS = require('../internals/engine-is-ios');
7var IS_NODE = require('../internals/engine-is-node');
8
9var set = global.setImmediate;
10var clear = global.clearImmediate;
11var process = global.process;
12var MessageChannel = global.MessageChannel;
13var Dispatch = global.Dispatch;
14var counter = 0;
15var queue = {};
16var ONREADYSTATECHANGE = 'onreadystatechange';
17var location, defer, channel, port;
18
19try {
20 // Deno throws a ReferenceError on `location` access without `--location` flag
21 location = global.location;
22} catch (error) { /* empty */ }
23
24var run = function (id) {
25 // eslint-disable-next-line no-prototype-builtins -- safe
26 if (queue.hasOwnProperty(id)) {
27 var fn = queue[id];
28 delete queue[id];
29 fn();
30 }
31};
32
33var runner = function (id) {
34 return function () {
35 run(id);
36 };
37};
38
39var listener = function (event) {
40 run(event.data);
41};
42
43var post = function (id) {
44 // old engines have not location.origin
45 global.postMessage(String(id), location.protocol + '//' + location.host);
46};
47
48// Node.js 0.9+ & IE10+ has setImmediate, otherwise:
49if (!set || !clear) {
50 set = function setImmediate(fn) {
51 var args = [];
52 var argumentsLength = arguments.length;
53 var i = 1;
54 while (argumentsLength > i) args.push(arguments[i++]);
55 queue[++counter] = function () {
56 // eslint-disable-next-line no-new-func -- spec requirement
57 (typeof fn == 'function' ? fn : Function(fn)).apply(undefined, args);
58 };
59 defer(counter);
60 return counter;
61 };
62 clear = function clearImmediate(id) {
63 delete queue[id];
64 };
65 // Node.js 0.8-
66 if (IS_NODE) {
67 defer = function (id) {
68 process.nextTick(runner(id));
69 };
70 // Sphere (JS game engine) Dispatch API
71 } else if (Dispatch && Dispatch.now) {
72 defer = function (id) {
73 Dispatch.now(runner(id));
74 };
75 // Browsers with MessageChannel, includes WebWorkers
76 // except iOS - https://github.com/zloirock/core-js/issues/624
77 } else if (MessageChannel && !IS_IOS) {
78 channel = new MessageChannel();
79 port = channel.port2;
80 channel.port1.onmessage = listener;
81 defer = bind(port.postMessage, port, 1);
82 // Browsers with postMessage, skip WebWorkers
83 // IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
84 } else if (
85 global.addEventListener &&
86 typeof postMessage == 'function' &&
87 !global.importScripts &&
88 location && location.protocol !== 'file:' &&
89 !fails(post)
90 ) {
91 defer = post;
92 global.addEventListener('message', listener, false);
93 // IE8-
94 } else if (ONREADYSTATECHANGE in createElement('script')) {
95 defer = function (id) {
96 html.appendChild(createElement('script'))[ONREADYSTATECHANGE] = function () {
97 html.removeChild(this);
98 run(id);
99 };
100 };
101 // Rest old browsers
102 } else {
103 defer = function (id) {
104 setTimeout(runner(id), 0);
105 };
106 }
107}
108
109module.exports = {
110 set: set,
111 clear: clear
112};
Note: See TracBrowser for help on using the repository browser.