UNPKG

teneturiste

Version:

Execute code when the js-process exits. On all javascript-environments

308 lines (280 loc) 9.05 kB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addBrowser = addBrowser; /* global WorkerGlobalScope */ function addBrowser(fn) { if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) { /** * Because killing a worker does directly stop the excution * of the code, our only chance is to overwrite the close function * which could work some times. * @link https://stackoverflow.com/q/72903255/3443137 */ var oldClose = self.close.bind(self); self.close = function () { fn(); return oldClose(); }; } else { /** * if we are on react-native, there is no window.addEventListener * @link https://github.com/pubkey/unload/issues/6 */ if (typeof window.addEventListener !== 'function') { return; } /** * for normal browser-windows, we use the beforeunload-event */ window.addEventListener('beforeunload', function () { fn(); }, true); /** * for iframes, we have to use the unload-event * @link https://stackoverflow.com/q/47533670/3443137 */ window.addEventListener('unload', function () { fn(); }, true); } /** * TODO add fallback for safari-mobile * @link https://stackoverflow.com/a/26193516/3443137 */ } },{}],2:[function(require,module,exports){ "use strict"; var unload = require('./index.js'); window['unload'] = unload; },{"./index.js":3}],3:[function(require,module,exports){ (function (process){(function (){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.add = add; exports.getSize = getSize; exports.removeAll = removeAll; exports.runAll = runAll; var _browser = require("./browser.js"); var _node = require("./node.js"); /** * Use the code directly to prevent import problems * with the detect-node package. * @link https://github.com/iliakan/detect-node/blob/master/index.js */ var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]'; var USE_METHOD = isNode ? _node.addNode : _browser.addBrowser; var LISTENERS = new Set(); var startedListening = false; function startListening() { if (startedListening) { return; } startedListening = true; USE_METHOD(runAll); } function add(fn) { startListening(); if (typeof fn !== 'function') { throw new Error('Listener is no function'); } LISTENERS.add(fn); var addReturn = { remove: function remove() { return LISTENERS["delete"](fn); }, run: function run() { LISTENERS["delete"](fn); return fn(); } }; return addReturn; } function runAll() { var promises = []; LISTENERS.forEach(function (fn) { promises.push(fn()); LISTENERS["delete"](fn); }); return Promise.all(promises); } function removeAll() { LISTENERS.clear(); } function getSize() { return LISTENERS.size; } }).call(this)}).call(this,require('_process')) },{"./browser.js":1,"./node.js":4,"_process":5}],4:[function(require,module,exports){ },{}],5:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it // don't break things. But we need to wrap it in a try catch in case it is // wrapped in strict mode code which doesn't define any globals. It's inside a // function because try/catches deoptimize in certain engines. var cachedSetTimeout; var cachedClearTimeout; function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } (function () { try { if (typeof setTimeout === 'function') { cachedSetTimeout = setTimeout; } else { cachedSetTimeout = defaultSetTimout; } } catch (e) { cachedSetTimeout = defaultSetTimout; } try { if (typeof clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } else { cachedClearTimeout = defaultClearTimeout; } } catch (e) { cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } process.nextTick = function (fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; },{}]},{},[2]);