This project is read-only.
1

Closed

Exposing COM objects

description

At the moment members (e.g. methods and properties) of COM objects are not accessible to JavaScript code run by Jint, because the standard .NET reflection API does not provide the necessary MethodInfos and PropertyInfos of those COM objects. In practice this means that for example the following code

var shell = createCom("WScript.Shell");
var path = shell.ExpandEnvironmentStrings("%PATH%");
alert(path);

fails with a "Jint.JintException: Method isn't defined: ExpandEnvironmentStrings" exception (createCom is a custom function which creates a COM object via ProgID).

I already wrote some code which retrieves the MemberInfos of a COM object and exposes it to Jint via a JsComInstance wrapper object (hooked into Marshaller.MarshalClrValue). If you're interested I can commit my changes (when their cleaned up) to my fork and send you a pull request.
Closed Oct 3, 2014 at 6:43 PM by sebastienros
Jint has been rewritten and this issue should be fixed in the new version. Please check it on https://github.com/sebastienros/jint or on using the nuget package here: https://www.nuget.org/packages/Jint/

comments

sebastienros wrote May 30, 2011 at 4:40 PM

Sure, Sergey and I can review it. As soon as all the tests are passing and it doesn't impact current performance, there should be no problem.

sebastienros wrote May 30, 2011 at 4:42 PM

Oh, and it needs some design on security, because you can expose very low level stuff with it. Like AlllowComInteroperability, or something like that. Can be decided during the review process.

smu01 wrote Jun 1, 2011 at 9:44 AM

Are your security concerns about scripts being able to arbitrarily create new COM objects (e.g. via "var x = new Prog.Id();"), or also about simply accessing COM objects which were provided by the hosting application via JintEngine.SetParameter beforehand? As a first step I only want to support the latter, i.e. providing access to members of provided COM objects, which IMHO is not that security critical, or am I missing something?

smu01 wrote Jun 6, 2011 at 12:56 PM

I'm having some difficulties with my approach with .NET versions prior to 4.0. I'll keep you posted about my progress.