forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-trycatch-scrub-gh287'
Scrub TRYCATCH catch registers on TRYCATCH setup to avoid a previous temporary value with a finalizer triggering harmful side effects. The concrete problem is that such a finalizer call would overwrite the heap->lj.type value which then causes finally handling to fail, see svaaralaGH-287.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Bug in Duktape 1.2 and before where finalization just before | ||
* 'finally' caused an internal error (GH-287). | ||
*/ | ||
|
||
/*=== | ||
The pig ate all the food, and then... | ||
*munch* | ||
Error: A pig ate everyone at 8:12 | ||
done | ||
===*/ | ||
|
||
function test() { | ||
function Food() { | ||
this.getEaten = function() { print("The pig ate all the food, and then..."); }; | ||
} | ||
Duktape.fin(Food.prototype, function() {}); | ||
new Food().getEaten(); | ||
|
||
// The above line is critical to triggering the bug: on entry to TRYCATCH | ||
// the first catch register must contain a value which (1) has only one | ||
// reference left, and (2) has a finalizer. When the error value is written | ||
// to the catch register when setting up for the finally block, the value | ||
// becomes unreachable and the finalizer is executed. | ||
|
||
try { throw new Error("A pig ate everyone at 8:12"); } | ||
finally { print("*munch*"); } | ||
} | ||
|
||
try { | ||
test(); | ||
} catch (e) { | ||
print(e); | ||
} | ||
print('done'); |