Discussion:
Compiling eval-style JScript
(too old to reply)
Oliver Bock
2010-08-04 23:45:47 UTC
Permalink
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
2010-08-06 05:58:36 UTC
Permalink
Hello Olive

If you add the "return" keyword, and use IActiveScriptParse.AddScriptlet()
and IActiveScriptParseProcedure.ParseProcedureText, is it still slow?
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
Oliver Bock
2010-08-09 23:51:30 UTC
Permalink
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
Post by Carlos
Hello Olive
If you add the "return" keyword, and use
IActiveScriptParse.AddScriptlet() and
IActiveScriptParseProcedure.ParseProcedureText, is it still slow?
Post by Oliver Bock
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
2010-08-11 01:58:07 UTC
Permalink
Nice FAQ!

Does the FAQ solve the problem?
Post by Oliver Bock
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
http://web.archive.org/web/20050408093442/www.mindspring.com/~mark_baker/toc.htm
Regards,
Oliver
Post by Carlos
Hello Olive
If you add the "return" keyword, and use
IActiveScriptParse.AddScriptlet() and
IActiveScriptParseProcedure.ParseProcedureText, is it still slow?
Post by Oliver Bock
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
Loading...