Implement the Set builtin object (#2841)
Also implement the missing iterator initializer part from the Map builtin object constructor. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -205,6 +205,13 @@ OBJECT_VALUE (LIT_MAGIC_STRING_MAP_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
/* ECMA-262 v6, 23.1.1.1 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_SET_UL,
|
||||
ECMA_BUILTIN_ID_SET,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
||||
/* ECMA-262 v6, 19.4.1.1 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_SYMBOL_UL,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-map-object.h"
|
||||
#include "ecma-container-object.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
static ecma_value_t
|
||||
ecma_builtin_map_prototype_object_clear (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
return ecma_op_map_clear (this_arg);
|
||||
return ecma_op_container_clear (this_arg, false);
|
||||
} /* ecma_builtin_map_prototype_object_clear */
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ static ecma_value_t
|
||||
ecma_builtin_map_prototype_object_delete (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t key_arg) /**< key argument */
|
||||
{
|
||||
return ecma_op_map_delete (this_arg, key_arg);
|
||||
return ecma_op_container_delete (this_arg, key_arg, false);
|
||||
} /* ecma_builtin_map_prototype_object_delete */
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ ecma_builtin_map_prototype_object_foreach (ecma_value_t this_arg, /**< this argu
|
||||
ecma_value_t predicate_this_arg) /**< this argument for
|
||||
* invoke predicate */
|
||||
{
|
||||
return ecma_op_map_foreach (this_arg, predicate, predicate_this_arg);
|
||||
return ecma_op_container_foreach (this_arg, predicate, predicate_this_arg, false);
|
||||
} /* ecma_builtin_map_prototype_object_foreach */
|
||||
|
||||
/**
|
||||
@@ -96,7 +96,7 @@ static ecma_value_t
|
||||
ecma_builtin_map_prototype_object_get (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t key_arg) /**< key argument */
|
||||
{
|
||||
return ecma_op_map_get (this_arg, key_arg);
|
||||
return ecma_op_container_get (this_arg, key_arg);
|
||||
} /* ecma_builtin_map_prototype_object_get */
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ static ecma_value_t
|
||||
ecma_builtin_map_prototype_object_has (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t key_arg) /**< key argument */
|
||||
{
|
||||
return ecma_op_map_has (this_arg, key_arg);
|
||||
return ecma_op_container_has (this_arg, key_arg, false);
|
||||
} /* ecma_builtin_map_prototype_object_has */
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,7 @@ ecma_builtin_map_prototype_object_set (ecma_value_t this_arg, /**< this argument
|
||||
ecma_value_t key_arg, /**< key argument */
|
||||
ecma_value_t value_arg) /**< value argument */
|
||||
{
|
||||
return ecma_op_map_set (this_arg, key_arg, value_arg);
|
||||
return ecma_op_container_set (this_arg, key_arg, value_arg, false);
|
||||
} /* ecma_builtin_map_prototype_object_set */
|
||||
|
||||
/**
|
||||
@@ -144,7 +144,7 @@ ecma_builtin_map_prototype_object_set (ecma_value_t this_arg, /**< this argument
|
||||
static ecma_value_t
|
||||
ecma_builtin_map_prototype_object_size_getter (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
return ecma_op_map_size (this_arg);
|
||||
return ecma_op_container_size (this_arg, false);
|
||||
} /* ecma_builtin_map_prototype_object_size_getter */
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-map-object.h"
|
||||
#include "ecma-container-object.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
|
||||
@@ -59,7 +59,7 @@ ecma_value_t
|
||||
ecma_builtin_map_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_op_map_create (arguments_list_p, arguments_list_len);
|
||||
return ecma_op_container_create (arguments_list_p, arguments_list_len, false);
|
||||
} /* ecma_builtin_map_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-container-object.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
|
||||
#if !ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
#error "Set builtin requires ES2015 map builtin"
|
||||
#endif /* !ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-set-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID set_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup set ECMA Set object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Set.prototype object's 'add' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 23.2.3.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_set_prototype_object_add (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t value_arg) /**< value argument */
|
||||
{
|
||||
return ecma_op_container_set (this_arg, value_arg, value_arg, true);
|
||||
} /* ecma_builtin_set_prototype_object_add */
|
||||
|
||||
/**
|
||||
* The Set.prototype object's 'clear' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 23.2.3.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_set_prototype_object_clear (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
return ecma_op_container_clear (this_arg, true);
|
||||
} /* ecma_builtin_set_prototype_object_clear */
|
||||
|
||||
/**
|
||||
* The Set.prototype object's 'delete' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 23.2.3.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_set_prototype_object_delete (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t value_arg) /**< value argument */
|
||||
{
|
||||
return ecma_op_container_delete (this_arg, value_arg, true);
|
||||
} /* ecma_builtin_set_prototype_object_delete */
|
||||
|
||||
/**
|
||||
* The Set.prototype object's 'forEach' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 23.2.3.6
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_set_prototype_object_foreach (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t predicate, /**< callback function */
|
||||
ecma_value_t predicate_this_arg) /**< this argument for
|
||||
* invoke predicate */
|
||||
{
|
||||
return ecma_op_container_foreach (this_arg, predicate, predicate_this_arg, true);
|
||||
} /* ecma_builtin_set_prototype_object_foreach */
|
||||
|
||||
/**
|
||||
* The Set.prototype object's 'has' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 23.2.3.7
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_set_prototype_object_has (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t value_arg) /**< value argument */
|
||||
{
|
||||
return ecma_op_container_has (this_arg, value_arg, true);
|
||||
} /* ecma_builtin_set_prototype_object_has */
|
||||
|
||||
/**
|
||||
* The Set.prototype object's 'size' getter
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 23.2.3.9
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_set_prototype_object_size_getter (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
return ecma_op_container_size (this_arg, true);
|
||||
} /* ecma_builtin_set_prototype_object_size_getter */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
@@ -0,0 +1,53 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set.prototype built-in description
|
||||
*/
|
||||
|
||||
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v6, 23.2.3.2 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_MAP,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
||||
/* ECMA-262 v6, 23.1.3.13 */
|
||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||
LIT_MAGIC_STRING_SET_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_ADD, ecma_builtin_set_prototype_object_add, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_CLEAR, ecma_builtin_set_prototype_object_clear, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_DELETE, ecma_builtin_set_prototype_object_delete, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ecma_builtin_set_prototype_object_foreach, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_HAS, ecma_builtin_set_prototype_object_has, 1, 1)
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE,
|
||||
ecma_builtin_set_prototype_object_size_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
@@ -0,0 +1,71 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-container-object.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-set.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID set
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup set ECMA Set object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Set object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_set_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor Set requires 'new'."));
|
||||
} /* ecma_builtin_set_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Map object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_set_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_op_container_create (arguments_list_p, arguments_list_len, true);
|
||||
} /* ecma_builtin_set_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
@@ -0,0 +1,47 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set built-in description
|
||||
*/
|
||||
|
||||
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v6, 23.2.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 23.1 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_SET_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v6, 23.2.2.1 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_SET_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
@@ -441,6 +441,24 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_MAP,
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
|
||||
/* The Set prototype object (23.1.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_SET_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
set_prototype)
|
||||
|
||||
/* The Set routine (ECMA-262 v6, 23.1.1.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_SET,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
set)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
||||
|
||||
/* The Symbol prototype object (ECMA-262 v6, 19.4.2.7) */
|
||||
|
||||
Reference in New Issue
Block a user