Subj : Re: Loading code into runtime; and error reporting issues To : Alan Kemp From : Brendan Eich Date : Wed Feb 04 2004 10:47 am Alan Kemp wrote: >First, what it the correct method to load a file from disk containing a >bunch of functions so that those functions are then available for other >scripts or c-code to call? At the moment I am JS_EvaluateScript(..)'ing the >code and the runtime (the context?) "remembers" them for later use. > Rather, the global object or other scoping object you pass as the 2nd arg to JS_EvaluateScript remembers them. Context is interpreter state, including stack, necessarily at least one per thread. Don't mix it up with scope or variable-binding object, which is an independent parameter. > I >thought that JS_CompileScript(..) would have the same effect, but doing that >instead results in undefined function names when I try to call them. > > That's correct. ECMA specifies, based on SpiderMonkey's progenitor, and on cloned implementations, circa 1996, that functions are bound only on entering an execution context. Compiling doesn't execute anything. >Secondly, when an attempt to call an undefined function is made I have an >error reporter setup to grab the error and handle it. However, there seems >to be no way of telling when function name was called from the error >reporter? I would like to provide a more meaningful output than the default >"undefined is not a function". Is that information available at this stage? > > Sure, you should be getting names. Sample JS shell session: js> var f; js> f() 2: TypeError: f is not a function js> function f(){return 42;} js> f() 42 js> g() 5: ReferenceError: g is not defined js> If you don't see the same results for the same input with your embedding, then we'll need to debug the code that calls js_DecompileValueGenerator before passing the decompiled reference expression to the error reporter. You might breakpoint there and see what you can see. Mail me if you need immediate help while debugging and we may be able to rendezvous on IRC. /be .