Browse Source

Scrub catch register on TRYCATCH init (GH-287)

Scrubbing runs possible finalizers for the previous catch register values
(which are temporaries) early to ensure that potential finalization does
not happen during error handling.  Finalizer side effects are not an issue
for actual error handling related values even if an error value has a
finalizer: such values never become unreachable during error handling.
add-comment-stripped-dist-source
Sami Vaarala 9 years ago
parent
commit
b5ab3755e2
  1. 15
      src/duk_js_executor.c

15
src/duk_js_executor.c

@ -3585,6 +3585,21 @@ DUK_INTERNAL void duk_js_execute_bytecode(duk_hthread *exec_thr) {
;
}
/* Registers 'bc' and 'bc + 1' are written in longjmp handling
* and if their previous values (which are temporaries) become
* unreachable -and- have a finalizer, there'll be a function
* call during error handling which is not supported now (GH-287).
* Ensure that both 'bc' and 'bc + 1' have primitive values to
* guarantee no finalizer calls in error handling. Scrubbing also
* ensures finalizers for the previous values run here rather than
* later. Error handling related values are also written to 'bc'
* and 'bc + 1' but those values never become unreachable during
* error handling, so there's no side effect problem even if the
* error value has a finalizer.
*/
duk_to_undefined(ctx, bc);
duk_to_undefined(ctx, bc + 1);
cat = thr->catchstack + thr->catchstack_top - 1; /* relookup (side effects) */
cat->callstack_index = thr->callstack_top - 1;
cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */

Loading…
Cancel
Save