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
+4 -10
View File
@@ -784,8 +784,9 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
ecma_free_value_if_not_object (ECMA_PROPERTY_VALUE_PTR (property_p)->value);
break;
}
case ECMA_PROPERTY_TYPE_NAMEDACCESSOR:
default:
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
#ifdef JERRY_CPOINTER_32_BIT
ecma_getter_setter_pointers_t *getter_setter_pair_p;
getter_setter_pair_p = ECMA_GET_POINTER (ecma_getter_setter_pointers_t,
@@ -794,11 +795,6 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
#endif /* JERRY_CPOINTER_32_BIT */
break;
}
default:
{
JERRY_UNREACHABLE ();
return;
}
}
if (ecma_is_property_lcached (property_p))
@@ -1056,8 +1052,9 @@ ecma_assert_object_contains_the_property (const ecma_object_t *object_p, /**< ec
prop_iter_p->next_property_cp);
}
while (prop_iter_p != NULL)
while (true)
{
JERRY_ASSERT (prop_iter_p != NULL);
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
@@ -1074,9 +1071,6 @@ ecma_assert_object_contains_the_property (const ecma_object_t *object_p, /**< ec
prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t,
prop_iter_p->next_property_cp);
}
JERRY_UNREACHABLE ();
#else /* JERRY_NDEBUG */
JERRY_UNUSED (object_p);
JERRY_UNUSED (prop_value_p);