rm numeric

This commit is contained in:
2026-01-20 20:09:06 -06:00
parent 854d94e5c3
commit ef49606098
3 changed files with 17 additions and 87 deletions

View File

@@ -188,7 +188,8 @@ function disrupt(err)
}
if (err) {
log.console(err);
if (err.message)
log.console(err.message)
if (err.stack)
log.console(err.stack)
}

View File

@@ -283,6 +283,7 @@ int uncaught_exception(JSContext *js, JSValue v)
return 1;
}
JSValue exp = JS_GetException(js);
if (JS_IsNull(rt->on_exception)) {
const char *str = JS_ToCString(js, exp);

View File

@@ -9487,13 +9487,7 @@ done:
goto done;
}
typedef enum JSToNumberHintEnum {
TON_FLAG_NUMBER,
TON_FLAG_NUMERIC,
} JSToNumberHintEnum;
static JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val,
JSToNumberHintEnum flag)
static JSValue JS_ToNumberFree(JSContext *ctx, JSValue val)
{
uint32_t tag;
JSValue ret;
@@ -9515,8 +9509,8 @@ static JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val,
return JS_ThrowTypeError(ctx, "cannot convert object to number");
case JS_TAG_STRING:
case JS_TAG_STRING_ROPE:
ret = JS_NewInt32(ctx,0);
break;
JS_FreeValue(ctx, val);
return JS_ThrowTypeError(ctx, "cannot convert text to a number");
case JS_TAG_SYMBOL:
JS_FreeValue(ctx, val);
return JS_ThrowTypeError(ctx, "cannot convert symbol to number");
@@ -9528,19 +9522,9 @@ static JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val,
return ret;
}
static JSValue JS_ToNumberFree(JSContext *ctx, JSValue val)
static JSValue JS_ToNumber(JSContext *ctx, JSValueConst val)
{
return JS_ToNumberHintFree(ctx, val, TON_FLAG_NUMBER);
}
static JSValue JS_ToNumericFree(JSContext *ctx, JSValue val)
{
return JS_ToNumberHintFree(ctx, val, TON_FLAG_NUMERIC);
}
static JSValue JS_ToNumeric(JSContext *ctx, JSValueConst val)
{
return JS_ToNumericFree(ctx, JS_DupValue(ctx, val));
return JS_ToNumberFree(ctx, JS_DupValue(ctx, val));
}
static __exception int __JS_ToFloat64Free(JSContext *ctx, double *pres,
@@ -9591,46 +9575,6 @@ int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val)
return JS_ToFloat64Free(ctx, pres, JS_DupValue(ctx, val));
}
static JSValue JS_ToNumber(JSContext *ctx, JSValueConst val)
{
return JS_ToNumberFree(ctx, JS_DupValue(ctx, val));
}
/* same as JS_ToNumber() but return 0 in case of NaN/Undefined */
static __maybe_unused JSValue JS_ToIntegerFree(JSContext *ctx, JSValue val)
{
uint32_t tag;
JSValue ret;
redo:
tag = JS_VALUE_GET_NORM_TAG(val);
switch(tag) {
case JS_TAG_INT:
case JS_TAG_BOOL:
case JS_TAG_NULL:
ret = JS_NewInt32(ctx, JS_VALUE_GET_INT(val));
break;
case JS_TAG_FLOAT64:
{
double d = JS_VALUE_GET_FLOAT64(val);
if (isnan(d)) {
ret = JS_NewInt32(ctx, 0);
} else {
/* convert -0 to +0 */
d = trunc(d) + 0.0;
ret = JS_NewFloat64(ctx, d);
}
}
break;
default:
val = JS_ToNumberFree(ctx, val);
if (JS_IsException(val))
return val;
goto redo;
}
return ret;
}
/* Note: the integer value is satured to 32 bits */
static int JS_ToInt32SatFree(JSContext *ctx, int *pres, JSValue val)
{
@@ -9855,6 +9799,8 @@ static int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val)
}
break;
default:
*pres = 0;
return -1;
val = JS_ToNumberFree(ctx, val);
if (JS_IsException(val)) {
*pres = 0;
@@ -10781,12 +10727,6 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx,
uint32_t tag;
op1 = sp[-1];
/* fast path for float64 */
if (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(op1)))
goto handle_float64;
op1 = JS_ToNumericFree(ctx, op1);
if (JS_IsException(op1))
goto exception;
tag = JS_VALUE_GET_TAG(op1);
switch(tag) {
case JS_TAG_INT:
@@ -10815,8 +10755,7 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx,
sp[-1] = JS_NewInt64(ctx, v64);
}
break;
default:
handle_float64:
case JS_TAG_FLOAT64:
{
double d;
d = JS_VALUE_GET_FLOAT64(op1);
@@ -10837,27 +10776,16 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx,
sp[-1] = __JS_NewFloat64(ctx, d);
}
break;
default:
sp[-1] = JS_NULL;
}
return 0;
exception:
sp[-1] = JS_NULL;
return -1;
}
static __exception int js_post_inc_slow(JSContext *ctx,
JSValue *sp, OPCodeEnum op)
{
JSValue op1;
/* XXX: allow custom operators */
op1 = sp[-1];
op1 = JS_ToNumericFree(ctx, op1);
if (JS_IsException(op1)) {
sp[-1] = JS_NULL;
return -1;
}
sp[-1] = op1;
sp[0] = JS_DupValue(ctx, op1);
sp[0] = JS_DupValue(ctx, sp[-1]);
return js_unary_arith_slow(ctx, sp + 1, op - OP_post_dec + OP_dec);
}
@@ -10866,7 +10794,7 @@ static no_inline int js_not_slow(JSContext *ctx, JSValue *sp)
JSValue op1;
op1 = sp[-1];
op1 = JS_ToNumericFree(ctx, op1);
op1 = JS_ToNumberFree(ctx, op1);
if (JS_IsException(op1))
goto exception;
int32_t v1;
@@ -10909,12 +10837,12 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
goto handle_float64;
}
op1 = JS_ToNumericFree(ctx, op1);
op1 = JS_ToNumberFree(ctx, op1);
if (JS_IsException(op1)) {
JS_FreeValue(ctx, op2);
goto exception;
}
op2 = JS_ToNumericFree(ctx, op2);
op2 = JS_ToNumberFree(ctx, op2);
if (JS_IsException(op2)) {
JS_FreeValue(ctx, op1);
goto exception;