MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at type-hints-typescript 64 lines 1.9 kB view raw
1#ifndef ERRORS_H 2#define ERRORS_H 3 4#include "types.h" 5#include <stdio.h> 6#include <stdbool.h> 7 8typedef struct sv_func sv_func_t; 9 10#define ERR_FMT "\x1b[31m%.*s\x1b[0m: \x1b[1m%.*s\x1b[0m" 11#define ERR_NAME_ONLY "\x1b[31m%.*s\x1b[0m" 12 13typedef enum { 14 JS_ERR_GENERIC = 0, 15 JS_ERR_TYPE, 16 JS_ERR_SYNTAX, 17 JS_ERR_REFERENCE, 18 JS_ERR_RANGE, 19 JS_ERR_EVAL, 20 JS_ERR_URI, 21 JS_ERR_INTERNAL, 22 JS_ERR_AGGREGATE, 23} js_err_type_t; 24 25js_err_type_t get_error_type(ant_t *js); 26 27bool print_uncaught_throw(ant_t *js); 28bool print_unhandled_promise_rejection(ant_t *js, ant_value_t value); 29 30void js_clear_error_site(ant_t *js); 31void js_print_stack_trace_vm(ant_t *js, FILE *stream); 32void js_set_error_site_from_vm_top(ant_t *js); 33void js_capture_stack(ant_t *js, ant_value_t err_obj); 34bool js_mark_errorlike_no_stack(ant_t *js, ant_value_t value); 35 36void js_get_call_location( 37 ant_t *js, const char **out_filename, 38 int *out_line, int *out_col 39); 40 41void js_set_error_site_from_bc( 42 ant_t *js, sv_func_t *func, 43 int bc_offset, const char *filename 44); 45 46void js_set_error_site( 47 ant_t *js, const char *src, 48 ant_offset_t src_len, const char *filename, 49 ant_offset_t off, ant_offset_t span_len 50); 51 52__attribute__((format(printf, 4, 5))) 53ant_value_t js_create_error(ant_t *js, js_err_type_t err_type, ant_value_t props, const char *fmt, ...); 54ant_value_t js_make_error_silent(ant_t *js, js_err_type_t err_type, const char *message); 55 56ant_value_t js_capture_raw_stack(ant_t *js); 57ant_value_t js_build_callsite_array(ant_t *js); 58ant_value_t js_throw(ant_t *js, ant_value_t value); 59 60#define js_mkerr(js, ...) js_create_error(js, JS_ERR_TYPE, js_mkundef(), __VA_ARGS__) 61#define js_mkerr_typed(js, err_type, ...) js_create_error(js, err_type, js_mkundef(), __VA_ARGS__) 62#define js_mkerr_props(js, err_type, props, ...) js_create_error(js, err_type, props, __VA_ARGS__) 63 64#endif