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

Compiling eval-style JScript

25 views
Skip to first unread message

Oliver Bock

unread,
Aug 4, 2010, 7:45:47 PM8/4/10
to
I am trying to work out how to use active scripting to compile a chunk
of JScript code once, and then execute it repeatedly. I need to
separate these stages because parsing the code every time makes it run
too slowly.

WHAT I DO NOW
-------------
My application runs small chunks of JScript code with the same style as
is accepted by eval() and within browser event handlers. That is to
say, a block of JScript where the last expression is returned as a
result, even though it has not 'return' statement. e.g.

var a = 1;
a * 2;

The result of this would be 2. I execute this using
IActiveScriptParse.ParseScriptText(), which works fine, but is slow if
done thousands of times.

WHAT I HAVE TRIED
-----------------
1. I tried IActiveScriptParse.AddScriptlet(), but it requires a
'return' statement if it is to give a result.
2. I tried IActiveScriptParseProcedure.ParseProcedureText, but it
also requires a 'return' statement, unless I pass in
SCRIPTPROC_ISEXPRESSION, in which case it will not accept
multiple statements.
3. I tried JScript.NET, but it also cannot handle blocks of code
like this, except within an eval(), in which case the code gets
parsed every time.

The only viable alternative I have at the moment is to use another
JavaScript library like v8, but this is not so good because it will
increase the size of my program and will require me to redistribute the
C runtime DLLs (because my applications is a .Net application and DLLs
compiled with /clr cannot be statatically linked to the C runtime).

Any help would be greatly appreciated.


Oliver

Carlos

unread,
Aug 6, 2010, 1:58:36 AM8/6/10
to
Hello Olive

If you add the "return" keyword, and use IActiveScriptParse.AddScriptlet()
and IActiveScriptParseProcedure.ParseProcedureText, is it still slow?


"Oliver Bock" <olive...@nospam.nospam> wrote in message
news:OXXGr8CN...@TK2MSFTNGP06.phx.gbl...

Oliver Bock

unread,
Aug 9, 2010, 7:51:30 PM8/9/10
to
Hi Carlos,

I have not tried that because I cannot add the 'return' keyword due to
an existing body of code that must keep working. It might still be a
good experiment, but I have since found good information on doing this
in an old (but excellent) scripting FAQ that is still available in an
archive:

http://web.archive.org/web/20050408093442/www.mindspring.com/~mark_baker/toc.htm

Regards,
Oliver

Carlos

unread,
Aug 10, 2010, 9:58:07 PM8/10/10
to
Nice FAQ!

Does the FAQ solve the problem?

"Oliver Bock" <olive...@nospam.nospam> wrote in message

news:u%23hjL3BO...@TK2MSFTNGP05.phx.gbl...

0 new messages