Remove unused internal functions

The internals have surprisingly large number of unused functions at
surprising places. This patch cleans them out to make maintenance
easier and to prevent dead code having effect on future decisions.

The patch intentionally does not try to clean up public API but
focuses on internal modules only that are/should not be reachable
from "outside".

However, unit tests do access private API, thus tests of literal
storage had to be adjusted.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2016-04-21 12:11:44 +02:00
parent a87aca4d84
commit 27682017e9
15 changed files with 31 additions and 919 deletions
@@ -1270,39 +1270,6 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
return ch;
} /* ecma_string_get_char_at_pos */
/**
* Get byte from specified position in the ecma-string.
*
* @return byte value
*/
lit_utf8_byte_t
ecma_string_get_byte_at_pos (const ecma_string_t *string_p, /**< ecma-string */
lit_utf8_size_t index) /**< byte index */
{
lit_utf8_size_t buffer_size;
bool is_ascii;
const lit_utf8_byte_t *chars_p = ecma_string_raw_chars (string_p, &buffer_size, &is_ascii);
JERRY_ASSERT (index < buffer_size);
if (chars_p != NULL)
{
return chars_p[index];
}
lit_utf8_byte_t byte;
MEM_DEFINE_LOCAL_ARRAY (utf8_str_p, buffer_size, lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (string_p, utf8_str_p, buffer_size);
JERRY_ASSERT (sz == buffer_size);
byte = utf8_str_p[index];
MEM_FINALIZE_LOCAL_ARRAY (utf8_str_p);
return byte;
} /* ecma_string_get_byte_at_pos */
/**
* Get specified magic string
*
@@ -1350,31 +1317,6 @@ ecma_is_string_magic_longpath (const ecma_string_t *string_p, /**< ecma-string *
return lit_is_utf8_string_magic (utf8_str_p, utf8_str_size, out_id_p);
} /* ecma_is_string_magic_longpath */
/**
* Long path part of ecma_is_ex_string_magic
*
* Converts passed ecma-string to zt-string and
* checks if it is equal to one of magic string
*
* @return true - if magic string equal to passed string was found,
* false - otherwise.
*/
static bool
ecma_is_ex_string_magic_longpath (const ecma_string_t *string_p, /**< ecma-string */
lit_magic_string_ex_id_t *out_id_p) /**< [out] external magic string's id */
{
lit_utf8_size_t utf8_str_size;
bool is_ascii;
const lit_utf8_byte_t *utf8_str_p = ecma_string_raw_chars (string_p, &utf8_str_size, &is_ascii);
if (utf8_str_p == NULL || !is_ascii)
{
return false;
}
return lit_is_ex_utf8_string_magic (utf8_str_p, utf8_str_size, out_id_p);
} /* ecma_is_ex_string_magic_longpath */
/**
* Check if passed string equals to one of magic strings
* and if equal magic string was found, return it's id in 'out_id_p' argument.
@@ -1408,39 +1350,6 @@ ecma_is_string_magic (const ecma_string_t *string_p, /**< ecma-string */
}
} /* ecma_is_string_magic */
/**
* Check if passed string equals to one of external magic strings
* and if equal external magic string was found, return it's id in 'out_id_p' argument.
*
* @return true - if external magic string equal to passed string was found,
* false - otherwise.
*/
bool
ecma_is_ex_string_magic (const ecma_string_t *string_p, /**< ecma-string */
lit_magic_string_ex_id_t *out_id_p) /**< [out] external magic string's id */
{
if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX)
{
JERRY_ASSERT (string_p->u.magic_string_ex_id < lit_get_magic_string_ex_count ());
*out_id_p = (lit_magic_string_ex_id_t) string_p->u.magic_string_ex_id;
return true;
}
else
{
/*
* Any ecma-string constructor except ecma_concat_ecma_strings
* should return ecma-string with ECMA_STRING_CONTAINER_MAGIC_STRING_EX
* container type if new ecma-string's content is equal to one of external magic strings.
*/
JERRY_ASSERT (ecma_string_get_length (string_p) > LIT_MAGIC_STRING_LENGTH_LIMIT
|| !ecma_is_ex_string_magic_longpath (string_p, out_id_p));
return false;
}
} /* ecma_is_ex_string_magic */
/**
* Try to calculate hash of the ecma-string
*
-2
View File
@@ -168,12 +168,10 @@ extern bool ecma_compare_ecma_strings_relational (const ecma_string_t *, const e
extern ecma_length_t ecma_string_get_length (const ecma_string_t *);
extern lit_utf8_size_t ecma_string_get_size (const ecma_string_t *);
extern ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *, ecma_length_t);
extern lit_utf8_byte_t ecma_string_get_byte_at_pos (const ecma_string_t *, lit_utf8_size_t);
extern ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t);
extern ecma_string_t *ecma_get_magic_string_ex (lit_magic_string_ex_id_t);
extern bool ecma_is_string_magic (const ecma_string_t *, lit_magic_string_id_t *);
extern bool ecma_is_ex_string_magic (const ecma_string_t *, lit_magic_string_ex_id_t *);
extern lit_string_hash_t ecma_string_hash (const ecma_string_t *);
extern ecma_string_t *ecma_string_substr (const ecma_string_t *, ecma_length_t, ecma_length_t);
@@ -909,29 +909,6 @@ ecma_date_set_internal_property (ecma_value_t this_arg, /**< this argument */
return ecma_make_number_value (value_p);
} /* ecma_date_set_internal_property */
/**
* Insert leading zeros to a string of a number if needed.
*/
void
ecma_date_insert_leading_zeros (ecma_string_t **str_p, /**< [in,out] ecma string */
ecma_number_t num, /**< input number */
uint32_t length) /**< length of string of number */
{
JERRY_ASSERT (length >= 1);
/* If the length is bigger than the number of digits in num, then insert leding zeros. */
uint32_t first_index = length - 1u;
ecma_number_t power_i = (ecma_number_t) pow (10, first_index);
for (uint32_t i = first_index; i > 0 && num < power_i; i--, power_i /= 10)
{
ecma_string_t *zero_str_p = ecma_new_ecma_string_from_uint32 (0);
ecma_string_t *concat_p = ecma_concat_ecma_strings (zero_str_p, *str_p);
ecma_deref_ecma_string (zero_str_p);
ecma_deref_ecma_string (*str_p);
*str_p = concat_p;
}
} /* ecma_date_insert_leading_zeros */
/**
* Common function to copy utf8 characters.
*
@@ -119,7 +119,6 @@ extern ecma_number_t ecma_date_time_clip (ecma_number_t);
extern ecma_number_t ecma_date_timezone_offset (ecma_number_t);
extern ecma_value_t ecma_date_set_internal_property (ecma_value_t, ecma_number_t,
ecma_number_t, ecma_date_timezone_t);
extern void ecma_date_insert_leading_zeros (ecma_string_t **, ecma_number_t, uint32_t);
extern ecma_value_t ecma_date_value_to_string (ecma_number_t);
extern ecma_value_t ecma_date_value_to_utc_string (ecma_number_t);
@@ -921,98 +921,6 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
return ret_value;
} /* ecma_op_function_construct */
/**
* Function declaration.
*
* See also: ECMA-262 v5, 10.5 - Declaration binding instantiation (block 5).
*
* @return ecma value
* returned value must be freed with ecma_free_value.
*/
ecma_value_t
ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *function_name_p, /**< function name */
const ecma_compiled_code_t *bytecode_data_p, /**< bytecode data */
bool is_decl_in_strict_mode, /**< flag, indicating if function is
* declared in strict mode code */
bool is_configurable_bindings) /**< flag indicating whether function
* is declared in eval code */
{
// b.
ecma_object_t *func_obj_p = ecma_op_create_function_object (lex_env_p,
is_decl_in_strict_mode,
bytecode_data_p);
// c.
bool func_already_declared = ecma_op_has_binding (lex_env_p, function_name_p);
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
// d.
if (!func_already_declared)
{
ecma_value_t completion = ecma_op_create_mutable_binding (lex_env_p,
function_name_p,
is_configurable_bindings);
JERRY_ASSERT (ecma_is_value_empty (completion));
}
else if (ecma_is_lexical_environment_global (lex_env_p))
{
// e.
ecma_object_t *glob_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
ecma_property_t *existing_prop_p = ecma_op_object_get_property (glob_obj_p, function_name_p);
if (ecma_is_property_configurable (existing_prop_p))
{
ecma_value_t completion;
completion = ecma_builtin_helper_def_prop (glob_obj_p,
function_name_p,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
true, /* Writable */
true, /* Enumerable */
is_configurable_bindings, /* Configurable */
true); /* Failure handling */
JERRY_ASSERT (ecma_is_value_true (completion));
}
else if (ECMA_PROPERTY_GET_TYPE (existing_prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
}
else
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (existing_prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA);
if (!ecma_is_property_writable (existing_prop_p)
|| !ecma_is_property_enumerable (existing_prop_p))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
}
}
ecma_deref_object (glob_obj_p);
}
if (ecma_is_value_empty (ret_value))
{
// f.
ret_value = ecma_op_set_mutable_binding (lex_env_p,
function_name_p,
ecma_make_object_value (func_obj_p),
is_decl_in_strict_mode);
}
else
{
JERRY_ASSERT (ecma_is_value_error (ret_value));
}
ecma_deref_object (func_obj_p);
return ret_value;
} /* ecma_op_function_declaration */
/**
* @}
* @}
@@ -53,10 +53,6 @@ ecma_op_function_construct (ecma_object_t *, const ecma_value_t *, ecma_length_t
extern ecma_value_t
ecma_op_function_has_instance (ecma_object_t *, ecma_value_t);
extern ecma_value_t
ecma_op_function_declaration (ecma_object_t *, ecma_string_t *,
const ecma_compiled_code_t *, bool, bool);
/**
* @}
* @}
@@ -207,133 +207,6 @@ ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< referenc
is_strict);
} /* ecma_op_put_value_lex_env_base */
/**
* Reject sequence for PutValue
*
* @return ecma value
* Returned value must be freed with ecma_free_value
*/
static ecma_value_t
ecma_reject_put (bool is_throw) /**< Throw flag */
{
if (is_throw)
{
return ecma_raise_type_error (ECMA_ERR_MSG (""));
}
else
{
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
}
} /* ecma_reject_put */
/**
* PutValue operation part (object base).
*
* See also: ECMA-262 v5, 8.7.2, section 4
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
ecma_value_t
ecma_op_put_value_object_base (ecma_reference_t ref, /**< ECMA-reference */
ecma_value_t value) /**< ECMA-value */
{
const ecma_value_t base = ref.base;
const bool is_unresolvable_reference = ecma_is_value_undefined (base);
const bool has_primitive_base = (ecma_is_value_boolean (base)
|| ecma_is_value_number (base)
|| ecma_is_value_string (base));
const bool has_object_base = (ecma_is_value_object (base)
&& !(ecma_is_lexical_environment (ecma_get_object_from_value (base))));
const bool is_property_reference = has_primitive_base || has_object_base;
JERRY_ASSERT (!is_unresolvable_reference);
JERRY_ASSERT (is_property_reference);
// 4.a
if (!has_primitive_base)
{
// 4.b case 1
ecma_object_t *obj_p = ecma_get_object_from_value (base);
JERRY_ASSERT (obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ECMA_TRY_CATCH (put_ret_value,
ecma_op_object_put (obj_p,
ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ref.referenced_name_cp),
value,
ref.is_strict),
ret_value);
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ECMA_FINALIZE (put_ret_value);
return ret_value;
}
else
{
// 4.b case 2
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
// sub_1.
ECMA_TRY_CATCH (obj_base, ecma_op_to_object (base), ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_base);
JERRY_ASSERT (obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
ecma_string_t *referenced_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ref.referenced_name_cp);
// sub_2.
if (!ecma_op_object_can_put (obj_p, referenced_name_p))
{
ret_value = ecma_reject_put (ref.is_strict);
}
else
{
// sub_3.
ecma_property_t *own_prop_p = ecma_op_object_get_own_property (obj_p, referenced_name_p);
// sub_5.
ecma_property_t *prop_p = ecma_op_object_get_property (obj_p, referenced_name_p);
// sub_4., sub_7
if ((own_prop_p != NULL && ECMA_PROPERTY_GET_TYPE (own_prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA)
|| (prop_p == NULL)
|| ECMA_PROPERTY_GET_TYPE (prop_p) != ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
{
ret_value = ecma_reject_put (ref.is_strict);
}
else
{
// sub_6.
JERRY_ASSERT (prop_p != NULL && ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
ecma_object_t *setter_p = ecma_get_named_accessor_property_setter (prop_p);
JERRY_ASSERT (setter_p != NULL);
ECMA_TRY_CATCH (call_ret,
ecma_op_function_call (setter_p, base, &value, 1),
ret_value);
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ECMA_FINALIZE (call_ret);
}
}
ECMA_FINALIZE (obj_base);
return ret_value;
}
} /* ecma_op_put_value_object_base */
/**
* @}
* @}
-15
View File
@@ -81,21 +81,6 @@ ecma_get_global_environment (void)
return ecma_global_lex_env_p;
} /* ecma_get_global_environment */
/**
* Figure out whether the lexical environment is global.
*
* @return true - if lexical environment is object-bound and corresponding object is global object,
* false - otherwise.
*/
bool
ecma_is_lexical_environment_global (ecma_object_t *lex_env_p) /**< lexical environment */
{
JERRY_ASSERT (lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
return (lex_env_p == ecma_global_lex_env_p);
} /* ecma_is_lexical_environment_global */
/**
* @}
*/
@@ -33,7 +33,6 @@
extern void ecma_init_environment (void);
extern void ecma_finalize_environment (void);
extern ecma_object_t *ecma_get_global_environment (void);
extern bool ecma_is_lexical_environment_global (ecma_object_t *);
/**
* @}
@@ -43,7 +42,6 @@ extern bool ecma_is_lexical_environment_global (ecma_object_t *);
extern ecma_value_t ecma_op_get_value_lex_env_base (ecma_object_t *, ecma_string_t *, bool);
extern ecma_value_t ecma_op_get_value_object_base (ecma_reference_t);
extern ecma_value_t ecma_op_put_value_lex_env_base (ecma_object_t *, ecma_string_t *, bool, ecma_value_t);
extern ecma_value_t ecma_op_put_value_object_base (ecma_reference_t, ecma_value_t);
/* ECMA-262 v5, Table 17. Abstract methods of Environment Records */
extern bool ecma_op_has_binding (ecma_object_t *, ecma_string_t *);