Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jerry-core/api/jerry-snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
return 0;
}

if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR)
{
globals_p->class_found = true;
}
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/api/jerry.c
Original file line number Diff line number Diff line change
Expand Up @@ -2782,7 +2782,7 @@ jerry_invoke_function (bool is_invoke_as_constructor, /**< true - invoke functio
JERRY_ASSERT (jerry_value_is_constructor (func_obj_val));

return jerry_return (ecma_op_function_construct (ecma_get_object_from_value (func_obj_val),
ECMA_VALUE_UNDEFINED,
ecma_get_object_from_value (func_obj_val),
args_p,
args_count));
}
Expand Down
6 changes: 6 additions & 0 deletions jerry-core/ecma/base/ecma-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,11 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
{
ecma_gc_set_object_visited (ecma_get_object_from_value (arrow_func_p->this_binding));
}

if (ecma_is_value_object (arrow_func_p->new_target))
{
ecma_gc_set_object_visited (ecma_get_object_from_value (arrow_func_p->new_target));
}
}
#endif /* ENABLED (JERRY_ES2015) */
}
Expand Down Expand Up @@ -1218,6 +1223,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
if (byte_code_p->status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION)
{
ecma_free_value_if_not_object (((ecma_arrow_function_t *) object_p)->this_binding);
ecma_free_value_if_not_object (((ecma_arrow_function_t *) object_p)->new_target);
ext_object_size = sizeof (ecma_arrow_function_t);
}
#endif /* ENABLED (JERRY_ES2015) */
Expand Down
36 changes: 19 additions & 17 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,14 @@ typedef enum
ECMA_PARSE_EVAL = (1u << 2), /**< eval is called */
ECMA_PARSE_DIRECT_EVAL = (1u << 3), /**< eval is called directly (ECMA-262 v5, 15.1.2.1.1) */

/* These four status flags must be in this order. See PARSER_CLASS_PARSE_OPTS_OFFSET. */
/* These three status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */
ECMA_PARSE_CLASS_CONSTRUCTOR = (1u << 4), /**< a class constructor is being parsed (this value must be kept in
* in sync with PARSER_CLASS_CONSTRUCTOR) */
ECMA_PARSE_HAS_SUPER = (1u << 5), /**< the current context has super reference */
ECMA_PARSE_HAS_IMPL_SUPER = (1u << 6), /**< the current context has implicit parent class */
ECMA_PARSE_HAS_STATIC_SUPER = (1u << 7), /**< the current context is a static class method */
ECMA_PARSE_ALLOW_SUPER = (1u << 5), /**< allow super property access */
ECMA_PARSE_ALLOW_SUPER_CALL = (1u << 6), /**< allow super constructor call */

ECMA_PARSE_CALLED_FROM_FUNCTION = (1u << 8), /**< a function body is parsed or the code is inside a function */
ECMA_PARSE_GENERATOR_FUNCTION = (1u << 9), /**< generator function is parsed */
ECMA_PARSE_CALLED_FROM_FUNCTION = (1u << 7), /**< a function body is parsed or the code is inside a function */
ECMA_PARSE_GENERATOR_FUNCTION = (1u << 8), /**< generator function is parsed */

/* These flags are internally used by the parser. */
} ecma_parse_opts_t;
Expand Down Expand Up @@ -195,7 +194,8 @@ enum
* ecma_op_object_find */
ECMA_VALUE_REGISTER_REF = ECMA_MAKE_VALUE (8), /**< register reference,
* a special "base" value for vm */
ECMA_VALUE_IMPLICIT_CONSTRUCTOR = ECMA_MAKE_VALUE (9), /**< special value for bound class constructors */
ECMA_VALUE_RELEASE_LEX_ENV = ECMA_MAKE_VALUE (9), /**< if this error remains on the stack when an exception occours
the top lexical environment of the VM frame should be popped */
ECMA_VALUE_UNINITIALIZED = ECMA_MAKE_VALUE (10), /**< a special value for uninitialized let/const declarations */
ECMA_VALUE_SPREAD_ELEMENT = ECMA_MAKE_VALUE (11), /**< a special value for spread elements in array initialization
* or function call argument list */
Expand Down Expand Up @@ -661,12 +661,12 @@ typedef enum
ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE = 13, /**< declarative lexical environment */
ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND = 14, /**< object-bound lexical environment
* with provideThis flag */
ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND = 15, /**< object-bound lexical environment
* with provided super reference */
ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND = 15, /**< object-bound lexical environment
* with provided home object reference */

