corrected the weirdness with saving the old argcount before restarting computation. Now the makeRestartFunction handles this low-level detail for us.

This commit is contained in:
Danny Yoo 2011-09-29 18:14:52 -04:00
parent 2251e7bf0e
commit c8f1ef07d4
5 changed files with 7 additions and 22 deletions

View File

@ -286,13 +286,11 @@ EXPORTS['bitmap/url'] =
1,
function(MACHINE) {
var url = checkString(MACHINE, 'bitmap/url', 0);
var oldArgcount = MACHINE.a;
PAUSE(
function(restart) {
var rawImage = new Image();
rawImage.onload = function() {
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall(
MACHINE,
makeFileImage(url.toString(),

View File

@ -432,8 +432,14 @@
},
0);
};
// Creates a restarting function, that reschedules f in a context
// with the old argcount in place.
// Meant to be used only by the trampoline.
var makeRestartFunction = function(MACHINE) {
var oldArgcount = MACHINE.a;
return function(f) {
MACHINE.a = oldArgcount;
return scheduleTrampoline(MACHINE, f);
};
};

View File

@ -71,7 +71,7 @@ EXPORTS['specialize!'] = makeClosure(
1,
function(MACHINE) {
var resource = checkResource(MACHINE, 'specialize!', 0);
var oldArgcount = MACHINE.a;
if (isImagePath(getResourceKey(resource).toString())) {
return PAUSE(
function(restart) {
@ -81,7 +81,6 @@ EXPORTS['specialize!'] = makeClosure(
delete(rawImage.onerror);
injectImageMethods(resource, rawImage);
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
return finalizeClosureCall(MACHINE, resource);
});
};
@ -91,7 +90,6 @@ EXPORTS['specialize!'] = makeClosure(
// on any kind of image-loading error, fail out and
// just return the resource unchanged.
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
return finalizeClosureCall(MACHINE, resource);
});
}

View File

@ -1083,7 +1083,6 @@
// bigBang.
var bigBang = function(MACHINE, world, handlers) {
var oldArgcount = MACHINE.a;
var oldCurrentBigBangRecord = currentBigBangRecord;
var running = true;
@ -1117,7 +1116,6 @@
running = false;
stopEventHandlers();
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
MACHINE.params.currentOutputPort = oldOutputPort;
currentBigBangRecord = oldCurrentBigBangRecord;
finalizeClosureCall(MACHINE, world);
@ -1543,12 +1541,10 @@
1,
function(MACHINE) {
var viewable = MACHINE.e[MACHINE.e.length - 1];
var oldArgcount = MACHINE.a;
PAUSE(function(restart) {
coerseToView(viewable,
function(v) {
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall(MACHINE,
new InitialViewHandler(v));
});
@ -1571,12 +1567,10 @@
1,
function(MACHINE) {
var viewable = MACHINE.e[MACHINE.e.length - 1];
var oldArgcount = MACHINE.a;
PAUSE(function(restart) {
coerseToMockView(viewable,
function(v) {
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall(MACHINE, v);
});
},
@ -1897,13 +1891,11 @@
2,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-append-child', 0);
var oldArgcount = MACHINE.a;
var x = MACHINE.e[MACHINE.e.length - 2];
PAUSE(function(restart) {
coerseToDomNode(x,
function(dom) {
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
var updatedView = view.appendChild(dom);
finalizeClosureCall(MACHINE, updatedView);
});
@ -1927,13 +1919,11 @@
2,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-insert-right', 0);
var oldArgcount = MACHINE.a;
var x = MACHINE.e[MACHINE.e.length - 2];
PAUSE(function(restart) {
coerseToDomNode(x,
function(dom) {
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
var updatedView = view.insertRight(dom);
finalizeClosureCall(MACHINE, updatedView);
});
@ -1959,13 +1949,11 @@
2,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-insert-left', 0);
var oldArgcount = MACHINE.a;
var x = MACHINE.e[MACHINE.e.length - 2];
PAUSE(function(restart) {
coerseToDomNode(x,
function(dom) {
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
var updatedView = view.insertLeft(dom);
finalizeClosureCall(MACHINE, updatedView);
});

View File

@ -24,9 +24,6 @@ var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;
//////////////////////////////////////////////////////////////////////
var bigBang = function(MACHINE, initW, handlers) {
var oldArgcount = MACHINE.a;
var outerToplevelNode = $('<span/>').css('padding', '0px').get(0);
MACHINE.params.currentOutputPort.writeDomNode(MACHINE, outerToplevelNode);
var toplevelNode = $('<span/>').css('padding', '0px').appendTo(outerToplevelNode).get(0);
@ -65,9 +62,7 @@ var bigBang = function(MACHINE, initW, handlers) {
function(finalWorldValue) {
// state.removeBreakRequestedListener(onBreak);
restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall(
MACHINE,
finalWorldValue);