зеркало из https://github.com/mozilla/pluotsorbet.git
add the ability to yield to the event loop from the first level interpreter
This commit is contained in:
Родитель
a585efe82e
Коммит
d97033bf60
|
@ -9,9 +9,6 @@ var Threads = function() {
|
|||
var mainThread = new Thread("main");
|
||||
this.add(mainThread);
|
||||
this.current = mainThread;
|
||||
window.addEventListener("message", function () {
|
||||
this.resume();
|
||||
}, false);
|
||||
}
|
||||
|
||||
Threads.prototype.add = function(thread) {
|
||||
|
|
10
vm.js
10
vm.js
|
@ -34,6 +34,8 @@ VM.invoke = function(methodInfo, args, callback) {
|
|||
}
|
||||
|
||||
VM.resume = function(frame, callback) {
|
||||
var cycles = 0;
|
||||
|
||||
var cp = frame.cp;
|
||||
var stack = frame.stack;
|
||||
|
||||
|
@ -995,5 +997,13 @@ VM.resume = function(frame, callback) {
|
|||
var opName = OPCODES[op];
|
||||
throw new Error("Opcode " + opName + " [" + op + "] not supported.");
|
||||
}
|
||||
if (VM.level <= 1) {
|
||||
if (cycles++ > 1000) {
|
||||
window.setZeroTimeout(function () {
|
||||
VM.resume(frame, callback);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче