示例#1
0
// Call any property of ClientRequest._Incoming
bool iotjs_https_jcallback(iotjs_https_t* https_data, const char* property,
                           const iotjs_jargs_t* jarg, bool resultvalue) {
  iotjs_jval_t* jthis = iotjs_https_jthis_from_https(https_data);
  bool retval = true;
  if (iotjs_jval_is_null(jthis))
    return retval;

  iotjs_jval_t jincoming =
      iotjs_jval_get_property(jthis, IOTJS_MAGIC_STRING__INCOMING);
  iotjs_jval_t cb = iotjs_jval_get_property(&jincoming, property);

  IOTJS_ASSERT(iotjs_jval_is_function(&cb));
  if (!resultvalue) {
    iotjs_make_callback(&cb, &jincoming, jarg);
  } else {
    iotjs_jval_t result =
        iotjs_make_callback_with_result(&cb, &jincoming, jarg);
    retval = iotjs_jval_as_boolean(&result);
    iotjs_jval_destroy(&result);
  }

  iotjs_jval_destroy(&jincoming);
  iotjs_jval_destroy(&cb);
  return retval;
}
示例#2
0
// Call onWrite and callback after ClientRequest._write
void iotjs_https_call_read_onwrite(uv_timer_t* timer) {
  iotjs_https_t* https_data = (iotjs_https_t*)(timer->data);
  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data);

  uv_timer_stop(&(_this->async_read_onwrite));
  if (iotjs_jval_is_null(&_this->jthis_native))
    return;
  const iotjs_jargs_t* jarg = iotjs_jargs_get_empty();
  const iotjs_jval_t* jthis = &(_this->jthis_native);
  IOTJS_ASSERT(iotjs_jval_is_function(&(_this->read_onwrite)));

  if (!iotjs_jval_is_undefined(&(_this->read_callback)))
    iotjs_make_callback(&(_this->read_callback), jthis, jarg);

  iotjs_make_callback(&(_this->read_onwrite), jthis, jarg);
}
示例#3
0
// Calls next tick callbacks registered via `process.nextTick()`.
bool iotjs_process_next_tick() {
  const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS);

  iotjs_jval_t jon_next_tick =
      iotjs_jval_get_property(process, IOTJS_MAGIC_STRING__ONNEXTTICK);
  IOTJS_ASSERT(iotjs_jval_is_function(&jon_next_tick));

  iotjs_jval_t jres =
      iotjs_jhelper_call_ok(&jon_next_tick, iotjs_jval_get_undefined(),
                            iotjs_jargs_get_empty());

  IOTJS_ASSERT(iotjs_jval_is_boolean(&jres));

  bool ret = iotjs_jval_as_boolean(&jres);
  iotjs_jval_destroy(&jres);
  iotjs_jval_destroy(&jon_next_tick);

  return ret;
}
示例#4
0
iotjs_jval_t iotjs_bufferwrap_create_buffer(size_t len) {
  iotjs_jval_t* jglobal = iotjs_jval_get_global_object();

  iotjs_jval_t jbuffer =
      iotjs_jval_get_property(jglobal, IOTJS_MAGIC_STRING_BUFFER);
  IOTJS_ASSERT(iotjs_jval_is_function(&jbuffer));

  iotjs_jargs_t jargs = iotjs_jargs_create(1);
  iotjs_jargs_append_number(&jargs, len);

  iotjs_jval_t jres =
      iotjs_jhelper_call_ok(&jbuffer, iotjs_jval_get_undefined(), &jargs);
  IOTJS_ASSERT(iotjs_jval_is_object(&jres));

  iotjs_jargs_destroy(&jargs);
  iotjs_jval_destroy(&jbuffer);

  return jres;
}
示例#5
0
// Cleanup before destructor
void iotjs_https_cleanup(iotjs_https_t* https_data) {
  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data);
  _this->loop = NULL;

  uv_close((uv_handle_t*)&_this->timeout,
           (uv_close_cb)iotjs_https_uv_close_callback);
  uv_close((uv_handle_t*)&_this->socket_timeout,
           (uv_close_cb)iotjs_https_uv_close_callback);
  uv_close((uv_handle_t*)&_this->async_read_onwrite,
           (uv_close_cb)iotjs_https_uv_close_callback);

  iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONEND,
                        iotjs_jargs_get_empty(), false);
  iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONCLOSED,
                        iotjs_jargs_get_empty(), false);

  curl_multi_remove_handle(_this->curl_multi_handle, _this->curl_easy_handle);
  curl_easy_cleanup(_this->curl_easy_handle);
  _this->curl_easy_handle = NULL;
  curl_multi_cleanup(_this->curl_multi_handle);
  _this->curl_multi_handle = NULL;
  curl_slist_free_all(_this->header_list);

  if (_this->poll_data != NULL)
    iotjs_https_poll_close_all(_this->poll_data);

  if (_this->to_destroy_read_onwrite) {
    const iotjs_jargs_t* jarg = iotjs_jargs_get_empty();
    const iotjs_jval_t* jthis = &(_this->jthis_native);
    IOTJS_ASSERT(iotjs_jval_is_function(&(_this->read_onwrite)));

    if (!iotjs_jval_is_undefined(&(_this->read_callback)))
      iotjs_make_callback(&(_this->read_callback), jthis, jarg);

    iotjs_make_callback(&(_this->read_onwrite), jthis, jarg);
    _this->to_destroy_read_onwrite = false;
    iotjs_string_destroy(&(_this->read_chunk));
    iotjs_jval_destroy(&(_this->read_onwrite));
    iotjs_jval_destroy(&(_this->read_callback));
  }
  return;
}
示例#6
0
void iotjs_process_emit_exit(int code) {
  const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS);

  iotjs_jval_t jexit =
      iotjs_jval_get_property(process, IOTJS_MAGIC_STRING_EMITEXIT);
  IOTJS_ASSERT(iotjs_jval_is_function(&jexit));

  iotjs_jargs_t jargs = iotjs_jargs_create(1);
  iotjs_jargs_append_number(&jargs, code);

  bool throws;
  iotjs_jval_t jres = iotjs_jhelper_call(&jexit, process, &jargs, &throws);

  iotjs_jargs_destroy(&jargs);
  iotjs_jval_destroy(&jres);
  iotjs_jval_destroy(&jexit);

  if (throws) {
    exit(2);
  }
}
示例#7
0
void iotjs_uncaught_exception(const iotjs_jval_t* jexception) {
  const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS);

  iotjs_jval_t jonuncaughtexception =
      iotjs_jval_get_property(process, IOTJS_MAGIC_STRING__ONUNCAUGHTEXCEPTION);
  IOTJS_ASSERT(iotjs_jval_is_function(&jonuncaughtexception));

  iotjs_jargs_t args = iotjs_jargs_create(1);
  iotjs_jargs_append_jval(&args, jexception);

  bool throws;
  iotjs_jval_t jres =
      iotjs_jhelper_call(&jonuncaughtexception, process, &args, &throws);

  iotjs_jargs_destroy(&args);
  iotjs_jval_destroy(&jres);
  iotjs_jval_destroy(&jonuncaughtexception);

  if (throws) {
    exit(2);
  }
}
示例#8
0
const iotjs_jval_t* iotjs_jval_as_function(const iotjs_jval_t* jval) {
  const IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jval_t, jval);
  IOTJS_ASSERT(iotjs_jval_is_function(jval));
  return jval;
}