Skip to content

Commit a08291e

Browse files
LaszloLangozherczeg
authored andcommitted
Unify the usage of boolean value creations. (#2623)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
1 parent 6dfa4ef commit a08291e

File tree

9 files changed

+23
-39
lines changed

9 files changed

+23
-39
lines changed

jerry-core/api/jerry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ jerry_has_property (const jerry_value_t obj_val, /**< object value */
18111811
if (!ecma_is_value_object (obj_val)
18121812
|| !ecma_is_value_string (prop_name_val))
18131813
{
1814-
return ecma_make_boolean_value (false);
1814+
return ECMA_VALUE_FALSE;
18151815
}
18161816

18171817
bool has_property = ecma_op_object_has_property (ecma_get_object_from_value (obj_val),
@@ -1835,7 +1835,7 @@ jerry_has_own_property (const jerry_value_t obj_val, /**< object value */
18351835
if (!ecma_is_value_object (obj_val)
18361836
|| !ecma_is_value_string (prop_name_val))
18371837
{
1838-
return ecma_make_boolean_value (false);
1838+
return ECMA_VALUE_FALSE;
18391839
}
18401840

18411841
bool has_property = ecma_op_object_has_own_property (ecma_get_object_from_value (obj_val),

jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argu
5959

6060
/* TODO: if arg has [[ViewArrayBuffer]], return true */
6161

62-
return ecma_make_boolean_value (false);
62+
return ECMA_VALUE_FALSE;
6363
} /* ecma_builtin_arraybuffer_object_is_view */
6464

6565
/**

jerry-core/ecma/builtin-objects/ecma-builtin-boolean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ecma_builtin_boolean_dispatch_call (const ecma_value_t *arguments_list_p, /**< a
6666
arg_value = arguments_list_p[0];
6767
}
6868

69-
return ecma_op_to_boolean (arg_value) ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
69+
return ecma_make_boolean_value (ecma_op_to_boolean (arg_value));
7070
} /* ecma_builtin_boolean_dispatch_call */
7171

7272
/**

jerry-core/ecma/builtin-objects/ecma-builtin-global.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,7 @@ ecma_builtin_global_object_is_nan (ecma_value_t this_arg, /**< this argument */
532532

533533
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
534534

535-
bool is_nan = ecma_number_is_nan (arg_num);
536-
537-
ret_value = is_nan ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
535+
ret_value = ecma_make_boolean_value (ecma_number_is_nan (arg_num));
538536

539537
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
540538

@@ -561,8 +559,7 @@ ecma_builtin_global_object_is_finite (ecma_value_t this_arg, /**< this argument
561559

562560
bool is_finite = !(ecma_number_is_nan (arg_num)
563561
|| ecma_number_is_infinity (arg_num));
564-
565-
ret_value = is_finite ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
562+
ret_value = ecma_make_boolean_value (is_finite);
566563

567564
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
568565

jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ ecma_builtin_object_prototype_object_is_prototype_of (ecma_value_t this_arg, /**
192192
ecma_object_t *v_obj_p = ecma_get_object_from_value (v_obj_value);
193193

194194
bool is_prototype_of = ecma_op_object_is_prototype_of (obj_p, v_obj_p);
195-
return_value = is_prototype_of ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
195+
return_value = ecma_make_boolean_value (is_prototype_of);
196196
ECMA_FINALIZE (v_obj_value);
197197

198198
ECMA_FINALIZE (obj_value);

jerry-core/ecma/builtin-objects/ecma-builtin-object.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,15 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_value_t this_arg, /**< 'this'
512512
{
513513
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
514514

515-
bool is_sealed_or_frozen;
516-
517515
/* 3. */
518516
if (ecma_get_object_extensible (obj_p))
519517
{
520-
is_sealed_or_frozen = false;
518+
ret_value = ECMA_VALUE_FALSE;
521519
}
522520
else
523521
{
524522
/* the value can be updated in the loop below */
525-
is_sealed_or_frozen = true;
523+
ret_value = ECMA_VALUE_TRUE;
526524

527525
/* 2. */
528526
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
@@ -545,23 +543,20 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_value_t this_arg, /**< 'this'
545543
&& ECMA_PROPERTY_GET_TYPE (property) != ECMA_PROPERTY_TYPE_NAMEDACCESSOR
546544
&& ecma_is_property_writable (property))
547545
{
548-
is_sealed_or_frozen = false;
546+
ret_value = ECMA_VALUE_FALSE;
549547
break;
550548
}
551549

552550
/* 2.b for isSealed, 2.c for isFrozen */
553551
if (ecma_is_property_configurable (property))
554552
{
555-
is_sealed_or_frozen = false;
553+
ret_value = ECMA_VALUE_FALSE;
556554
break;
557555
}
558556
}
559557

560558
ecma_free_values_collection (props_p, 0);
561559
}
562-
563-
/* 4. */
564-
ret_value = is_sealed_or_frozen ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
565560
}
566561

567562
return ret_value;
@@ -613,22 +608,14 @@ ecma_builtin_object_object_is_extensible (ecma_value_t this_arg, /**< 'this' arg
613608
ecma_value_t arg) /**< routine's argument */
614609
{
615610
JERRY_UNUSED (this_arg);
616-
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
617611

618612
if (!ecma_is_value_object (arg))
619613
{
620-
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object."));
621-
}
622-
else
623-
{
624-
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
625-
626-
bool extensible = ecma_get_object_extensible (obj_p);
627-
628-
ret_value = extensible ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
614+
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object."));
629615
}
630616

631-
return ret_value;
617+
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
618+
return ecma_make_boolean_value (ecma_get_object_extensible (obj_p));
632619
} /* ecma_builtin_object_object_is_extensible */
633620

634621
/**

jerry-core/ecma/builtin-objects/ecma-builtin-promise.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ ecma_builtin_promise_all_handler (const ecma_value_t function, /**< the function
341341
/* 3. */
342342
ecma_op_object_put (function_p,
343343
already_called_str_p,
344-
ecma_make_boolean_value (true),
344+
ECMA_VALUE_TRUE,
345345
false);
346346

347347
ecma_string_t *str_index_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_PROMISE_PROPERTY_INDEX);
@@ -500,7 +500,7 @@ ecma_builtin_promise_do_all (ecma_value_t array, /**< the array for all */
500500
/* l. */
501501
ecma_op_object_put (res_ele_p,
502502
already_called_str_p,
503-
ecma_make_boolean_value (false),
503+
ECMA_VALUE_FALSE,
504504
false);
505505
/* m. */
506506
ecma_op_object_put (res_ele_p,

jerry-core/ecma/operations/ecma-function-object.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
373373
ecma_object_t *prototype_obj_p = ecma_get_object_from_value (prototype_obj_value);
374374
JERRY_ASSERT (prototype_obj_p != NULL);
375375

376-
bool result = false;
376+
ecma_value_t result = ECMA_VALUE_FALSE;
377377

378378
while (true)
379379
{
@@ -386,13 +386,13 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
386386

387387
if (v_obj_p == prototype_obj_p)
388388
{
389-
result = true;
389+
result = ECMA_VALUE_TRUE;
390390
break;
391391
}
392392
}
393393

394394
ecma_deref_object (prototype_obj_p);
395-
return ecma_make_boolean_value (result);
395+
return result;
396396
} /* ecma_op_function_has_instance */
397397

398398

jerry-core/ecma/operations/ecma-promise-object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ ecma_get_already_resolved_bool_value (ecma_value_t already_resolved) /**< the al
119119

120120
JERRY_ASSERT (ext_object_p->u.class_prop.class_id == LIT_MAGIC_STRING_BOOLEAN_UL);
121121

122-
return ext_object_p->u.class_prop.u.value == ecma_make_boolean_value (true);
122+
return ext_object_p->u.class_prop.u.value == ECMA_VALUE_TRUE;
123123
} /* ecma_get_already_resolved_bool_value */
124124

125125
/**
@@ -421,7 +421,7 @@ ecma_promise_resolving_functions_t *
421421
ecma_promise_create_resolving_functions (ecma_object_t *object_p) /**< the promise object */
422422
{
423423
/* 1. */
424-
ecma_value_t already_resolved = ecma_op_create_boolean_object (ecma_make_boolean_value (false));
424+
ecma_value_t already_resolved = ecma_op_create_boolean_object (ECMA_VALUE_FALSE);
425425

426426
ecma_string_t *str_promise_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_PROMISE);
427427
ecma_string_t *str_already_resolved_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_ALREADY_RESOLVED);
@@ -670,13 +670,13 @@ ecma_promise_do_then (ecma_value_t promise, /**< the promise which call 'then' *
670670
/* 3. boolean true indicates "indentity" */
671671
if (!ecma_op_is_callable (on_fulfilled))
672672
{
673-
on_fulfilled = ecma_make_boolean_value (true);
673+
on_fulfilled = ECMA_VALUE_TRUE;
674674
}
675675

676676
/* 4. boolean false indicates "thrower" */
677677
if (!ecma_op_is_callable (on_rejected))
678678
{
679-
on_rejected = ecma_make_boolean_value (false);
679+
on_rejected = ECMA_VALUE_FALSE;
680680
}
681681

682682
/* 5-6. */

0 commit comments

Comments
 (0)