Implement Object.create function
JerryScript-DCO-1.0-Signed-off-by: Kristof Kosztyo kkosztyo.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Peter Gal
parent
3f28cb3bf8
commit
61ab205130
@@ -637,7 +637,46 @@ ecma_builtin_object_object_create (ecma_value_t this_arg, /**< 'this' argument *
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg1) && !ecma_is_value_null (arg1))
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = NULL;
|
||||
|
||||
if (!ecma_is_value_null (arg1))
|
||||
{
|
||||
obj_p = ecma_get_object_from_value (arg1);
|
||||
}
|
||||
// 2-3.
|
||||
ecma_object_t *result_obj_p = ecma_op_create_object_object_noarg_and_set_prototype (obj_p);
|
||||
|
||||
// 4.
|
||||
if (!ecma_is_value_undefined (arg2))
|
||||
{
|
||||
ECMA_TRY_CATCH (obj,
|
||||
ecma_builtin_object_object_define_properties (this_arg,
|
||||
ecma_make_object_value (result_obj_p),
|
||||
arg2),
|
||||
ret_value);
|
||||
ECMA_FINALIZE (obj);
|
||||
}
|
||||
|
||||
// 5.
|
||||
if (ecma_is_completion_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_normal_completion_value (ecma_copy_value (ecma_make_object_value (result_obj_p),
|
||||
true));
|
||||
}
|
||||
|
||||
ecma_deref_object (result_obj_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_create */
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,18 +62,10 @@ ecma_op_create_object_object_noarg (void)
|
||||
ecma_object_t *object_prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
|
||||
// 3., 4., 6., 7.
|
||||
ecma_object_t *obj_p = ecma_create_object (object_prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
|
||||
ecma_object_t *obj_p = ecma_op_create_object_object_noarg_and_set_prototype (object_prototype_p);
|
||||
|
||||
ecma_deref_object (object_prototype_p);
|
||||
|
||||
/*
|
||||
* [[Class]] property of ECMA_OBJECT_TYPE_GENERAL type objects
|
||||
* without ECMA_INTERNAL_PROPERTY_CLASS internal property
|
||||
* is "Object".
|
||||
*
|
||||
* See also: ecma_object_get_class_name
|
||||
*/
|
||||
|
||||
return obj_p;
|
||||
} /* ecma_op_create_object_object_noarg */
|
||||
|
||||
@@ -109,6 +101,32 @@ ecma_op_create_object_object_arg (ecma_value_t value) /**< argument of construct
|
||||
}
|
||||
} /* ecma_op_create_object_object_arg */
|
||||
|
||||
/**
|
||||
* Object creation operation with no arguments.
|
||||
* It sets the given prototype to the newly created object.
|
||||
*
|
||||
* See also: ECMA-262 v5, 15.2.2.1, 15.2.3.5
|
||||
*
|
||||
* @return pointer to newly created object
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_op_create_object_object_noarg_and_set_prototype (ecma_object_t *object_prototype_p) /**< pointer to prototype of
|
||||
the object
|
||||
(can be NULL) */
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_create_object (object_prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
|
||||
|
||||
/*
|
||||
* [[Class]] property of ECMA_OBJECT_TYPE_GENERAL type objects
|
||||
* without ECMA_INTERNAL_PROPERTY_CLASS internal property
|
||||
* is "Object".
|
||||
*
|
||||
* See also: ecma_object_get_class_name
|
||||
*/
|
||||
|
||||
return obj_p;
|
||||
} /* ecma_op_create_object_object_noarg_and_set_prototype */
|
||||
|
||||
/**
|
||||
* [[Get]] ecma general object's operation
|
||||
*
|
||||
|
||||
@@ -26,8 +26,9 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_object_t* ecma_op_create_object_object_noarg (void);
|
||||
extern ecma_object_t *ecma_op_create_object_object_noarg (void);
|
||||
extern ecma_completion_value_t ecma_op_create_object_object_arg (ecma_value_t value);
|
||||
extern ecma_object_t *ecma_op_create_object_object_noarg_and_set_prototype (ecma_object_t *object_prototype_p);
|
||||
|
||||
extern ecma_completion_value_t ecma_op_general_object_get (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
|
||||
Reference in New Issue
Block a user