ECMA_LEXICAL_ENVIRONMENT_TYPE_START = ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< first lexical
* environment type */
ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND /**< maximum value */
ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND /**< maximum value */
} ecma_lexical_environment_type_t;

#if ENABLED (JERRY_ES2015)
Expand All @@ -686,29 +686,29 @@ typedef enum
/**
* Offset for JERRY_CONTEXT (status_flags) top 8 bits.
*/
#define ECMA_SUPER_EVAL_OPTS_OFFSET (32 - 8)
#define ECMA_LOCAL_PARSE_OPTS_OFFSET ((sizeof (uint32_t) - sizeof (uint8_t)) * JERRY_BITSINBYTE)

/**
* Set JERRY_CONTEXT (status_flags) top 8 bits to the specified 'opts'.
*/
#define ECMA_SET_SUPER_EVAL_PARSER_OPTS(opts) \
#define ECMA_SET_LOCAL_PARSE_OPTS(opts) \
do \
{ \
JERRY_CONTEXT (status_flags) |= ((uint32_t) opts << ECMA_SUPER_EVAL_OPTS_OFFSET) | ECMA_STATUS_DIRECT_EVAL; \
JERRY_CONTEXT (status_flags) |= ((uint32_t) opts << ECMA_LOCAL_PARSE_OPTS_OFFSET) | ECMA_STATUS_DIRECT_EVAL; \
} while (0)

/**
* Get JERRY_CONTEXT (status_flags) top 8 bits.
*/
#define ECMA_GET_SUPER_EVAL_PARSER_OPTS() (JERRY_CONTEXT (status_flags) >> ECMA_SUPER_EVAL_OPTS_OFFSET)
#define ECMA_GET_LOCAL_PARSE_OPTS() (JERRY_CONTEXT (status_flags) >> ECMA_LOCAL_PARSE_OPTS_OFFSET)

/**
* Clear JERRY_CONTEXT (status_flags) top 8 bits.
*/
#define ECMA_CLEAR_SUPER_EVAL_PARSER_OPTS() \
#define ECMA_CLEAR_LOCAL_PARSE_OPTS() \
do \
{ \
JERRY_CONTEXT (status_flags) &= ((1 << ECMA_SUPER_EVAL_OPTS_OFFSET) - 1); \
JERRY_CONTEXT (status_flags) &= ((1 << ECMA_LOCAL_PARSE_OPTS_OFFSET) - 1); \
} while (0)

/**
Expand Down Expand Up @@ -778,8 +778,9 @@ typedef struct
union
{
jmem_cpointer_t property_list_cp; /**< compressed pointer to object's
* or declerative lexical environments's property list */
* or declerative lexical environments's property list */
jmem_cpointer_t bound_object_cp; /**< compressed pointer to lexical environments's the bound object */
jmem_cpointer_t home_object_cp; /**< compressed pointer to lexical environments's the home object */
} u1;

/** object prototype or outer reference */
Expand Down Expand Up @@ -961,6 +962,7 @@ typedef struct
{
ecma_extended_object_t header; /**< extended object header */
ecma_value_t this_binding; /**< value of 'this' binding */
ecma_value_t new_target; /**< value of new.target */
} ecma_arrow_function_t;

