@@ -1286,6 +1286,13 @@ static JSValue js_int32(int32_t v)
1286
1286
return JS_MKVAL(JS_TAG_INT, v);
1287
1287
}
1288
1288
1289
+ static JSValue js_uint32(uint32_t v)
1290
+ {
1291
+ if (v <= INT32_MAX)
1292
+ return js_int32(v);
1293
+ return js_float64(v);
1294
+ }
1295
+
1289
1296
static void js_trigger_gc(JSRuntime *rt, size_t size)
1290
1297
{
1291
1298
BOOL force_gc;
@@ -7803,7 +7810,7 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj,
7803
7810
return js_int32(p->u.array.u.int32_ptr[idx]);
7804
7811
case JS_CLASS_UINT32_ARRAY:
7805
7812
if (unlikely(idx >= p->u.array.count)) goto slow_path;
7806
- return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]);
7813
+ return js_uint32( p->u.array.u.uint32_ptr[idx]);
7807
7814
case JS_CLASS_BIG_INT64_ARRAY:
7808
7815
if (unlikely(idx >= p->u.array.count)) goto slow_path;
7809
7816
return JS_NewBigInt64(ctx, p->u.array.u.int64_ptr[idx]);
@@ -7834,7 +7841,7 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj,
7834
7841
JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
7835
7842
uint32_t idx)
7836
7843
{
7837
- return JS_GetPropertyValue(ctx, this_obj, JS_NewUint32(ctx, idx));
7844
+ return JS_GetPropertyValue(ctx, this_obj, js_uint32( idx));
7838
7845
}
7839
7846
7840
7847
/* Check if an object has a generalized numeric property. Return value:
@@ -8115,7 +8122,7 @@ static int set_array_length(JSContext *ctx, JSObject *p, JSValue val,
8115
8122
}
8116
8123
p->u.array.count = len;
8117
8124
}
8118
- p->prop[0].u.value = JS_NewUint32(ctx, len);
8125
+ p->prop[0].u.value = js_uint32( len);
8119
8126
} else {
8120
8127
/* Note: length is always a uint32 because the object is an
8121
8128
array */
@@ -8175,7 +8182,7 @@ static int set_array_length(JSContext *ctx, JSObject *p, JSValue val,
8175
8182
} else {
8176
8183
cur_len = len;
8177
8184
}
8178
- set_value(ctx, &p->prop[0].u.value, JS_NewUint32(ctx, cur_len));
8185
+ set_value(ctx, &p->prop[0].u.value, js_uint32( cur_len));
8179
8186
if (unlikely(cur_len > len)) {
8180
8187
return JS_ThrowTypeErrorOrFalse(ctx, flags, "not configurable");
8181
8188
}
@@ -8731,7 +8738,7 @@ static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
8731
8738
int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
8732
8739
uint32_t idx, JSValue val)
8733
8740
{
8734
- return JS_SetPropertyValue(ctx, this_obj, JS_NewUint32(ctx, idx), val,
8741
+ return JS_SetPropertyValue(ctx, this_obj, js_uint32( idx), val,
8735
8742
JS_PROP_THROW);
8736
8743
}
8737
8744
@@ -8828,7 +8835,7 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p,
8828
8835
/* XXX: should update the length after defining
8829
8836
the property */
8830
8837
len = idx + 1;
8831
- set_value(ctx, &plen->u.value, JS_NewUint32(ctx, len));
8838
+ set_value(ctx, &plen->u.value, js_uint32( len));
8832
8839
}
8833
8840
}
8834
8841
} else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
@@ -8997,7 +9004,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
8997
9004
return -1;
8998
9005
}
8999
9006
/* this code relies on the fact that Uint32 are never allocated */
9000
- val = (JSValueConst)JS_NewUint32(ctx, array_length);
9007
+ val = (JSValueConst)js_uint32( array_length);
9001
9008
/* prs may have been modified */
9002
9009
prs = find_own_property(&pr, p, prop);
9003
9010
assert(prs != NULL);
@@ -9299,7 +9306,7 @@ int JS_DefinePropertyValueValue(JSContext *ctx, JSValueConst this_obj,
9299
9306
int JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,
9300
9307
uint32_t idx, JSValue val, int flags)
9301
9308
{
9302
- return JS_DefinePropertyValueValue(ctx, this_obj, JS_NewUint32(ctx, idx),
9309
+ return JS_DefinePropertyValueValue(ctx, this_obj, js_uint32( idx),
9303
9310
val, flags);
9304
9311
}
9305
9312
@@ -12735,7 +12742,7 @@ static no_inline int js_shr_slow(JSContext *ctx, JSValue *sp)
12735
12742
JS_ToUint32Free(ctx, &v1, op1);
12736
12743
JS_ToUint32Free(ctx, &v2, op2);
12737
12744
r = v1 >> (v2 & 0x1f);
12738
- sp[-2] = JS_NewUint32(ctx, r);
12745
+ sp[-2] = js_uint32( r);
12739
12746
return 0;
12740
12747
exception:
12741
12748
sp[-2] = JS_UNDEFINED;
@@ -16445,9 +16452,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
16445
16452
uint32_t v2;
16446
16453
v2 = JS_VALUE_GET_INT(op2);
16447
16454
v2 &= 0x1f;
16448
- sp[-2] = JS_NewUint32(ctx,
16449
- (uint32_t)JS_VALUE_GET_INT(op1) >>
16450
- v2);
16455
+ sp[-2] = js_uint32((uint32_t)JS_VALUE_GET_INT(op1) >> v2);
16451
16456
sp--;
16452
16457
} else {
16453
16458
if (js_shr_slow(ctx, sp))
@@ -36026,7 +36031,7 @@ static JSValue js_array_constructor(JSContext *ctx, JSValueConst new_target,
36026
36031
uint32_t len;
36027
36032
if (JS_ToArrayLengthFree(ctx, &len, JS_DupValue(ctx, argv[0]), TRUE))
36028
36033
goto fail;
36029
- if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewUint32(ctx, len)) < 0)
36034
+ if (JS_SetProperty(ctx, obj, JS_ATOM_length, js_uint32( len)) < 0)
36030
36035
goto fail;
36031
36036
} else {
36032
36037
for(i = 0; i < argc; i++) {
@@ -36136,7 +36141,7 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val,
36136
36141
goto exception;
36137
36142
}
36138
36143
}
36139
- if (JS_SetProperty(ctx, r, JS_ATOM_length, JS_NewUint32(ctx, k)) < 0)
36144
+ if (JS_SetProperty(ctx, r, JS_ATOM_length, js_uint32( k)) < 0)
36140
36145
goto exception;
36141
36146
goto done;
36142
36147
@@ -36173,7 +36178,7 @@ static JSValue js_array_of(JSContext *ctx, JSValueConst this_val,
36173
36178
goto fail;
36174
36179
}
36175
36180
}
36176
- if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewUint32(ctx, argc)) < 0) {
36181
+ if (JS_SetProperty(ctx, obj, JS_ATOM_length, js_uint32( argc)) < 0) {
36177
36182
fail:
36178
36183
JS_FreeValue(ctx, obj);
36179
36184
return JS_EXCEPTION;
@@ -37946,7 +37951,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val,
37946
37951
it->idx = idx + 1;
37947
37952
*pdone = FALSE;
37948
37953
if (it->kind == JS_ITERATOR_KIND_KEY) {
37949
- return JS_NewUint32(ctx, idx);
37954
+ return js_uint32( idx);
37950
37955
} else {
37951
37956
val = JS_GetPropertyUint32(ctx, it->obj, idx);
37952
37957
if (JS_IsException(val))
@@ -37956,7 +37961,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val,
37956
37961
} else {
37957
37962
JSValueConst args[2];
37958
37963
JSValue num;
37959
- num = JS_NewUint32(ctx, idx);
37964
+ num = js_uint32( idx);
37960
37965
args[0] = num;
37961
37966
args[1] = val;
37962
37967
obj = js_create_array(ctx, 2, args);
@@ -44307,7 +44312,7 @@ static JSValue js_map_get_size(JSContext *ctx, JSValueConst this_val, int magic)
44307
44312
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
44308
44313
if (!s)
44309
44314
return JS_EXCEPTION;
44310
- return JS_NewUint32(ctx, s->record_count);
44315
+ return js_uint32( s->record_count);
44311
44316
}
44312
44317
44313
44318
static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val,
@@ -47940,7 +47945,7 @@ static JSValue js_array_buffer_get_byteLength(JSContext *ctx,
47940
47945
if (!abuf)
47941
47946
return JS_EXCEPTION;
47942
47947
/* return 0 if detached */
47943
- return JS_NewUint32(ctx, abuf->byte_length);
47948
+ return js_uint32( abuf->byte_length);
47944
47949
}
47945
47950
47946
47951
void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj)
@@ -48436,7 +48441,7 @@ static JSValue js_typed_array_at(JSContext *ctx, JSValueConst this_val,
48436
48441
case JS_CLASS_INT32_ARRAY:
48437
48442
return js_int32(p->u.array.u.int32_ptr[idx]);
48438
48443
case JS_CLASS_UINT32_ARRAY:
48439
- return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]);
48444
+ return js_uint32( p->u.array.u.uint32_ptr[idx]);
48440
48445
case JS_CLASS_FLOAT32_ARRAY:
48441
48446
return __JS_NewFloat64(p->u.array.u.float_ptr[idx]);
48442
48447
case JS_CLASS_FLOAT64_ARRAY:
@@ -49385,7 +49390,7 @@ static JSValue js_TA_get_int32(JSContext *ctx, const void *a) {
49385
49390
}
49386
49391
49387
49392
static JSValue js_TA_get_uint32(JSContext *ctx, const void *a) {
49388
- return JS_NewUint32(ctx, *(const uint32_t *)a);
49393
+ return js_uint32( *(const uint32_t *)a);
49389
49394
}
49390
49395
49391
49396
static JSValue js_TA_get_int64(JSContext *ctx, const void *a) {
@@ -50041,7 +50046,7 @@ static JSValue js_dataview_getValue(JSContext *ctx,
50041
50046
v = get_u32(ptr);
50042
50047
if (is_swap)
50043
50048
v = bswap32(v);
50044
- return JS_NewUint32(ctx, v);
50049
+ return js_uint32( v);
50045
50050
case JS_CLASS_BIG_INT64_ARRAY:
50046
50051
{
50047
50052
uint64_t v;
@@ -50447,7 +50452,7 @@ static JSValue js_atomics_op(JSContext *ctx,
50447
50452
ret = js_int32(a);
50448
50453
break;
50449
50454
case JS_CLASS_UINT32_ARRAY:
50450
- ret = JS_NewUint32(ctx, a);
50455
+ ret = js_uint32( a);
50451
50456
break;
50452
50457
case JS_CLASS_BIG_INT64_ARRAY:
50453
50458
ret = JS_NewBigInt64(ctx, a);
0 commit comments