Ejemplo n.º 1
0
napi_value Init(napi_env env, napi_value exports) {
  napi_value number;
  NAPI_CALL(env, napi_create_double(env, value_, &number));

  napi_property_descriptor properties[] = {
    { "echo", 0, Echo, 0, 0, 0, napi_enumerable, 0 },
    { "readwriteValue", 0, 0, 0, 0, number, napi_enumerable | napi_writable, 0 },
    { "readonlyValue", 0, 0, 0, 0, number, napi_enumerable, 0},
    { "hiddenValue", 0, 0, 0, 0, number, napi_default, 0},
    { "readwriteAccessor1", 0, 0, GetValue, SetValue, 0, napi_default, 0},
    { "readwriteAccessor2", 0, 0, GetValue, SetValue, 0, napi_writable, 0},
    { "readonlyAccessor1", 0, 0, GetValue, NULL, 0, napi_default, 0},
    { "readonlyAccessor2", 0, 0, GetValue, NULL, 0, napi_writable, 0},
    { "staticReadonlyAccessor1", 0, 0, GetStaticValue, NULL, 0,
        napi_default | napi_static, 0},
  };

  napi_value cons;
  NAPI_CALL(env, napi_define_class(env, "MyObject", -1, New,
      NULL, sizeof(properties)/sizeof(*properties), properties, &cons));

  NAPI_CALL(env, napi_create_reference(env, cons, 1, &constructor_));

  return cons;
}
Ejemplo n.º 2
0
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
  napi_value number;
  NAPI_CALL_RETURN_VOID(env, napi_create_number(env, value_, &number));

  napi_property_descriptor properties[] = {
    { "echo", 0, Echo, 0, 0, 0, napi_enumerable, 0 },
    { "readwriteValue", 0, 0, 0, 0, number, napi_enumerable | napi_writable, 0 },
    { "readonlyValue", 0, 0, 0, 0, number, napi_enumerable, 0},
    { "hiddenValue", 0, 0, 0, 0, number, napi_default, 0},
    { "readwriteAccessor1", 0, 0, GetValue, SetValue, 0, napi_default, 0},
    { "readwriteAccessor2", 0, 0, GetValue, SetValue, 0, napi_writable, 0},
    { "readonlyAccessor1", 0, 0, GetValue, NULL, 0, napi_default, 0},
    { "readonlyAccessor2", 0, 0, GetValue, NULL, 0, napi_writable, 0},
  };

  napi_value cons;
  NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "MyObject", New,
    NULL, sizeof(properties)/sizeof(*properties), properties, &cons));

  NAPI_CALL_RETURN_VOID(env,
    napi_set_named_property(env, module, "exports", cons));

  NAPI_CALL_RETURN_VOID(env,
    napi_create_reference(env, cons, 1, &constructor_));
}
Ejemplo n.º 3
0
napi_value Init(napi_env env, napi_value exports) {
  napi_value cons;
  NAPI_CALL(env, napi_define_class(
      env, "MyObject_Extra", 8, New, NULL, 0, NULL, &cons));

  NAPI_CALL(env,
      napi_create_reference(env, cons, 1, &constructor_));
  return cons;
}