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
+23 -17
View File
@@ -16,10 +16,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "shell.h"
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
#include "jerryscript-port.h"
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
#include "shell.h"
/**
* Standalone Jerry exit codes
@@ -34,26 +36,27 @@ static void
register_js_function (const char *name_p, /**< name of the function */
jerry_external_handler_t handler_p) /**< function callback */
{
jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p);
jerry_value_t result_val = jerryx_handler_register_global (name_p, handler_p);
if (jerry_value_is_error (result_val))
if (jerry_value_is_exception (result_val))
{
printf ("Warning: failed to register '%s' method.", name_p);
}
jerry_release_value (result_val);
jerry_value_free (result_val);
} /* register_js_function */
/**
* Jerryscript simple test
*/
int test_jerry (int argc, char **argv)
int
test_jerry (int argc, char **argv)
{
/* Suppress compiler errors */
(void) argc;
(void) argv;
jerry_value_t ret_value = jerry_create_undefined ();
jerry_value_t ret_value = jerry_undefined ();
const jerry_char_t script[] = "print ('Hello, World!');";
printf ("This test run the following script code: [%s]\n\n", script);
@@ -67,7 +70,7 @@ int test_jerry (int argc, char **argv)
/* Setup Global scope code */
ret_value = jerry_parse (script, sizeof (script) - 1, NULL);
if (!jerry_value_is_error (ret_value))
if (!jerry_value_is_exception (ret_value))
{
/* Execute the parsed source code in the Global scope */
ret_value = jerry_run (ret_value);
@@ -75,14 +78,14 @@ int test_jerry (int argc, char **argv)
int ret_code = JERRY_STANDALONE_EXIT_CODE_OK;
if (jerry_value_is_error (ret_value))
if (jerry_value_is_exception (ret_value))
{
printf ("Script Error!");
ret_code = JERRY_STANDALONE_EXIT_CODE_FAIL;
}
jerry_release_value (ret_value);
jerry_value_free (ret_value);
/* Cleanup engine */
jerry_cleanup ();
@@ -91,14 +94,17 @@ int test_jerry (int argc, char **argv)
} /* test_jerry */
const shell_command_t shell_commands[] = {
{ "test", "Jerryscript Hello World test", test_jerry },
{ NULL, NULL, NULL }
};
const shell_command_t shell_commands[] = { { "test", "Jerryscript Hello World test", test_jerry },
{ NULL, NULL, NULL } };
int main (void)
int
main (void)
{
union { double d; unsigned u; } now = { .d = jerry_port_get_current_time () };
union
{
double d;
unsigned u;
} now = { .d = jerry_port_get_current_time () };
srand (now.u);
printf ("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
printf ("This board features a(n) %s MCU.\n", RIOT_MCU);