![]() |
BSB Developer Docs
|
Utility functions for working with JS values. More...
Go to the source code of this file.
Macros | |
| #define | JS_CHECK_ARGS_COUNT(n) |
| #define | JS_CHECK_INSTANCE() |
| #define | JS_CHECK_CONSTRUCTOR() |
| #define | JS_CHECK_ARG_IS_FUNCTION(arg) |
| #define | JS_CHECK_ARG_IS_STRING(arg) |
Functions | |
| void | js_check_and_free (jerry_value_t value) |
| Check if value is not an exception and free it. | |
| void | js_set_constructor_prototype (jerry_value_t constructor, jerry_value_t prototype) |
| Set a prototype object to be used with a constructor. | |
| jerry_value_t | js_object_construct (const char *name, const jerry_value_t args[], const jerry_length_t args_count) |
| Construct an object given the class name. | |
| void | js_set_property (jerry_value_t object, const char *name, jerry_value_t property) |
| Set a property in a JS object. | |
| void | js_set_method (jerry_value_t object, const char *name, jerry_external_handler_t handler) |
| Set a method in a JS object. | |
| void | js_set_method_sym (jerry_value_t object, jerry_well_known_symbol_t key, jerry_external_handler_t handler) |
| Set a method in a JS object using a well-known symbol as a key. | |
| void | js_set_property_sym (jerry_value_t object, jerry_well_known_symbol_t key, jerry_value_t property) |
| Set a property in a JS object using a well-known symbol as a key. | |
| void | js_set_property_getset (jerry_value_t object, const char *name, jerry_external_handler_t getter, jerry_external_handler_t setter) |
| Set a property defined by its getter and setter in a JS object. | |
| bool | js_object_has_property (jerry_value_t object, const char *key) |
| Test if an object has a property with given name. | |
| jerry_value_t | js_object_get_nested_property (jerry_value_t object, const char *const keys[], size_t nesting_count) |
| Get a value of a property nested under several layers. | |
| jerry_value_t | js_iterator_result (bool done, jerry_value_t value) |
| Create a return value of an Iterator's next() method. | |
| char * | js_string_to_c_string (jerry_value_t value) |
| If value is a JS string, return its UTF8 representation. | |
| char * | js_value_to_c_string (jerry_value_t value) |
| Convert any value to a character string. | |
| FuriString * | js_string_to_furi_string (jerry_value_t value) |
| If value is a JS string, return its UTF8 representation. | |
| jerry_value_t | js_utf8_string (const FuriString *s) |
| Create a JS string by decoding a UTF-8 FuriString. | |
| bool | js_value_to_integer (jerry_value_t value, int *result) |
| Convert a JS value to an integer. | |
| void | js_copy_property (jerry_value_t dst, jerry_value_t src, const char *key) |
| Copy a property (if it exists) from one object to another. | |
| bool | js_is_instance_of (jerry_value_t obj, const char *constructor_name) |
Check if an object is an instance of a given constructor (JS instanceof operation). | |
| jerry_value_t | js_rejected_promise (const char *msg) |
| Create and reject a Promise with a message. | |
| jerry_value_t | js_rejected_promise_from_exception (jerry_value_t exception) |
| Create and reject a Promise with a message extracted from an exception. | |
| void | js_reject_promise_with_exception (jerry_value_t promise, jerry_value_t exception) |
| Reject a Promise with a message extracted from an exception. | |
| bool | js_exception_is_null (jerry_value_t exception) |
| Check if the exception holds a null as the value. | |
| FuriString * | js_get_exception_string (jerry_value_t exception) |
| Create a string out of a JS exception. | |
| void | js_log_exception (const char *tag, const char *msg, jerry_value_t exception) |
| Log exception message with ERROR severity. | |
| jerry_value_t | js_arraybuffer_from_byte_array (ByteArray_t *array) |
| Create an external ArrayBuffer referencing ByteArray's data. | |
| jerry_value_t | js_arraybuffer_from_sized_buffer (SizedBuffer buffer) |
| Create an external ArrayBuffer referencing SizedBuffer's data. | |
Utility functions for working with JS values.
| #define JS_CHECK_ARG_IS_FUNCTION | ( | arg | ) |
| #define JS_CHECK_ARG_IS_STRING | ( | arg | ) |
| #define JS_CHECK_ARGS_COUNT | ( | n | ) |
| #define JS_CHECK_CONSTRUCTOR | ( | ) |
| #define JS_CHECK_INSTANCE | ( | ) |
| jerry_value_t js_arraybuffer_from_byte_array | ( | ByteArray_t * | array | ) |
Create an external ArrayBuffer referencing ByteArray's data.
Ownership of the ByteArray is transferred to jerryscript.
| array | pointer to ByteArray (heap-allocated). |
| jerry_value_t js_arraybuffer_from_sized_buffer | ( | SizedBuffer | buffer | ) |
Create an external ArrayBuffer referencing SizedBuffer's data.
Ownership of the buffer is transferred to jerryscript.
| buffer | data to build an ArrayBuffer from. |
| void js_check_and_free | ( | jerry_value_t | value | ) |
Check if value is not an exception and free it.
| value | value to check and free |
| bool js_exception_is_null | ( | jerry_value_t | exception | ) |
Check if the exception holds a null as the value.
| exception | JS exception. This value is not freed. |
true if the exception holds null, false otherwise | FuriString * js_get_exception_string | ( | jerry_value_t | exception | ) |
Create a string out of a JS exception.
| exception | JS exception. This value is not freed. |
| jerry_value_t js_iterator_result | ( | bool | done, |
| jerry_value_t | value ) |
Create a return value of an Iterator's next() method.
The object has two properties: done and value.
| done | value for the done property |
| value | contents of the value property (freed). |
| jerry_value_t js_object_construct | ( | const char * | name, |
| const jerry_value_t | args[], | ||
| const jerry_length_t | args_count ) |
Construct an object given the class name.
args can be NULL if the constructor takes no arguments, in which case args_count must be 0.
| name | class name as a zero-terminated string |
| args | array of arguments to pass to the constructor |
| args_count | number of arguments passed to the constructor |
| jerry_value_t js_object_get_nested_property | ( | jerry_value_t | object, |
| const char *const | keys[], | ||
| size_t | nesting_count ) |
Get a value of a property nested under several layers.
Example: get object.foo.bar.baz
const char* const keys[] = {"foo", "bar", "baz"}; jerry_value_t baz_value = js_object_get_nested_property(object, keys, 3);
| object | root object. |
| keys | array of property names for each nesting level. |
| nesting_count | number of entries in the keys array. |
| void js_reject_promise_with_exception | ( | jerry_value_t | promise, |
| jerry_value_t | exception ) |
Reject a Promise with a message extracted from an exception.
| promise | promise (freed) |
| exception | exception (freed) |
| jerry_value_t js_rejected_promise_from_exception | ( | jerry_value_t | exception | ) |
Create and reject a Promise with a message extracted from an exception.
| exception | exception (freed) |
| void js_set_constructor_prototype | ( | jerry_value_t | constructor, |
| jerry_value_t | prototype ) |
Set a prototype object to be used with a constructor.
| constructor | Constructor function (not freed) |
| prototype | Prototype value to set (freed) |
| void js_set_method | ( | jerry_value_t | object, |
| const char * | name, | ||
| jerry_external_handler_t | handler ) |
Set a method in a JS object.
| object | Object (not freed) |
| name | Method name |
| handler | handler Method handler |
| void js_set_method_sym | ( | jerry_value_t | object, |
| jerry_well_known_symbol_t | key, | ||
| jerry_external_handler_t | handler ) |
Set a method in a JS object using a well-known symbol as a key.
| object | Object (not freed) |
| key | Method name |
| handler | handler Method handler |
| void js_set_property | ( | jerry_value_t | object, |
| const char * | name, | ||
| jerry_value_t | property ) |
Set a property in a JS object.
| object | Object (not freed) |
| name | Property name |
| property | Property value to set (freed) |
| void js_set_property_getset | ( | jerry_value_t | object, |
| const char * | name, | ||
| jerry_external_handler_t | getter, | ||
| jerry_external_handler_t | setter ) |
Set a property defined by its getter and setter in a JS object.
| object | Object (not freed) |
| name | Property name |
| getter | getter callback (can be NULL) |
| setter | getter callback (can be NULL) |
| void js_set_property_sym | ( | jerry_value_t | object, |
| jerry_well_known_symbol_t | key, | ||
| jerry_value_t | property ) |
Set a property in a JS object using a well-known symbol as a key.
| object | Object (not freed) |
| key | Property name |
| property | Property value to set (freed) |
| char * js_string_to_c_string | ( | jerry_value_t | value | ) |
If value is a JS string, return its UTF8 representation.
| FuriString * js_string_to_furi_string | ( | jerry_value_t | value | ) |
If value is a JS string, return its UTF8 representation.
| jerry_value_t js_utf8_string | ( | const FuriString * | s | ) |
Create a JS string by decoding a UTF-8 FuriString.
| s | source string |
| char * js_value_to_c_string | ( | jerry_value_t | value | ) |
Convert any value to a character string.
If the value is already a string, it is used as-is, otherwise it will be converted using the toString method.
| bool js_value_to_integer | ( | jerry_value_t | value, |
| int * | result ) |
Convert a JS value to an integer.
Usual JS rules are applied.
| value | The value. | |
| [out] | result | Result placeholder. |