Просмотр исходного кода

Merge pull request #19 from yangfasheng/master

update rtthread-port event\util\port
Bernard Xiong 7 лет назад
Родитель
Сommit
8d067f7c60

+ 8 - 1
rtthread-port/jerry_event.c

@@ -219,6 +219,7 @@ rt_bool_t js_emit_event(jerry_value_t obj, const char *event_name, const jerry_v
             {
                 rt_kprintf("error calling listener\n");
             }
+            jerry_release_value(ret);
             listener = listener->next;
         }
 
@@ -359,7 +360,6 @@ DECLARE_HANDLER(get_event_names)
 void js_destroy_emitter(jerry_value_t obj)
 {
     void* native_handle = NULL;
-    struct js_event *event = NULL;
 
     jerry_get_object_native_pointer(obj, &native_handle, NULL);
 
@@ -441,3 +441,10 @@ int js_event_init(void)
     REGISTER_HANDLER(Event);
     return 0;
 }
+
+int js_event_deinit(void)
+{
+    if (_js_emitter_prototype)
+        jerry_release_value(_js_emitter_prototype);
+    return 0;
+}

+ 1 - 0
rtthread-port/jerry_event.h

@@ -14,6 +14,7 @@ rt_bool_t js_emit_event(jerry_value_t obj, const char *event_name, const jerry_v
 void js_destroy_emitter(jerry_value_t obj);
 void js_make_emitter(jerry_value_t obj, jerry_value_t prototype);
 int js_event_init(void);
+int js_event_deinit(void);
 
 #ifdef __cplusplus
 }

+ 23 - 2
rtthread-port/jerry_util.c

@@ -5,6 +5,7 @@
 #include <rtthread.h>
 #include <dfs_posix.h>
 #include "jerry_util.h"
+#include <jerry_event.h>
 
 static rt_mutex_t _util_lock = RT_NULL;
 
@@ -216,7 +217,7 @@ int js_read_file(const char* filename, char **script)
     if(!(*script)) return 0;
     (*script)[length] = '\0';
     fp = fopen(filename,"rb");
-    if(!fp) 
+    if(!fp)
     {
         rt_free(*script);
         *script = RT_NULL;
@@ -237,7 +238,8 @@ extern int js_console_init();
 extern int js_module_init();
 extern int js_buffer_init();
 extern int js_buffer_cleanup();
-extern int js_event_init(void);
+
+static js_util_user _user_init = NULL, _user_cleanup = NULL;
 
 int js_util_init(void)
 {
@@ -248,6 +250,10 @@ int js_util_init(void)
     js_module_init();
     js_buffer_init();
     js_event_init();
+    if (_user_init != NULL)
+    {
+        _user_init();
+    }
 
     return 0;
 }
@@ -255,10 +261,25 @@ int js_util_init(void)
 int js_util_cleanup(void)
 {
     js_buffer_cleanup();
+    js_event_deinit();
+    if (_user_cleanup != NULL)
+    {
+        _user_cleanup();
+    }
 
     return 0;
 }
 
+void js_util_user_init(js_util_user func)
+{
+    _user_init = func;
+}
+
+void js_util_user_cleanup(js_util_user func)
+{
+    _user_cleanup = func;
+}
+
 int js_util_lock(void)
 {
     return rt_mutex_take(_util_lock, RT_WAITING_FOREVER);

+ 4 - 0
rtthread-port/jerry_util.h

@@ -34,6 +34,8 @@ extern "C"
 {
 #endif
 
+typedef void(*js_util_user)(void);
+
 void js_set_property(const jerry_value_t obj, const char *name,
                      const jerry_value_t prop);
 void js_set_string_property(const jerry_value_t obj, const char *name,
@@ -57,6 +59,8 @@ int js_util_init(void);
 int js_util_cleanup(void);
 int js_util_lock(void);
 int js_util_unlock(void);
+void js_util_user_init(js_util_user func);
+void js_util_user_cleanup(js_util_user func);
 
 #ifdef __cplusplus
 }

+ 18 - 2
rtthread-port/port.c

@@ -31,9 +31,25 @@
  *
  * Example: a libc-based port may implement this with exit() or abort(), or both.
  */
-void jerry_port_fatal (jerry_fatal_code_t code)
+void jerry_port_fatal(jerry_fatal_code_t code)
 {
-    rt_kprintf("jerryScritp fatal...\n");
+    rt_kprintf("jerryScritp fatal [");
+    switch (code)
+    {
+    case ERR_OUT_OF_MEMORY:
+        rt_kprintf(" ERR_OUT_OF_MEMORY ");
+        break;
+    case ERR_SYSCALL:
+        rt_kprintf(" ERR_SYSCALL ");
+        break;
+    case ERR_REF_COUNT_LIMIT:
+        rt_kprintf(" ERR_REF_COUNT_LIMIT ");
+        break;
+    case ERR_FAILED_INTERNAL_ASSERTION:
+        rt_kprintf(" ERR_FAILED_INTERNAL_ASSERTION ");
+        break;
+    };
+    rt_kprintf("]...\n");
     rt_hw_interrupt_disable();
     while (1);
 }