Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compiling <script> src into a function

34 views
Skip to first unread message

Mohan

unread,
Oct 28, 2009, 6:40:38 PM10/28/09
to
Hi All,

I would like to know if there is a mechanism to compile the script
code from the "src" attribute of the <script> tag into a function that
can be later invoked from my JS code. For eg:

<script src="some.url">
Now this if the source script compiles to a function say "foo", then I
would like to execute the script by calling foo();

I have tried to make changes to the nsJSContext::EvaluateString()
method in nsJSEnvironment.cpp to compile it to a function using
JS_CompileUCFunction. When I later use the compiled function in a JS
code, it does not work. I then used JS_CallFunction() in
nsJSEnvironment.cpp on my compiled function and the script executed,
but is it possible to achieve the above functionality from within the
JS code.

I am sure I am missing something. Could anyone suggest some pointers
and/or modifications that may be required?

Regards,
mohan

Igor Tandetnik

unread,
Oct 28, 2009, 6:52:30 PM10/28/09
to
Mohan <mohan....@gmail.com> wrote:
> I would like to know if there is a mechanism to compile the script
> code from the "src" attribute of the <script> tag into a function that
> can be later invoked from my JS code. For eg:
>
> <script src="some.url">
> Now this if the source script compiles to a function say "foo", then I
> would like to execute the script by calling foo();

I suppose you could download the text from some.url using XMLHttpRequest, then surround it with "function myfunc() {" and "}", and finally eval() the whole thing.

Igor Tandetnik

0 new messages