@@ -1220,6 +1220,7 @@ static JSValue js_typed_array_constructor_ta(JSContext *ctx,
1220
1220
JSValue new_target,
1221
1221
JSValue src_obj,
1222
1222
int classid, uint32_t len);
1223
+ static bool is_typed_array(JSClassID class_id);
1223
1224
static bool typed_array_is_oob(JSObject *p);
1224
1225
static uint32_t typed_array_get_length(JSContext *ctx, JSObject *p);
1225
1226
static JSValue JS_ThrowTypeErrorDetachedArrayBuffer(JSContext *ctx);
@@ -7454,12 +7455,10 @@ static JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValue obj,
7454
7455
if (idx < p->u.array.count) {
7455
7456
/* we avoid duplicating the code */
7456
7457
return JS_GetPropertyUint32(ctx, JS_MKPTR(JS_TAG_OBJECT, p), idx);
7457
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
7458
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
7458
+ } else if (is_typed_array(p->class_id)) {
7459
7459
return JS_UNDEFINED;
7460
7460
}
7461
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
7462
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
7461
+ } else if (is_typed_array(p->class_id)) {
7463
7462
int ret;
7464
7463
ret = JS_AtomIsNumericIndex(ctx, prop);
7465
7464
if (ret != 0) {
@@ -8135,8 +8134,7 @@ int JS_HasProperty(JSContext *ctx, JSValue obj, JSAtom prop)
8135
8134
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));
8136
8135
if (ret != 0)
8137
8136
return ret;
8138
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
8139
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
8137
+ if (is_typed_array(p->class_id)) {
8140
8138
ret = JS_AtomIsNumericIndex(ctx, prop);
8141
8139
if (ret != 0) {
8142
8140
if (ret < 0)
@@ -8773,12 +8771,10 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop,
8773
8771
return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), val, flags);
8774
8772
else
8775
8773
break;
8776
- } else if (p1->class_id >= JS_CLASS_UINT8C_ARRAY &&
8777
- p1->class_id <= JS_CLASS_FLOAT64_ARRAY) {
8774
+ } else if (is_typed_array(p1->class_id)) {
8778
8775
goto typed_array_oob;
8779
8776
}
8780
- } else if (p1->class_id >= JS_CLASS_UINT8C_ARRAY &&
8781
- p1->class_id <= JS_CLASS_FLOAT64_ARRAY) {
8777
+ } else if (is_typed_array(p1->class_id)) {
8782
8778
ret = JS_AtomIsNumericIndex(ctx, prop);
8783
8779
if (ret != 0) {
8784
8780
if (ret < 0)
@@ -9230,8 +9226,7 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p,
9230
9226
set_value(ctx, &plen->u.value, js_uint32(len));
9231
9227
}
9232
9228
}
9233
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
9234
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
9229
+ } else if (is_typed_array(p->class_id)) {
9235
9230
ret = JS_AtomIsNumericIndex(ctx, prop);
9236
9231
if (ret != 0) {
9237
9232
if (ret < 0)
@@ -9587,8 +9582,7 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
9587
9582
return true;
9588
9583
}
9589
9584
}
9590
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
9591
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
9585
+ } else if (is_typed_array(p->class_id)) {
9592
9586
JSValue num;
9593
9587
int ret;
9594
9588
@@ -34491,8 +34485,7 @@ static int JS_WriteObjectRec(BCWriterState *s, JSValue obj)
34491
34485
ret = JS_WriteSet(s, p->u.map_state);
34492
34486
break;
34493
34487
default:
34494
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
34495
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
34488
+ if (is_typed_array(p->class_id)) {
34496
34489
ret = JS_WriteTypedArray(s, obj);
34497
34490
} else {
34498
34491
JS_ThrowTypeError(s->ctx, "unsupported object class");
@@ -38622,8 +38615,7 @@ static JSObject *get_typed_array(JSContext *ctx, JSValue this_val)
38622
38615
if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)
38623
38616
goto fail;
38624
38617
p = JS_VALUE_GET_OBJ(this_val);
38625
- if (!(p->class_id >= JS_CLASS_UINT8C_ARRAY &&
38626
- p->class_id <= JS_CLASS_FLOAT64_ARRAY)) {
38618
+ if (!is_typed_array(p->class_id)) {
38627
38619
fail:
38628
38620
JS_ThrowTypeError(ctx, "not a TypedArray");
38629
38621
return NULL;
@@ -40124,8 +40116,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val,
40124
40116
if (JS_IsUndefined(it->obj))
40125
40117
goto done;
40126
40118
p = JS_VALUE_GET_OBJ(it->obj);
40127
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
40128
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
40119
+ if (is_typed_array(p->class_id)) {
40129
40120
if (typed_array_is_oob(p)) {
40130
40121
JS_ThrowTypeErrorArrayBufferOOB(ctx);
40131
40122
goto fail1;
@@ -52067,16 +52058,13 @@ static JSValue js_array_buffer_isView(JSContext *ctx,
52067
52058
int argc, JSValue *argv)
52068
52059
{
52069
52060
JSObject *p;
52070
- bool res;
52071
- res = false;
52061
+
52072
52062
if (JS_VALUE_GET_TAG(argv[0]) == JS_TAG_OBJECT) {
52073
52063
p = JS_VALUE_GET_OBJ(argv[0]);
52074
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
52075
- p->class_id <= JS_CLASS_DATAVIEW) {
52076
- res = true;
52077
- }
52064
+ return js_bool(is_typed_array(p->class_id) ||
52065
+ p->class_id == JS_CLASS_DATAVIEW);
52078
52066
}
52079
- return js_bool(res) ;
52067
+ return JS_FALSE ;
52080
52068
}
52081
52069
52082
52070
static const JSCFunctionListEntry js_array_buffer_funcs[] = {
@@ -52431,6 +52419,11 @@ static const JSCFunctionListEntry js_shared_array_buffer_proto_funcs[] = {
52431
52419
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "SharedArrayBuffer", JS_PROP_CONFIGURABLE ),
52432
52420
};
52433
52421
52422
+ static bool is_typed_array(JSClassID class_id)
52423
+ {
52424
+ return class_id >= JS_CLASS_UINT8C_ARRAY && class_id <= JS_CLASS_FLOAT64_ARRAY;
52425
+ }
52426
+
52434
52427
// is the typed array detached or out of bounds relative to its RAB?
52435
52428
// |p| must be a typed array, *not* a DataView
52436
52429
static bool typed_array_is_oob(JSObject *p)
@@ -52440,8 +52433,7 @@ static bool typed_array_is_oob(JSObject *p)
52440
52433
int len, size_elem;
52441
52434
int64_t end;
52442
52435
52443
- assert(p->class_id >= JS_CLASS_UINT8C_ARRAY);
52444
- assert(p->class_id <= JS_CLASS_FLOAT64_ARRAY);
52436
+ assert(is_typed_array(p->class_id));
52445
52437
52446
52438
ta = p->u.typed_array;
52447
52439
abuf = ta->buffer->u.array_buffer;
@@ -52603,8 +52595,7 @@ static JSValue js_typed_array_get_toStringTag(JSContext *ctx,
52603
52595
if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)
52604
52596
return JS_UNDEFINED;
52605
52597
p = JS_VALUE_GET_OBJ(this_val);
52606
- if (!(p->class_id >= JS_CLASS_UINT8C_ARRAY &&
52607
- p->class_id <= JS_CLASS_FLOAT64_ARRAY))
52598
+ if (!is_typed_array(p->class_id))
52608
52599
return JS_UNDEFINED;
52609
52600
return JS_AtomToString(ctx, ctx->rt->class_array[p->class_id].class_name);
52610
52601
}
@@ -52637,8 +52628,7 @@ static JSValue js_typed_array_set_internal(JSContext *ctx,
52637
52628
if (JS_IsException(src_obj))
52638
52629
goto fail;
52639
52630
src_p = JS_VALUE_GET_OBJ(src_obj);
52640
- if (src_p->class_id >= JS_CLASS_UINT8C_ARRAY &&
52641
- src_p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
52631
+ if (is_typed_array(src_p->class_id)) {
52642
52632
JSTypedArray *dest_ta = p->u.typed_array;
52643
52633
JSArrayBuffer *dest_abuf = dest_ta->buffer->u.array_buffer;
52644
52634
JSTypedArray *src_ta = src_p->u.typed_array;
@@ -54372,8 +54362,7 @@ static JSValue js_typed_array_constructor(JSContext *ctx,
54372
54362
}
54373
54363
buffer = js_dup(argv[0]);
54374
54364
} else {
54375
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
54376
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
54365
+ if (is_typed_array(p->class_id)) {
54377
54366
return js_typed_array_constructor_ta(ctx, new_target, argv[0],
54378
54367
classid, p->u.array.count);
54379
54368
} else {
@@ -54852,7 +54841,7 @@ JSValue JS_NewUint8ArrayCopy(JSContext *ctx, const uint8_t *buf, size_t len)
54852
54841
int JS_GetTypedArrayType(JSValue obj)
54853
54842
{
54854
54843
JSClassID class_id = JS_GetClassID(obj);
54855
- if (class_id >= JS_CLASS_UINT8C_ARRAY && class_id <= JS_CLASS_FLOAT64_ARRAY )
54844
+ if (is_typed_array( class_id) )
54856
54845
return class_id - JS_CLASS_UINT8C_ARRAY;
54857
54846
else
54858
54847
return -1;
0 commit comments