Javascript function naming.

Feb 7, 2013 at 7:43 PM
I must say, I like Clearscript alot. Kudos.

Is there a way to specify what the exposed method's javascript function name is gonna be? I know jurassic solves it by annotations on methods. I cant stand beginning my C# methods with a lowercase character just because javascript's function should start with a lowercase. :)

Is there a way to hide non-private method from being accessible from javascript? I use javascript to populate objects and afterwards (back in c#) collect relevant data and results and use them. I wanna disable access from javascript to some of these public methods. Trying to keep the javascript interface as clean and straight forward as possible.
(Again - Jurassic does it with annotations.)
Coordinator
Feb 7, 2013 at 9:30 PM
Edited Aug 3, 2013 at 3:35 AM
Hi Klator,

Thanks for the kind words!

ClearScript currently does not have explicit support for method hiding or renaming. One way to achieve the desired effect might be to create a forwarding wrapper that exposes precisely the interface you want:
public class MyObject
{
    public void SomeMethod() { }
    public void HiddenMethod() { }
}

public class MyObjectForScript
{
    private readonly MyObject _target;
    public MyObjectForScript(MyObject target) { _target = target; }

    public void someMethod() { _target.SomeMethod(); }
}

var myObject = new MyObject();
engine.AddHostObject("myObject", new MyObjectForScript(myObject));
Of course, this might be tedious if you're exposing a large interface, and you still have to break your C# naming conventions in the wrapper. We'll definitely consider other solutions. Stay tuned!
Feb 7, 2013 at 11:01 PM
Yeah, I thought about that.

Just feels like an awful lot of boilerplate code just to get that functionality.
I hoped you guys had a solution that ive missed somewhere.

An other way would be using interfaces, but I think dont think that would work. (2 interfaces: one for internal, one for external/javascript)

Hmmm, back to the drawing table.
Anyway, it doesnt stop me from using Clearscript, worst case scenario is that there might be some undocumented functions, I guess.

Thanks anyway, looking forward to future releases.
Coordinator
Feb 11, 2013 at 2:56 PM
We are tracking this issue here.
Coordinator
Feb 27, 2013 at 3:45 AM
Edited Feb 27, 2013 at 3:52 AM
ClearScript 5.1 is now available!

It includes the following new features for customizing your script interfaces:
  • ScriptEngine.AddRestrictedHostObject() lets you expose a host object so that script code can only access the members of one of its base classes or interfaces.
  • NoScriptAccessAttribute allows you to hide public type members from script code.
  • ScriptMemberAttribute lets you expose a type member to script code under a different name, and to limit fields and properties to read-only access from script code.
Please check out the updated ClearScript Library Reference here.
Feb 27, 2013 at 7:57 PM
Great work.

Looks good, Ill try it right away.
Feb 28, 2013 at 3:06 AM
Edited Feb 28, 2013 at 3:32 AM
I was just going to ask for this also! LOL ;)

You guys are doing a great job! I just love the thought of being able to include various scripting models - especially various JS engines - into my .NET apps. Just for fun (for now). I'm building a JavaScript server similar to Node (but much different), by using .NET as a wrapper instead (why? why not; because I can). ;) I figure there's always Mono to help make it cross-platform later on, which is why I like the V8 engine that's included.
Coordinator
Feb 28, 2013 at 1:46 PM
Hi jamesnw. We appreciate your kind words, and would love to get feedback about using ClearScript on the server!