Implement the core of Proxy object (#3562)
- Internal routines of the of the proxy object are unimplemented - For-in enumerate with proxy target is currently not supported JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -167,8 +167,7 @@ opfunc_in (ecma_value_t left_value, /**< left value */
|
||||
}
|
||||
|
||||
ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value);
|
||||
ecma_value_t result = ecma_make_boolean_value (ecma_op_object_has_property (right_value_obj_p,
|
||||
property_name_p));
|
||||
ecma_value_t result = ecma_op_object_has_property (right_value_obj_p, property_name_p);
|
||||
ecma_deref_ecma_string (property_name_p);
|
||||
return result;
|
||||
} /* opfunc_in */
|
||||
|
||||
+33
-9
@@ -44,13 +44,25 @@
|
||||
* '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
|
||||
*/
|
||||
inline void JERRY_ATTR_ALWAYS_INLINE
|
||||
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 */
|
||||
{
|
||||
if (!ecma_op_has_binding (lex_env_p, var_name_str_p))
|
||||
ecma_value_t has_binding = ecma_op_has_binding (lex_env_p, var_name_str_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (has_binding))
|
||||
{
|
||||
return has_binding;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_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,
|
||||
@@ -65,12 +77,17 @@ vm_var_decl (ecma_object_t *lex_env_p, /**< target lexical environment */
|
||||
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
|
||||
*/
|
||||
inline void JERRY_ATTR_ALWAYS_INLINE
|
||||
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 */
|
||||
@@ -83,12 +100,9 @@ vm_set_var (ecma_object_t *lex_env_p, /**< target lexical environment */
|
||||
|| ecma_is_value_empty (put_value_result)
|
||||
|| ECMA_IS_VALUE_ERROR (put_value_result));
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (put_value_result))
|
||||
{
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
|
||||
ecma_free_value (lit_value);
|
||||
|
||||
return put_value_result;
|
||||
} /* vm_set_var */
|
||||
|
||||
/**
|
||||
@@ -206,7 +220,7 @@ vm_op_delete_prop (ecma_value_t object, /**< base object */
|
||||
JERRY_ASSERT (!ecma_is_lexical_environment (obj_p));
|
||||
|
||||
ecma_value_t delete_op_ret = ecma_op_object_delete (obj_p, name_string_p, is_strict);
|
||||
JERRY_ASSERT (ecma_is_value_boolean (delete_op_ret) || (is_strict == true && ECMA_IS_VALUE_ERROR (delete_op_ret)));
|
||||
JERRY_ASSERT (ecma_is_value_boolean (delete_op_ret) || ECMA_IS_VALUE_ERROR (delete_op_ret));
|
||||
ecma_deref_object (obj_p);
|
||||
ecma_deref_ecma_string (name_string_p);
|
||||
|
||||
@@ -229,6 +243,13 @@ vm_op_delete_var (ecma_value_t name_literal, /**< name literal */
|
||||
|
||||
ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (lex_env_p, var_name_str_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (JERRY_UNLIKELY (ref_base_lex_env_p == ECMA_OBJECT_POINTER_ERROR))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ref_base_lex_env_p == NULL)
|
||||
{
|
||||
completion_value = ECMA_VALUE_TRUE;
|
||||
@@ -267,6 +288,9 @@ opfunc_for_in (ecma_value_t left_value, /**< left value */
|
||||
/* ecma_op_to_object will only raise error on null/undefined values but those are handled above. */
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_expr_value));
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (obj_p));
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE_PROTOTYPE);
|
||||
|
||||
if (prop_names_p->item_count != 0)
|
||||
|
||||
@@ -56,10 +56,10 @@ typedef enum
|
||||
*/
|
||||
#define OPFUNC_HAS_SPREAD_ELEMENT (1 << 8)
|
||||
|
||||
void
|
||||
ecma_value_t
|
||||
vm_var_decl (ecma_object_t *lex_env_p, ecma_string_t *var_name_str_p, bool is_configurable_bindings);
|
||||
|
||||
void
|
||||
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
|
||||
|
||||
+58
-7
@@ -185,7 +185,7 @@ vm_op_set_value (ecma_value_t object, /**< base object */
|
||||
}
|
||||
|
||||
object_p = ecma_get_object_from_value (to_object);
|
||||
ecma_set_object_extensible (object_p, false);
|
||||
ecma_op_ordinary_object_prevent_extensions (object_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1321,11 +1321,21 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) && !JERRY_NDEBUG */
|
||||
|
||||
vm_var_decl (lex_env_p, name_p, frame_ctx_p->is_eval_code);
|
||||
result = vm_var_decl (lex_env_p, name_p, frame_ctx_p->is_eval_code);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (lit_value != ECMA_VALUE_UNDEFINED)
|
||||
{
|
||||
vm_set_var (lex_env_p, name_p, is_strict, lit_value);
|
||||
result = vm_set_var (lex_env_p, name_p, is_strict, lit_value);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -1423,7 +1433,22 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp);
|
||||
}
|
||||
|
||||
if (binding_p != NULL || ecma_op_has_binding (lex_env_p, literal_name_p))
|
||||
if (binding_p != NULL)
|
||||
{
|
||||
result = ecma_raise_syntax_error (ECMA_ERR_MSG ("Local variable is redeclared."));
|
||||
goto error;
|
||||
}
|
||||
|
||||
result = ecma_op_has_binding (lex_env_p, literal_name_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_true (result))
|
||||
{
|
||||
result = ecma_raise_syntax_error (ECMA_ERR_MSG ("Local variable is redeclared."));
|
||||
goto error;
|
||||
@@ -1486,7 +1511,13 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) && !JERRY_NDEBUG */
|
||||
|
||||
vm_set_var (lex_env_p, name_p, is_strict, left_value);
|
||||
result = vm_set_var (lex_env_p, name_p, is_strict, left_value);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
case VM_OC_CLONE_CONTEXT:
|
||||
@@ -3421,6 +3452,20 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
|
||||
JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ecma_is_value_object (value)
|
||||
&& ECMA_OBJECT_IS_PROXY (ecma_get_object_from_value (value)))
|
||||
{
|
||||
/* Note: - For proxy objects we should create a new object which implements the iterable protocol,
|
||||
and iterates through the enumerated collection below.
|
||||
- This inkoves that the VM context type should be adjusted and checked in all FOR-IN related
|
||||
instruction.
|
||||
- For other objects we should keep the current implementation due to performance reasons.*/
|
||||
result = ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy support in for-in."));
|
||||
goto error;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t expr_obj_value = ECMA_VALUE_UNDEFINED;
|
||||
ecma_collection_t *prop_names_p = opfunc_for_in (value, &expr_obj_value);
|
||||
ecma_free_value (value);
|
||||
@@ -3478,12 +3523,17 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[-4]);
|
||||
uint32_t index = stack_top_p[-3];
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p));
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
while (index < collection_p->item_count)
|
||||
{
|
||||
ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (buffer_p[index]);
|
||||
|
||||
if (JERRY_LIKELY (ecma_op_object_has_property (object_p, prop_name_p)))
|
||||
result = ecma_op_object_has_property (object_p, prop_name_p);
|
||||
|
||||
if (JERRY_LIKELY (ecma_is_value_true (result)))
|
||||
{
|
||||
byte_code_p = byte_code_start_p + branch_offset;
|
||||
break;
|
||||
@@ -4088,7 +4138,8 @@ error:
|
||||
/**
|
||||
* Initialize code block execution
|
||||
*
|
||||
* @return ecma value
|
||||
* @return ECMA_VALUE_ERROR - if the initialization fails
|
||||
* ECMA_VALUE_EMPTY - otherwise
|
||||
*/
|
||||
static void JERRY_ATTR_NOINLINE
|
||||
vm_init_exec (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
|
||||
|
||||
Reference in New Issue
Block a user