Skip to content

Commit

Permalink
Curr_pc related bug testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
svaarala committed Aug 28, 2015
1 parent a2d487f commit 8625fd5
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/ecmascript/test-bug-currpc-blit-gh294.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Some problem code used in investigating GH-294.
*/

/*===
blitMask 11 52 123
done
===*/

function Image() {
}
Image.prototype.blitMask = function (x, y, color) {
print('blitMask', x, y, color);
};
var myImage = new Image();

function CreateColor() { return 123; }

this.spriteset = {
directions: [ { frames: [ { index: 0 } ] } ],
images: [ myImage ],
};
this.directionID = 0;
this.frameID = 0;
this.xOff = 10;
this.yOff = 50;

this.blit = function(x, y, alpha) {
alpha = alpha !== void null ? alpha : 255;

this.spriteset.images[this.spriteset.directions[this.directionID].frames[this.frameID].index]
.blitMask(x + this.xOff, y + this.yOff, CreateColor(255, 255, 255, alpha));
//print("*munch*");
};

this.blit(1,2,3);
print('done');
46 changes: 46 additions & 0 deletions tests/ecmascript/test-bug-currpc-unwind-gh294.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Unwind and thr->ptr_curr_pc related bug when developing GH-294.
*/

/*===
returning
obj finalized
returning
obj finalized
done
===*/

function finalizer() {
print('obj finalized');
}

function func() {
var obj = {};
Duktape.fin(obj, finalizer);

print('returning');
}

function test() {
/*
* During development of GH-294 there was a bug in thr->ptr_curr_pc
* handling: thr->ptr_curr_pc was not NULLed before a longjmp (it was
* synced though) with the assumption that the unwind path would never
* touch it and it would therefore be harmless.
*
* However, if an unwind side effect (such as a finalizer call) causes
* a function call, the call handling will use thr->ptr_curr_pc to sync
* the current PC, but the topmost activation has changed. This leads
* to the incorrect activation's curr_pc being updated.
*/

func();
func();
}

try {
test();
print('done');
} catch (e) {
print(e.stack || e);
}

0 comments on commit 8625fd5

Please sign in to comment.