Browse Source

add a DUK_USE_ERRHANDLER define

pull/2/head
Sami Vaarala 11 years ago
parent
commit
af5890af3d
  1. 3
      src/duk_api.c
  2. 4
      src/duk_bi_thread.c
  3. 4
      src/duk_error.h
  4. 4
      src/duk_error_throw.c
  5. 1
      src/duk_features.h
  6. 2
      src/duk_js_executor.c

3
src/duk_api.c

@ -3227,9 +3227,10 @@ void duk_throw(duk_context *ctx) {
*/
DUK_DDDPRINT("THROW ERROR (API): %!dT (before errhandler)", duk_get_tval(ctx, -1));
#if defined(DUK_USE_ERRHANDLER)
duk_err_call_errhandler(thr);
DUK_DDDPRINT("THROW ERROR (API): %!dT (after errhandler)", duk_get_tval(ctx, -1));
#endif
duk_err_setup_heap_ljstate(thr, DUK_LJ_TYPE_THROW);

4
src/duk_bi_thread.c

@ -135,10 +135,12 @@ duk_ret_t duk_bi_thread_resume(duk_context *ctx) {
* from the resumee but this is not the case now.
*/
#if defined(DUK_USE_ERRHANDLER)
if (is_error) {
DUK_ASSERT_TOP(ctx, 2); /* value (error) is at stack top */
duk_err_call_errhandler(thr); /* in resumer's context */
}
#endif
#ifdef DUK_USE_DEBUG /* debug logging */
if (is_error) {
@ -257,10 +259,12 @@ duk_ret_t duk_bi_thread_yield(duk_context *ctx) {
* and runs in the yielder's thread.
*/
#if defined(DUK_USE_ERRHANDLER)
if (is_error) {
DUK_ASSERT_TOP(ctx, 1); /* value (error) is at stack top */
duk_err_call_errhandler(thr); /* in yielder's context */
}
#endif
#ifdef DUK_USE_DEBUG
if (is_error) {

4
src/duk_error.h

@ -227,10 +227,12 @@ DUK_NORETURN(void duk_err_create_and_throw(duk_hthread *thr, duk_uint32_t code))
DUK_NORETURN(void duk_error_throw_from_negative_rc(duk_hthread *thr, int rc));
#ifdef DUK_USE_AUGMENT_ERRORS
#if defined(DUK_USE_AUGMENT_ERRORS)
void duk_err_augment_error(duk_hthread *thr, duk_hthread *thr_callstack, int err_index, const char *filename, int line, int noblame_fileline);
#endif
#if defined(DUK_USE_ERRHANDLER)
void duk_err_call_errhandler(duk_hthread *thr);
#endif
DUK_NORETURN(void duk_err_longjmp(duk_hthread *thr));

4
src/duk_error_throw.c

@ -45,6 +45,7 @@
* written after the errhandler finishes.
*/
#if defined(DUK_USE_ERRHANDLER)
void duk_err_call_errhandler(duk_hthread *thr) {
duk_context *ctx = (duk_context *) thr;
duk_tval *tv_hnd;
@ -123,6 +124,7 @@ void duk_err_call_errhandler(duk_hthread *thr) {
/* [ ... errval ] */
}
#endif /* DUK_USE_ERRHANDLER */
/*
* Create and throw an error
@ -203,8 +205,10 @@ void duk_err_create_and_throw(duk_hthread *thr, duk_uint32_t code) {
if (double_error || code == DUK_ERR_ALLOC_ERROR) {
DUK_DPRINT("alloc or double error: skip calling errhandler to avoid further trouble");
} else {
#if defined(DUK_USE_ERRHANDLER)
DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before errhandler)", duk_get_tval(ctx, -1));
duk_err_call_errhandler(thr);
#endif
}
/*

1
src/duk_features.h

@ -1516,6 +1516,7 @@ typedef FILE duk_file;
#define DUK_USE_AUGMENT_ERRORS
#define DUK_USE_TRACEBACKS
#define DUK_USE_ERRHANDLER
#define DUK_USE_VERBOSE_ERRORS
#if defined(DUK_OPT_NO_AUGMENT_ERRORS)

2
src/duk_js_executor.c

@ -3336,8 +3336,10 @@ void duk_js_execute_bytecode(duk_hthread *entry_thread) {
duk_dup(ctx, b);
DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (before errhandler)", duk_get_tval(ctx, -1));
#if defined(DUK_USE_ERRHANDLER)
duk_err_call_errhandler(thr);
DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after errhandler)", duk_get_tval(ctx, -1));
#endif
duk_err_setup_heap_ljstate(thr, DUK_LJ_TYPE_THROW);

Loading…
Cancel
Save