Chased issue where we lose the trampoline down to incorrect use of setTimeout. Yikes.

This commit is contained in:
Danny Yoo 2011-07-11 15:48:58 -04:00
parent 34c9d7954b
commit ca7c8eb9a3
4 changed files with 43 additions and 35 deletions

View File

@ -12,6 +12,7 @@ var checkImage = plt.baselib.check.makeCheckArgumentType(
var Closure = plt.baselib.functions.Closure;
var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;
var PAUSE = plt.runtime.PAUSE;
@ -61,27 +62,29 @@ EXPORTS['image-url'] =
new Closure(
function(MACHINE) {
var url = checkString(MACHINE, 'image-url', 0);
PAUSE(function(restart) {
PAUSE(
function(restart) {
var rawImage = new Image();
rawImage.onload = function() {
restart(function(MACHINE) {
finalizeClosureCall(
makeFileImage(
path.toString(),
rawImage));
})
});
rawImage.onerror =
(function(e) {
finalizeClosureCall(
MACHINE,
makeFileImage(url.toString(),
rawImage));
});
};
rawImage.onerror = function(e) {
restart(function(MACHINE) {
plt.baselib.exceptions.raise(
MACHINE,
new Error(plt.baselib.format.format(
"unable to load: ~a",
url)));
"unable to load ~a: ~a",
url,
e.message)));
});
});
rawImage.src = path.toString();
}
rawImage.src = url.toString();
}
);
},
1,

View File

@ -155,7 +155,7 @@ MACHINE.modules[~s] =
(define (assemble-modinvoke path after)
(let ([name (rewrite-path (path->string path))])
(format "if (! MACHINE.modules[~s].isInvoked) {
MACHINE.modules[~s].invoke(MACHINE,
MACHINE.modules[~s].internalInvoke(MACHINE,
function() {
///////////////////////////

View File

@ -26,6 +26,17 @@
// External invokation of a module.
ModuleRecord.prototype.invoke = function(MACHINE, succ, fail) {
this._invoke(false, MACHINE, succ, fail);
};
// Internal invokation of a module.
ModuleRecord.prototype.internalInvoke = function(MACHINE, succ, fail) {
this._invoke(true, MACHINE, succ, fail);
};
// Private: general invokation of a module
ModuleRecord.prototype._invoke = function(isInternal, MACHINE, succ, fail) {
var that = this;
MACHINE = MACHINE || plt.runtime.currentMachine;
succ = succ || function(){};
fail = fail || function(){};
@ -33,22 +44,22 @@
var oldErrorHandler = MACHINE.params['currentErrorHandler'];
var afterGoodInvoke = function(MACHINE) {
MACHINE.params['currentErrorHandler'] = oldErrorHandler;
setTimeout(succ, 0);
succ();
};
if (this.isInvoked) {
setTimeout(succ, 0);
succ();
} else {
MACHINE.params['currentErrorHandler'] = function(MACHINE, anError) {
MACHINE.params['currentErrorHandler'] = oldErrorHandler;
setTimeout(
function() {
fail(MACHINE, anError)
},
0);
fail(MACHINE, anError)
};
MACHINE.control.push(new plt.baselib.frames.CallFrame(afterGoodInvoke, null));
plt.runtime.trampoline(MACHINE, this.label);
if (isInternal) {
throw that.label;
} else {
plt.runtime.trampoline(MACHINE, that.label);
}
}
};
@ -57,6 +68,8 @@
exports.ModuleRecord = ModuleRecord;

View File

@ -339,8 +339,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
};
var PAUSE = function(onPause) {
throw new Pause(onPause);
}
throw(new Pause(onPause));
};
@ -411,23 +411,15 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function() { trampoline(MACHINE, thunk); },
0);
};
setTimeout(
function() {
e.onPause(restart);
},
0);
e.onPause(restart);
return;
} else if (e instanceof HaltError) {
MACHINE.running = false;
setTimeout(
function() { e.onHalt(MACHINE); },
0);
e.onHalt(MACHINE);
return;
} else {
MACHINE.running = false;
setTimeout(
function() { MACHINE.params.currentErrorHandler(MACHINE, e); },
0);
MACHINE.params.currentErrorHandler(MACHINE, e);
return;
}
}