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:
@@ -82,12 +82,6 @@ ecma_new_standard_error (ecma_standard_error_t error_type) /**< native error typ
|
||||
|
||||
switch (error_type)
|
||||
{
|
||||
case ECMA_ERROR_COMMON:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_EVAL:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE;
|
||||
@@ -124,9 +118,11 @@ ecma_new_standard_error (ecma_standard_error_t error_type) /**< native error typ
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_NONE:
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
JERRY_ASSERT (error_type == ECMA_ERROR_COMMON);
|
||||
|
||||
prototype_id = ECMA_BUILTIN_ID_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,18 +169,15 @@ ecma_op_general_object_delete (ecma_object_t *obj_p, /**< the object */
|
||||
/* b. */
|
||||
return ECMA_VALUE_TRUE;
|
||||
}
|
||||
else if (is_throw)
|
||||
|
||||
/* 4. */
|
||||
if (is_throw)
|
||||
{
|
||||
/* 4. */
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Expected a configurable property."));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 5. */
|
||||
return ECMA_VALUE_FALSE;
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
/* 5. */
|
||||
return ECMA_VALUE_FALSE;
|
||||
} /* ecma_op_general_object_delete */
|
||||
|
||||
/**
|
||||
|
||||
@@ -1136,18 +1136,24 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
is_throw);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (type == ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
#ifndef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS)
|
||||
{
|
||||
#else /* CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */
|
||||
JERRY_ASSERT (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS);
|
||||
#endif /* !CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */
|
||||
return ecma_op_arguments_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
|
||||
}
|
||||
/* ES2015 9.4.5.3 */
|
||||
if (ecma_is_typedarray (ecma_make_object_value (obj_p)))
|
||||
{
|
||||
@@ -1184,19 +1190,10 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (false);
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
|
||||
return ecma_reject (is_throw);
|
||||
} /* ecma_op_object_define_own_property */
|
||||
|
||||
/**
|
||||
@@ -1391,10 +1388,6 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
#ifndef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
|
||||
@@ -1454,7 +1447,8 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
JERRY_ASSERT (type == ECMA_OBJECT_TYPE_GENERAL);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1795,10 +1789,6 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */
|
||||
|
||||
switch (ext_obj_p->u.pseudo_array.type)
|
||||
{
|
||||
case ECMA_PSEUDO_ARRAY_ARGUMENTS:
|
||||
{
|
||||
return LIT_MAGIC_STRING_ARGUMENTS_UL;
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY:
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO:
|
||||
@@ -1808,11 +1798,12 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */
|
||||
#endif /* !CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
JERRY_ASSERT (ext_obj_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS);
|
||||
|
||||
return LIT_MAGIC_STRING_ARGUMENTS_UL;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
|
||||
@@ -364,21 +364,19 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
const lit_utf8_byte_t *str_p, /**< input string pointer */
|
||||
const lit_utf8_byte_t **out_str_p) /**< [out] matching substring iterator */
|
||||
{
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
re_opcode_t op;
|
||||
|
||||
const lit_utf8_byte_t *str_curr_p = str_p;
|
||||
|
||||
while ((op = re_get_opcode (&bc_p)))
|
||||
while (true)
|
||||
{
|
||||
re_opcode_t op = re_get_opcode (&bc_p);
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case RE_OP_MATCH:
|
||||
{
|
||||
JERRY_TRACE_MSG ("Execute RE_OP_MATCH: match\n");
|
||||
*out_str_p = str_curr_p;
|
||||
ret_value = ECMA_VALUE_TRUE;
|
||||
return ret_value; /* match */
|
||||
return ECMA_VALUE_TRUE; /* match */
|
||||
}
|
||||
case RE_OP_CHAR:
|
||||
{
|
||||
@@ -1086,8 +1084,10 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
}
|
||||
return ECMA_VALUE_FALSE; /* fail */
|
||||
}
|
||||
case RE_OP_GREEDY_ITERATOR:
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (op == RE_OP_GREEDY_ITERATOR);
|
||||
|
||||
uint32_t min, max, offset, num_of_iter;
|
||||
const lit_utf8_byte_t *sub_str_p = NULL;
|
||||
|
||||
@@ -1142,16 +1142,8 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
}
|
||||
return ECMA_VALUE_FALSE; /* fail */
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_TRACE_MSG ("UNKNOWN opcode (%u)!\n", (unsigned int) op);
|
||||
return ecma_raise_common_error (ECMA_ERR_MSG ("Unknown RegExp opcode."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
return ECMA_VALUE_FALSE; /* fail */
|
||||
} /* re_match_regexp */
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,7 +94,6 @@ ecma_get_typedarray_element (lit_utf8_byte_t *src, /**< the location in the inte
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} /* ecma_get_typedarray_element */
|
||||
|
||||
Reference in New Issue
Block a user