return JS_ThrowTypeError(ctx, "not an object");
}
+static JSValue JS_ThrowTypeErrorNotAConstructor(JSContext *ctx,
+ JSValueConst func_obj)
+{
+ const char *name;
+ if (!JS_IsFunction(ctx, func_obj))
+ goto fail;
+ name = get_prop_string(ctx, func_obj, JS_ATOM_name);
+ if (!name) {
+ fail:
+ return JS_ThrowTypeError(ctx, "not a constructor");
+ }
+ JS_ThrowTypeError(ctx, "%s is not a constructor", name);
+ JS_FreeCString(ctx, name);
+ return JS_EXCEPTION;
+}
+
static JSValue JS_ThrowTypeErrorNotASymbol(JSContext *ctx)
{
return JS_ThrowTypeError(ctx, "not a symbol");
goto not_a_function;
p = JS_VALUE_GET_OBJ(func_obj);
if (unlikely(!p->is_constructor))
- return JS_ThrowTypeError(ctx, "not a constructor");
+ return JS_ThrowTypeErrorNotAConstructor(ctx, func_obj);
if (unlikely(p->class_id != JS_CLASS_BYTECODE_FUNCTION)) {
JSClassCall *call_func;
call_func = ctx->rt->class_array[p->class_id].call;
if (JS_IsUndefined(species) || JS_IsNull(species))
return JS_DupValue(ctx, defaultConstructor);
if (!JS_IsConstructor(ctx, species)) {
+ JS_ThrowTypeErrorNotAConstructor(ctx, species);
JS_FreeValue(ctx, species);
- return JS_ThrowTypeError(ctx, "not a constructor");
+ return JS_EXCEPTION;
}
return species;
}
if (argc > 2) {
new_target = argv[2];
if (!JS_IsConstructor(ctx, new_target))
- return JS_ThrowTypeError(ctx, "not a constructor");
+ return JS_ThrowTypeErrorNotAConstructor(ctx, new_target);
} else {
new_target = func;
}
if (!s)
return JS_EXCEPTION;
if (!JS_IsConstructor(ctx, s->target))
- return JS_ThrowTypeError(ctx, "not a constructor");
+ return JS_ThrowTypeErrorNotAConstructor(ctx, s->target);
if (JS_IsUndefined(method))
return JS_CallConstructor2(ctx, s->target, new_target, argc, argv);
arg_array = js_create_array(ctx, argc, argv);
JSString *p;
if (!JS_IsUndefined(new_target))
- return JS_ThrowTypeError(ctx, "not a constructor");
+ return JS_ThrowTypeErrorNotAConstructor(ctx, new_target);
if (argc == 0 || JS_IsUndefined(argv[0])) {
p = NULL;
} else {
int argc, JSValueConst *argv)
{
if (!JS_IsUndefined(new_target))
- return JS_ThrowTypeError(ctx, "not a constructor");
+ return JS_ThrowTypeErrorNotAConstructor(ctx, new_target);
return JS_ToBigIntCtorFree(ctx, JS_DupValue(ctx, argv[0]));
}