@@ -3197,7 +3197,6 @@ JSValue JS_NewSymbol(JSContext *ctx, const char *description, bool is_global)
3197
3197
3198
3198
#define ATOM_GET_STR_BUF_SIZE 64
3199
3199
3200
- /* Should only be used for debug. */
3201
3200
static const char *JS_AtomGetStrRT(JSRuntime *rt, char *buf, int buf_size,
3202
3201
JSAtom atom)
3203
3202
{
@@ -3220,13 +3219,6 @@ static const char *JS_AtomGetStrRT(JSRuntime *rt, char *buf, int buf_size,
3220
3219
/* encode surrogates correctly */
3221
3220
utf8_encode_buf16(buf, buf_size, str->u.str16, str->len);
3222
3221
} else {
3223
- /* special case ASCII strings */
3224
- int i, c = 0;
3225
- for(i = 0; i < str->len; i++) {
3226
- c |= str->u.str8[i];
3227
- }
3228
- if (c < 0x80)
3229
- return (const char *)str->u.str8;
3230
3222
utf8_encode_buf8(buf, buf_size, str->u.str8, str->len);
3231
3223
}
3232
3224
}
@@ -6856,8 +6848,9 @@ static JSValue JS_MakeError(JSContext *ctx, JSErrorEnum error_num,
6856
6848
}
6857
6849
6858
6850
/* fmt and arguments may be pure ASCII or UTF-8 encoded contents */
6859
- static JSValue JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,
6860
- const char *fmt, va_list ap, bool add_backtrace)
6851
+ static JSValue JS_PRINTF_FORMAT_ATTR(4, 0)
6852
+ JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,
6853
+ bool add_backtrace, JS_PRINTF_FORMAT const char *fmt, va_list ap)
6861
6854
{
6862
6855
char buf[256];
6863
6856
JSValue obj;
@@ -6871,8 +6864,9 @@ static JSValue JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,
6871
6864
return JS_Throw(ctx, obj);
6872
6865
}
6873
6866
6874
- static JSValue JS_ThrowError(JSContext *ctx, JSErrorEnum error_num,
6875
- const char *fmt, va_list ap)
6867
+ static JSValue JS_PRINTF_FORMAT_ATTR(3, 0)
6868
+ JS_ThrowError(JSContext *ctx, JSErrorEnum error_num,
6869
+ JS_PRINTF_FORMAT const char *fmt, va_list ap)
6876
6870
{
6877
6871
JSRuntime *rt = ctx->rt;
6878
6872
JSStackFrame *sf;
@@ -6882,7 +6876,7 @@ static JSValue JS_ThrowError(JSContext *ctx, JSErrorEnum error_num,
6882
6876
sf = rt->current_stack_frame;
6883
6877
add_backtrace = !rt->in_out_of_memory &&
6884
6878
(!sf || (JS_GetFunctionBytecode(sf->cur_func) == NULL));
6885
- return JS_ThrowError2(ctx, error_num, fmt, ap, add_backtrace );
6879
+ return JS_ThrowError2(ctx, error_num, add_backtrace, fmt, ap );
6886
6880
}
6887
6881
6888
6882
JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowPlainError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
@@ -6933,26 +6927,22 @@ static int JS_PRINTF_FORMAT_ATTR(3, 4) JS_ThrowTypeErrorOrFalse(JSContext *ctx,
6933
6927
}
6934
6928
}
6935
6929
6936
- /* never use it directly */
6937
- static JSValue JS_PRINTF_FORMAT_ATTR(3, 4) __JS_ThrowTypeErrorAtom(JSContext *ctx, JSAtom atom, JS_PRINTF_FORMAT const char *fmt, ...)
6930
+ #pragma GCC diagnostic push
6931
+ #pragma GCC diagnostic ignored "-Wformat-nonliteral"
6932
+ static JSValue JS_ThrowTypeErrorAtom(JSContext *ctx, const char *fmt, JSAtom atom)
6938
6933
{
6939
6934
char buf[ATOM_GET_STR_BUF_SIZE];
6940
- return JS_ThrowTypeError (ctx, fmt,
6941
- JS_AtomGetStr (ctx, buf, sizeof( buf), atom) );
6935
+ JS_AtomGetStr (ctx, buf, sizeof(buf), atom);
6936
+ return JS_ThrowTypeError (ctx, fmt, buf);
6942
6937
}
6943
6938
6944
- /* never use it directly */
6945
- static JSValue JS_PRINTF_FORMAT_ATTR(3, 4) __JS_ThrowSyntaxErrorAtom(JSContext *ctx, JSAtom atom, JS_PRINTF_FORMAT const char *fmt, ...)
6939
+ static JSValue JS_ThrowSyntaxErrorAtom(JSContext *ctx, const char *fmt, JSAtom atom)
6946
6940
{
6947
6941
char buf[ATOM_GET_STR_BUF_SIZE];
6948
- return JS_ThrowSyntaxError (ctx, fmt,
6949
- JS_AtomGetStr (ctx, buf, sizeof( buf), atom) );
6942
+ JS_AtomGetStr (ctx, buf, sizeof(buf), atom);
6943
+ return JS_ThrowSyntaxError (ctx, fmt, buf);
6950
6944
}
6951
-
6952
- /* %s is replaced by 'atom'. The macro is used so that gcc can check
6953
- the format string. */
6954
- #define JS_ThrowTypeErrorAtom(ctx, fmt, atom) __JS_ThrowTypeErrorAtom(ctx, atom, fmt, "")
6955
- #define JS_ThrowSyntaxErrorAtom(ctx, fmt, atom) __JS_ThrowSyntaxErrorAtom(ctx, atom, fmt, "")
6945
+ #pragma GCC diagnostic pop // ignored "-Wformat-nonliteral"
6956
6946
6957
6947
static int JS_ThrowTypeErrorReadOnly(JSContext *ctx, int flags, JSAtom atom)
6958
6948
{
@@ -19038,7 +19028,7 @@ int JS_PRINTF_FORMAT_ATTR(2, 3) js_parse_error(JSParseState *s, JS_PRINTF_FORMAT
19038
19028
int backtrace_flags;
19039
19029
19040
19030
va_start(ap, fmt);
19041
- JS_ThrowError2(ctx, JS_SYNTAX_ERROR, fmt, ap, false );
19031
+ JS_ThrowError2(ctx, JS_SYNTAX_ERROR, false, fmt, ap );
19042
19032
va_end(ap);
19043
19033
backtrace_flags = 0;
19044
19034
if (s->cur_func && s->cur_func->backtrace_barrier)
0 commit comments