Refactor: extract postMessage
This commit is contained in:
@@ -25,6 +25,23 @@ getJasmineRequireObj().clearStack = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function messageChannelImpl(global) {
|
function messageChannelImpl(global) {
|
||||||
|
const { setTimeout } = global;
|
||||||
|
const postMessage = getPostMessage(global);
|
||||||
|
|
||||||
|
let currentCallCount = 0;
|
||||||
|
return function clearStack(fn) {
|
||||||
|
currentCallCount++;
|
||||||
|
|
||||||
|
if (currentCallCount < maxInlineCallCount) {
|
||||||
|
postMessage(fn);
|
||||||
|
} else {
|
||||||
|
currentCallCount = 0;
|
||||||
|
setTimeout(fn);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPostMessage(global) {
|
||||||
const { MessageChannel, setTimeout } = global;
|
const { MessageChannel, setTimeout } = global;
|
||||||
const channel = new MessageChannel();
|
const channel = new MessageChannel();
|
||||||
let head = {};
|
let head = {};
|
||||||
@@ -48,17 +65,9 @@ getJasmineRequireObj().clearStack = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let currentCallCount = 0;
|
return function postMessage(fn) {
|
||||||
return function clearStack(fn) {
|
tail = tail.next = { task: fn };
|
||||||
currentCallCount++;
|
channel.port2.postMessage(0);
|
||||||
|
|
||||||
if (currentCallCount < maxInlineCallCount) {
|
|
||||||
tail = tail.next = { task: fn };
|
|
||||||
channel.port2.postMessage(0);
|
|
||||||
} else {
|
|
||||||
currentCallCount = 0;
|
|
||||||
setTimeout(fn);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user