Ejemplo n.º 1
0
void load_class(
    context &ctx, object &constructor) 
{
  root_object prototype(T::class_info::create_prototype());
  ctx.add_prototype<T>(prototype);

  prototype.define_property(
    "constructor",
    constructor,
    permanent_property | read_only_property | dont_enumerate);

  root_value old_to_string(prototype.get_property("toString"));
  if (old_to_string == ctx.prototype("").get_property("toString")
      || root_object(old_to_string.to_object()).get_property("auto").to_boolean())
  {
    root_object fn(
      flusspferd::create<function>(
        "toString",
        &default_to_string<T>,
        param::_container = prototype));
    fn.set_property("auto", true);
  }

  root_value old_to_source(prototype.get_property("toSource"));
  if (old_to_source == ctx.prototype("").get_property("toSource")
      || root_object(old_to_source.to_object()).get_property("auto").to_boolean())
  {
    root_object fn(
      flusspferd::create<function>(
        "toSource",
        &default_to_source<T>,
        param::_container = prototype));
    fn.set_property("auto", true);
  }

  constructor.define_property(
    "prototype",
    prototype,
    dont_enumerate);

  T::class_info::augment_constructor(constructor);
}