kolibrios-gitea/programs/develop/kosjs/libmujs/jsboolean.c
maxcodehack 91ae0dee0b kosjs: replace libmujs.a with sources; if argc = 0, see "usage"
git-svn-id: svn://kolibrios.org@8456 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-12-20 08:45:42 +00:00

41 lines
969 B
C
Executable File

#include "jsi.h"
#include "jsvalue.h"
#include "jsbuiltin.h"
static void jsB_new_Boolean(js_State *J)
{
js_newboolean(J, js_toboolean(J, 1));
}
static void jsB_Boolean(js_State *J)
{
js_pushboolean(J, js_toboolean(J, 1));
}
static void Bp_toString(js_State *J)
{
js_Object *self = js_toobject(J, 0);
if (self->type != JS_CBOOLEAN) js_typeerror(J, "not a boolean");
js_pushliteral(J, self->u.boolean ? "true" : "false");
}
static void Bp_valueOf(js_State *J)
{
js_Object *self = js_toobject(J, 0);
if (self->type != JS_CBOOLEAN) js_typeerror(J, "not a boolean");
js_pushboolean(J, self->u.boolean);
}
void jsB_initboolean(js_State *J)
{
J->Boolean_prototype->u.boolean = 0;
js_pushobject(J, J->Boolean_prototype);
{
jsB_propf(J, "Boolean.prototype.toString", Bp_toString, 0);
jsB_propf(J, "Boolean.prototype.valueOf", Bp_valueOf, 0);
}
js_newcconstructor(J, jsB_Boolean, jsB_new_Boolean, "Boolean", 1);
js_defglobal(J, "Boolean", JS_DONTENUM);
}