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.
49 lines
1.0 KiB
49 lines
1.0 KiB
12 years ago
|
|
||
|
/*---
|
||
|
{
|
||
|
"custom": true
|
||
|
}
|
||
|
---*/
|
||
|
|
||
12 years ago
|
/*===
|
||
|
object
|
||
|
Finalizer
|
||
|
object
|
||
|
Finalizer's finalizer
|
||
|
undefined
|
||
|
===*/
|
||
|
|
||
|
/* Finalizer of a finalizer */
|
||
|
|
||
|
var func1 = function(x) { print("Finalizer's finalizer"); };
|
||
|
var func2 = function(x) { print("Finalizer"); obj = x; /*rescue*/ };
|
||
|
var obj = {};
|
||
|
|
||
|
__duk__.setFinalizer(obj, func2);
|
||
|
__duk__.setFinalizer(func2, func1);
|
||
|
func1 = null;
|
||
|
func2 = null;
|
||
|
|
||
|
print(typeof obj);
|
||
|
obj = null; // func2 will rescue
|
||
|
print(typeof obj);
|
||
|
|
||
|
// Refcount of func2 should drop to zero, which should cause func'2
|
||
|
// finalizer, func1, to be executed. Once func2 is freed, func1's
|
||
|
// refcount should also drop to zero, and func1 should be freed
|
||
|
// (without a finalizer call).
|
||
|
//
|
||
|
// However, this does not happen right now because every function
|
||
|
// closure is by default participates in a reference loop through
|
||
|
// its automatic prototype (e.g. f.prototype.constructor === f).
|
||
|
|
||
|
__duk__.setFinalizer(obj, null);
|
||
|
|
||
|
// Explicit GC causes the finalizer's finalizer to run.
|
||
|
|
||
|
__duk__.gc();
|
||
|
|
||
|
obj = undefined;
|
||
|
print(typeof obj);
|
||
|
|