mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
719 B
48 lines
719 B
12 years ago
|
/*
|
||
|
* Test Duktape specific reference counter initiated finalizer calling.
|
||
|
* In particular, test that "rescuing" and re-finalizing an object
|
||
|
* multiple times works correctly.
|
||
|
*/
|
||
|
|
||
12 years ago
|
/*---
|
||
|
{
|
||
|
"custom": true
|
||
|
}
|
||
|
---*/
|
||
|
|
||
12 years ago
|
/*===
|
||
|
rescued
|
||
|
object
|
||
|
rescued
|
||
|
object
|
||
|
not rescued
|
||
|
undefined
|
||
|
===*/
|
||
|
|
||
|
var o = { foo: "bar" };
|
||
|
var rescue;
|
||
|
|
||
|
function finalizer(x) {
|
||
|
if (rescue) {
|
||
|
o = x;
|
||
|
print("rescued");
|
||
|
} else {
|
||
|
print("not rescued");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
__duk__.setFinalizer(o, finalizer);
|
||
|
|
||
|
rescue = true;
|
||
|
o = undefined; // refzero, finalize, gets rescued
|
||
|
print(typeof o);
|
||
|
|
||
|
rescue = true;
|
||
|
o = undefined; // refzero, finalize, gets rescued
|
||
|
print(typeof o);
|
||
|
|
||
|
rescue = false;
|
||
|
o = undefined; // refzero, finalize, not rescue
|
||
|
print(typeof o);
|
||
|
|