#if ENABLED (JERRY_SNAPSHOT_EXEC)
Expand Down
39 changes: 39 additions & 0 deletions jerry-core/ecma/base/ecma-helpers-collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,45 @@ ecma_collection_push_back (ecma_collection_t *collection_p, /**< value collectio
collection_p->buffer_p = buffer_p;
} /* ecma_collection_push_back */

/**
* Reserve space for the given amount of ecma_values in the collection
*/
void
ecma_collection_reserve (ecma_collection_t *collection_p, /**< value collection */
uint32_t count) /**< number of ecma values to reserve */
{
JERRY_ASSERT (collection_p != NULL);
JERRY_ASSERT (UINT32_MAX - count > collection_p->capacity);

const uint32_t new_capacity = collection_p->capacity + count;
const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity);
const uint32_t new_size = ECMA_COLLECTION_ALLOCATED_SIZE (new_capacity);

ecma_value_t *buffer_p = collection_p->buffer_p;
buffer_p = jmem_heap_realloc_block (buffer_p, old_size, new_size);

collection_p->capacity = new_capacity;
collection_p->buffer_p = buffer_p;
} /* ecma_collection_reserve */

/**
* Append a list of values to the end of the collection
*/
void
ecma_collection_append (ecma_collection_t *collection_p, /**< value collection */
const ecma_value_t *buffer_p, /**< values to append */
uint32_t count) /**< number of ecma values to append */
{
JERRY_ASSERT (collection_p != NULL);
if (collection_p->capacity - collection_p->item_count > count)
{
ecma_collection_reserve (collection_p, count);
}

memcpy (collection_p->buffer_p + collection_p->item_count, buffer_p, count * sizeof (ecma_value_t));
collection_p->item_count += count;
} /* ecma_collection_append */

