Subj : Re: Equivalent of JS_InitClass for global object? To : netscape.public.mozilla.jseng From : John J Lee Date : Mon Aug 25 2003 02:11 pm On Sun, 24 Aug 2003, Brendan Eich wrote: > John J. Lee wrote: [...] > The docs lie, they were written by some Netscape techwriter no longer > around, who sometimes made up facts (probably frustrated by lack of [...] Thanks -- useful to know! In the absence of a complete fix, maybe it would be useful to add a health warning ('the embedding docs are inaccurate in places')? [...] > >because, if a class isn't exposed outside the API, why else would one > >want to call JS_InitClass unless one is *required* to call it on *all* > >JSClass structures? > > > > That doesn't follow at all. > > You can use a statically initialized JSClass struct by passing its > address to JS_NewObject as the second parameter. See js.c's 'glob = > JS_NewObject(cx, &global_class, NULL, NULL);' without any prior or later > JS_InitClass on that global_class struct. Yeah, I found that and I know it doesn't follow -- I was just explaining my thought processes to make it clear why I didn't understand the docs. But it seems you already know the docs have problems. > >I assume there's no reason to require "window" to *really* be the > >global object? > > > > There is if you want to run scripts from real-world web pages, > especially those that know about multiple windows (frames in framesets, > top-level windows). I'll take your word for that, but I don't understand why (I *do* still have window objects in Python -- it's just that rather than bind one directly as the global object, I just have a function bind_window that fakes a JS global object by grabbing the individual attributes and methods from a window object and binding them to my simple JS global object). What's the best way to find out about this kind of thing? ATM, I don't know, for example, whether all these frames / windows have their own scopes / global objects / JSContexts -- your answer seems to hint at something like this. Am I stuck with either attempting to read the Mozilla source, or guessing by looking at piles of real-world JS code? John .