Merge pull request #918 from yxl/setZeroTimeout

Reimplement setZeroTimeout with Promise.
This commit is contained in:
Myk Melez 2015-01-25 13:30:19 -08:00
Родитель 6bddad65e4 e533c4a615
Коммит d60f51d940
8 изменённых файлов: 9 добавлений и 17 удалений

Просмотреть файл

@ -18,6 +18,7 @@
<!--<script type="text/javascript" src="build/shumway.js" defer></script>-->
<!--<script type="text/javascript" src="libs/terminal.js" defer></script>-->
<script type="text/javascript" src="libs/console.js" defer></script>
<script type="text/javascript" src="libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="legacy.js" defer></script>
<script type="text/javascript" src="blackBox.js" defer></script>
<script type="text/javascript" src="timer.js" defer></script>
@ -39,7 +40,6 @@
<script type="text/javascript" src="libs/jsbn/jsbn.js" defer></script>
<script type="text/javascript" src="libs/jsbn/jsbn2.js" defer></script>
<script type="text/javascript" src="libs/contacts.js" defer></script>
<script type="text/javascript" src="libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="libs/pipe.js" defer></script>
<script type="text/javascript" src="libs/contact2vcard.js" defer></script>
<script type="text/javascript" src="libs/emoji.js" defer></script>

Просмотреть файл

@ -5,6 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0">
<script type="text/javascript" src="../../libs/fs.js" defer></script>
<script type="text/javascript" src="../../libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="../../timer.js" defer></script>
<script type="text/javascript" src="../qunit/core.js" defer></script>
<script type="text/javascript" src="../qunit/equiv.js" defer></script>

Просмотреть файл

@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="../../libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="../../timer.js" defer></script>
<script type="text/javascript" src="../../libs/load.js" defer></script>
<script type="text/javascript" src="fs-v1.js" defer></script>

Просмотреть файл

@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="../../libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="../../timer.js" defer></script>
<script type="text/javascript" src="../../libs/load.js" defer></script>
<script type="text/javascript" src="fs-v2.js" defer></script>

Просмотреть файл

@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="../../libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="../../timer.js" defer></script>
<script type="text/javascript" src="../../libs/load.js" defer></script>
<script type="text/javascript" src="fs-v2.js" defer></script>

Просмотреть файл

@ -5,6 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0">
<script type="text/javascript" src="../../libs/fs.js" defer></script>
<script type="text/javascript" src="../../libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="../../timer.js" defer></script>
<script type="text/javascript" src="test-fs-harness.js" defer></script>
<script type="text/javascript" src="test-fs-init.js" defer></script>

Просмотреть файл

@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="../../libs/promise-6.0.0.js" defer></script>
<script type="text/javascript" src="../../timer.js" defer></script>
<script type="text/javascript" src="../../libs/fs.js" defer></script>
<script type="text/javascript" src="test-fs-harness.js" defer></script>

Просмотреть файл

@ -6,29 +6,15 @@
// Only add setZeroTimeout to the window object, and hide everything
// else in a closure.
(function() {
var timeouts = [];
var messageName = "zero-timeout-message";
var resolved = Promise.resolve();
// Like setTimeout, but only takes a function argument. There's
// no time argument (always zero) and no arguments (you have to
// use a closure).
function setZeroTimeout(fn) {
timeouts.push(fn);
window.postMessage(messageName, "*");
resolved.then(fn);
}
function handleMessage(event) {
if (event.source == window && event.data == messageName) {
event.stopPropagation();
if (timeouts.length > 0) {
var fn = timeouts.shift();
fn();
}
}
}
window.addEventListener("message", handleMessage, true);
// Add the one thing we want added to the window object.
window.setZeroTimeout = setZeroTimeout;
})();