mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-26 22:20:41 -04:00
Add single-frame yield mode
This commit is contained in:
parent
5876681bc7
commit
de6ba08866
4 changed files with 39 additions and 11 deletions
src/engine
|
@ -63,8 +63,14 @@ var execute = function (sequencer, thread) {
|
|||
|
||||
var primitiveReportedValue = null;
|
||||
primitiveReportedValue = blockFunction(argValues, {
|
||||
yield: thread.yield.bind(thread),
|
||||
yield: function() {
|
||||
thread.setStatus(Thread.STATUS_YIELD);
|
||||
},
|
||||
yieldFrame: function() {
|
||||
thread.setStatus(Thread.STATUS_YIELD_FRAME);
|
||||
},
|
||||
done: function() {
|
||||
thread.setStatus(Thread.STATUS_RUNNING);
|
||||
sequencer.proceedThread(thread);
|
||||
},
|
||||
stackFrame: currentStackFrame.executionContext,
|
||||
|
@ -84,17 +90,19 @@ var execute = function (sequencer, thread) {
|
|||
if (isPromise) {
|
||||
if (thread.status === Thread.STATUS_RUNNING) {
|
||||
// Primitive returned a promise; automatically yield thread.
|
||||
thread.status = Thread.STATUS_YIELD;
|
||||
thread.setStatus(Thread.STATUS_YIELD);
|
||||
}
|
||||
// Promise handlers
|
||||
primitiveReportedValue.then(function(resolvedValue) {
|
||||
// Promise resolved: the primitive reported a value.
|
||||
thread.pushReportedValue(resolvedValue);
|
||||
thread.setStatus(Thread.STATUS_RUNNING);
|
||||
sequencer.proceedThread(thread);
|
||||
}, function(rejectionReason) {
|
||||
// Promise rejected: the primitive had some error.
|
||||
// Log it and proceed.
|
||||
console.warn('Primitive rejected promise: ', rejectionReason);
|
||||
thread.setStatus(Thread.STATUS_RUNNING);
|
||||
sequencer.proceedThread(thread);
|
||||
});
|
||||
} else if (thread.status === Thread.STATUS_RUNNING) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue