Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lygstate opened this issue Feb 11, 2021 · 0 comments

Comments

@lygstate
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant