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:
Robert Fancsik
2018-10-25 16:00:48 +02:00
committed by Akos Kiss
parent e0e6363f85
commit d1860d0e34
54 changed files with 2543 additions and 199 deletions
+69 -6
View File
@@ -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
*
@@ -43,6 +43,12 @@ ecma_value_t
ecma_op_create_array_object (const ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len,
bool is_treat_single_arg_as_length);
#ifndef CONFIG_DISABLE_ES2015_CLASS
ecma_value_t
ecma_op_create_array_object_by_constructor (const ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len,
bool is_treat_single_arg_as_length, ecma_object_t *object_p);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
ecma_value_t
ecma_op_array_object_set_length (ecma_object_t *object_p, ecma_value_t new_value, uint32_t flags);
+6 -3
View File
@@ -22,10 +22,7 @@
#include "ecma-lex-env.h"
#include "js-parser.h"
#include "vm.h"
#ifdef JERRY_ENABLE_LINE_INFO
#include "jcontext.h"
#endif /* JERRY_ENABLE_LINE_INFO */
/** \addtogroup ecma ECMA
* @{
@@ -98,6 +95,12 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
#endif /* JERRY_ENABLE_LINE_INFO */
#ifndef CONFIG_DISABLE_ES2015_CLASS
parse_opts |= ECMA_GET_SUPER_EVAL_PARSER_OPTS ();
ECMA_CLEAR_SUPER_EVAL_PARSER_OPTS ();
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
ecma_value_t parse_status = parser_parse_script (NULL,
0,
code_p,
+236 -13
View File
@@ -453,12 +453,165 @@ ecma_op_function_has_construct_flag (const ecma_value_t *arguments_list_p) /**<
{
#ifndef CONFIG_DISABLE_ES2015_CLASS
return (((uintptr_t) arguments_list_p) & ECMA_CLASS_CONSTRUCT_FLAG);
#else
#else /* CONFIG_DISABLE_ES2015_CLASS */
JERRY_UNUSED (arguments_list_p);
return false;
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
} /* ecma_op_function_has_construct_flag */
#ifndef CONFIG_DISABLE_ES2015
/**
* Returns the closest declarative lexical enviroment to the super object bound lexical enviroment.
*
* @return the found lexical enviroment
*/
static ecma_object_t *
ecma_op_find_super_declerative_lex_env (ecma_object_t *lex_env_p) /**< starting lexical enviroment */
{
JERRY_ASSERT (lex_env_p);
JERRY_ASSERT (ecma_op_resolve_super_reference_value (lex_env_p));
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) != ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND);
while (true)
{
ecma_object_t *lex_env_outer_p = ecma_get_lex_env_outer_reference (lex_env_p);
JERRY_ASSERT (lex_env_outer_p);
if (ecma_get_lex_env_type (lex_env_outer_p) == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND)
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
return lex_env_p;
}
lex_env_p = lex_env_outer_p;
}
} /* ecma_op_find_super_declerative_lex_env */
/**
* Returns with the current class this_binding property
*
* @return NULL - if the property was not found
* the found property - otherwise
*/
static ecma_property_t *
ecma_op_get_class_this_binding_property (ecma_object_t *lex_env_p) /**< starting lexical enviroment */
{
JERRY_ASSERT (lex_env_p);
JERRY_ASSERT (ecma_is_lexical_environment (lex_env_p));
lex_env_p = ecma_op_find_super_declerative_lex_env (lex_env_p);
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_CLASS_THIS_BINDING);
return ecma_find_named_property (lex_env_p, name_p);
} /* ecma_op_get_class_this_binding_property */
/**
* Checks whether the 'super(...)' has been called.
*
* @return true - if the 'super (...)' has been called
* false - otherwise
*/
inline bool JERRY_ATTR_PURE
ecma_op_is_super_called (ecma_object_t *lex_env_p) /**< starting lexical enviroment */
{
ecma_property_t *property_p = ecma_op_get_class_this_binding_property (lex_env_p);
JERRY_ASSERT (property_p);
return (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA);
} /* ecma_op_is_super_called */
/**
* Sets the value of 'super(...)' has been called.
*/
inline void
ecma_op_set_super_called (ecma_object_t *lex_env_p) /**< starting lexical enviroment */
{
ecma_property_t *property_p = ecma_op_get_class_this_binding_property (lex_env_p);
JERRY_ASSERT (property_p);
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_INTERNAL);
ECMA_CONVERT_INTERNAL_PROPERTY_TO_DATA_PROPERTY (property_p);
} /* ecma_op_set_super_called */
/**
* Sets the class context this_binding value.
*/
void
ecma_op_set_class_this_binding (ecma_object_t *lex_env_p, /**< starting lexical enviroment */
ecma_value_t this_binding) /**< 'this' argument's value */
{
JERRY_ASSERT (ecma_is_value_object (this_binding));
ecma_property_t *property_p = ecma_op_get_class_this_binding_property (lex_env_p);
ecma_property_value_t *value_p;
if (property_p)
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA);
value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
}
else
{
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_CLASS_THIS_BINDING);
value_p = ecma_create_named_data_property (lex_env_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, &property_p);
ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY (property_p);
}
value_p->value = this_binding;
} /* ecma_op_set_class_this_binding */
/**
* Gets the class context this binding value.
*
* @return the class context this binding value
*/
ecma_value_t
ecma_op_get_class_this_binding (ecma_object_t *lex_env_p) /**< starting lexical enviroment */
{
ecma_property_t *property_p = ecma_op_get_class_this_binding_property (lex_env_p);
JERRY_ASSERT (property_p);
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
JERRY_ASSERT (ecma_is_value_object (value_p->value));
return value_p->value;
} /* ecma_op_get_class_this_binding */
/**
* Dummy external function for implicit constructor call.
*
* @return ECMA_VALUE_ERROR - TypeError
*/
ecma_value_t
ecma_op_function_implicit_constructor_handler_cb (const ecma_value_t function_obj, /**< the function itself */
const ecma_value_t this_val, /**< this_arg of the function */
const ecma_value_t args_p[], /**< argument list */
const ecma_length_t args_count) /**< argument number */
{
JERRY_UNUSED_4 (function_obj, this_val, args_p, args_count);
return ecma_raise_type_error (ECMA_ERR_MSG ("Class constructor cannot be invoked without 'new'."));
} /* ecma_op_function_implicit_constructor_handler_cb */
/**
* Sets the completion value [[Prototype]] based on the this_arg value
*/
void
ecma_op_set_class_prototype (ecma_value_t completion_value, /**< completion_value */
ecma_value_t this_arg) /**< this argument*/
{
JERRY_ASSERT (ecma_is_value_object (completion_value));
JERRY_ASSERT (ecma_is_value_object (this_arg));
ecma_object_t *completion_obj_p = ecma_get_object_from_value (completion_value);
ecma_object_t *prototype_obj_p = ecma_get_object_prototype (ecma_get_object_from_value (this_arg));
JERRY_ASSERT (prototype_obj_p);
ECMA_SET_POINTER (completion_obj_p->prototype_or_outer_reference_cp, prototype_obj_p);
} /* ecma_op_set_class_prototype */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* [[Call]] implementation for Function objects,
* created through 13.2 (ECMA_OBJECT_TYPE_FUNCTION)
@@ -484,6 +637,8 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
ecma_object_type_t func_type = ecma_get_object_type (func_obj_p);
JERRY_ASSERT (func_type == ECMA_OBJECT_TYPE_FUNCTION
|| func_type == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION
|| func_type == ECMA_OBJECT_TYPE_BOUND_FUNCTION
|| !ecma_op_function_has_construct_flag (arguments_list_p));
if (func_type == ECMA_OBJECT_TYPE_FUNCTION)
@@ -507,21 +662,20 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
/* 8. */
ecma_value_t this_binding = this_arg_value;
bool free_this_binding = false;
bool is_strict;
bool is_no_lex_env;
const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR &&
!ecma_op_function_has_construct_flag (arguments_list_p))
bool is_class_constructor = bytecode_data_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR;
if (is_class_constructor && !ecma_op_function_has_construct_flag (arguments_list_p))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Class constructor cannot be invoked without 'new'."));
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
is_strict = (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) ? true : false;
is_no_lex_env = (bytecode_data_p->status_flags & CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED) ? true : false;
bool is_strict = (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) ? true : false;
bool is_no_lex_env = (bytecode_data_p->status_flags & CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED) ? true : false;
/* 1. */
if (!is_strict)
@@ -561,6 +715,12 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
arguments_list_len,
bytecode_data_p);
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (JERRY_UNLIKELY (is_class_constructor))
{
ecma_op_set_class_this_binding (local_env_p, this_binding);
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
}
ecma_value_t ret_value = vm_run (bytecode_data_p,
@@ -658,7 +818,26 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
if (!ecma_is_value_integer_number (args_len_or_this))
{
this_arg_value = args_len_or_this;
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (JERRY_UNLIKELY (args_len_or_this == ECMA_VALUE_IMPLICIT_CONSTRUCTOR))
{
if (!ecma_op_function_has_construct_flag (arguments_list_p))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Class constructor cannot be invoked without 'new'."));
}
if (ecma_get_object_is_builtin (target_func_obj_p))
{
arguments_list_p = ecma_op_function_clear_construct_flag (arguments_list_p);
}
}
else
{
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
this_arg_value = args_len_or_this;
#ifndef CONFIG_DISABLE_ES2015_CLASS
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
args_length = 1;
}
else
@@ -675,6 +854,11 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
continue;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
arguments_list_p = ecma_op_function_clear_construct_flag (arguments_list_p);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
JERRY_ASSERT (!ecma_op_function_has_construct_flag (arguments_list_p));
args_length--;
ecma_length_t merged_args_list_len = args_length + arguments_list_len;
@@ -721,12 +905,13 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
JERRY_ASSERT (ecma_is_value_object (this_arg_value)
|| this_arg_value == ECMA_VALUE_UNDEFINED);
ecma_object_t *target_func_obj_p = NULL;
while (JERRY_UNLIKELY (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION))
{
/* 1-3. */
ecma_extended_object_t *ext_function_p = (ecma_extended_object_t *) func_obj_p;
ecma_object_t *target_func_obj_p;
target_func_obj_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
ext_function_p->u.bound_function.target_function);
@@ -742,9 +927,15 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
JERRY_ASSERT (args_length > 0);
/* 5. */
if (args_length == 1)
{
/* 5. */
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (args_len_or_this == ECMA_VALUE_IMPLICIT_CONSTRUCTOR && ecma_is_value_undefined (this_arg_value))
{
break;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
func_obj_p = target_func_obj_p;
continue;
}
@@ -787,9 +978,18 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
return ecma_raise_type_error (ECMA_ERR_MSG ("Built-in routines have no constructor."));
}
return ecma_builtin_dispatch_construct (func_obj_p,
arguments_list_p,
arguments_list_len);
ecma_value_t ret_value = ecma_builtin_dispatch_construct (func_obj_p,
arguments_list_p,
arguments_list_len);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (!ecma_is_value_undefined (this_arg_value) && !ECMA_IS_VALUE_ERROR (ret_value))
{
ecma_op_set_class_prototype (ret_value, this_arg_value);
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return ret_value;
}
ecma_object_t *new_this_obj_p = NULL;
@@ -843,10 +1043,33 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
arguments_list_len);
break;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
JERRY_ASSERT (!ecma_op_function_has_construct_flag (arguments_list_p));
JERRY_ASSERT (target_func_obj_p != NULL);
ret_value = ecma_op_function_construct (target_func_obj_p,
this_arg_value,
arguments_list_p,
arguments_list_len);
break;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
default:
{
JERRY_ASSERT (type == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION);
#ifndef CONFIG_DISABLE_ES2015_CLASS
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
if (ext_func_obj_p->u.external_handler_cb == ecma_op_function_implicit_constructor_handler_cb)
{
ret_value = ECMA_VALUE_UNDEFINED;
break;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
ret_value = ecma_op_function_call (func_obj_p,
this_arg_value,
arguments_list_p,
@@ -46,6 +46,29 @@ ecma_op_create_external_function_object (ecma_external_handler_t handler_cb);
const ecma_compiled_code_t *
ecma_op_function_get_compiled_code (ecma_extended_object_t *function_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
void
ecma_op_set_super_called (ecma_object_t *lex_env_p);
bool
ecma_op_is_super_called (ecma_object_t *lex_env_p);
void
ecma_op_set_class_this_binding (ecma_object_t *lex_env_p, ecma_value_t this_binding);
ecma_value_t
ecma_op_get_class_this_binding (ecma_object_t *lex_env_p);
ecma_value_t
ecma_op_function_implicit_constructor_handler_cb (const ecma_value_t function_obj,
const ecma_value_t this_val,
const ecma_value_t args_p[],
const ecma_length_t args_count);
void
ecma_op_set_class_prototype (ecma_value_t completion_value, ecma_value_t this_arg);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
const ecma_compiled_code_t *
ecma_op_arrow_function_get_compiled_code (ecma_arrow_function_t *arrow_function_p);
+12 -3
View File
@@ -41,7 +41,9 @@ ecma_init_global_lex_env (void)
{
ecma_object_t *glob_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
JERRY_CONTEXT (ecma_global_lex_env_p) = ecma_create_object_lex_env (NULL, glob_obj_p);
JERRY_CONTEXT (ecma_global_lex_env_p) = ecma_create_object_lex_env (NULL,
glob_obj_p,
ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
ecma_deref_object (glob_obj_p);
} /* ecma_init_global_lex_env */
@@ -86,7 +88,9 @@ ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */
JERRY_ASSERT (lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
ecma_lexical_environment_type_t lex_env_type = ecma_get_lex_env_type (lex_env_p);
if (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p);
@@ -94,7 +98,12 @@ ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */
}
else
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
#ifndef CONFIG_DISABLE_ES2015_CLASS
JERRY_ASSERT (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND
|| lex_env_type == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND);
#else /* CONFIG_DISABLE_ES2015_CLASS */
JERRY_ASSERT (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
+35 -4
View File
@@ -59,6 +59,29 @@ ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, /**< starting lexical
return NULL;
} /* ecma_op_resolve_reference_base */
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* Resolve super reference.
*
* @return value of the reference
*/
ecma_object_t *
ecma_op_resolve_super_reference_value (ecma_object_t *lex_env_p) /**< starting lexical environment */
{
while (true)
{
JERRY_ASSERT (lex_env_p != NULL);
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND)
{
return ecma_get_lex_env_binding_object (lex_env_p);
}
lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p);
}
} /* ecma_op_resolve_super_reference_value */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* Resolve value corresponding to reference.
*
@@ -72,7 +95,9 @@ ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, /**< starting lexical
while (lex_env_p != NULL)
{
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
ecma_lexical_environment_type_t lex_env_type = ecma_get_lex_env_type (lex_env_p);
if (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p);
@@ -81,10 +106,8 @@ ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, /**< starting lexical
return ecma_fast_copy_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value);
}
}
else
else if (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND)
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
#ifndef CONFIG_ECMA_LCACHE_DISABLE
@@ -120,6 +143,14 @@ ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, /**< starting lexical
return prop_value;
}
}
else
{
#ifndef CONFIG_DISABLE_ES2015_CLASS
JERRY_ASSERT (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND);
#else /* CONFIG_DISABLE_ES2015_CLASS */
JERRY_UNREACHABLE ();
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
}
lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p);
}
@@ -28,6 +28,9 @@
ecma_object_t *ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, ecma_string_t *name_p);
ecma_value_t ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, ecma_string_t *name_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
ecma_object_t *ecma_op_resolve_super_reference_value (ecma_object_t *lex_env_p);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* @}
@@ -257,7 +257,7 @@ ecma_typedarray_create_object_with_length (ecma_length_t array_length, /**< leng
ecma_free_value (new_arraybuffer_p);
return ecma_make_object_value (object_p);
} /* !ecma_typedarray_create_object_with_length */
} /* ecma_typedarray_create_object_with_length */
/**
* Create a TypedArray object by given buffer, offset, and array_length
@@ -984,6 +984,31 @@ ecma_op_create_typedarray_with_type_and_length (ecma_object_t *obj_p, /**< Typed
}
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
ecma_value_t constructor_value = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_CONSTRUCTOR);
if (ECMA_IS_VALUE_ERROR (constructor_value)
|| !ecma_is_value_object (constructor_value)
|| !ecma_is_constructor (constructor_value))
{
ecma_deref_object (proto_p);
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))
{
ecma_deref_object (proto_p);
return constructor_prototype;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
ecma_value_t new_obj = ecma_typedarray_create_object_with_length (array_length,
proto_p,
element_size_shift,
@@ -991,6 +1016,14 @@ ecma_op_create_typedarray_with_type_and_length (ecma_object_t *obj_p, /**< Typed
ecma_deref_object (proto_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
ecma_object_t *constructor_prototype_object_p = ecma_get_object_from_value (constructor_prototype);
ecma_object_t *new_obj_p = ecma_get_object_from_value (new_obj);
ECMA_SET_POINTER (new_obj_p->prototype_or_outer_reference_cp, constructor_prototype_object_p);
ecma_deref_object (constructor_prototype_object_p);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return new_obj;
} /* ecma_op_create_typedarray_with_type_and_length */