JsRT: Wrappers updated to v1.1

Even though I may not be working on the Chakra team any more, I’m still doing some noodling on making the hosting APIs easier to use. I’ve got some other interesting things coming soon, but on the way there I made some improvements/fixes to the wrappers that I released a while back.

Changes to v1.1:

  • PDB files are generated along with the LIB, and debug builds are included. All flavors are now packaged together.
  • Header file name is changed to jsrt-wrappers.h to be consistent with the other files.
  • Added equality operators for handles.
  • Added function_base::create which can deduce the strongly typed function wrapper from the function signature.
  • Fixes the handling of optional parameters in functions.
  • Changes the handling of rest parameters to use std::vector rather than a JavaScript array, which is more efficient.
  • Simplified prototype handling.
  • Bug fixes.

Let me know if there are any problems!

You should also follow me on Twitter here.

6 thoughts on “JsRT: Wrappers updated to v1.1

  1. Andi

    Hi Paul,

    Happy to see you’re still poking around this code 🙂 A bit of unrelated question. I find myself in a situation where i’d want to cancel/interrupt the current execution. The challenge here comes from the fact that the running thread is blocked in execution while the interrupt comes off another thread.

    Any ideas on how to make this happen?



    1. paulvick Post author

      You can use JsDisableRuntimeExecution from an another thread to stop execution. This basically marks the JS thread as being interrupted, which the JS engine checks on function entry/exit and at the top of loops, so you should hit it fairly quickly. Hope this helps!

  2. Simon

    Hi Paul,

    Using JsRt (I’m on C#, but the question is general), is it possible to parse a script, like this for example: ParseScript(“function Mul(a,b){return a*b;}”), and then call the resulting “Mul” function? ParseScript runs fine, but how to call “Mul”? I can’t find a way… How can we use the parsed script then? Only RunScript seems to work, but it expects a return value.

    1. paulvick Post author

      ParseScript returns a function that represents the body of the script you parsed (in your example, it would return a function that would be equivalent to “function () { function Mul(a,b) { return a*b; } }”). RunScript is equivalent to calling ParseScript + CallFunction on the function that comes back from ParseScript. I’m talking off the top of my head, but I believe what you want is a script like:

      function Mul(a, b) { return a*b }

      This will define the function and then return the function as the value of the script. Then when you do RunScript on this, the return value of the script will be the Mul function. Hope this helps!

      1. Simon

        Thanks for your reply. I know understand how it works. The drawback is if we create a lot of functions, we need to return an array for all these functions at the end of the script(for example). Not super easy. The old ActiveScript used to create a full COM/IDispatch object from a code like this and it was quite convenient. Another question! In this “Mul” case, when I use CallFunction, the first parameter seems not to be used. I mean it seems I have to do CallFunction(whatever, a, b) to call Mul successfully. Is this normal?

        1. paulvick Post author

          You could also create an object and just return that, dispatching from there. Not sure that’s simpler or not, but might be closer to what used to happen. The first element in the argument array for CallFunction is always the value of “this” for the function call. For unbound functions, you can just pass in undefined.


Leave a Reply

Your email address will not be published. Required fields are marked *