Files
mujs/jsboolean.c
Tor Andersson 90b54a9eec Add userdata class.
js_newuserdata(J, tag, ptr) creates a userdata object, wrapping the ptr.
It takes the prototype for the new object from the top of the stack, just
like js_newcconstructor does.

js_touserdata(J, tag, idx) extracts the userdata pointer. Throws a
TypeError if the object is not a userdata object with a matching tag.

js_isuserdata(J, tag, idx) checks if a value on the stack is a userdata
object with a matching tag.
2014-01-24 17:11:49 +01:00

45 lines
1002 B
C

#include "jsi.h"
#include "jsvalue.h"
#include "jsbuiltin.h"
static int jsB_new_Boolean(js_State *J, int argc)
{
js_newboolean(J, js_toboolean(J, 1));
return 1;
}
static int jsB_Boolean(js_State *J, int argc)
{
js_pushboolean(J, js_toboolean(J, 1));
return 1;
}
static int Bp_toString(js_State *J, int argc)
{
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");
return 1;
}
static int Bp_valueOf(js_State *J, int argc)
{
js_Object *self = js_toobject(J, 0);
if (self->type != JS_CBOOLEAN) js_typeerror(J, "not a boolean");
js_pushboolean(J, self->u.boolean);
return 1;
}
void jsB_initboolean(js_State *J)
{
J->Boolean_prototype->u.boolean = 0;
js_pushobject(J, J->Boolean_prototype);
{
jsB_propf(J, "toString", Bp_toString, 0);
jsB_propf(J, "valueOf", Bp_valueOf, 0);
}
js_newcconstructor(J, jsB_Boolean, jsB_new_Boolean, 1);
js_defglobal(J, "Boolean", JS_DONTENUM);
}