Skip to content
Snippets Groups Projects
js_file.c 76.9 KiB
Newer Older
		,&js_file_class
		,js_file_constructor
		,1		/* number of constructor args */
		,NULL	/* props, set in constructor */
		,NULL	/* funcs, set in constructor */
	return(obj);
JSObject* DLLCALL js_CreateFileObject(JSContext* cx, JSObject* parent, char *name, int fd, const char* mode)
{
	JSObject* obj;
	private_t*	p;
deuce's avatar
deuce committed
	int newfd = dup(fd);
	FILE* fp;
deuce's avatar
deuce committed
	if (newfd == -1)
deuce's avatar
deuce committed
	fp = fdopen(newfd, mode);
	if(fp == NULL) {
		close(newfd);
		return NULL;
	}

	obj = JS_DefineObject(cx, parent, name, &js_file_class, NULL
		,JSPROP_ENUMERATE|JSPROP_READONLY);
deuce's avatar
deuce committed
	if((p=(private_t*)calloc(1,sizeof(private_t)))==NULL) {
		fclose(fp);
deuce's avatar
deuce committed
	}

	p->fp=fp;
	p->debug=JS_FALSE;

	if(!JS_SetPrivate(cx, obj, p)) {
		dbprintf(TRUE, p, "JS_SetPrivate failed");
		return(NULL);
	}
	dbprintf(FALSE, p, "object created");

	return(obj);
}


#endif	/* JAVSCRIPT */