PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/lib_duktape/src-separate/duk_error_misc.c

https://bitbucket.org/xixs/lua
C | 54 lines | 35 code | 9 blank | 10 comment | 1 complexity | 8313d482bd71c3526b3a1cb2c1f5446b MD5 | raw file
Possible License(s): Zlib, BSD-3-Clause, CC0-1.0, GPL-3.0, GPL-2.0, CPL-1.0, MPL-2.0-no-copyleft-exception, LGPL-2.0, LGPL-2.1, LGPL-3.0, 0BSD, Cube
  1. /*
  2. * Error helpers
  3. */
  4. #include "duk_internal.h"
  5. /*
  6. * Get prototype object for an integer error code.
  7. */
  8. DUK_INTERNAL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t code) {
  9. switch (code) {
  10. case DUK_ERR_EVAL_ERROR:
  11. return thr->builtins[DUK_BIDX_EVAL_ERROR_PROTOTYPE];
  12. case DUK_ERR_RANGE_ERROR:
  13. return thr->builtins[DUK_BIDX_RANGE_ERROR_PROTOTYPE];
  14. case DUK_ERR_REFERENCE_ERROR:
  15. return thr->builtins[DUK_BIDX_REFERENCE_ERROR_PROTOTYPE];
  16. case DUK_ERR_SYNTAX_ERROR:
  17. return thr->builtins[DUK_BIDX_SYNTAX_ERROR_PROTOTYPE];
  18. case DUK_ERR_TYPE_ERROR:
  19. return thr->builtins[DUK_BIDX_TYPE_ERROR_PROTOTYPE];
  20. case DUK_ERR_URI_ERROR:
  21. return thr->builtins[DUK_BIDX_URI_ERROR_PROTOTYPE];
  22. /* XXX: more specific error classes? */
  23. case DUK_ERR_UNIMPLEMENTED_ERROR:
  24. case DUK_ERR_INTERNAL_ERROR:
  25. case DUK_ERR_ALLOC_ERROR:
  26. case DUK_ERR_ASSERTION_ERROR:
  27. case DUK_ERR_API_ERROR:
  28. case DUK_ERR_ERROR:
  29. default:
  30. return thr->builtins[DUK_BIDX_ERROR_PROTOTYPE];
  31. }
  32. }
  33. /*
  34. * Exposed helper for setting up heap longjmp state.
  35. */
  36. DUK_INTERNAL void duk_err_setup_heap_ljstate(duk_hthread *thr, duk_small_int_t lj_type) {
  37. duk_tval tv_tmp;
  38. thr->heap->lj.type = lj_type;
  39. DUK_ASSERT(thr->valstack_top > thr->valstack);
  40. DUK_TVAL_SET_TVAL(&tv_tmp, &thr->heap->lj.value1);
  41. DUK_TVAL_SET_TVAL(&thr->heap->lj.value1, thr->valstack_top - 1);
  42. DUK_TVAL_INCREF(thr, &thr->heap->lj.value1);
  43. DUK_TVAL_DECREF(thr, &tv_tmp);
  44. duk_pop((duk_context *) thr);
  45. }