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.
 
 
 
 
 
 

42 lines
1.2 KiB

name: duk_set_finalizer
proto: |
void duk_set_finalizer(duk_context *ctx, duk_idx_t idx);
stack: |
[ ... val! ... finalizer! ] -> [ ... val! ... ]
summary: |
<p>Set the finalizer of the value at <code>idx</code> to the value at
stack top. If the target value is not an object an error is thrown. The
finalizer value can be an arbitrary one; non-function values are treated
as if no finalizer was set. To delete a finalizer from an object, set it
to <code>undefined</code>.</p>
<div class="note">
Finalizer on a Proxy object is currently unsupported.
At present the finalizer is stored as a hidden Symbol; a finalizer cannot
be set if the object is non-extensible (sealed or frozen), so set the
finalizer before sealing/freezing the object.
</div>
example: |
duk_ret_t my_finalizer(duk_context *ctx) {
/* Object being finalized is at stack index 0. */
printf("object being finalized\n");
return 0;
}
/* Create an object whose finalizer is my_finalizer(). */
duk_push_object(ctx);
duk_push_c_function(ctx, my_finalizer, 1 /*nargs*/);
duk_set_finalizer(ctx, -2);
tags:
- object
- finalizer
seealso:
- duk_get_finalizer
introduced: 1.0.0