示例#1
0
bool object::instance_of(value constructor) const {
  root_object cons(constructor.to_object());

  if (cons.is_null())
    throw exception("Could not check instance constructor: "
                    "constructor has to be a non-null object");

  JSBool result;
  if (!JS_HasInstance(
          Impl::current_context(),
          Impl::get_object(cons),
          Impl::get_jsval(value(*this)),
          &result))
    throw exception("Could not check instance constructor");

  return result;
}
示例#2
0
static int get_byte(value byte_) {
  int byte;
  if (byte_.is_int()) {
    byte = byte_.get_int();
    if (byte < 0 || byte > 255)
      throw exception("Byte is outside the valid range for bytes");
    return byte;
  }
  object byte_o = byte_.to_object();
  if (byte_o.is_null())
    throw exception("Not a valid byte");
  binary &byte_bin = flusspferd::get_native<binary>(byte_o);
  if (byte_bin.get_length() != 1)
    throw exception("Byte must not be a non single-element Binary");
  byte = byte_bin.get_const_data()[0];
  return byte;
}
示例#3
0
std::size_t convert_container_base::from_value::length(value obj_v) {
  array arr(obj_v.to_object());
  return arr.length();
}
示例#4
0
value convert_container_base::from_value::element(value obj_v, std::size_t i) {
  array arr(obj_v.to_object());
  return arr.get_element(i);
}
示例#5
0
void convert_container_base::to_value::add(value obj, value el) {
  obj.to_object().call("push", el);
}