This commit is contained in:
Andreas Gal 2014-07-17 21:18:53 -07:00
Родитель c0d9e4bc44
Коммит f351476bfb
3 изменённых файлов: 35 добавлений и 14 удалений

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

@ -4,6 +4,7 @@
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="zipfile.js" defer></script>
<script type="text/javascript" src="timer.js" defer></script>
<script type="text/javascript" src="util.js" defer></script>
<script type="text/javascript" src="long.js" defer></script>
<script type="text/javascript" src="classfile/reader.js" defer></script>

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

@ -6,7 +6,6 @@
var Threads = function() {
this.threads = [];
this.empty = [];
this.ready = [];
var mainThread = new Thread("main");
this.add(mainThread);
this.current = mainThread;
@ -37,16 +36,3 @@ Threads.prototype.count = function() {
Threads.prototype.getThread = function(pid) {
return this.threads[pid];
}
Threads.prototype.yield = function(frame) {
if (this.ready.length) {
this.current.frame = frame;
this.ready.unshift(this.current);
this.current = this.ready[this.ready.length - 1];
}
window.postMessage(null, "*");
}
Threads.prototype.resume = function() {
VM.resume(this.current.frame);
}

34
timer.js Normal file
Просмотреть файл

@ -0,0 +1,34 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
// Only add setZeroTimeout to the window object, and hide everything
// else in a closure.
(function() {
var timeouts = [];
var messageName = "zero-timeout-message";
// 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, "*");
}
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;
})();