MCPcopy Create free account
hub / github.com/buke/quickjs-go / new_errors

Function new_errors

deps/quickjs/api-test.c:741–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

739}
740
741static 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
779static void backtrace_oom_current_exception(void)
780{

Callers 1

mainFunction · 0.85

Calls 6

new_runtimeFunction · 0.85
JS_IsExceptionFunction · 0.85
JS_IsObjectFunction · 0.85
JS_ToCStringFunction · 0.85
JS_IsStringFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected