Optimize lexenv binding creation (#4502)

- Declarative environment no longer need to lookup the created binding for setting it's value
- Unfold vm_decl_var and vm_set_var into vm_loop to reduce error checks
- Reduce code duplication in ecma_module_connect_imports
- Fix deleted binding setting in `ecma_op_set_mutable_binding` (fixes #4468)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2021-01-18 17:38:54 +01:00
committed by GitHub
parent 3b77117a2e
commit 2ade072e53
8 changed files with 104 additions and 119 deletions
-72
View File
@@ -40,78 +40,6 @@
* @{
*/
/**
* 'Variable declaration' opcode handler.
*
* See also: ECMA-262 v5, 10.5 - Declaration binding instantiation (block 8).
*
* @return ECMA_VALUE_ERROR - if no the operation fails
* ECMA_VALUE_EMPTY - otherwise
*/
extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
vm_var_decl (ecma_object_t *lex_env_p, /**< target lexical environment */
ecma_string_t *var_name_str_p, /**< variable name */
bool is_configurable_bindings) /**< true if the binding can be deleted */
{
ecma_value_t has_binding = ecma_op_has_binding (lex_env_p, var_name_str_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (has_binding))
{
return has_binding;
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
if (ecma_is_value_false (has_binding))
{
ecma_value_t completion_value = ecma_op_create_mutable_binding (lex_env_p,
var_name_str_p,
is_configurable_bindings);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (completion_value))
{
return completion_value;
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
JERRY_ASSERT (ecma_is_value_empty (completion_value));
/* Skipping SetMutableBinding as we have already checked that there were not
* any binding with specified name in current lexical environment
* and CreateMutableBinding sets the created binding's value to undefined */
JERRY_ASSERT (ecma_is_value_undefined (ecma_op_get_binding_value (lex_env_p,
var_name_str_p,
vm_is_strict_mode ())));
}
return ECMA_VALUE_EMPTY;
} /* vm_var_decl */
/**
* Set var binding to a function literal value.
*
* @return ECMA_VALUE_ERROR - if no the operation fails
* ECMA_VALUE_EMPTY - otherwise
*/
extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
vm_set_var (ecma_object_t *lex_env_p, /**< target lexical environment */
ecma_string_t *var_name_str_p, /**< variable name */
bool is_strict, /**< true, if the engine is in strict mode */
ecma_value_t lit_value) /**< function value */
{
ecma_value_t put_value_result;
put_value_result = ecma_op_put_value_lex_env_base (lex_env_p, var_name_str_p, is_strict, lit_value);
JERRY_ASSERT (ecma_is_value_boolean (put_value_result)
|| ecma_is_value_empty (put_value_result)
|| ECMA_IS_VALUE_ERROR (put_value_result));
ecma_free_value (lit_value);
return put_value_result;
} /* vm_set_var */
/**
* 'typeof' opcode handler.
*
-6
View File
@@ -71,12 +71,6 @@ typedef enum
*/
#define OPFUNC_HAS_SPREAD_ELEMENT (1 << 8)
ecma_value_t
vm_var_decl (ecma_object_t *lex_env_p, ecma_string_t *var_name_str_p, bool is_configurable_bindings);
ecma_value_t
vm_set_var (ecma_object_t *lex_env_p, ecma_string_t *var_name_str_p, bool is_strict, ecma_value_t lit_value);
ecma_value_t
opfunc_equality (ecma_value_t left_value, ecma_value_t right_value);
+33 -4
View File
@@ -1395,23 +1395,52 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
}
#endif /* ENABLED (JERRY_ESNEXT) && !JERRY_NDEBUG */
result = vm_var_decl (lex_env_p, name_p, (frame_ctx_p->status_flags & VM_FRAME_CTX_DIRECT_EVAL) != 0);
/* 'Variable declaration' */
result = ecma_op_has_binding (lex_env_p, name_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (ECMA_IS_VALUE_ERROR (result))
{
goto error;
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
if (lit_value != ECMA_VALUE_UNDEFINED)
ecma_property_t *prop_p = NULL;
if (ecma_is_value_false (result))
{
result = vm_set_var (lex_env_p, name_p, is_strict, lit_value);
bool is_configurable = (frame_ctx_p->status_flags & VM_FRAME_CTX_DIRECT_EVAL) != 0;
prop_p = ecma_op_create_mutable_binding (lex_env_p, name_p, is_configurable);
if (ECMA_IS_VALUE_ERROR (result))
if (JERRY_UNLIKELY (prop_p == ECMA_PROPERTY_POINTER_ERROR))
{
result = ECMA_VALUE_ERROR;
goto error;
}
}
if (lit_value != ECMA_VALUE_UNDEFINED)
{
JERRY_ASSERT (ecma_is_value_object (lit_value));
if (prop_p != NULL)
{
JERRY_ASSERT (ecma_is_value_undefined (ECMA_PROPERTY_VALUE_PTR (prop_p)->value));
JERRY_ASSERT (ecma_is_property_writable (*prop_p));
ECMA_PROPERTY_VALUE_PTR (prop_p)->value = lit_value;
ecma_free_object (lit_value);
}
else
{
result = ecma_op_put_value_lex_env_base (lex_env_p, name_p, is_strict, lit_value);
ecma_free_object (lit_value);
if (ECMA_IS_VALUE_ERROR (result))
{
goto error;
}
}
}
continue;
}
#if ENABLED (JERRY_ESNEXT)