Rework the public API (#4829)

Related to #4186.

Some notable changes:
  - The term 'Error' now strictly refers to native Error objects defined in
    the ECMA standard, which are ordinary objects. All other uses of
    'error' or 'error reference' where the term refers to a thrown value is
    now called 'exception'.

  - Simplified the naming scheme of many String API functions. These functions
    will now also take an 'encoding' argument to specify the desired
    encoding in which to operate.

  - Removed the substring-copy-to-buffer functions. These functions
    behaved awkwardly, as they use character index to specify the
    start/end positions, and were mostly used incorrectly with byte
    offsets instead. The functionality can still be replicated with
    other functions if necessary.

  - String-to-buffer functions will no longer fail if the buffer is not
    sufficiently large, the string will instead be cropped.

  - Fixed the usage of the '_sz' prefix in many API functions. The term
    'sz' means zero-terminated string in hungarian notation, this was
    used incorrectly in many cases.

  - Renamed most of the public API functions to have shorter, more on-point
    names, rather than the often too long descriptive names. Functions are now
    also grouped by the type of value they operate on, where this makes
    sense.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
Dániel Bátyai
2021-12-06 10:20:09 +01:00
committed by GitHub
parent 81d2319144
commit 9860d66a56
180 changed files with 10738 additions and 11025 deletions
+7 -7
View File
@@ -4,7 +4,7 @@
**Summary**
Macro for `const jerry_value_t` for which jerry_release_value() is
Macro for `const jerry_value_t` for which jerry_value_free() is
automatically called when the variable goes out of scope.
*Note*: The macro depends on compiler support. For GCC and LLVM/clang, the macro is implemented
@@ -21,23 +21,23 @@ using the `__cleanup__` variable attribute. For other compilers, no support has
static void
foo (bool enable)
{
JERRYX_AR_VALUE_T bar = jerry_create_string ((const jerry_char_t *) "...");
JERRYX_AR_VALUE_T bar = jerry_string_sz ("...");
if (enable)
{
JERRYX_AR_VALUE_T baz = jerry_get_global_object ();
JERRYX_AR_VALUE_T baz = jerry_current_realm ();
/* bar and baz can now be used. */
/*
* jerry_release_value (baz) and jerry_release_value (bar) is called automatically before
* jerry_value_free (baz) and jerry_value_free (bar) is called automatically before
* returning, because `baz` and `bar` go out of scope.
*/
return;
}
/*
* jerry_release_value (bar) is called automatically when the function returns,
* jerry_value_free (bar) is called automatically when the function returns,
* because `bar` goes out of scope.
*/
}
@@ -46,5 +46,5 @@ foo (bool enable)
**See also**
- [jerry_value_t](../docs/02.API-REFERENCE.md#jerry_value_t)
- [jerry_acquire_value](../docs/02.API-REFERENCE.md#jerry_acquire_value)
- [jerry_release_value](../docs/02.API-REFERENCE.md#jerry_release_value)
- [jerry_value_copy](../docs/02.API-REFERENCE.md#jerry_value_copy)
- [jerry_value_free](../docs/02.API-REFERENCE.md#jerry_value_free)