Oliver Bock
2010-08-04 23:45:47 UTC
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
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