view mupdf-source/thirdparty/mujs/jsboolean.c @ 38:8934ac156ef5

Allow to build with the PyPI package "clang" instead of "libclang". 1. It seems to be maintained. 2. In the FreeBSD base system there is no pre-built libclang.so. If you need this library you have to install llvm from ports additionally. 2. On FreeBSD there is no pre-built wheel "libclang" with a packaged libclang.so.
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 23 Sep 2025 10:27:15 +0200
parents b50eed0cc0ef
children
line wrap: on
line source

#include "jsi.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);
}