Removing construction of ecma_reference_t in get_variable_value and set_variable_value.

This commit is contained in:
Ruben Ayrapetyan
2014-11-20 22:04:41 +03:00
parent f5ffae0fec
commit 14ab1b3355
6 changed files with 119 additions and 90 deletions
+20 -20
View File
@@ -44,10 +44,11 @@
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_get_value_lex_env_base (ecma_reference_t ref) /**< ECMA-reference */
ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */
ecma_string_t *var_name_string_p, /**< variable name */
bool is_strict) /**< flag indicating strict mode */
{
const ecma_value_t base = ref.base;
const bool is_unresolvable_reference = ecma_is_value_undefined (base);
const bool is_unresolvable_reference = (ref_base_lex_env_p == NULL);
// 3.
if (unlikely (is_unresolvable_reference))
@@ -56,14 +57,13 @@ ecma_op_get_value_lex_env_base (ecma_reference_t ref) /**< ECMA-reference */
}
// 5.
ecma_object_t *lex_env_p = ECMA_GET_NON_NULL_POINTER(base.value);
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT(ref_base_lex_env_p != NULL
&& ecma_is_lexical_environment (ref_base_lex_env_p));
// 5.a
return ecma_op_get_binding_value (lex_env_p,
ECMA_GET_NON_NULL_POINTER (ref.referenced_name_cp),
ref.is_strict);
return ecma_op_get_binding_value (ref_base_lex_env_p,
var_name_string_p,
is_strict);
} /* ecma_op_get_value_lex_env_base */
/**
@@ -128,17 +128,18 @@ ecma_op_get_value_object_base (ecma_reference_t ref) /**< ECMA-reference */
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_put_value_lex_env_base (ecma_reference_t ref, /**< ECMA-reference */
ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */
ecma_string_t *var_name_string_p, /**< variable name */
bool is_strict, /**< flag indicating strict mode */
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 is_unresolvable_reference = (ref_base_lex_env_p == NULL);
// 3.
if (unlikely (is_unresolvable_reference))
{
// 3.a.
if (ref.is_strict)
if (is_strict)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
}
@@ -148,7 +149,7 @@ ecma_op_put_value_lex_env_base (ecma_reference_t ref, /**< ECMA-reference */
ecma_object_t *global_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
ecma_completion_value_t completion = ecma_op_object_put (global_object_p,
ECMA_GET_NON_NULL_POINTER (ref.referenced_name_cp),
var_name_string_p,
value,
false);
@@ -162,15 +163,14 @@ ecma_op_put_value_lex_env_base (ecma_reference_t ref, /**< ECMA-reference */
}
// 5.
ecma_object_t *lex_env_p = ECMA_GET_NON_NULL_POINTER(base.value);
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT(ref_base_lex_env_p != NULL
&& ecma_is_lexical_environment (ref_base_lex_env_p));
// 5.a
return ecma_op_set_mutable_binding (lex_env_p,
ECMA_GET_NON_NULL_POINTER (ref.referenced_name_cp),
return ecma_op_set_mutable_binding (ref_base_lex_env_p,
var_name_string_p,
value,
ref.is_strict);
is_strict);
} /* ecma_op_put_value_lex_env_base */
/**
+6 -2
View File
@@ -29,9 +29,13 @@
*/
/* ECMA-262 v5, 8.7.1 and 8.7.2 */
extern ecma_completion_value_t ecma_op_get_value_lex_env_base (ecma_reference_t ref);
extern ecma_completion_value_t ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
ecma_string_t *var_name_string_p,
bool is_strict);
extern ecma_completion_value_t ecma_op_get_value_object_base (ecma_reference_t ref);
extern ecma_completion_value_t ecma_op_put_value_lex_env_base (ecma_reference_t ref,
extern ecma_completion_value_t ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
ecma_string_t *var_name_string_p,
bool is_strict,
ecma_value_t value);
extern ecma_completion_value_t ecma_op_put_value_object_base (ecma_reference_t ref,
ecma_value_t value);
+39 -14
View File
@@ -29,6 +29,34 @@
* @{
*/
/**
* Resolve syntactic reference.
*
* @return if reference was resolved successfully,
* pointer to lexical environment - reference's base,
* else - NULL.
*/
ecma_object_t*
ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, /**< starting lexical environment */
ecma_string_t *name_p) /**< identifier's name */
{
JERRY_ASSERT(lex_env_p != NULL);
ecma_object_t *lex_env_iter_p = lex_env_p;
while (lex_env_iter_p != NULL)
{
if (ecma_op_has_binding (lex_env_iter_p, name_p))
{
return lex_env_iter_p;
}
lex_env_iter_p = ecma_get_lex_env_outer_reference (lex_env_iter_p);
}
return NULL;
} /* ecma_op_resolve_reference_base */
/**
* Resolve syntactic reference to ECMA-reference.
*
@@ -42,23 +70,20 @@ ecma_op_get_identifier_reference (ecma_object_t *lex_env_p, /**< lexical environ
{
JERRY_ASSERT(lex_env_p != NULL);
ecma_object_t *lex_env_iter_p = lex_env_p;
ecma_object_t *base_lex_env_p = ecma_op_resolve_reference_base (lex_env_p, name_p);
while (lex_env_iter_p != NULL)
if (base_lex_env_p != NULL)
{
if (ecma_op_has_binding (lex_env_iter_p, name_p))
{
return ecma_make_reference (ecma_make_object_value (lex_env_iter_p),
name_p,
is_strict);
}
lex_env_iter_p = ecma_get_lex_env_outer_reference (lex_env_iter_p);
return ecma_make_reference (ecma_make_object_value (base_lex_env_p),
name_p,
is_strict);
}
else
{
return ecma_make_reference (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
name_p,
is_strict);
}
return ecma_make_reference (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
name_p,
is_strict);
} /* ecma_op_get_identifier_reference */
/**
+3
View File
@@ -28,6 +28,9 @@
* @{
*/
extern ecma_object_t* ecma_op_resolve_reference_base (ecma_object_t *lex_env_p,
ecma_string_t *name_p);
extern ecma_reference_t ecma_op_get_identifier_reference (ecma_object_t *lex_env_p,
ecma_string_t *name_p,
bool is_strict);