Skip to content
Snippets Groups Projects
js_system.c 52.9 KiB
Newer Older
deuce's avatar
deuce committed
static JSBool js_system_enumerate(JSContext *cx, JSObject *obj)
{
	return(js_node_resolve(cx, obj, JSVAL_NULL));
}
deuce's avatar
deuce committed
static JSClass js_system_class = {
     "System"				/* name			*/
    ,JSCLASS_HAS_PRIVATE	/* flags		*/
	,JS_PropertyStub		/* addProperty	*/
	,JS_PropertyStub		/* delProperty	*/
	,js_system_get			/* getProperty	*/
	,js_system_set			/* setProperty	*/
	,js_system_enumerate	/* enumerate	*/
	,js_system_resolve		/* resolve		*/
	,JS_ConvertStub			/* convert		*/
	,JS_FinalizeStub		/* finalize		*/
};
deuce's avatar
deuce committed
JSObject* DLLCALL js_CreateSystemObject(JSContext* cx, JSObject* parent
										,scfg_t* cfg, time_t uptime, char* host_name, char* socklib_desc)
{
	jsval		val;
	JSObject*	sysobj;
	JSString*	js_str;
	char		str[256];
deuce's avatar
deuce committed
	sysobj = JS_DefineObject(cx, parent, "system", &js_system_class, NULL
		,JSPROP_ENUMERATE|JSPROP_READONLY);
deuce's avatar
deuce committed
	if(sysobj==NULL)
deuce's avatar
deuce committed
	if(!JS_SetPrivate(cx, sysobj, cfg))	/* Store a pointer to scfg_t */
deuce's avatar
deuce committed
	/****************************/
	/* static string properties */
	if((js_str=JS_NewStringCopyZ(cx, host_name))==NULL)
		return(NULL);
	val = STRING_TO_JSVAL(js_str);
	if(!JS_SetProperty(cx, sysobj, "host_name", &val))
		return(NULL);
deuce's avatar
deuce committed
	if((js_str=JS_NewStringCopyZ(cx, socklib_version(str, socklib_desc)))==NULL)
		return(NULL);
	val = STRING_TO_JSVAL(js_str);
	if(!JS_SetProperty(cx, sysobj, "socket_lib", &val))
		return(NULL);
deuce's avatar
deuce committed
	/***********************/
deuce's avatar
deuce committed
	JS_NewNumberValue(cx,uptime,&val);
	if(!JS_SetProperty(cx, sysobj, "uptime", &val))
		return(NULL);
deuce's avatar
deuce committed
	js_DescribeSyncObject(cx,sysobj,"Global system-related properties and methods",310);
	js_CreateArrayOfStrings(cx, sysobj, "_property_desc_list", sys_prop_desc, JSPROP_READONLY);
deuce's avatar
deuce committed
#ifdef BUILD_JSDOCS
rswindell's avatar
rswindell committed
	{
		JSObject*	statsobj;

		js_DescribeSyncObject(cx,statsobj,"System statistics",310);
		js_CreateArrayOfStrings(cx, statsobj, "_property_desc_list", sysstat_prop_desc, JSPROP_READONLY);
	}
deuce's avatar
deuce committed
#endif
#endif	/* JAVSCRIPT */