Add Map, Set, WeakMap, WeakSet basic functionality to the API (#3502)
JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
This commit is contained in:
@@ -71,8 +71,25 @@ Possible compile time enabled feature types:
|
||||
- JERRY_FEATURE_SYMBOL - symbol support
|
||||
- JERRY_FEATURE_DATAVIEW - DataView support
|
||||
- JERRY_FEATURE_PROXY - Proxy support
|
||||
- JERRY_FEATURE_MAP - Map support
|
||||
- JERRY_FEATURE_SET - Set support
|
||||
- JERRY_FEATURE_WEAKMAP - WeakMap support
|
||||
- JERRY_FEATURE_WEAKSET - WeakSet support
|
||||
|
||||
*New in version 2.0*.
|
||||
*Changed in version 2.3* : Added `JERRY_FEATURE_WEAKMAP`, `JERRY_FEATURE_WEAKSET` values.
|
||||
|
||||
## jerry_container_type_t
|
||||
|
||||
Container object types:
|
||||
|
||||
- JERRY_CONTAINER_TYPE_INVALID - Invalid container
|
||||
- JERRY_CONTAINER_TYPE_MAP - Map type
|
||||
- JERRY_CONTAINER_TYPE_SET - Set type
|
||||
- JERRY_CONTAINER_TYPE_WEAKMAP - WeakMap type
|
||||
- JERRY_CONTAINER_TYPE_WEAKSET - WeakSet type
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
## jerry_regexp_flags_t
|
||||
|
||||
@@ -2072,6 +2089,64 @@ main (void)
|
||||
- [jerry_create_typedarray](#jerry_create_typedarray)
|
||||
|
||||
|
||||
## jerry_get_container_type
|
||||
|
||||
**Summary**
|
||||
|
||||
Checks whether the given `jerry_value_t` is the given `jerry_container_type_t` type container object.
|
||||
|
||||
*Notes*
|
||||
- This API function depends on a build option (`JERRY_ES2015_BUILTIN_CONTAINER`) and can be checked
|
||||
runtime with the `JERRY_FEATURE_MAP, JERRY_FEATURE_SET, JERRY_FEATURE_WEAKMAP, JERRY_FEATURE_WEAKSET`
|
||||
feature enum values.
|
||||
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||
- The ES2015-subset profile enables this by default.
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_container_type_t
|
||||
jerry_get_container_type (const jerry_value_t value)
|
||||
```
|
||||
|
||||
- `value` - Container object
|
||||
- return value
|
||||
- The corresponding enum value of `jerry_container_type_t`, or `JERRY_CONTAINER_TYPE_INVALID` if the container
|
||||
was not a valid container object.
|
||||
**Example**
|
||||
|
||||
[doctest]: # ()
|
||||
|
||||
```c
|
||||
#include "jerryscript.h"
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
jerry_value_t value = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0);
|
||||
|
||||
if (jerry_get_container_type (value) == JERRY_CONTAINER_TYPE_MAP)
|
||||
{
|
||||
/* "value" is a map. */
|
||||
}
|
||||
|
||||
jerry_release_value (value);
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_create_container](#jerry_create_container)
|
||||
- [jerry_container_type_t](#jerry_container_type_t)
|
||||
|
||||
|
||||
## jerry_value_is_undefined
|
||||
|
||||
**Summary**
|
||||
@@ -4802,6 +4877,70 @@ jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name,
|
||||
- [jerry_release_value](#jerry_release_value)
|
||||
|
||||
|
||||
## jerry_create_container
|
||||
|
||||
**Summary**
|
||||
|
||||
Create a jerry_value_t representing a given type container object.
|
||||
|
||||
*Notes*:
|
||||
- This method is expected to work the same way as the JavaScript Map constructor.
|
||||
- Returned value must be freed with [jerry_release_value](#jerry_release_value)
|
||||
when it is no longer needed.
|
||||
- This API depends on a build option (`JERRY_ES2015_BUILTIN_CONTAINER`) and can be checked
|
||||
in runtime with the `JERRY_FEATURE_MAP, JERRY_FEATURE_SET, JERRY_FEATURE_WEAKMAP, JERRY_FEATURE_WEAKSET`
|
||||
feature enum values.
|
||||
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||
- The ES2015-subset profile enables this by default.
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_value_t
|
||||
jerry_create_container (jerry_container_type_t container_type,
|
||||
const jerry_value_t *arguments_list_p,
|
||||
jerry_length_t arguments_list_len);
|
||||
```
|
||||
|
||||
- `container_type` - Type of the container to be created, see `jerry_container_type_t`.
|
||||
- `arguments_list_p` - The arguments passed to the container constructor to be inserted to the container.
|
||||
- `arguments_list_len` - The length of the above arguments.
|
||||
- return value - the new container object as a `jerry_value_t`
|
||||
|
||||
**Example**
|
||||
|
||||
[doctest]: # ()
|
||||
|
||||
```c
|
||||
#include "jerryscript.h"
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
jerry_char_t src[] = "[1,2,3,4].entries()";
|
||||
jerry_value_t iterable = jerry_eval (src, sizeof (src) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
jerry_value_t map = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, &iterable, 1);
|
||||
jerry_release_value (iterable);
|
||||
|
||||
// use the Map
|
||||
|
||||
jerry_release_value (map);
|
||||
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_container_type_t](#jerry_container_type_t)
|
||||
- [jerry_get_container_type](#jerry_get_container_type)
|
||||
|
||||
|
||||
## jerry_create_undefined
|
||||
|
||||
**Summary**
|
||||
|
||||
Reference in New Issue
Block a user