Skip to content

DRY TypeError throwing code #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7129,6 +7129,11 @@ static JSValue JS_ThrowStackOverflow(JSContext *ctx)
return JS_ThrowRangeError(ctx, "Maximum call stack size exceeded");
}

static JSValue JS_ThrowTypeErrorNotAFunction(JSContext *ctx)
{
return JS_ThrowTypeError(ctx, "not a function");
}

static JSValue JS_ThrowTypeErrorNotAnObject(JSContext *ctx)
{
return JS_ThrowTypeError(ctx, "not an object");
Expand Down Expand Up @@ -15045,7 +15050,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
call_func = rt->class_array[p->class_id].call;
if (!call_func) {
not_a_function:
return JS_ThrowTypeError(caller_ctx, "not a function");
return JS_ThrowTypeErrorNotAFunction(caller_ctx);
}
return call_func(caller_ctx, func_obj, this_obj, argc,
argv, flags);
Expand Down Expand Up @@ -17685,7 +17690,7 @@ static JSValue JS_CallConstructorInternal(JSContext *ctx,
call_func = ctx->rt->class_array[p->class_id].call;
if (!call_func) {
not_a_function:
return JS_ThrowTypeError(ctx, "not a function");
return JS_ThrowTypeErrorNotAFunction(ctx);
}
return call_func(ctx, func_obj, new_target, argc,
argv, flags);
Expand Down Expand Up @@ -36063,7 +36068,7 @@ static int check_function(JSContext *ctx, JSValue obj)
{
if (likely(JS_IsFunction(ctx, obj)))
return 0;
JS_ThrowTypeError(ctx, "not a function");
JS_ThrowTypeErrorNotAFunction(ctx);
return -1;
}

Expand Down Expand Up @@ -40094,7 +40099,7 @@ static JSValue js_array_toSorted(JSContext *ctx, JSValue this_val,

ok = JS_IsUndefined(argv[0]) || JS_IsFunction(ctx, argv[0]);
if (!ok)
return JS_ThrowTypeError(ctx, "not a function");
return JS_ThrowTypeErrorNotAFunction(ctx);

ret = JS_EXCEPTION;
arr = JS_UNDEFINED;
Expand Down Expand Up @@ -46844,7 +46849,7 @@ static JSValue js_proxy_call(JSContext *ctx, JSValue func_obj,
return JS_EXCEPTION;
if (!s->is_func) {
JS_FreeValue(ctx, method);
return JS_ThrowTypeError(ctx, "not a function");
return JS_ThrowTypeErrorNotAFunction(ctx);
}
if (JS_IsUndefined(method))
return JS_Call(ctx, s->target, this_obj, argc, argv);
Expand Down