source: trip-planner-front/node_modules/core-js/internals/microtask.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1var global = require('../internals/global');
2var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
3var macrotask = require('../internals/task').set;
4var IS_IOS = require('../internals/engine-is-ios');
5var IS_WEBOS_WEBKIT = require('../internals/engine-is-webos-webkit');
6var IS_NODE = require('../internals/engine-is-node');
7
8var MutationObserver = global.MutationObserver || global.WebKitMutationObserver;
9var document = global.document;
10var process = global.process;
11var Promise = global.Promise;
12// Node.js 11 shows ExperimentalWarning on getting `queueMicrotask`
13var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global, 'queueMicrotask');
14var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value;
15
16var flush, head, last, notify, toggle, node, promise, then;
17
18// modern engines have queueMicrotask method
19if (!queueMicrotask) {
20 flush = function () {
21 var parent, fn;
22 if (IS_NODE && (parent = process.domain)) parent.exit();
23 while (head) {
24 fn = head.fn;
25 head = head.next;
26 try {
27 fn();
28 } catch (error) {
29 if (head) notify();
30 else last = undefined;
31 throw error;
32 }
33 } last = undefined;
34 if (parent) parent.enter();
35 };
36
37 // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339
38 // also except WebOS Webkit https://github.com/zloirock/core-js/issues/898
39 if (!IS_IOS && !IS_NODE && !IS_WEBOS_WEBKIT && MutationObserver && document) {
40 toggle = true;
41 node = document.createTextNode('');
42 new MutationObserver(flush).observe(node, { characterData: true });
43 notify = function () {
44 node.data = toggle = !toggle;
45 };
46 // environments with maybe non-completely correct, but existent Promise
47 } else if (Promise && Promise.resolve) {
48 // Promise.resolve without an argument throws an error in LG WebOS 2
49 promise = Promise.resolve(undefined);
50 // workaround of WebKit ~ iOS Safari 10.1 bug
51 promise.constructor = Promise;
52 then = promise.then;
53 notify = function () {
54 then.call(promise, flush);
55 };
56 // Node.js without promises
57 } else if (IS_NODE) {
58 notify = function () {
59 process.nextTick(flush);
60 };
61 // for other environments - macrotask based on:
62 // - setImmediate
63 // - MessageChannel
64 // - window.postMessag
65 // - onreadystatechange
66 // - setTimeout
67 } else {
68 notify = function () {
69 // strange IE + webpack dev server bug - use .call(global)
70 macrotask.call(global, flush);
71 };
72 }
73}
74
75module.exports = queueMicrotask || function (fn) {
76 var task = { fn: fn, next: undefined };
77 if (last) last.next = task;
78 if (!head) {
79 head = task;
80 notify();
81 } last = task;
82};
Note: See TracBrowser for help on using the repository browser.