[Jslib] example code that doesn't work for me...

Stephen Knight stknight at ultralifebatteries.com
Tue Sep 23 13:01:56 EDT 2003

Wingnut wrote:
> Well done, stknight!  (And you too, Pete!)  The privilege manager 
> security loosening is a definite GOTTA apparently, at least on my W2k 
> Moz 1.5b SVG.
> Note:  "c:\WINDOWS\Application 
> Data\Mozilla\Profiles\default\generated.slt\chrome\" is not the correct 
> path to jslib on my W2k.  My xpi-install of jslib appears to have landed 
> at...
> C:\Documents and Settings\Wingnut\Application 
> Data\Mozilla\Profiles\Wingnut\yp8au0ow.slt\chrome
> Of course, w2k has all that fancy admin stuff, and I'm an admin-grade 
> user on it, so... its just a whole lot of unnecessary security layers 
> and crap that I don't really understand.
> All I know, is that stknight's example got me past a huge hurdle, and in 
>  my opinion, his message and demo code should be made available in jslib 
> docs.

glad I could help.

I should probably post a followup (as a matter of fact :) :
the issues of the privilege-manager and including filesystem.js go away once you've actually 
"installed" your application.  (environment:  Windows2000, Mozilla 1.4)

so, basically, if you want to use the "resource" reference, ie:
mozilla -chrome resource:/yourDir/path/appl.xul
a) you have to make calls to the privilege manager to allow connection to various things.
b) you might have to insert extra includes to use all of the parts of jslib
c) you might have to play games before starting your appl.xul
	1) having mozilla running
	2) run "chrome://jslib/content" (in a new tab or window)

once you've shifted your application-folder to chrome so you can do:
mozilla -chrome chrome://yourAppl/content

the extra lines don't matter anymore (no errors, they can go away) and the extra steps go away too.

your mileage may vary...

> Lastly, does jslib really "just" wrap xpcom components?  If so, I don't 
> think its going to solve my problem of getting xpcom to read a so-called 
> NTFS unicode file like Marias_u.tdb found in 
> http://www.winternet.com/~wingnut/html/test/localfile_readers/.
> Wanna try?  Take both Marias test text files and ns_read18_u.htm from 
> that dir and put them into a local folder.  Adjust filepaths in the JS 
> and go for it.  available() is wrong too, showing the unicode Marias 
> file to be twice the number of available bytes as the 8 bit version.... 
> cuz it knows-not that its a unicode (16 bit byte) file if there is such 
> a thing.

last I knew (I'm sure somebody will correct me), the above behavior is correct.  the only way 
available() could return the correct number of "characters" is by opening up the file and checking 
for the byte-order mark.  the other alternative (and, IMHO, not a good one) is to start checking the 

see: http://www.w3.org/TR/unicode-xml/#BOM and http://www.w3.org/TR/REC-xml#charencoding for 
descriptions on the byte-order mark.

I don't believe that checking the file size is a 100% safe tactic when dealing with Unicode.  If I 
remember correctly, not all "Unicode" characters are UTF-16;  apparently there were some 
combinations that could combine two UTF-16 values.  Unfortunately, it's been quite awhile and (at 
the time) I didn't have to worry about those cases (because we couldn't handle them anyway...ha!).

> I probably should have tested to see if jslib could do it before I 
> posted this.... but I was excited that I (stknight) finally got jslib 
> awakened.  Am I in for disappointment in getting jslib to .read that 
> file?  :)  Anyone got advice?  I sure would appreciate anything!

I found that particular area fairly painless (since I was numb from all the other !@#$% I 
encountered).  I wouldn't expect much difficulty.

> Ok, off to torture jslib.  Thanks again, gang!

no problem.
Stephen Knight
Ultralife Batteries, Inc.

More information about the Jslib mailing list