Subj : Re: getting a URL from JSContext! To : netscape.public.mozilla.jseng From : Sterling Bates Date : Wed May 05 2004 12:50 am "Boris Zbarsky" wrote in message news:c79q22$hva1@ripley.netscape.com... > This feels like more of a jseng issue than a DOM one.... > > Joey wrote: > > Hi! > > I was wondering how you can get a scripts sourceURL from a JSContext. > > How does the jsengine differentiate between internal contexts and > > contexts that are created for the execution of javascript from an URL. I think I understand (a little) more clearly what Joey means. Here's the problem with the question: A context is not associated with a script. A context is more accurately (AFAIK) associated with a thread. Each script that is executed is compiled to a JSScript and the filename (or URL) is associated with that JSScript, not the JSContext. Furthermore, SpiderMonkey doesn't run scripts from a URL. The application embedding SpiderMonkey must first download the script, which is then passed to, for instance, the JS_EvaluateScript API. The application may choose to pass the URL from which the script was obtained in the filename parameter of JS_EvaluateScript, or it may not. SpiderMonkey doesn't concern itself with that detail. Moreover, the JSScript struct is intended to be opaque -- not visible to the embedding application. As far as I can tell, there is no API available to extract the filename from the JSScript struct. In theory the application running the script knows exactly where the script came from (unless the app permits anonymous third-party script). The key here is that an application can evaluate multiple independent scripts at different times, each of which becomes visible to the other. Because of this, it makes more sense to associate the filename with the JSScript struct, rather than the JSContext. Hopefully I haven't made any glaring errors here :) Sterling .