Cleanup code around JERRY_UNREACHABLEs (#2342)

`JERRY_UNREACHABLE`s often signal code structure that could be
improved: they can usually either be rewritten to `JERRY_ASSERT`s
or eliminated by restructuring loops, `if`s or `#if`s. Roughly,
the only valid occurences are in default cases of `switch`es. And
even they can often be merged into non-default cases.

Moreover, it is dangerous to write meaningful code after
`JERRY_UNREACHABLE` because it pretends as if there was a way to
recover from an impossible situation.

This patch rewrites/eliminates `JERRY_UNREACHABLE`s where possible
and removes misleading code from after them.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2018-05-25 07:27:30 +02:00
committed by GitHub
parent acb3e71436
commit 4779451284
24 changed files with 168 additions and 256 deletions
@@ -416,6 +416,7 @@ ecma_instantiate_builtin_helper (ecma_builtin_id_t builtin_id, /**< built-in id
static void
ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
{
JERRY_ASSERT (id < ECMA_BUILTIN_ID__COUNT);
switch (id)
{
#define BUILTIN(builtin_id, \
@@ -437,8 +438,6 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
#undef BUILTIN_ROUTINE
default:
{
JERRY_ASSERT (id < ECMA_BUILTIN_ID__COUNT);
JERRY_UNREACHABLE (); /* The built-in is not implemented. */
}
}
@@ -685,11 +684,6 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
{
switch (curr_property_p->value)
{
case ECMA_BUILTIN_NUMBER_NAN:
{
num = ecma_number_make_nan ();
break;
}
case ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY:
{
num = ecma_number_make_infinity (false);
@@ -702,7 +696,9 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
}
default:
{
JERRY_UNREACHABLE ();
JERRY_ASSERT (curr_property_p->value == ECMA_BUILTIN_NUMBER_NAN);
num = ecma_number_make_nan ();
break;
}
}
@@ -739,18 +735,15 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
setter_p = ecma_builtin_make_function_object_for_setter_accessor (builtin_id, setter_id);
break;
}
case ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY:
default:
{
JERRY_ASSERT (curr_property_p->type == ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY);
is_accessor = true;
getter_p = ecma_builtin_make_function_object_for_getter_accessor (builtin_id,
curr_property_p->value);
break;
}
default:
{
JERRY_UNREACHABLE ();
return NULL;
}
}
ecma_property_t *prop_p;