Subj : Re: Calling functions without the lookup To : Brendan Eich From : ggadwa@voyager.net (Brian Barnes) Date : Wed Jan 15 2003 05:48 pm Brendan Eich wrote: > But (more super-technical detail alert) you may not be able to use > that API anyway, if you need to preserve the scope chain (linked by > the parent slot) of the object tagged in myfunc. If you extract that > object's private data (a JSFunction*, call it fun), and then call that > function via JS_CallFunction, the API will use fun->object as the > callable object to invoke -- which means you'll get the scope chain > that the compiler saw when it created fun. > > That is not necessarily the right scope chain, if you are using > JS_CloneFunctionObject, or if the function object you got from the > obj.BLECH property was cloned for you automatically. If it came from > a nested function declared in JS, or even a top-level function in a > script that you precompile in a null top-level object, or a > "compile-time only" top-level object used for precompiling, if the > script was executed against a different top-level, then the functions > declared in it at top-level will be automatically cloned. Capturing > the value of such a function in script, and storing it in obj.BLECH, > could lead to a situation where you can't use JS_CallFunction from > native code to invoke the function with the right scope chain. > > In other words, JSObject => JSFunction is many to one, while > JSFunction => JSObject (fun->object) is a 1:1 link back to the > compiler-created function object. > > I hope this helps. You are the true definition of too smart for all *our* goods :) I get it. I shouldn't have any problems. Basically, a script is compiled to an object, and that script stays static for the length of run. There's a function, always called "event", that gets called A LOT (sometimes, for a timer, an awful lot.) I should be golden with what's above, and it saves me a lookup. Nothing complex goes on in the scoping, or cloning, etc. I've said this before, but there's a lot in spider-monkey that you don't get on a quick examination; the more I get into the nuts and bolts the better I understand how well engineered this thing was and how much power you can squeeze from it when you know what you are doing. In short: thanks. [>] Brian .