Skip to content

Commit c0e67c4

Browse files
committed
Simplify redundant initializers for JS_NewBool()
1 parent 0665131 commit c0e67c4

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

quickjs-libc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ static JSValue js_os_isatty(JSContext *ctx, JSValueConst this_val,
16871687
int fd;
16881688
if (JS_ToInt32(ctx, &fd, argv[0]))
16891689
return JS_EXCEPTION;
1690-
return JS_NewBool(ctx, (isatty(fd) != 0));
1690+
return JS_NewBool(ctx, isatty(fd));
16911691
}
16921692

16931693
#if defined(_WIN32)

quickjs.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37069,12 +37069,10 @@ static JSValue js_global_isNaN(JSContext *ctx, JSValueConst this_val,
3706937069
static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val,
3707037070
int argc, JSValueConst *argv)
3707137071
{
37072-
BOOL res;
3707337072
double d;
3707437073
if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))
3707537074
return JS_EXCEPTION;
37076-
res = isfinite(d);
37077-
return JS_NewBool(ctx, res);
37075+
return JS_NewBool(ctx, isfinite(d));
3707837076
}
3707937077

3708037078
/* Object class */
@@ -37468,13 +37466,13 @@ static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst t
3746837466
} else {
3746937467
if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, desc.value), flags) < 0
3747037468
|| JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable,
37471-
JS_NewBool(ctx, (desc.flags & JS_PROP_WRITABLE) != 0), flags) < 0)
37469+
JS_NewBool(ctx, desc.flags & JS_PROP_WRITABLE), flags) < 0)
3747237470
goto exception1;
3747337471
}
3747437472
if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable,
37475-
JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0), flags) < 0
37473+
JS_NewBool(ctx, desc.flags & JS_PROP_ENUMERABLE), flags) < 0
3747637474
|| JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable,
37477-
JS_NewBool(ctx, (desc.flags & JS_PROP_CONFIGURABLE) != 0), flags) < 0)
37475+
JS_NewBool(ctx, desc.flags & JS_PROP_CONFIGURABLE), flags) < 0)
3747837476
goto exception1;
3747937477
js_free_desc(ctx, &desc);
3748037478
}
@@ -38222,7 +38220,7 @@ static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValueConst this_
3822238220
if (has_prop < 0)
3822338221
goto exception;
3822438222
if (has_prop) {
38225-
res = JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0);
38223+
res = JS_NewBool(ctx, desc.flags & JS_PROP_ENUMERABLE);
3822638224
js_free_desc(ctx, &desc);
3822738225
} else {
3822838226
res = JS_FALSE;
@@ -39630,9 +39628,10 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val,
3963039628
int argc, JSValueConst *argv)
3963139629
{
3963239630
JSValue obj, val;
39633-
int64_t len, n, res;
39631+
int64_t len, n;
3963439632
JSValue *arrp;
3963539633
uint32_t count;
39634+
int res;
3963639635

3963739636
obj = JS_ToObject(ctx, this_val);
3963839637
if (js_get_length64(ctx, &len, obj))
@@ -43777,7 +43776,7 @@ static JSValue js_regexp_get_flag(JSContext *ctx, JSValueConst this_val, int mas
4377743776
}
4377843777

4377943778
flags = lre_get_flags(re->bytecode->u.str8);
43780-
return JS_NewBool(ctx, (flags & mask) != 0);
43779+
return JS_NewBool(ctx, flags & mask);
4378143780
}
4378243781

4378343782
static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val)
@@ -45078,7 +45077,7 @@ static JSValue json_parse_value(JSParseState *s)
4507845077
case TOK_IDENT:
4507945078
if (s->token.u.ident.atom == JS_ATOM_false ||
4508045079
s->token.u.ident.atom == JS_ATOM_true) {
45081-
val = JS_NewBool(ctx, (s->token.u.ident.atom == JS_ATOM_true));
45080+
val = JS_NewBool(ctx, s->token.u.ident.atom == JS_ATOM_true);
4508245081
} else if (s->token.u.ident.atom == JS_ATOM_null) {
4508345082
val = JS_NULL;
4508445083
} else {
@@ -46194,17 +46193,17 @@ static JSValue js_create_desc(JSContext *ctx, JSValueConst val,
4619446193
}
4619546194
if (flags & JS_PROP_HAS_WRITABLE) {
4619646195
JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable,
46197-
JS_NewBool(ctx, (flags & JS_PROP_WRITABLE) != 0),
46196+
JS_NewBool(ctx, flags & JS_PROP_WRITABLE),
4619846197
JS_PROP_C_W_E);
4619946198
}
4620046199
if (flags & JS_PROP_HAS_ENUMERABLE) {
4620146200
JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable,
46202-
JS_NewBool(ctx, (flags & JS_PROP_ENUMERABLE) != 0),
46201+
JS_NewBool(ctx, flags & JS_PROP_ENUMERABLE),
4620346202
JS_PROP_C_W_E);
4620446203
}
4620546204
if (flags & JS_PROP_HAS_CONFIGURABLE) {
4620646205
JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable,
46207-
JS_NewBool(ctx, (flags & JS_PROP_CONFIGURABLE) != 0),
46206+
JS_NewBool(ctx, flags & JS_PROP_CONFIGURABLE),
4620846207
JS_PROP_C_W_E);
4620946208
}
4621046209
return ret;
@@ -47298,7 +47297,7 @@ static JSValue js_map_has(JSContext *ctx, JSValueConst this_val,
4729847297
return JS_EXCEPTION;
4729947298
key = map_normalize_key(ctx, argv[0]);
4730047299
mr = map_find_record(ctx, s, key);
47301-
return JS_NewBool(ctx, (mr != NULL));
47300+
return JS_NewBool(ctx, mr != NULL);
4730247301
}
4730347302

4730447303
static JSValue js_map_delete(JSContext *ctx, JSValueConst this_val,
@@ -50934,7 +50933,7 @@ static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)
5093450933
case JS_TAG_UNDEFINED:
5093550934
default:
5093650935
JS_FreeValue(ctx, val);
50937-
return JS_ThrowTypeError(ctx, "cannot convert to bigint");
50936+
return JS_ThrowTypeError(ctx, "cannot convert to BigInt");
5093850937
}
5093950938
return val;
5094050939
}
@@ -50960,7 +50959,7 @@ static JSValue js_thisBigIntValue(JSContext *ctx, JSValueConst this_val)
5096050959
return JS_DupValue(ctx, p->u.object_data);
5096150960
}
5096250961
}
50963-
return JS_ThrowTypeError(ctx, "not a bigint");
50962+
return JS_ThrowTypeError(ctx, "not a BigInt");
5096450963
}
5096550964

5096650965
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
5200152000
case FE_RNDMODE:
5200252001
return JS_NewInt32(ctx, fe->flags & BF_RND_MASK);
5200352002
case FE_SUBNORMAL:
52004-
return JS_NewBool(ctx, (fe->flags & BF_FLAG_SUBNORMAL) != 0);
52003+
return JS_NewBool(ctx, fe->flags & BF_FLAG_SUBNORMAL);
5200552004
default:
52006-
return JS_NewBool(ctx, (fe->status & magic) != 0);
52005+
return JS_NewBool(ctx, fe->status & magic);
5200752006
}
5200852007
}
5200952008

0 commit comments

Comments
 (0)