var global = require('../internals/global');
-var fails = require('../internals/fails');
+var apply = require('../internals/function-apply');
var bind = require('../internals/function-bind-context');
+var isCallable = require('../internals/is-callable');
+var hasOwn = require('../internals/has-own-property');
+var fails = require('../internals/fails');
var html = require('../internals/html');
+var arraySlice = require('../internals/array-slice');
var createElement = require('../internals/document-create-element');
var IS_IOS = require('../internals/engine-is-ios');
var IS_NODE = require('../internals/engine-is-node');
-var location = global.location;
var set = global.setImmediate;
var clear = global.clearImmediate;
var process = global.process;
-var MessageChannel = global.MessageChannel;
var Dispatch = global.Dispatch;
+var Function = global.Function;
+var MessageChannel = global.MessageChannel;
+var String = global.String;
var counter = 0;
var queue = {};
var ONREADYSTATECHANGE = 'onreadystatechange';
-var defer, channel, port;
+var location, defer, channel, port;
+
+try {
+ // Deno throws a ReferenceError on `location` access without `--location` flag
+ location = global.location;
+} catch (error) { /* empty */ }
var run = function (id) {
- // eslint-disable-next-line no-prototype-builtins -- safe
- if (queue.hasOwnProperty(id)) {
+ if (hasOwn(queue, id)) {
var fn = queue[id];
delete queue[id];
fn();
var post = function (id) {
// old engines have not location.origin
- global.postMessage(id + '', location.protocol + '//' + location.host);
+ global.postMessage(String(id), location.protocol + '//' + location.host);
};
// Node.js 0.9+ & IE10+ has setImmediate, otherwise:
if (!set || !clear) {
set = function setImmediate(fn) {
- var args = [];
- var i = 1;
- while (arguments.length > i) args.push(arguments[i++]);
+ var args = arraySlice(arguments, 1);
queue[++counter] = function () {
- // eslint-disable-next-line no-new-func -- spec requirement
- (typeof fn == 'function' ? fn : Function(fn)).apply(undefined, args);
+ apply(isCallable(fn) ? fn : Function(fn), undefined, args);
};
defer(counter);
return counter;
channel = new MessageChannel();
port = channel.port2;
channel.port1.onmessage = listener;
- defer = bind(port.postMessage, port, 1);
+ defer = bind(port.postMessage, port);
// Browsers with postMessage, skip WebWorkers
// IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
} else if (
global.addEventListener &&
- typeof postMessage == 'function' &&
+ isCallable(global.postMessage) &&
!global.importScripts &&
location && location.protocol !== 'file:' &&
!fails(post)