@@ -1513,6 +1513,10 @@ static inline int is_digit(int c) {
1513
1513
return c >= '0' && c <= '9';
1514
1514
}
1515
1515
1516
+ static inline int string_get(const JSString *p, int idx) {
1517
+ return p->is_wide_char ? p->u.str16[idx] : p->u.str8[idx];
1518
+ }
1519
+
1516
1520
static inline BOOL is_be(void)
1517
1521
{
1518
1522
union {
@@ -2404,10 +2408,7 @@ static inline BOOL is_num_string(uint32_t *pval, const JSString *p)
2404
2408
len = p->len;
2405
2409
if (len == 0 || len > 10)
2406
2410
return FALSE;
2407
- if (p->is_wide_char)
2408
- c = p->u.str16[0];
2409
- else
2410
- c = p->u.str8[0];
2411
+ c = string_get(p, 0);
2411
2412
if (is_num(c)) {
2412
2413
if (c == '0') {
2413
2414
if (len != 1)
@@ -2416,10 +2417,7 @@ static inline BOOL is_num_string(uint32_t *pval, const JSString *p)
2416
2417
} else {
2417
2418
n = c - '0';
2418
2419
for(i = 1; i < len; i++) {
2419
- if (p->is_wide_char)
2420
- c = p->u.str16[i];
2421
- else
2422
- c = p->u.str8[i];
2420
+ c = string_get(p, i);
2423
2421
if (!is_num(c))
2424
2422
return FALSE;
2425
2423
n64 = (uint64_t)n * 10 + (c - '0');
@@ -2477,10 +2475,7 @@ static __maybe_unused void JS_DumpString(JSRuntime *rt,
2477
2475
sep = (p->header.ref_count == 1) ? '\"' : '\'';
2478
2476
putchar(sep);
2479
2477
for(i = 0; i < p->len; i++) {
2480
- if (p->is_wide_char)
2481
- c = p->u.str16[i];
2482
- else
2483
- c = p->u.str8[i];
2478
+ c = string_get(p, i);
2484
2479
if (c == sep || c == '\\') {
2485
2480
putchar('\\');
2486
2481
putchar(c);
@@ -3042,10 +3037,7 @@ static const char *JS_AtomGetStrRT(JSRuntime *rt, char *buf, int buf_size,
3042
3037
return (const char *)str->u.str8;
3043
3038
}
3044
3039
for(i = 0; i < str->len; i++) {
3045
- if (str->is_wide_char)
3046
- c = str->u.str16[i];
3047
- else
3048
- c = str->u.str8[i];
3040
+ c = string_get(str, i);
3049
3041
if ((q - buf) >= buf_size - UTF8_CHAR_LEN_MAX)
3050
3042
break;
3051
3043
if (c < 128) {
@@ -3671,10 +3663,6 @@ static int string_buffer_putc(StringBuffer *s, uint32_t c)
3671
3663
return string_buffer_putc16(s, c);
3672
3664
}
3673
3665
3674
- static int string_get(const JSString *p, int idx) {
3675
- return p->is_wide_char ? p->u.str16[idx] : p->u.str8[idx];
3676
- }
3677
-
3678
3666
static int string_getc(const JSString *p, int *pidx)
3679
3667
{
3680
3668
int idx, c, c1;
@@ -7142,10 +7130,7 @@ static JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValue obj,
7142
7130
uint32_t idx, ch;
7143
7131
idx = __JS_AtomToUInt32(prop);
7144
7132
if (idx < p1->len) {
7145
- if (p1->is_wide_char)
7146
- ch = p1->u.str16[idx];
7147
- else
7148
- ch = p1->u.str8[idx];
7133
+ ch = string_get(p1, idx);
7149
7134
return js_new_string_char(ctx, ch);
7150
7135
}
7151
7136
} else if (prop == JS_ATOM_length) {
@@ -39106,10 +39091,7 @@ static int js_string_get_own_property(JSContext *ctx,
39106
39091
idx = __JS_AtomToUInt32(prop);
39107
39092
if (idx < p1->len) {
39108
39093
if (desc) {
39109
- if (p1->is_wide_char)
39110
- ch = p1->u.str16[idx];
39111
- else
39112
- ch = p1->u.str8[idx];
39094
+ ch = string_get(p1, idx);
39113
39095
desc->flags = JS_PROP_ENUMERABLE;
39114
39096
desc->value = js_new_string_char(ctx, ch);
39115
39097
desc->getter = JS_UNDEFINED;
@@ -39264,7 +39246,7 @@ static JSValue js_string_fromCodePoint(JSContext *ctx, JSValue this_val,
39264
39246
} else {
39265
39247
if (JS_ToFloat64(ctx, &d, argv[i]))
39266
39248
goto fail;
39267
- if (d < 0 || d > 0x10ffff || (c = (int)d) != d)
39249
+ if (!(d >= 0 && d <= 0x10ffff) || (c = (int)d) != d)
39268
39250
goto range_error;
39269
39251
}
39270
39252
if (string_buffer_putc(b, c))
@@ -39366,10 +39348,7 @@ static JSValue js_string_at(JSContext *ctx, JSValue this_val,
39366
39348
if (idx < 0 || idx >= p->len) {
39367
39349
ret = JS_UNDEFINED;
39368
39350
} else {
39369
- if (p->is_wide_char)
39370
- c = p->u.str16[idx];
39371
- else
39372
- c = p->u.str8[idx];
39351
+ c = string_get(p, idx);
39373
39352
ret = js_new_string_char(ctx, c);
39374
39353
}
39375
39354
JS_FreeValue(ctx, val);
@@ -39394,10 +39373,7 @@ static JSValue js_string_charCodeAt(JSContext *ctx, JSValue this_val,
39394
39373
if (idx < 0 || idx >= p->len) {
39395
39374
ret = JS_NAN;
39396
39375
} else {
39397
- if (p->is_wide_char)
39398
- c = p->u.str16[idx];
39399
- else
39400
- c = p->u.str8[idx];
39376
+ c = string_get(p, idx);
39401
39377
ret = js_int32(c);
39402
39378
}
39403
39379
JS_FreeValue(ctx, val);
@@ -39422,10 +39398,7 @@ static JSValue js_string_charAt(JSContext *ctx, JSValue this_val,
39422
39398
if (idx < 0 || idx >= p->len) {
39423
39399
ret = js_new_string8(ctx, NULL, 0);
39424
39400
} else {
39425
- if (p->is_wide_char)
39426
- c = p->u.str16[idx];
39427
- else
39428
- c = p->u.str8[idx];
39401
+ c = string_get(p, idx);
39429
39402
ret = js_new_string_char(ctx, c);
39430
39403
}
39431
39404
JS_FreeValue(ctx, val);
0 commit comments