Simplify redundant initializers for JS_NewBool()

This commit is contained in:
Charlie Gordon 2024-03-23 09:28:38 +01:00
parent 06651314f5
commit c0e67c47cd
2 changed files with 18 additions and 19 deletions

View file

@ -1687,7 +1687,7 @@ static JSValue js_os_isatty(JSContext *ctx, JSValueConst this_val,
int fd; int fd;
if (JS_ToInt32(ctx, &fd, argv[0])) if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION; return JS_EXCEPTION;
return JS_NewBool(ctx, (isatty(fd) != 0)); return JS_NewBool(ctx, isatty(fd));
} }
#if defined(_WIN32) #if defined(_WIN32)

View file

@ -37069,12 +37069,10 @@ static JSValue js_global_isNaN(JSContext *ctx, JSValueConst this_val,
static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val, static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
BOOL res;
double d; double d;
if (unlikely(JS_ToFloat64(ctx, &d, argv[0]))) if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))
return JS_EXCEPTION; return JS_EXCEPTION;
res = isfinite(d); return JS_NewBool(ctx, isfinite(d));
return JS_NewBool(ctx, res);
} }
/* Object class */ /* Object class */
@ -37468,13 +37466,13 @@ static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst t
} else { } else {
if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, desc.value), flags) < 0 if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, desc.value), flags) < 0
|| JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable, || JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable,
JS_NewBool(ctx, (desc.flags & JS_PROP_WRITABLE) != 0), flags) < 0) JS_NewBool(ctx, desc.flags & JS_PROP_WRITABLE), flags) < 0)
goto exception1; goto exception1;
} }
if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable, if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable,
JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0), flags) < 0 JS_NewBool(ctx, desc.flags & JS_PROP_ENUMERABLE), flags) < 0
|| JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable, || JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable,
JS_NewBool(ctx, (desc.flags & JS_PROP_CONFIGURABLE) != 0), flags) < 0) JS_NewBool(ctx, desc.flags & JS_PROP_CONFIGURABLE), flags) < 0)
goto exception1; goto exception1;
js_free_desc(ctx, &desc); js_free_desc(ctx, &desc);
} }
@ -38222,7 +38220,7 @@ static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValueConst this_
if (has_prop < 0) if (has_prop < 0)
goto exception; goto exception;
if (has_prop) { if (has_prop) {
res = JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0); res = JS_NewBool(ctx, desc.flags & JS_PROP_ENUMERABLE);
js_free_desc(ctx, &desc); js_free_desc(ctx, &desc);
} else { } else {
res = JS_FALSE; res = JS_FALSE;
@ -39630,9 +39628,10 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
JSValue obj, val; JSValue obj, val;
int64_t len, n, res; int64_t len, n;
JSValue *arrp; JSValue *arrp;
uint32_t count; uint32_t count;
int res;
obj = JS_ToObject(ctx, this_val); obj = JS_ToObject(ctx, this_val);
if (js_get_length64(ctx, &len, obj)) if (js_get_length64(ctx, &len, obj))
@ -43777,7 +43776,7 @@ static JSValue js_regexp_get_flag(JSContext *ctx, JSValueConst this_val, int mas
} }
flags = lre_get_flags(re->bytecode->u.str8); flags = lre_get_flags(re->bytecode->u.str8);
return JS_NewBool(ctx, (flags & mask) != 0); return JS_NewBool(ctx, flags & mask);
} }
static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val) static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val)
@ -45078,7 +45077,7 @@ static JSValue json_parse_value(JSParseState *s)
case TOK_IDENT: case TOK_IDENT:
if (s->token.u.ident.atom == JS_ATOM_false || if (s->token.u.ident.atom == JS_ATOM_false ||
s->token.u.ident.atom == JS_ATOM_true) { s->token.u.ident.atom == JS_ATOM_true) {
val = JS_NewBool(ctx, (s->token.u.ident.atom == JS_ATOM_true)); val = JS_NewBool(ctx, s->token.u.ident.atom == JS_ATOM_true);
} else if (s->token.u.ident.atom == JS_ATOM_null) { } else if (s->token.u.ident.atom == JS_ATOM_null) {
val = JS_NULL; val = JS_NULL;
} else { } else {
@ -46194,17 +46193,17 @@ static JSValue js_create_desc(JSContext *ctx, JSValueConst val,
} }
if (flags & JS_PROP_HAS_WRITABLE) { if (flags & JS_PROP_HAS_WRITABLE) {
JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable, JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable,
JS_NewBool(ctx, (flags & JS_PROP_WRITABLE) != 0), JS_NewBool(ctx, flags & JS_PROP_WRITABLE),
JS_PROP_C_W_E); JS_PROP_C_W_E);
} }
if (flags & JS_PROP_HAS_ENUMERABLE) { if (flags & JS_PROP_HAS_ENUMERABLE) {
JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable, JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable,
JS_NewBool(ctx, (flags & JS_PROP_ENUMERABLE) != 0), JS_NewBool(ctx, flags & JS_PROP_ENUMERABLE),
JS_PROP_C_W_E); JS_PROP_C_W_E);
} }
if (flags & JS_PROP_HAS_CONFIGURABLE) { if (flags & JS_PROP_HAS_CONFIGURABLE) {
JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable, JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable,
JS_NewBool(ctx, (flags & JS_PROP_CONFIGURABLE) != 0), JS_NewBool(ctx, flags & JS_PROP_CONFIGURABLE),
JS_PROP_C_W_E); JS_PROP_C_W_E);
} }
return ret; return ret;
@ -47298,7 +47297,7 @@ static JSValue js_map_has(JSContext *ctx, JSValueConst this_val,
return JS_EXCEPTION; return JS_EXCEPTION;
key = map_normalize_key(ctx, argv[0]); key = map_normalize_key(ctx, argv[0]);
mr = map_find_record(ctx, s, key); mr = map_find_record(ctx, s, key);
return JS_NewBool(ctx, (mr != NULL)); return JS_NewBool(ctx, mr != NULL);
} }
static JSValue js_map_delete(JSContext *ctx, JSValueConst this_val, static JSValue js_map_delete(JSContext *ctx, JSValueConst this_val,
@ -50934,7 +50933,7 @@ static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)
case JS_TAG_UNDEFINED: case JS_TAG_UNDEFINED:
default: default:
JS_FreeValue(ctx, val); JS_FreeValue(ctx, val);
return JS_ThrowTypeError(ctx, "cannot convert to bigint"); return JS_ThrowTypeError(ctx, "cannot convert to BigInt");
} }
return val; return val;
} }
@ -50960,7 +50959,7 @@ static JSValue js_thisBigIntValue(JSContext *ctx, JSValueConst this_val)
return JS_DupValue(ctx, p->u.object_data); return JS_DupValue(ctx, p->u.object_data);
} }
} }
return JS_ThrowTypeError(ctx, "not a bigint"); return JS_ThrowTypeError(ctx, "not a BigInt");
} }
static JSValue js_bigint_toString(JSContext *ctx, JSValueConst this_val, static JSValue js_bigint_toString(JSContext *ctx, JSValueConst this_val,
@ -52001,9 +52000,9 @@ static JSValue js_float_env_proto_get_status(JSContext *ctx, JSValueConst this_v
case FE_RNDMODE: case FE_RNDMODE:
return JS_NewInt32(ctx, fe->flags & BF_RND_MASK); return JS_NewInt32(ctx, fe->flags & BF_RND_MASK);
case FE_SUBNORMAL: case FE_SUBNORMAL:
return JS_NewBool(ctx, (fe->flags & BF_FLAG_SUBNORMAL) != 0); return JS_NewBool(ctx, fe->flags & BF_FLAG_SUBNORMAL);
default: default:
return JS_NewBool(ctx, (fe->status & magic) != 0); return JS_NewBool(ctx, fe->status & magic);
} }
} }