/**
* @}
* @}
Expand Down
4 changes: 2 additions & 2 deletions jerry-core/ecma/base/ecma-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, /**< out
{
#if ENABLED (JERRY_ES2015)
JERRY_ASSERT (type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND
|| type == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND);
|| type == ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND);
#else /* !ENABLED (JERRY_ES2015) */
JERRY_ASSERT (type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
#endif /* ENABLED (JERRY_ES2015) */
Expand Down Expand Up @@ -288,7 +288,7 @@ ecma_get_lex_env_binding_object (const ecma_object_t *object_p) /**< object-boun
JERRY_ASSERT (ecma_is_lexical_environment (object_p));
#if ENABLED (JERRY_ES2015)
JERRY_ASSERT (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND
|| ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND);
|| ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND);
#else /* !ENABLED (JERRY_ES2015) */
JERRY_ASSERT (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
#endif /* ENABLED (JERRY_ES2015) */
Expand Down
12 changes: 10 additions & 2 deletions jerry-core/ecma/base/ecma-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,20 @@ typedef enum
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (false)
#endif /* ENABLED (JERRY_ES2015) */

/**
* Check whether the given type is ECMA_OBJECT_TYPE_PROXY
*
* @param type object type
*/
#define ECMA_OBJECT_TYPE_IS_PROXY(type) (JERRY_UNLIKELY ((type) == ECMA_OBJECT_TYPE_PROXY))

/**
* Check whether the given object has [[ProxyHandler]] and [[ProxyTarger]] internal slots
*
* @param obj_p ecma-object
*/
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
#define ECMA_OBJECT_IS_PROXY(obj_p) (JERRY_UNLIKELY (ecma_get_object_type ((obj_p)) == ECMA_OBJECT_TYPE_PROXY))
#define ECMA_OBJECT_IS_PROXY(obj_p) (ECMA_OBJECT_TYPE_IS_PROXY (ecma_get_object_type ((obj_p))))
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
#define ECMA_OBJECT_IS_PROXY(obj_p) (false)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
Expand Down Expand Up @@ -402,6 +409,8 @@ lit_utf8_size_t ecma_number_to_binary_floating_point_number (ecma_number_t num,
/* ecma-helpers-collection.c */
ecma_collection_t *ecma_new_collection (void);
void ecma_collection_push_back (ecma_collection_t *collection_p, ecma_value_t value);
void ecma_collection_reserve (ecma_collection_t *collection_p, uint32_t count);
void ecma_collection_append (ecma_collection_t *collection_p, const ecma_value_t *buffer_p, uint32_t count);
void ecma_collection_destroy (ecma_collection_t *collection_p);
void ecma_collection_free (ecma_collection_t *collection_p);
void ecma_collection_free_if_not_object (ecma_collection_t *collection_p);
Expand All @@ -419,7 +428,6 @@ bool JERRY_ATTR_PURE ecma_get_object_is_builtin (const ecma_object_t *object_p);
void ecma_set_object_is_builtin (ecma_object_t *object_p);
uint8_t ecma_get_object_builtin_id (ecma_object_t *object_p);
ecma_lexical_environment_type_t JERRY_ATTR_PURE ecma_get_lex_env_type (const ecma_object_t *object_p);
ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_outer_reference (const ecma_object_t *object_p);
ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p);
ecma_object_t *ecma_clone_decl_lexical_environment (ecma_object_t *lex_env_p, bool copy_values);

Expand Down
6 changes: 3 additions & 3 deletions jerry-core/ecma/builtin-objects/ecma-builtin-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ecma_builtin_array_object_from (ecma_value_t this_arg, /**< 'this' argument */
{
ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor);

array = ecma_op_function_construct (constructor_obj_p, ECMA_VALUE_UNDEFINED, NULL, 0);
array = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, NULL, 0);

if (ecma_is_value_undefined (array) || ecma_is_value_null (array))
{
Expand Down Expand Up @@ -289,7 +289,7 @@ ecma_builtin_array_object_from (ecma_value_t this_arg, /**< 'this' argument */
{
ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor);

array = ecma_op_function_construct (constructor_obj_p, ECMA_VALUE_UNDEFINED, &len_value, 1);
array = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, &len_value, 1);

if (ecma_is_value_undefined (array) || ecma_is_value_null (array))
{
Expand Down Expand Up @@ -414,7 +414,7 @@ ecma_builtin_array_object_of (ecma_value_t this_arg, /**< 'this' argument */
ecma_value_t len = ecma_make_uint32_value (arguments_list_len);

ecma_value_t ret_val = ecma_op_function_construct (ecma_get_object_from_value (this_arg),
ECMA_VALUE_UNDEFINED,
ecma_get_object_from_value (this_arg),
&len,
1);

Expand Down
2 changes: 1 addition & 1 deletion jerry-core/ecma/builtin-objects/ecma-builtin-global.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument *
#if ENABLED (JERRY_ES2015)
if (vm_is_direct_eval_form_call ())
{
parse_opts |= ECMA_GET_SUPER_EVAL_PARSER_OPTS ();
parse_opts |= ECMA_GET_LOCAL_PARSE_OPTS ();
}
#endif /* ENABLED (JERRY_ES2015) */

Expand Down
8 changes: 3 additions & 5 deletions jerry-core/ecma/builtin-objects/ecma-builtin-helpers-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**<
ecma_deref_ecma_string (message_string_p);
return ecma_make_object_value (new_error_object_p);
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type);

return ecma_make_object_value (new_error_object_p);
}
ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type);

return ecma_make_object_value (new_error_object_p);
} /* ecma_builtin_helper_error_dispatch_call */

/**
Expand Down
4 changes: 1 addition & 3 deletions jerry-core/ecma/builtin-objects/ecma-builtin-reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
return ECMA_VALUE_ERROR;
}

// TODO: add new_target_p to construct when it'll be supported
JERRY_UNUSED (new_target_p);
ecma_value_t ret_value = ecma_op_function_construct (target_p,
ECMA_VALUE_UNDEFINED,
new_target_p,
coll_p->buffer_p,
coll_p->item_count);

Expand Down
Loading