forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduk_error_misc.c
More file actions
54 lines (45 loc) · 1.45 KB
/
Copy pathduk_error_misc.c
File metadata and controls
54 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Error helpers
*/
#include "duk_internal.h"
/*
* Get prototype object for an integer error code.
*/
DUK_INTERNAL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t code) {
switch (code) {
case DUK_ERR_EVAL_ERROR:
return thr->builtins[DUK_BIDX_EVAL_ERROR_PROTOTYPE];
case DUK_ERR_RANGE_ERROR:
return thr->builtins[DUK_BIDX_RANGE_ERROR_PROTOTYPE];
case DUK_ERR_REFERENCE_ERROR:
return thr->builtins[DUK_BIDX_REFERENCE_ERROR_PROTOTYPE];
case DUK_ERR_SYNTAX_ERROR:
return thr->builtins[DUK_BIDX_SYNTAX_ERROR_PROTOTYPE];
case DUK_ERR_TYPE_ERROR:
return thr->builtins[DUK_BIDX_TYPE_ERROR_PROTOTYPE];
case DUK_ERR_URI_ERROR:
return thr->builtins[DUK_BIDX_URI_ERROR_PROTOTYPE];
/* XXX: more specific error classes? */
case DUK_ERR_UNIMPLEMENTED_ERROR:
case DUK_ERR_INTERNAL_ERROR:
case DUK_ERR_ALLOC_ERROR:
case DUK_ERR_ASSERTION_ERROR:
case DUK_ERR_API_ERROR:
case DUK_ERR_ERROR:
default:
return thr->builtins[DUK_BIDX_ERROR_PROTOTYPE];
}
}
/*
* Exposed helper for setting up heap longjmp state.
*/
DUK_INTERNAL void duk_err_setup_heap_ljstate(duk_hthread *thr, duk_small_int_t lj_type) {
duk_tval tv_tmp;
thr->heap->lj.type = lj_type;
DUK_ASSERT(thr->valstack_top > thr->valstack);
DUK_TVAL_SET_TVAL(&tv_tmp, &thr->heap->lj.value1);
DUK_TVAL_SET_TVAL(&thr->heap->lj.value1, thr->valstack_top - 1);
DUK_TVAL_INCREF(thr, &thr->heap->lj.value1);
DUK_TVAL_DECREF(thr, &tv_tmp);
duk_pop((duk_context *) thr);
}