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