jsboolean.c 925 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "jsi.h"
  2. static void jsB_new_Boolean(js_State *J)
  3. {
  4. js_newboolean(J, js_toboolean(J, 1));
  5. }
  6. static void jsB_Boolean(js_State *J)
  7. {
  8. js_pushboolean(J, js_toboolean(J, 1));
  9. }
  10. static void Bp_toString(js_State *J)
  11. {
  12. js_Object *self = js_toobject(J, 0);
  13. if (self->type != JS_CBOOLEAN) js_typeerror(J, "not a boolean");
  14. js_pushliteral(J, self->u.boolean ? "true" : "false");
  15. }
  16. static void Bp_valueOf(js_State *J)
  17. {
  18. js_Object *self = js_toobject(J, 0);
  19. if (self->type != JS_CBOOLEAN) js_typeerror(J, "not a boolean");
  20. js_pushboolean(J, self->u.boolean);
  21. }
  22. void jsB_initboolean(js_State *J)
  23. {
  24. J->Boolean_prototype->u.boolean = 0;
  25. js_pushobject(J, J->Boolean_prototype);
  26. {
  27. jsB_propf(J, "Boolean.prototype.toString", Bp_toString, 0);
  28. jsB_propf(J, "Boolean.prototype.valueOf", Bp_valueOf, 0);
  29. }
  30. js_newcconstructor(J, jsB_Boolean, jsB_new_Boolean, "Boolean", 1);
  31. js_defglobal(J, "Boolean", JS_DONTENUM);
  32. }