aboutsummaryrefslogtreecommitdiff
path: root/targets/esp8266/user/jerry_run.c
diff options
context:
space:
mode:
authorDániel Bátyai <dbatyai@inf.u-szeged.hu>2021-12-06 10:20:09 +0100
committerGitHub <noreply@github.com>2021-12-06 10:20:09 +0100
commit9860d66a56ed44f62e1dafb9900e6f2c886a56d3 (patch)
treefd96679ecb136c3fe03711811d2b655e92cbca43 /targets/esp8266/user/jerry_run.c
parent81d2319144377f87e716c73a9b8b46f2bf5d09e5 (diff)
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
Diffstat (limited to 'targets/esp8266/user/jerry_run.c')
-rw-r--r--targets/esp8266/user/jerry_run.c87
1 files changed, 48 insertions, 39 deletions
diff --git a/targets/esp8266/user/jerry_run.c b/targets/esp8266/user/jerry_run.c
index e7fff4c3..b3205bac 100644
--- a/targets/esp8266/user/jerry_run.c
+++ b/targets/esp8266/user/jerry_run.c
@@ -13,88 +13,97 @@
* limitations under the License.
*/
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "jerry_extapi.h"
#include "jerry_run.h"
-#include "jerryscript.h"
+#include <stdio.h>
+#include <stdlib.h>
+
#include "jerryscript-port.h"
+#include "jerryscript.h"
+
+#include "jerry_extapi.h"
-static const char* fn_sys_loop_name = "sysloop";
+static const char *fn_sys_loop_name = "sysloop";
-void js_entry ()
+void
+js_entry ()
{
- 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);
jerry_init (JERRY_INIT_EMPTY);
js_register_functions ();
}
-int js_eval (const char *source_p, const size_t source_size)
+int
+js_eval (const char *source_p, const size_t source_size)
{
- jerry_value_t res = jerry_eval ((jerry_char_t *) source_p,
- source_size,
- JERRY_PARSE_NO_OPTS);
- if (jerry_value_is_error (res)) {
- jerry_release_value (res);
+ jerry_value_t res = jerry_eval ((jerry_char_t *) source_p, source_size, JERRY_PARSE_NO_OPTS);
+ if (jerry_value_is_exception (res))
+ {
+ jerry_value_free (res);
return -1;
}
- jerry_release_value (res);
+ jerry_value_free (res);
return 0;
}
-int js_loop (uint32_t ticknow)
+int
+js_loop (uint32_t ticknow)
{
- jerry_value_t global_obj_val = jerry_get_global_object ();
- jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) fn_sys_loop_name);
- jerry_value_t sysloop_func = jerry_get_property (global_obj_val, prop_name_val);
- jerry_release_value (prop_name_val);
+ jerry_value_t global_obj_val = jerry_current_realm ();
+ jerry_value_t prop_name_val = jerry_string_sz (fn_sys_loop_name);
+ jerry_value_t sysloop_func = jerry_object_get (global_obj_val, prop_name_val);
+ jerry_value_free (prop_name_val);
- if (jerry_value_is_error (sysloop_func)) {
+ if (jerry_value_is_exception (sysloop_func))
+ {
printf ("Error: '%s' not defined!!!\r\n", fn_sys_loop_name);
- jerry_release_value (sysloop_func);
- jerry_release_value (global_obj_val);
+ jerry_value_free (sysloop_func);
+ jerry_value_free (global_obj_val);
return -1;
}
- if (!jerry_value_is_function (sysloop_func)) {
+ if (!jerry_value_is_function (sysloop_func))
+ {
printf ("Error: '%s' is not a function!!!\r\n", fn_sys_loop_name);
- jerry_release_value (sysloop_func);
- jerry_release_value (global_obj_val);
+ jerry_value_free (sysloop_func);
+ jerry_value_free (global_obj_val);
return -2;
}
- jerry_value_t val_args[] = { jerry_create_number (ticknow) };
+ jerry_value_t val_args[] = { jerry_number (ticknow) };
uint16_t val_argv = sizeof (val_args) / sizeof (jerry_value_t);
- jerry_value_t res = jerry_call_function (sysloop_func,
- global_obj_val,
- val_args,
- val_argv);
+ jerry_value_t res = jerry_call (sysloop_func, global_obj_val, val_args, val_argv);
- for (uint16_t i = 0; i < val_argv; i++) {
- jerry_release_value (val_args[i]);
+ for (uint16_t i = 0; i < val_argv; i++)
+ {
+ jerry_value_free (val_args[i]);
}
- jerry_release_value (sysloop_func);
- jerry_release_value (global_obj_val);
+ jerry_value_free (sysloop_func);
+ jerry_value_free (global_obj_val);
- if (jerry_value_is_error (res)) {
- jerry_release_value (res);
+ if (jerry_value_is_exception (res))
+ {
+ jerry_value_free (res);
return -3;
}
- jerry_release_value (res);
+ jerry_value_free (res);
return 0;
}
-void js_exit (void)
+void
+js_exit (void)
{
jerry_cleanup ();
}