Skip to content

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

Open
@lygstate

Description

@lygstate
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions