Implement ES2015 class feature (part II.) (#2439)
This patch is the second milestone of the implementation of this new language element. Supported: - Single class inheritance - Functionality of 'super' keyword - Implicit constructor in class heritage - Specific behaviour while extending with the built-in 'Array' or '%TypedArray%' object - Abstract subclasses (Mix-ins) JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
committed by
Akos Kiss
parent
e0e6363f85
commit
d1860d0e34
@@ -24,6 +24,7 @@
|
||||
#include "ecma-number-arithmetic.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-function-object.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
@@ -43,14 +44,14 @@
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_create_array_object (const ecma_value_t *arguments_list_p, /**< list of arguments that
|
||||
are passed to Array constructor */
|
||||
* are passed to Array constructor */
|
||||
ecma_length_t arguments_list_len, /**< length of the arguments' list */
|
||||
bool is_treat_single_arg_as_length) /**< if the value is true,
|
||||
arguments_list_len is 1
|
||||
and single argument is Number,
|
||||
then treat the single argument
|
||||
as new Array's length rather
|
||||
than as single item of the Array */
|
||||
* arguments_list_len is 1
|
||||
* and single argument is Number,
|
||||
* then treat the single argument
|
||||
* as new Array's length rather
|
||||
* than as single item of the Array */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0
|
||||
|| arguments_list_p != NULL);
|
||||
@@ -131,6 +132,68 @@ ecma_op_create_array_object (const ecma_value_t *arguments_list_p, /**< list of
|
||||
return ecma_make_object_value (object_p);
|
||||
} /* ecma_op_create_array_object */
|
||||
|
||||
#ifndef CONFIG_DISABLE_ES2015_CLASS
|
||||
/**
|
||||
* Array object creation with custom prototype.
|
||||
*
|
||||
* See also: ECMA-262 v6, 9.4.2.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_create_array_object_by_constructor (const ecma_value_t *arguments_list_p, /**< list of arguments that
|
||||
* are passed to
|
||||
* Array constructor */
|
||||
ecma_length_t arguments_list_len, /**< length of the arguments' list */
|
||||
bool is_treat_single_arg_as_length, /**< if the value is true,
|
||||
* arguments_list_len is 1
|
||||
* and single argument is Number,
|
||||
* then treat the single argument
|
||||
* as new Array's length rather
|
||||
* than as single item of the
|
||||
* Array */
|
||||
ecma_object_t *object_p) /**< The object from whom the new array object
|
||||
* is being created */
|
||||
{
|
||||
ecma_value_t constructor_value = ecma_op_object_get_by_magic_id (object_p, LIT_MAGIC_STRING_CONSTRUCTOR);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (constructor_value)
|
||||
|| !ecma_is_value_object (constructor_value)
|
||||
|| !ecma_is_constructor (constructor_value))
|
||||
{
|
||||
ecma_free_value (constructor_value);
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("object.constructor is not a constructor."));
|
||||
}
|
||||
|
||||
ecma_object_t *constructor_object_p = ecma_get_object_from_value (constructor_value);
|
||||
ecma_value_t constructor_prototype = ecma_op_object_get_by_magic_id (constructor_object_p,
|
||||
LIT_MAGIC_STRING_PROTOTYPE);
|
||||
|
||||
ecma_deref_object (constructor_object_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (constructor_prototype))
|
||||
{
|
||||
return constructor_prototype;
|
||||
}
|
||||
|
||||
ecma_value_t result = ecma_op_create_array_object (arguments_list_p,
|
||||
arguments_list_len,
|
||||
is_treat_single_arg_as_length);
|
||||
|
||||
if (ecma_is_value_object (constructor_prototype))
|
||||
{
|
||||
ecma_object_t *result_object_p = ecma_get_object_from_value (result);
|
||||
ecma_object_t *constructor_prototpye_object_p = ecma_get_object_from_value (constructor_prototype);
|
||||
ECMA_SET_POINTER (result_object_p->prototype_or_outer_reference_cp, constructor_prototpye_object_p);
|
||||
}
|
||||
|
||||
ecma_free_value (constructor_prototype);
|
||||
|
||||
return result;
|
||||
} /* ecma_op_create_array_object_by_constructor */
|
||||
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
|
||||
|
||||
/**
|
||||
* Update the length of an array to a new length
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user