Subj : Re: SM: JS_ExecuteScript and rval To : netscape.public.mozilla.jseng From : "Franky Braem" Date : Tue Apr 08 2003 10:25 pm "Brendan Eich" wrote in message news:3E90A00D.7040208@meer.net... > Franky Braem wrote: > > Hi, > > > > I read the following in the API-docs > > > > JS_ExecuteScript executes a previously compiled script, script. On > > successful completion, rval is a > > pointer to a variable that holds the value from the last executed expression > > statement processed in > > the script. > > > > What happens when the script only contains a function? I returns undefined. > > Wouldn't it be nice when the function object is returned? > > > > I want to use this to implement a better way for event handling in wxJS. eg. > > > > frame.onClose = wxScript("close.js"); > > > This seems wrong: the value returned by wxScript is not the result of > evaluating the script in close.js, correct? It's a script object that > can be executed later, whose code is compiled from the source in > close.js, right? > > You are removing one level of reference here. I think that makes for > problems where users explicitly want a script object, to defer multiple > executions and amortize compilation overhead. What if there are several > functions in close.js? Why can't I refer to each of them? Why must I > break each handler into its own source file? > > It would be better to require users to say what they mean: > > frame.onClose = wxScript("close.js").onCloseHandler; I've got something working now like this. My only concern is: do I have to root the JSScript that I compile and execute in the wxScript constructor? If you wish you can take a look at the code here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/wxjs/wxJS/src/misc/script.cpp ?rev=1.1&content-type=text/vnd.viewcvs-markup tia, Franky. .