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