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.
58 lines
1.3 KiB
58 lines
1.3 KiB
/*
|
|
* A lightfunc cannot have a finalizer for two reasons:
|
|
*
|
|
* (1) Lightfuncs are primitive values and have no refcount, so they are
|
|
* not finalized like objects.
|
|
*
|
|
* (2) Even if they were finalized, they cannot store a finalizer reference.
|
|
* This could be worked around by storing a finalizer reference in
|
|
* Function.prototype and have that deal with lightfuncs.
|
|
*
|
|
* This testcase demonstrates that lightfunc finalizers don't work.
|
|
*/
|
|
|
|
/*---
|
|
{
|
|
"custom": true
|
|
}
|
|
---*/
|
|
|
|
function isLightFunc(x) {
|
|
return Duktape.info(x)[0] == 9; // tag
|
|
}
|
|
|
|
/*===
|
|
true
|
|
TypeError
|
|
===*/
|
|
|
|
function lightfuncFinalizerTest() {
|
|
var lfunc = Math.max;
|
|
|
|
// Verify built-ins are lightfuncs
|
|
print(isLightFunc(lfunc));
|
|
|
|
// Attempt to set a finalizer on the lightfunc directly fails.
|
|
try {
|
|
Duktape.fin(lfunc, function (v) { print('lfunc finalizer'); });
|
|
} catch (e) {
|
|
print(e.name);
|
|
//print(e.stack);
|
|
}
|
|
|
|
// Finalizer can be set to Function.prototype but it won't get called
|
|
// because lightfuncs are primitive values without a refcount field.
|
|
Duktape.fin(Function.prototype, function (v) {
|
|
if (isLightFunc(v)) {
|
|
print('inherited finalizer for lightfunc');
|
|
}
|
|
});
|
|
|
|
lfunc = null;
|
|
}
|
|
|
|
try {
|
|
lightfuncFinalizerTest();
|
|
} catch (e) {
|
|
print(e.stack || e);
|
|
}
|
|
|