jerryscript-project / iotjs

Platform for Internet of Things with JavaScript http://www.iotjs.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An implementation of AS_JERRY_VALUE and AS_NAPI_VALUE to resolve NULL is integer problem.

lygstate opened this issue · comments

static inline jerry_value_t AS_JERRY_VALUE(napi_value nvalue) {
  jerry_value_t jval = (jerry_value_t)(uintptr_t)nvalue;
  if ((jval & 0x7) == 0) {
    jval ^= 1 << 3;
  }
  return jval;
}

static inline jerry_value_t AS_JERRY_OBJECT(napi_value nvalue) {
  jerry_value_t val = AS_JERRY_VALUE(nvalue);
  if (jerry_value_is_error(val)) {
    val = jerry_get_value_from_error(val, false);
    jerry_release_value(val);
    return val;
  }
  return val;
}

static inline napi_value AS_NAPI_VALUE(jerry_value_t jval) {
  if ((jval & 0x7) == 0) {
    jval ^= 1 << 3;
  }
  return (napi_value)(uintptr_t)jval;
}

As you can see, there is an if in the convert expression, is there any way to remove the if expression by bitwise operation only?