Subj : Re: about File.currentDir To : Taro Kato From : Brendan Eich Date : Thu Mar 25 2004 08:42 pm This is a multi-part message in MIME format. --------------030505070707060001020609 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit > I wish solution of this problem. I do too. The jsfile.c code is pretty awful, and I'm hoping to cvs remove it in favor of a better implementation. Any volunteers? In the mean time, please try the attached patch. /be --------------030505070707060001020609 Content-Type: text/x-patch; name="jsfile.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="jsfile.patch" Index: jsfile.c =================================================================== RCS file: /cvsroot/mozilla/js/src/jsfile.c,v retrieving revision 3.34 diff -p -u -8 -r3.34 jsfile.c --- jsfile.c 15 Nov 2003 00:10:57 -0000 3.34 +++ jsfile.c 26 Mar 2004 04:43:25 -0000 @@ -2504,32 +2504,31 @@ out: /* File.currentDir = new File("D:\") or File.currentDir = "D:\" */ static JSBool file_currentDirSetter(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { JSObject *rhsObject; char *path; - JSFile *file = JS_GetInstancePrivate(cx, rhsObject, &file_class, NULL); + JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL); /* Look at the rhs and extract a file object from it */ - if (JSVAL_IS_OBJECT(*vp)){ + if (!JSVAL_IS_PRIMITIVE(*vp)){ + rhsObject = JSVAL_TO_OBJECT(*vp); if (JS_InstanceOf(cx, rhsObject, &file_class, NULL)){ /* Braindamaged rhs -- just return the old value */ if (file && (!js_exists(cx, file) || !js_isDirectory(cx, file))){ JS_GetProperty(cx, obj, CURRENTDIR_PROPERTY, vp); goto out; - }else{ - rhsObject = JSVAL_TO_OBJECT(*vp); - chdir(file->path); - return JS_TRUE; } - }else - goto out; + chdir(file->path); + return JS_TRUE; + } + goto out; }else{ path = JS_GetStringBytes(JS_ValueToString(cx, *vp)); rhsObject = js_NewFileObject(cx, path); if (!rhsObject) goto out; if (!file || !js_exists(cx, file) || !js_isDirectory(cx, file)){ JS_GetProperty(cx, obj, CURRENTDIR_PROPERTY, vp); }else{ --------------030505070707060001020609-- .