iotjs icon indicating copy to clipboard operation
iotjs copied to clipboard

Wrapper for Javascript native function binding.

Open ILyoan opened this issue 11 years ago • 2 comments

Currently IoT.js binds its native javascipt function using external handler API of Jerry Engine. The prototype of the handler is defined as:

typedef bool (*jerry_external_handler_t) (const jerry_api_object_t *function_obj_p,
                                          const jerry_api_value_t *this_p,
                                          jerry_api_value_t *ret_val_p,
                                          const jerry_api_value_t args_p [],
                                          const uint16_t args_count);

And each module should implement handlers like:

static bool ToString(const jerry_api_object_t *function_obj_p,
                     const jerry_api_value_t *this_p,
                     jerry_api_value_t *ret_val_p,
                     const jerry_api_value_t args_p [],
                     const uint16_t args_cnt) {
  assert(args_cnt == 0);

  JObject buffer_obj(this_p, false);
  char* buffer = reinterpret_cast<char*>(buffer_obj.GetNative());
  assert(buffer != NULL);

  JObject jstring(buffer);
  jstring.Ref();
  *ret_val_p = jstring.val();

  return true;
}

In spite of JObject wrapper for object type, there is no wrapping layer for external handlers. I think we should introduce a layer that wrap external handler in consistent way with JObject wrapper so that developers who does not know about jerry also could work with it more easily.

ILyoan avatar May 07 '15 07:05 ILyoan

Yes, we really need to simplify this. good to issue this. please describe if you have something in mind. what I am thinking is something like JFunctionArgument to wrap all the values with attributes.

seanshpark avatar May 07 '15 08:05 seanshpark

Closing as #18 landed

ILyoan avatar May 11 '15 05:05 ILyoan