Introduce new API functions to obtain detailed object type information (#4162)
- jerry_object_get_type - jerry_function_get_type - jerry_iterator_get_type - jerry_value_is_async_function JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -30,6 +30,56 @@ Enum that contains JerryScript API value types:
|
||||
|
||||
*New in version 2.0*.
|
||||
|
||||
## jerry_object_type_t
|
||||
|
||||
Enum that contains JerryScript **object** value types:
|
||||
|
||||
- JERRY_OBJECT_TYPE_NONE - Non-object type
|
||||
- JERRY_OBJECT_TYPE_GENERIC - Generic JavaScript object without any internal property
|
||||
- JERRY_OBJECT_TYPE_ARRAY - Array object
|
||||
- JERRY_OBJECT_TYPE_PROXY - Proxy object
|
||||
- JERRY_OBJECT_TYPE_FUNCTION - Function object (see [jerry_function_get_type](#jerry_function_get_type))
|
||||
- JERRY_OBJECT_TYPE_TYPEDARRAY - %TypedArray% object (see [jerry_get_typedarray_type](#jerry_get_typedarray_type))
|
||||
- JERRY_OBJECT_TYPE_ITERATOR - Iterator object (see [jerry_iterator_get_type](#jerry_get_typedarray_type))
|
||||
- JERRY_OBJECT_TYPE_CONTAINER - Container object (see [jerry_get_container_type](#jerry_get_container_type))
|
||||
|
||||
- JERRY_OBJECT_TYPE_ARGUMENTS - Arguments object
|
||||
- JERRY_OBJECT_TYPE_BOOLEAN - Boolean object
|
||||
- JERRY_OBJECT_TYPE_DATE - Date object
|
||||
- JERRY_OBJECT_TYPE_NUMBER - Number object
|
||||
- JERRY_OBJECT_TYPE_REGEXP - RegExp object
|
||||
- JERRY_OBJECT_TYPE_STRING - String object
|
||||
- JERRY_OBJECT_TYPE_SYMBOL - Symbol object
|
||||
- JERRY_OBJECT_TYPE_GENERATOR - Generator object
|
||||
- JERRY_OBJECT_TYPE_BIGINT - BigInt object
|
||||
|
||||
*New in version [[NEXT_RELEASE]]*.
|
||||
|
||||
## jerry_function_type_t
|
||||
|
||||
Enum that contains JerryScript **function** value types:
|
||||
|
||||
- JERRY_FUNCTION_TYPE_NONE - Non-function type
|
||||
- JERRY_FUNCTION_TYPE_GENERIC - Generic JavaScript function
|
||||
- JERRY_FUNCTION_TYPE_ACCESSOR - Accessor function
|
||||
- JERRY_FUNCTION_TYPE_BOUND - Bound function
|
||||
- JERRY_FUNCTION_TYPE_ARROW - Arrow fuction
|
||||
- JERRY_FUNCTION_TYPE_GENERATOR - Generator function object
|
||||
|
||||
*New in version [[NEXT_RELEASE]]*.
|
||||
|
||||
## jerry_iterator_type_t
|
||||
|
||||
Enum that contains JerryScript **iterator** value types:
|
||||
|
||||
- JERRY_ITERATOR_TYPE_NONE - Non-iterator type
|
||||
- JERRY_ITERATOR_TYPE_ARRAY - Array iterator
|
||||
- JERRY_ITERATOR_TYPE_STRING - String iterator
|
||||
- JERRY_ITERATOR_TYPE_MAP - Map iterator
|
||||
- JERRY_ITERATOR_TYPE_SET - Set iterator
|
||||
|
||||
*New in version [[NEXT_RELEASE]]*.
|
||||
|
||||
## jerry_error_t
|
||||
|
||||
Possible types of an error:
|
||||
@@ -1717,6 +1767,44 @@ jerry_value_is_function (const jerry_value_t value)
|
||||
- [jerry_release_value](#jerry_release_value)
|
||||
|
||||
|
||||
## jerry_value_is_async_function
|
||||
|
||||
**Summary**
|
||||
|
||||
Returns whether the given `jerry_value_t` is an async function.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
bool
|
||||
jerry_value_is_async_function (const jerry_value_t value)
|
||||
```
|
||||
|
||||
- `value` - api value
|
||||
- return value
|
||||
- true, if the given `jerry_value_t` is an async function
|
||||
- false, otherwise
|
||||
|
||||
**Example**
|
||||
|
||||
```c
|
||||
{
|
||||
jerry_value_t value;
|
||||
... // create or acquire value
|
||||
|
||||
if (jerry_value_is_async_function (value))
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
jerry_release_value (value);
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_release_value](#jerry_release_value)
|
||||
|
||||
## jerry_value_is_number
|
||||
|
||||
**Summary**
|
||||
@@ -2293,6 +2381,142 @@ jerry_value_get_type (const jerry_value_t value);
|
||||
|
||||
- [jerry_type_t](#jerry_type_t)
|
||||
|
||||
## jerry_object_get_type
|
||||
|
||||
**Summary**
|
||||
|
||||
Returns the **object** type
|
||||
for a given value as a [jerry_object_type_t](#jerry_object_type_t) enum value.
|
||||
|
||||
Note: For non-object parameters `JERRY_OBJECT_TYPE_NONE` is returned.
|
||||
Note: the returned type can be checked for more detailed type information in the following cases:
|
||||
- `JERRY_OBJECT_TYPE_CONTAINER`, *see also:* [jerry_container_get_type](#jerry_container_get_type)
|
||||
- `JERRY_OBJECT_TYPE_FUNCTION`, *see also:* [jerry_function_get_type](#jerry_function_get_type)
|
||||
- `JERRY_OBJECT_TYPE_ITERATOR`, *see also:* [jerry_iterator_get_type](#jerry_iterator_get_type)
|
||||
- `JERRY_OBJECT_TYPE_TYPEDARRAY`, *see also:* [jerry_get_typedarray_type](#jerry_get_typedarray_type)
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_object_type_t
|
||||
jerry_object_get_type (const jerry_value_t value);
|
||||
```
|
||||
|
||||
- `value` - JavaScript value to check.
|
||||
- return value
|
||||
- One of the [jerry_object_type_t](#jerry_object_type_t) value.
|
||||
|
||||
*New in version [[NEXT_RELEASE]]*.
|
||||
|
||||
**Example**
|
||||
|
||||
```c
|
||||
{
|
||||
jerry_value_t object = jerry_create_object ();
|
||||
|
||||
jerry_object_type_t object_type_info = jerry_object_get_type (object);
|
||||
|
||||
if (type_info == JERRY_OBJECT_TYPE_GENERIC)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
jerry_release_value (object);
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_object_type_t](#jerry_object_type_t)
|
||||
|
||||
## jerry_function_get_type
|
||||
|
||||
**Summary**
|
||||
|
||||
Returns the **function** type
|
||||
for a given value as a [jerry_function_type_t](#jerry_function_type_t) enum value.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_function_type_t
|
||||
jerry_function_get_type (const jerry_value_t value);
|
||||
```
|
||||
|
||||
- `value` - JavaScript value to check.
|
||||
- return value
|
||||
- One of the [jerry_function_type_t](#jerry_function_type_t) value.
|
||||
|
||||
Note: For non-function parameters `JERRY_FUNCTION_TYPE_NONE` is returned.
|
||||
|
||||
*New in version [[NEXT_RELEASE]]*.
|
||||
|
||||
**Example**
|
||||
|
||||
```c
|
||||
{
|
||||
const jerry_char_t script[] = "function f() {}; f";
|
||||
jerry_value_t function_object = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
jerry_function_type_t function_type_info = jerry_function_get_type (function_object);
|
||||
|
||||
if (type_info == JERRY_FUNCTION_TYPE_GENERIC)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
jerry_release_value (function_object);
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_function_type_t](#jerry_function_type_t)
|
||||
|
||||
## jerry_iterator_get_type
|
||||
|
||||
**Summary**
|
||||
|
||||
Returns the **iterator** type
|
||||
for a given value as a [jerry_iterator_type_t](#jerry_iterator_type_t) enum value.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_iterator_type_t
|
||||
jerry_iterator_get_type (const jerry_value_t value);
|
||||
```
|
||||
|
||||
- `value` - JavaScript value to check.
|
||||
- return value
|
||||
- One of the [jerry_iterator_type_t](#jerry_iterator_type_t) value.
|
||||
|
||||
Note: For non-iterator parameters `JERRY_ITERATOR_TYPE_NONE` is returned.
|
||||
|
||||
*New in version [[NEXT_RELEASE]]*.
|
||||
|
||||
**Example**
|
||||
|
||||
```c
|
||||
{
|
||||
const jerry_char_t script[] = "[1, 2, 3].values()";
|
||||
jerry_value_t iterator = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
jerry_iterator_type_t iterator_type_info = jerry_iterator_get_type (iterator);
|
||||
|
||||
if (type_info == JERRY_ITERATOR_TYPE_ARRAY)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
jerry_release_value (iterator);
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_iterator_type_t](#jerry_iterator_type_t)
|
||||
|
||||
## jerry_is_feature_enabled
|
||||
|
||||
**Summary**
|
||||
|
||||
@@ -738,6 +738,41 @@ jerry_value_is_function (const jerry_value_t value) /**< api value */
|
||||
return ecma_op_is_callable (value);
|
||||
} /* jerry_value_is_function */
|
||||
|
||||
/**
|
||||
* Check if the specified value is an async function object value.
|
||||
*
|
||||
* @return true - if the specified value is an async function,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_value_is_async_function (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
&& !ecma_get_object_is_builtin (obj_p))
|
||||
{
|
||||
const ecma_compiled_code_t *bytecode_data_p;
|
||||
bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) obj_p);
|
||||
uint16_t type = CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags);
|
||||
|
||||
return (type == CBC_FUNCTION_ASYNC
|
||||
|| type == CBC_FUNCTION_ASYNC_ARROW
|
||||
|| type == CBC_FUNCTION_ASYNC_GENERATOR);
|
||||
}
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_UNUSED (value);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
return false;
|
||||
} /* jerry_value_is_async_function */
|
||||
|
||||
/**
|
||||
* Check if the specified value is number.
|
||||
*
|
||||
@@ -943,6 +978,274 @@ jerry_value_get_type (const jerry_value_t value) /**< input value to check */
|
||||
}
|
||||
} /* jerry_value_get_type */
|
||||
|
||||
/**
|
||||
* Get the object type of the given value
|
||||
*
|
||||
* @return JERRY_OBJECT_TYPE_NONE - if the given value is not an object
|
||||
* jerry_object_type_t value - otherwise
|
||||
*/
|
||||
jerry_object_type_t
|
||||
jerry_object_get_type (const jerry_value_t value) /**< input value to check */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
if (!ecma_is_value_object (value))
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_NONE;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
switch (ecma_get_object_type (obj_p))
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_FUNCTION;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_ARRAY;
|
||||
}
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
case ECMA_OBJECT_TYPE_PROXY:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_PROXY;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
switch (ext_obj_p->u.pseudo_array.type)
|
||||
{
|
||||
case ECMA_PSEUDO_ARRAY_ARGUMENTS:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_ARGUMENTS;
|
||||
}
|
||||
#if ENABLED (JERRY_BUILTIN_TYPEDARRAY)
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY:
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_TYPEDARRAY;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_TYPEDARRAY) */
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
case ECMA_PSEUDO_STRING_ITERATOR:
|
||||
case ECMA_PSEUDO_ARRAY_ITERATOR:
|
||||
#if ENABLED (JERRY_BUILTIN_MAP)
|
||||
case ECMA_PSEUDO_MAP_ITERATOR:
|
||||
#endif /* ENABLED (JERRY_BUILTIN_MAP) */
|
||||
#if ENABLED (JERRY_BUILTIN_SET)
|
||||
case ECMA_PSEUDO_SET_ITERATOR:
|
||||
#endif /* ENABLED (JERRY_BUILTIN_SET) */
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_ITERATOR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_CLASS:
|
||||
{
|
||||
switch (ext_obj_p->u.class_prop.class_id)
|
||||
{
|
||||
case LIT_MAGIC_STRING_ARGUMENTS_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_ARGUMENTS;
|
||||
}
|
||||
case LIT_MAGIC_STRING_BOOLEAN_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_BOOLEAN;
|
||||
}
|
||||
case LIT_MAGIC_STRING_DATE_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_DATE;
|
||||
}
|
||||
case LIT_MAGIC_STRING_NUMBER_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_NUMBER;
|
||||
}
|
||||
case LIT_MAGIC_STRING_REGEXP_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_REGEXP;
|
||||
}
|
||||
case LIT_MAGIC_STRING_STRING_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_STRING;
|
||||
}
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
case LIT_MAGIC_STRING_SYMBOL_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_SYMBOL;
|
||||
}
|
||||
case LIT_MAGIC_STRING_GENERATOR_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_GENERATOR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
#if ENABLED (JERRY_BUILTIN_BIGINT)
|
||||
case LIT_MAGIC_STRING_BIGINT_UL:
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_BIGINT;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
|
||||
#if ENABLED (JERRY_BUILTIN_CONTAINER)
|
||||
#if ENABLED (JERRY_BUILTIN_MAP)
|
||||
case LIT_MAGIC_STRING_MAP_UL:
|
||||
#endif /* ENABLED (JERRY_BUILTIN_MAP) */
|
||||
#if ENABLED (JERRY_BUILTIN_SET)
|
||||
case LIT_MAGIC_STRING_SET_UL:
|
||||
#endif /* ENABLED (JERRY_BUILTIN_SET) */
|
||||
#if ENABLED (JERRY_BUILTIN_WEAKMAP)
|
||||
case LIT_MAGIC_STRING_WEAKMAP_UL:
|
||||
#endif /* ENABLED (JERRY_BUILTIN_WEAKMAP) */
|
||||
#if ENABLED (JERRY_BUILTIN_WEAKSET)
|
||||
case LIT_MAGIC_STRING_WEAKSET_UL:
|
||||
#endif /* ENABLED (JERRY_BUILTIN_WEAKSET) */
|
||||
{
|
||||
return JERRY_OBJECT_TYPE_CONTAINER;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_CONTAINER) */
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return JERRY_OBJECT_TYPE_GENERIC;
|
||||
} /* jerry_object_get_type */
|
||||
|
||||
/**
|
||||
* Get the function type of the given value
|
||||
*
|
||||
* @return JERRY_FUNCTION_TYPE_NONE - if the given value is not a function object
|
||||
* jerry_function_type_t value - otherwise
|
||||
*/
|
||||
jerry_function_type_t
|
||||
jerry_function_get_type (const jerry_value_t value) /**< input value to check */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
switch (ecma_get_object_type (obj_p))
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
{
|
||||
return JERRY_FUNCTION_TYPE_BOUND;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
|
||||
{
|
||||
return JERRY_FUNCTION_TYPE_GENERIC;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
{
|
||||
if (!ecma_get_object_is_builtin (obj_p))
|
||||
{
|
||||
const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_obj_p);
|
||||
|
||||
switch (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags))
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
case CBC_FUNCTION_ARROW:
|
||||
case CBC_FUNCTION_ASYNC_ARROW:
|
||||
{
|
||||
return JERRY_FUNCTION_TYPE_ARROW;
|
||||
}
|
||||
case CBC_FUNCTION_GENERATOR:
|
||||
case CBC_FUNCTION_ASYNC_GENERATOR:
|
||||
{
|
||||
return JERRY_FUNCTION_TYPE_GENERATOR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
case CBC_FUNCTION_ACCESSOR:
|
||||
{
|
||||
return JERRY_FUNCTION_TYPE_ACCESSOR;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return JERRY_FUNCTION_TYPE_GENERIC;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JERRY_FUNCTION_TYPE_NONE;
|
||||
} /* jerry_function_get_type */
|
||||
|
||||
/**
|
||||
* Get the itearator type of the given value
|
||||
*
|
||||
* @return JERRY_ITERATOR_TYPE_NONE - if the given value is not an iterator object
|
||||
* jerry_iterator_type_t value - otherwise
|
||||
*/
|
||||
jerry_iterator_type_t
|
||||
jerry_iterator_get_type (const jerry_value_t value) /**< input value to check */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_PSEUDO_ARRAY)
|
||||
{
|
||||
switch (ext_obj_p->u.pseudo_array.type)
|
||||
{
|
||||
case ECMA_PSEUDO_ARRAY_ITERATOR:
|
||||
{
|
||||
return JERRY_ITERATOR_TYPE_ARRAY;
|
||||
}
|
||||
case ECMA_PSEUDO_STRING_ITERATOR:
|
||||
{
|
||||
return JERRY_ITERATOR_TYPE_STRING;
|
||||
}
|
||||
#if ENABLED (JERRY_BUILTIN_MAP)
|
||||
case ECMA_PSEUDO_MAP_ITERATOR:
|
||||
{
|
||||
return JERRY_ITERATOR_TYPE_MAP;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_MAP) */
|
||||
#if ENABLED (JERRY_BUILTIN_SET)
|
||||
case ECMA_PSEUDO_SET_ITERATOR:
|
||||
{
|
||||
return JERRY_ITERATOR_TYPE_SET;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_SET) */
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_UNUSED (value);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
return JERRY_ITERATOR_TYPE_NONE;
|
||||
} /* jerry_iterator_get_type */
|
||||
|
||||
/**
|
||||
* Check if the specified feature is enabled.
|
||||
*
|
||||
|
||||
@@ -381,6 +381,7 @@ bool jerry_value_is_boolean (const jerry_value_t value);
|
||||
bool jerry_value_is_constructor (const jerry_value_t value);
|
||||
bool jerry_value_is_error (const jerry_value_t value);
|
||||
bool jerry_value_is_function (const jerry_value_t value);
|
||||
bool jerry_value_is_async_function (const jerry_value_t value);
|
||||
bool jerry_value_is_number (const jerry_value_t value);
|
||||
bool jerry_value_is_null (const jerry_value_t value);
|
||||
bool jerry_value_is_object (const jerry_value_t value);
|
||||
@@ -408,7 +409,60 @@ typedef enum
|
||||
JERRY_TYPE_SYMBOL, /**< symbol type */
|
||||
} jerry_type_t;
|
||||
|
||||
/**
|
||||
* JerryScript object type information.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_OBJECT_TYPE_NONE = 0u, /**< Non object type */
|
||||
JERRY_OBJECT_TYPE_GENERIC, /**< Generic JavaScript object without any internal property */
|
||||
JERRY_OBJECT_TYPE_ARRAY, /**< Array object */
|
||||
JERRY_OBJECT_TYPE_PROXY, /**< Proxy object */
|
||||
JERRY_OBJECT_TYPE_FUNCTION, /**< Function object (see jerry_function_get_type) */
|
||||
JERRY_OBJECT_TYPE_TYPEDARRAY, /**< %TypedArray% object (see jerry_get_typedarray_type) */
|
||||
JERRY_OBJECT_TYPE_ITERATOR, /**< Iterator object (see jerry_iterator_get_type) */
|
||||
JERRY_OBJECT_TYPE_CONTAINER, /**< Container object (see jerry_container_get_type) */
|
||||
|
||||
JERRY_OBJECT_TYPE_ARGUMENTS, /**< Arguments object */
|
||||
JERRY_OBJECT_TYPE_BOOLEAN, /**< Boolean object */
|
||||
JERRY_OBJECT_TYPE_DATE, /**< Date object */
|
||||
JERRY_OBJECT_TYPE_NUMBER, /**< Number object */
|
||||
JERRY_OBJECT_TYPE_REGEXP, /**< RegExp object */
|
||||
JERRY_OBJECT_TYPE_STRING, /**< String object */
|
||||
JERRY_OBJECT_TYPE_SYMBOL, /**< Symbol object */
|
||||
JERRY_OBJECT_TYPE_GENERATOR, /**< Generator object */
|
||||
JERRY_OBJECT_TYPE_BIGINT, /**< BigInt object */
|
||||
} jerry_object_type_t;
|
||||
|
||||
/**
|
||||
* JerryScript function object type information.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_FUNCTION_TYPE_NONE = 0u, /**< Non function type */
|
||||
JERRY_FUNCTION_TYPE_GENERIC, /**< Generic JavaScript function */
|
||||
JERRY_FUNCTION_TYPE_ACCESSOR, /**< Accessor function */
|
||||
JERRY_FUNCTION_TYPE_BOUND, /**< Bound function */
|
||||
JERRY_FUNCTION_TYPE_ARROW, /**< Arrow fuction */
|
||||
JERRY_FUNCTION_TYPE_GENERATOR, /**< Generator function */
|
||||
} jerry_function_type_t;
|
||||
|
||||
/**
|
||||
* JerryScript iterator object type information.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_ITERATOR_TYPE_NONE = 0u, /**< Non iterator type */
|
||||
JERRY_ITERATOR_TYPE_ARRAY, /**< Array iterator */
|
||||
JERRY_ITERATOR_TYPE_STRING, /**< String iterator */
|
||||
JERRY_ITERATOR_TYPE_MAP, /**< Map iterator */
|
||||
JERRY_ITERATOR_TYPE_SET, /**< Set iterator */
|
||||
} jerry_iterator_type_t;
|
||||
|
||||
jerry_type_t jerry_value_get_type (const jerry_value_t value);
|
||||
jerry_object_type_t jerry_object_get_type (const jerry_value_t value);
|
||||
jerry_function_type_t jerry_function_get_type (const jerry_value_t value);
|
||||
jerry_iterator_type_t jerry_iterator_get_type (const jerry_value_t value);
|
||||
|
||||
/**
|
||||
* Checker function of whether the specified compile feature is enabled.
|
||||
|
||||
@@ -1313,12 +1313,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
byte_code_p = (uint8_t *) compiled_code_p;
|
||||
compiled_code_p->size = (uint16_t) (total_size >> JMEM_ALIGNMENT_LOG);
|
||||
compiled_code_p->refs = 1;
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
compiled_code_p->status_flags = 0;
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
compiled_code_p->status_flags = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_NORMAL);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM)
|
||||
@@ -1396,13 +1391,13 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
compiled_code_p->status_flags |= CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
uint16_t function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_NORMAL);
|
||||
|
||||
if (context_p->status_flags & (PARSER_IS_PROPERTY_GETTER | PARSER_IS_PROPERTY_SETTER))
|
||||
{
|
||||
function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ACCESSOR);
|
||||
}
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
else if (context_p->status_flags & PARSER_IS_ARROW_FUNCTION)
|
||||
{
|
||||
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
|
||||
@@ -1442,8 +1437,6 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_NORMAL);
|
||||
}
|
||||
|
||||
compiled_code_p->status_flags |= function_type;
|
||||
|
||||
if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM)
|
||||
{
|
||||
compiled_code_p->status_flags |= CBC_CODE_FLAGS_REST_PARAMETER;
|
||||
@@ -1461,6 +1454,8 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
compiled_code_p->status_flags |= function_type;
|
||||
|
||||
literal_pool_p = ((ecma_value_t *) byte_code_p) - context_p->register_count;
|
||||
byte_code_p += literal_length;
|
||||
dst_p = byte_code_p;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/* 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 "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "test-common.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
jerry_function_type_t type_info;
|
||||
jerry_value_t value;
|
||||
bool active;
|
||||
bool is_async;
|
||||
} test_entry_t;
|
||||
|
||||
#define ENTRY(TYPE, VALUE) { TYPE, VALUE, true, false }
|
||||
#define ENTRY_IF(TYPE, VALUE, FEATURE, ASYNC) { TYPE, VALUE, jerry_is_feature_enabled (FEATURE), ASYNC }
|
||||
#define EVALUATE(BUFF) (jerry_eval ((BUFF), sizeof ((BUFF)) - 1, JERRY_PARSE_NO_OPTS))
|
||||
static jerry_value_t
|
||||
test_ext_function (const jerry_value_t function_obj, /**< function object */
|
||||
const jerry_value_t this_val, /**< function this value */
|
||||
const jerry_value_t args_p[], /**< array of arguments */
|
||||
const jerry_length_t args_cnt) /**< number of arguments */
|
||||
{
|
||||
(void) function_obj;
|
||||
(void) this_val;
|
||||
(void) args_p;
|
||||
(void) args_cnt;
|
||||
return jerry_create_boolean (true);
|
||||
} /* test_ext_function */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
const jerry_char_t arrow_function[] = "_ => 5";
|
||||
const jerry_char_t async_arrow_function[] = "async _ => 5";
|
||||
const jerry_char_t generator_function[] = "function *f() {}; f";
|
||||
const jerry_char_t async_generator_function[] = "async function *f() {}; f";
|
||||
const jerry_char_t getter_function[] = "Object.getOwnPropertyDescriptor({get a(){}}, 'a').get";
|
||||
const jerry_char_t setter_function[] = "Object.getOwnPropertyDescriptor({set a(b){}}, 'a').set";
|
||||
const jerry_char_t method_function[] = "Object.getOwnPropertyDescriptor({a(){}}, 'a').value";
|
||||
|
||||
const jerry_char_t builtin_function[] = "Object";
|
||||
const jerry_char_t simple_function[] = "function f() {}; f";
|
||||
const jerry_char_t bound_function[] = "function f() {}; f.bind(1,2)";
|
||||
|
||||
test_entry_t entries[] =
|
||||
{
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_number (-33.0)),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_boolean (true)),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_undefined ()),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_null ()),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_string ((const jerry_char_t *) "foo")),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error")),
|
||||
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_object ()),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_array (10)),
|
||||
|
||||
ENTRY_IF (JERRY_FUNCTION_TYPE_ARROW, EVALUATE (arrow_function), JERRY_FEATURE_SYMBOL, false),
|
||||
ENTRY_IF (JERRY_FUNCTION_TYPE_ARROW, EVALUATE (async_arrow_function), JERRY_FEATURE_SYMBOL, true),
|
||||
ENTRY_IF (JERRY_FUNCTION_TYPE_GENERATOR, EVALUATE (generator_function), JERRY_FEATURE_SYMBOL, false),
|
||||
ENTRY_IF (JERRY_FUNCTION_TYPE_GENERATOR, EVALUATE (async_generator_function), JERRY_FEATURE_SYMBOL, true),
|
||||
ENTRY_IF (JERRY_FUNCTION_TYPE_GENERIC, EVALUATE (method_function), JERRY_FEATURE_SYMBOL, false),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_GENERIC, EVALUATE (builtin_function)),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_GENERIC, EVALUATE (simple_function)),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_BOUND, EVALUATE (bound_function)),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_GENERIC, jerry_create_external_function (test_ext_function)),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_ACCESSOR, EVALUATE (getter_function)),
|
||||
ENTRY (JERRY_FUNCTION_TYPE_ACCESSOR, EVALUATE (setter_function)),
|
||||
};
|
||||
|
||||
for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++)
|
||||
{
|
||||
jerry_function_type_t type_info = jerry_function_get_type (entries[idx].value);
|
||||
TEST_ASSERT (!entries[idx].active
|
||||
|| (type_info == entries[idx].type_info
|
||||
&& jerry_value_is_async_function (entries[idx].value) == entries[idx].is_async));
|
||||
jerry_release_value (entries[idx].value);
|
||||
}
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
return 0;
|
||||
} /* main */
|
||||
@@ -0,0 +1,106 @@
|
||||
/* 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 "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "test-common.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
jerry_iterator_type_t type_info;
|
||||
jerry_value_t value;
|
||||
bool active;
|
||||
} test_entry_t;
|
||||
|
||||
#define ENTRY(TYPE, VALUE) { TYPE, VALUE, true }
|
||||
#define ENTRY_IF(TYPE, VALUE, FEATURE) { TYPE, VALUE, jerry_is_feature_enabled (FEATURE) }
|
||||
#define EVALUATE(BUFF) (jerry_eval ((BUFF), sizeof ((BUFF)) - 1, JERRY_PARSE_NO_OPTS))
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
const jerry_char_t array_iterator_keys[] = "[1, 2, 3].keys()";
|
||||
const jerry_char_t array_iterator_values[] = "[1, 2, 3].values()";
|
||||
const jerry_char_t array_iterator_entries[] = "[1, 2, 3].entries()";
|
||||
const jerry_char_t array_iterator_symbol_iterator[] = "([1, 2, 3])[Symbol.iterator]()";
|
||||
|
||||
const jerry_char_t typedarray_iterator_keys[] = "new Uint8Array([1, 2, 3]).keys()";
|
||||
const jerry_char_t typedarray_iterator_values[] = "new Uint8Array([1, 2, 3]).values()";
|
||||
const jerry_char_t typedarray_iterator_entries[] = "new Uint8Array([1, 2, 3]).entries()";
|
||||
const jerry_char_t typedarray_iterator_symbol_iterator[] = "new Uint8Array([1, 2, 3])[Symbol.iterator]()";
|
||||
|
||||
const jerry_char_t string_symbol_iterator[] = "('foo')[Symbol.iterator]()";
|
||||
|
||||
const jerry_char_t map_iterator_keys[] = "new Map([1, 2, 3].entries()).keys()";
|
||||
const jerry_char_t map_iterator_values[] = "new Map([1, 2, 3].entries()).values()";
|
||||
const jerry_char_t map_iterator_entries[] = "new Map([1, 2, 3].entries()).entries()";
|
||||
const jerry_char_t map_iterator_symbol_iterator[] = "new Map([1, 2, 3].entries())[Symbol.iterator]()";
|
||||
|
||||
const jerry_char_t set_iterator_keys[] = "new Set([1, 2, 3]).keys()";
|
||||
const jerry_char_t set_iterator_values[] = "new Set([1, 2, 3]).values()";
|
||||
const jerry_char_t set_iterator_entries[] = "new Set([1, 2, 3]).entries()";
|
||||
const jerry_char_t set_iterator_symbol_iterator[] = "new Set([1, 2, 3])[Symbol.iterator]()";
|
||||
|
||||
test_entry_t entries[] =
|
||||
{
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_number (-33.0)),
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_boolean (true)),
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_undefined ()),
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_null ()),
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_string ((const jerry_char_t *) "foo")),
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error")),
|
||||
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_object ()),
|
||||
ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_array (10)),
|
||||
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (array_iterator_keys), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (array_iterator_values), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (array_iterator_entries), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (array_iterator_symbol_iterator), JERRY_FEATURE_SYMBOL),
|
||||
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (typedarray_iterator_keys), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (typedarray_iterator_values), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (typedarray_iterator_entries), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (typedarray_iterator_symbol_iterator), JERRY_FEATURE_SYMBOL),
|
||||
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_STRING, EVALUATE (string_symbol_iterator), JERRY_FEATURE_SYMBOL),
|
||||
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_MAP, EVALUATE (map_iterator_keys), JERRY_FEATURE_MAP),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_MAP, EVALUATE (map_iterator_values), JERRY_FEATURE_MAP),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_MAP, EVALUATE (map_iterator_entries), JERRY_FEATURE_MAP),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_MAP, EVALUATE (map_iterator_symbol_iterator), JERRY_FEATURE_MAP),
|
||||
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_SET, EVALUATE (set_iterator_keys), JERRY_FEATURE_SET),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_SET, EVALUATE (set_iterator_values), JERRY_FEATURE_SET),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_SET, EVALUATE (set_iterator_entries), JERRY_FEATURE_SET),
|
||||
ENTRY_IF (JERRY_ITERATOR_TYPE_SET, EVALUATE (set_iterator_symbol_iterator), JERRY_FEATURE_SET),
|
||||
};
|
||||
|
||||
for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++)
|
||||
{
|
||||
jerry_iterator_type_t type_info = jerry_iterator_get_type (entries[idx].value);
|
||||
TEST_ASSERT (!entries[idx].active || type_info == entries[idx].type_info);
|
||||
jerry_release_value (entries[idx].value);
|
||||
}
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
return 0;
|
||||
} /* main */
|
||||
@@ -0,0 +1,129 @@
|
||||
/* 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 "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "test-common.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
jerry_object_type_t type_info;
|
||||
jerry_value_t value;
|
||||
bool active;
|
||||
} test_entry_t;
|
||||
|
||||
#define ENTRY(TYPE, VALUE) { TYPE, VALUE, true }
|
||||
#define ENTRY_IF(TYPE, VALUE, FEATURE) { TYPE, VALUE, jerry_is_feature_enabled (FEATURE) }
|
||||
#define EVALUATE(BUFF) (jerry_eval ((BUFF), sizeof ((BUFF)) - 1, JERRY_PARSE_NO_OPTS))
|
||||
static jerry_value_t
|
||||
test_ext_function (const jerry_value_t function_obj, /**< function object */
|
||||
const jerry_value_t this_val, /**< function this value */
|
||||
const jerry_value_t args_p[], /**< array of arguments */
|
||||
const jerry_length_t args_cnt) /**< number of arguments */
|
||||
{
|
||||
(void) function_obj;
|
||||
(void) this_val;
|
||||
(void) args_p;
|
||||
(void) args_cnt;
|
||||
return jerry_create_boolean (true);
|
||||
} /* test_ext_function */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
const jerry_char_t proxy_object[] = "new Proxy({}, {})";
|
||||
const jerry_char_t typedarray_object[] = "new Uint8Array()";
|
||||
const jerry_char_t container_object[] = "new Map()";
|
||||
const jerry_char_t iterator_object[] = "[1, 2, 3].values()";
|
||||
const jerry_char_t arrow_function[] = "_ => 5";
|
||||
const jerry_char_t async_arrow_function[] = "async _ => 5";
|
||||
const jerry_char_t generator_function[] = "function *f() {}; f";
|
||||
const jerry_char_t async_generator_function[] = "async function *f() {}; f";
|
||||
const jerry_char_t getter_function[] = "Object.getOwnPropertyDescriptor({get a(){}}, 'a').get";
|
||||
const jerry_char_t setter_function[] = "Object.getOwnPropertyDescriptor({set a(b){}}, 'a').set";
|
||||
const jerry_char_t method_function[] = "Object.getOwnPropertyDescriptor({a(){}}, 'a').value";
|
||||
|
||||
const jerry_char_t symbol_object[] = "new Object(Symbol('foo'))";
|
||||
const jerry_char_t generator_object[] = "function *f() { yield 5 }; f()";
|
||||
const jerry_char_t bigint_object[] = "Object(5n)";
|
||||
|
||||
const jerry_char_t builtin_function[] = "Object";
|
||||
const jerry_char_t simple_function[] = "function f() {}; f";
|
||||
const jerry_char_t bound_function[] = "function f() {}; f.bind(1,2)";
|
||||
const jerry_char_t mapped_arguments[] = "function f(a, b) { return arguments; }; f()";
|
||||
const jerry_char_t unmapped_arguments[] = "function f(a, b) {'use strict'; return arguments; }; f()";
|
||||
const jerry_char_t boolean_object[] = "new Boolean(true)";
|
||||
const jerry_char_t date_object[] = "new Date()";
|
||||
const jerry_char_t number_object[] = "new Number(5)";
|
||||
const jerry_char_t regexp_object[] = "new RegExp()";
|
||||
const jerry_char_t string_object[] = "new String('foo')";
|
||||
|
||||
test_entry_t entries[] =
|
||||
{
|
||||
ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_number (-33.0)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_boolean (true)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_undefined ()),
|
||||
ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_null ()),
|
||||
ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_string ((const jerry_char_t *) "foo")),
|
||||
ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error")),
|
||||
|
||||
ENTRY (JERRY_OBJECT_TYPE_GENERIC, jerry_create_object ()),
|
||||
ENTRY (JERRY_OBJECT_TYPE_ARRAY, jerry_create_array (10)),
|
||||
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_PROXY, EVALUATE (proxy_object), JERRY_FEATURE_PROXY),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_TYPEDARRAY, EVALUATE (typedarray_object), JERRY_FEATURE_TYPEDARRAY),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_CONTAINER, EVALUATE (container_object), JERRY_FEATURE_MAP),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_ITERATOR, EVALUATE (iterator_object), JERRY_FEATURE_SYMBOL),
|
||||
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (arrow_function), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (async_arrow_function), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (generator_function), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (async_generator_function), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (method_function), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (builtin_function)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (simple_function)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (bound_function)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_FUNCTION, jerry_create_external_function (test_ext_function)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (getter_function)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (setter_function)),
|
||||
|
||||
ENTRY (JERRY_OBJECT_TYPE_ARGUMENTS, EVALUATE (mapped_arguments)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_ARGUMENTS, EVALUATE (unmapped_arguments)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_BOOLEAN, EVALUATE (boolean_object)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_DATE, EVALUATE (date_object)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_NUMBER, EVALUATE (number_object)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_REGEXP, EVALUATE (regexp_object)),
|
||||
ENTRY (JERRY_OBJECT_TYPE_STRING, EVALUATE (string_object)),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_SYMBOL, EVALUATE (symbol_object), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_GENERATOR, EVALUATE (generator_object), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_BIGINT, EVALUATE (bigint_object), JERRY_FEATURE_BIGINT),
|
||||
};
|
||||
|
||||
for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++)
|
||||
{
|
||||
jerry_object_type_t type_info = jerry_object_get_type (entries[idx].value);
|
||||
TEST_ASSERT (!entries[idx].active || type_info == entries[idx].type_info);
|
||||
jerry_release_value (entries[idx].value);
|
||||
}
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
return 0;
|
||||
} /* main */
|
||||
Reference in New Issue
Block a user