Add C API to query the type of a JS value (#2195)

New API function:
 * jerry_value_get_type

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
This commit is contained in:
Péter Gál
2018-02-13 13:48:07 +01:00
committed by László Langó
parent 4652c3caaf
commit d7991ae54c
7 changed files with 266 additions and 41 deletions
+51
View File
@@ -11,6 +11,19 @@ Enum that contains the following elements:
- JERRY_INIT_MEM_STATS_SEPARATE - dump memory statistics and reset peak values after parse
- JERRY_INIT_DEBUGGER - deprecated, an unused placeholder now
## jerry_type_t
Enum that contains a set of elements to represent JavaScript type:
- JERRY_TYPE_NONE - no type information
- JERRY_TYPE_UNDEFINED - undefined value
- JERRY_TYPE_NULL - null value
- JERRY_TYPE_BOOLEAN - boolean value
- JERRY_TYPE_NUMBER - number value
- JERRY_TYPE_STRING - string value
- JERRY_TYPE_OBJECT - object value
- JERRY_TYPE_FUNCTION - function value
## jerry_error_t
Possible types of an error:
@@ -1447,6 +1460,44 @@ jerry_value_is_undefined (const jerry_value_t value)
- [jerry_release_value](#jerry_release_value)
## jerry_value_get_type
**Summary**
Returns the JavaScript type
for a given value as a [jerry_type_t](#jerry_type_t) enum value.
This is a similar operation as the 'typeof' operator
in the standard with an exception that the 'null'
value has its own enum value.
**Prototype**
```c
jerry_type_t
jerry_value_get_type (const jerry_value_t value);
```
**Example**
```c
{
jerry_value_t number = jerry_create_number (3.3);
jerry_type_t type_info = jerry_value_get_type (number);
if (type_info == JERRY_TYPE_NUMBER)
{
...
}
jerry_value_release (number);
}
```
**See also**
- [jerry_type_t](#jerry_type_t)
## jerry_is_feature_enabled
**Summary**