Skip to content

Commit 766d967

Browse files
authored
DRY TypeError throwing code (#888)
1 parent bb14020 commit 766d967

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

quickjs.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -7129,6 +7129,11 @@ static JSValue JS_ThrowStackOverflow(JSContext *ctx)
71297129
return JS_ThrowRangeError(ctx, "Maximum call stack size exceeded");
71307130
}
71317131

7132+
static JSValue JS_ThrowTypeErrorNotAFunction(JSContext *ctx)
7133+
{
7134+
return JS_ThrowTypeError(ctx, "not a function");
7135+
}
7136+
71327137
static JSValue JS_ThrowTypeErrorNotAnObject(JSContext *ctx)
71337138
{
71347139
return JS_ThrowTypeError(ctx, "not an object");
@@ -15045,7 +15050,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
1504515050
call_func = rt->class_array[p->class_id].call;
1504615051
if (!call_func) {
1504715052
not_a_function:
15048-
return JS_ThrowTypeError(caller_ctx, "not a function");
15053+
return JS_ThrowTypeErrorNotAFunction(caller_ctx);
1504915054
}
1505015055
return call_func(caller_ctx, func_obj, this_obj, argc,
1505115056
argv, flags);
@@ -17685,7 +17690,7 @@ static JSValue JS_CallConstructorInternal(JSContext *ctx,
1768517690
call_func = ctx->rt->class_array[p->class_id].call;
1768617691
if (!call_func) {
1768717692
not_a_function:
17688-
return JS_ThrowTypeError(ctx, "not a function");
17693+
return JS_ThrowTypeErrorNotAFunction(ctx);
1768917694
}
1769017695
return call_func(ctx, func_obj, new_target, argc,
1769117696
argv, flags);
@@ -36063,7 +36068,7 @@ static int check_function(JSContext *ctx, JSValue obj)
3606336068
{
3606436069
if (likely(JS_IsFunction(ctx, obj)))
3606536070
return 0;
36066-
JS_ThrowTypeError(ctx, "not a function");
36071+
JS_ThrowTypeErrorNotAFunction(ctx);
3606736072
return -1;
3606836073
}
3606936074

@@ -40094,7 +40099,7 @@ static JSValue js_array_toSorted(JSContext *ctx, JSValue this_val,
4009440099

4009540100
ok = JS_IsUndefined(argv[0]) || JS_IsFunction(ctx, argv[0]);
4009640101
if (!ok)
40097-
return JS_ThrowTypeError(ctx, "not a function");
40102+
return JS_ThrowTypeErrorNotAFunction(ctx);
4009840103

4009940104
ret = JS_EXCEPTION;
4010040105
arr = JS_UNDEFINED;
@@ -46844,7 +46849,7 @@ static JSValue js_proxy_call(JSContext *ctx, JSValue func_obj,
4684446849
return JS_EXCEPTION;
4684546850
if (!s->is_func) {
4684646851
JS_FreeValue(ctx, method);
46847-
return JS_ThrowTypeError(ctx, "not a function");
46852+
return JS_ThrowTypeErrorNotAFunction(ctx);
4684846853
}
4684946854
if (JS_IsUndefined(method))
4685046855
return JS_Call(ctx, s->target, this_obj, argc, argv);

0 commit comments

Comments
 (0)