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