Closed TooTallNate closed 1 month ago
I guess it was skipped because it's a 2 liner? You can JS_NewError
, assign the message and then JS_Throw
the error object. That said, the printf syntax is very convenient, I think we should have it.
JS_NewError
only takes a ctx
arg, not a message value, so you need to do the whole JS_DefinePropertyValueStr(ctx, err, "message", JS_NewString(ctx, message), JS_PROP_C_W)
dance
Yeah I realized midways writing the reply 😅 . A PR would be welcome!
In fact, static JSValue JS_ThrowError(JSContext *ctx, JSErrorEnum error_num, const char *fmt, va_list ap)
is already exists, but it is a un-exported static function inside quickjs.c.
Not quite, that function doesn't throw plain Error
objects.
There are convenience functions such as
JS_ThrowTypeError()
which create a newTypeError
using printf syntax, however there is no such function for a regularError
instance. Would it make sense to add that? Or is there some reason why it doesn't exist already?