Newer
Older
#endif
dbprintf(FALSE, p, "object constructed");
return(JS_TRUE);
}
JSObject* DLLCALL js_CreateFileClass(JSContext* cx, JSObject* parent)
{
obj = JS_InitClass(cx, parent, NULL
,&js_file_class
,js_file_constructor
,1 /* number of constructor args */
,NULL /* props, set in constructor */
,NULL /* funcs, set in constructor */
JSObject* DLLCALL js_CreateFileObject(JSContext* cx, JSObject* parent, char *name, int fd, const char* mode)
{
JSObject* obj;
private_t* p;
FILE* fp = fdopen(dup(fd), mode);
if(fp == NULL)
return NULL;
obj = JS_DefineObject(cx, parent, name, &js_file_class, NULL
,JSPROP_ENUMERATE|JSPROP_READONLY);
if(obj==NULL) {
fclose(fp);
}
if((p=(private_t*)calloc(1,sizeof(private_t)))==NULL)
return(NULL);
p->fp=fp;
p->debug=JS_FALSE;
if(!JS_SetPrivate(cx, obj, p)) {
fclose(fp);
dbprintf(TRUE, p, "JS_SetPrivate failed");
return(NULL);
}
dbprintf(FALSE, p, "object created");
return(obj);
}