| 739 | } |
| 740 | |
| 741 | static void new_errors(void) |
| 742 | { |
| 743 | typedef struct { |
| 744 | const char name[16]; |
| 745 | JSValue (*func)(JSContext *, const char *, ...); |
| 746 | } Entry; |
| 747 | static const Entry entries[] = { |
| 748 | {"Error", JS_NewPlainError}, |
| 749 | {"InternalError", JS_NewInternalError}, |
| 750 | {"RangeError", JS_NewRangeError}, |
| 751 | {"ReferenceError", JS_NewReferenceError}, |
| 752 | {"SyntaxError", JS_NewSyntaxError}, |
| 753 | {"TypeError", JS_NewTypeError}, |
| 754 | }; |
| 755 | const Entry *e; |
| 756 | |
| 757 | JSRuntime *rt = new_runtime(); |
| 758 | JSContext *ctx = JS_NewContext(rt); |
| 759 | for (e = entries; e < endof(entries); e++) { |
| 760 | JSValue obj = (*e->func)(ctx, "the %s", "needle"); |
| 761 | assert(!JS_IsException(obj)); |
| 762 | assert(JS_IsObject(obj)); |
| 763 | assert(JS_IsError(obj)); |
| 764 | const char *haystack = JS_ToCString(ctx, obj); |
| 765 | char needle[256]; |
| 766 | snprintf(needle, sizeof(needle), "%s: the needle", e->name); |
| 767 | assert(strstr(haystack, needle)); |
| 768 | JS_FreeCString(ctx, haystack); |
| 769 | JSValue stack = JS_GetPropertyStr(ctx, obj, "stack"); |
| 770 | assert(!JS_IsException(stack)); |
| 771 | assert(JS_IsString(stack)); |
| 772 | JS_FreeValue(ctx, stack); |
| 773 | JS_FreeValue(ctx, obj); |
| 774 | } |
| 775 | JS_FreeContext(ctx); |
| 776 | JS_FreeRuntime(rt); |
| 777 | } |
| 778 | |
| 779 | static void backtrace_oom_current_exception(void) |
| 780 | { |
no test coverage detected