@@ -32325,6 +32325,7 @@ static const char * const bc_tag_str[] = {
32325
32325
"TypedArray",
32326
32326
"ArrayBuffer",
32327
32327
"SharedArrayBuffer",
32328
+ "RegExp",
32328
32329
"Date",
32329
32330
"ObjectValue",
32330
32331
"ObjectReference",
@@ -32613,20 +32614,14 @@ static int JS_WriteBigInt(BCWriterState *s, JSValue obj)
32613
32614
bc_put_leb128(s, len);
32614
32615
/* always saved in byte based little endian representation */
32615
32616
for(j = 0; j < n1; j++) {
32616
- dbuf_putc(&s->dbuf , v >> (j * 8));
32617
+ bc_put_u8(s , v >> (j * 8));
32617
32618
}
32618
32619
for(; i < a->len; i++) {
32619
32620
limb_t v = a->tab[i];
32620
32621
#if LIMB_BITS == 32
32621
- #ifdef WORDS_BIGENDIAN
32622
- v = bswap32(v);
32623
- #endif
32624
- dbuf_put_u32(&s->dbuf, v);
32622
+ bc_put_u32(s, v);
32625
32623
#else
32626
- #ifdef WORDS_BIGENDIAN
32627
- v = bswap64(v);
32628
- #endif
32629
- dbuf_put_u64(&s->dbuf, v);
32624
+ bc_put_u64(s, v);
32630
32625
#endif
32631
32626
}
32632
32627
}
@@ -33218,33 +33213,45 @@ static int bc_get_u8(BCReaderState *s, uint8_t *pval)
33218
33213
33219
33214
static int bc_get_u16(BCReaderState *s, uint16_t *pval)
33220
33215
{
33216
+ uint16_t v;
33221
33217
if (unlikely(s->buf_end - s->ptr < 2)) {
33222
33218
*pval = 0; /* avoid warning */
33223
33219
return bc_read_error_end(s);
33224
33220
}
33225
- *pval = get_u16(s->ptr);
33221
+ v = get_u16(s->ptr);
33222
+ if (is_be())
33223
+ v = bswap16(v);
33224
+ *pval = v;
33226
33225
s->ptr += 2;
33227
33226
return 0;
33228
33227
}
33229
33228
33230
33229
static __maybe_unused int bc_get_u32(BCReaderState *s, uint32_t *pval)
33231
33230
{
33231
+ uint32_t v;
33232
33232
if (unlikely(s->buf_end - s->ptr < 4)) {
33233
33233
*pval = 0; /* avoid warning */
33234
33234
return bc_read_error_end(s);
33235
33235
}
33236
- *pval = get_u32(s->ptr);
33236
+ v = get_u32(s->ptr);
33237
+ if (is_be())
33238
+ v = bswap32(v);
33239
+ *pval = v;
33237
33240
s->ptr += 4;
33238
33241
return 0;
33239
33242
}
33240
33243
33241
33244
static int bc_get_u64(BCReaderState *s, uint64_t *pval)
33242
33245
{
33246
+ uint64_t v;
33243
33247
if (unlikely(s->buf_end - s->ptr < 8)) {
33244
33248
*pval = 0; /* avoid warning */
33245
33249
return bc_read_error_end(s);
33246
33250
}
33247
- *pval = get_u64(s->ptr);
33251
+ v = get_u64(s->ptr);
33252
+ if (is_be())
33253
+ v = bswap64(v);
33254
+ *pval = v;
33248
33255
s->ptr += 8;
33249
33256
return 0;
33250
33257
}
@@ -33387,6 +33394,9 @@ static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b,
33387
33394
return -1;
33388
33395
b->byte_code_buf = bc_buf;
33389
33396
33397
+ if (is_be())
33398
+ bc_byte_swap(bc_buf, bc_len);
33399
+
33390
33400
pos = 0;
33391
33401
while (pos < bc_len) {
33392
33402
op = bc_buf[pos];
@@ -33481,15 +33491,9 @@ static JSValue JS_ReadBigInt(BCReaderState *s)
33481
33491
#if LIMB_BITS == 32
33482
33492
if (bc_get_u32(s, &v))
33483
33493
goto fail;
33484
- #ifdef WORDS_BIGENDIAN
33485
- v = bswap32(v);
33486
- #endif
33487
33494
#else
33488
33495
if (bc_get_u64(s, &v))
33489
33496
goto fail;
33490
- #ifdef WORDS_BIGENDIAN
33491
- v = bswap64(v);
33492
- #endif
33493
33497
#endif
33494
33498
a->tab[i] = v;
33495
33499
}
@@ -50561,7 +50565,8 @@ static JSValue js_dataview_getValue(JSContext *ctx,
50561
50565
{
50562
50566
JSTypedArray *ta;
50563
50567
JSArrayBuffer *abuf;
50564
- int is_swap, size;
50568
+ BOOL littleEndian, is_swap;
50569
+ int size;
50565
50570
uint8_t *ptr;
50566
50571
uint32_t v;
50567
50572
uint64_t pos;
@@ -50572,12 +50577,8 @@ static JSValue js_dataview_getValue(JSContext *ctx,
50572
50577
size = 1 << typed_array_size_log2(class_id);
50573
50578
if (JS_ToIndex(ctx, &pos, argv[0]))
50574
50579
return JS_EXCEPTION;
50575
- is_swap = FALSE;
50576
- if (argc > 1)
50577
- is_swap = JS_ToBool(ctx, argv[1]);
50578
- #ifndef WORDS_BIGENDIAN
50579
- is_swap ^= 1;
50580
- #endif
50580
+ littleEndian = argc > 1 && JS_ToBool(ctx, argv[1]);
50581
+ is_swap = littleEndian ^ !is_be();
50581
50582
abuf = ta->buffer->u.array_buffer;
50582
50583
if (abuf->detached)
50583
50584
return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
@@ -50663,7 +50664,8 @@ static JSValue js_dataview_setValue(JSContext *ctx,
50663
50664
{
50664
50665
JSTypedArray *ta;
50665
50666
JSArrayBuffer *abuf;
50666
- int is_swap, size;
50667
+ BOOL littleEndian, is_swap;
50668
+ int size;
50667
50669
uint8_t *ptr;
50668
50670
uint64_t v64;
50669
50671
uint32_t v;
@@ -50703,12 +50705,8 @@ static JSValue js_dataview_setValue(JSContext *ctx,
50703
50705
v64 = u.u64;
50704
50706
}
50705
50707
}
50706
- is_swap = FALSE;
50707
- if (argc > 2)
50708
- is_swap = JS_ToBool(ctx, argv[2]);
50709
- #ifndef WORDS_BIGENDIAN
50710
- is_swap ^= 1;
50711
- #endif
50708
+ littleEndian = argc > 2 && JS_ToBool(ctx, argv[2]);
50709
+ is_swap = littleEndian ^ !is_be();
50712
50710
abuf = ta->buffer->u.array_buffer;
50713
50711
if (abuf->detached)
50714
50712
return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
0 commit comments