Evaluating JsFunction passed to external function

Oct 24, 2011 at 11:58 AM
Edited Oct 24, 2011 at 11:59 AM

Hello,

first of all thank you very much for this great engine, its simple to use but yet very powerful.

In my project I use "Awesomium" (http://awesomium.com) to display a browser window in my WinForms app. It works perfectly but the embedded script engine doesn`t provide a feasonable way to call external functions AND return values synchronously yet. So i`ve decided to use Jint as my primary (logical) scripting engine because it perfectly communicates with the .Net Framework and my applications methods.

But due this "mixing" of engines in my special case I need to pass certain (browser-specific) code blocks - which run in Jint`s context - to Awesomiums script engine.

Is it possible (in any way) to receive a javascript function as parameter in an external function in my application and then fully evaluate/compile it (includings locals) to pass it to the other engine ?

I could not yet find a way or documentation on how to accomplish this. Maybe you have any suggestions for me ?

Example:

  JS

var anyVar = "test"

DelegateToAwesomium(function () { 
    document.write(anyVar); // should be processed by other engine
 });

C#
public void DelegateToAwesomium(JsFunction function)
{
    OtherEngine.Run(function.ToString()); // Just prototyping. My problem: I need the fully evaluated code "document.write("test")" here
}

Thank you very much !

Greets,
Thomas


Nov 7, 2011 at 4:57 PM
Edited Nov 7, 2011 at 4:58 PM

Hello,

for the moment I`ve "workarounded" this problem by passing parameters to the function which should be executed so that no further evaluation is needed. Not very beautiful but however it works:

 

JS

DelegateToAwesomium(function (varAsParam) { document.write(varAsParam); // should be processed by other engine },"a variable passed as parameter");
C#

 

 

        private void DelegateBrowser(object fct, JsArray param)
        {
            JsFunction fctJs = fct as JsFunction;

            if (fctJs != null)
            {
                //retreive function code

                OtherEngine.ExecuteFunction(code, param);
            }
        } 

If someone knows a better solution for this situation please provide it here. I couldn`t find any. Thank you very much !

Greets,
Thomas