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.
47 lines
719 B
47 lines
719 B
/*
|
|
* Test Duktape specific reference counter initiated finalizer calling.
|
|
* In particular, test that "rescuing" and re-finalizing an object
|
|
* multiple times works correctly.
|
|
*/
|
|
|
|
/*---
|
|
{
|
|
"custom": true
|
|
}
|
|
---*/
|
|
|
|
/*===
|
|
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);
|
|
|
|
|