Getting started with JINT and javascript

Feb 8, 2011 at 10:43 PM

I am a veteran C/C++/CS developer.

I need to embed javascript into an application and find JINT to be worthy of candidate.

Thing is - I have no idea how to use it out of the box.  what I mean is can someone provide me with step by step instructions how to interact with the shell please?

I tried simple lines like

print("hello)";

hit enter 2x and get an error message like

'Request for the permission of type 'system.security.Permissions.UIPermission, mscorlib, ....

 

Also tried

alert("hi");

and I get Method isn't defined : alert

 

What am I missing here?  I am just trying to get started with this.

Help please!

Feb 9, 2011 at 12:49 AM

I'm new to Jint too,  and JeffRosenthal (above) is coding my project.   To save us time, allow me to post a few additional questions: 

1) Unicode strings originating from UTF-8 websites or RSS feeds, in foreign languages including Chinese and Japanese, need to be handled correctly, and typically a script would: Find a pattern in a string,  discard the left,  find another pattern, discard the right,  keeping the center. Then Find a pattern in the center remaining string,  and replace a portion of it with something else.  Then pass the result to a text-to-speech parser.    Is Jint good for this, unicode-wise?

2) I want to minimize extra files added into my main app folder/directory.  What (if any) files, (eg. antler.exe?)  must be present for this to work,  and I'm hoping that Jint compiles directly inside my main app,  without needing any extra files nearby.

Feb 9, 2011 at 1:06 AM

'print' happens to be a method defined by default in Jint, which uses Console.WriteLine. By default, the security is turned on, which means writing anything in the UI is forbidden, and needs to be granted the privilege for that. Take a look at this page under Security. There is a known bug on the Shell with that one too, we have to correct it.

Then you tried to use 'alert' which is a non javascript standard one. Actually it's here inside a browser, because part of the DOM. If you need alert() then you need to define it, as explained in the documentation too.

Jint is handling any unicode string nicely. There are unit tests in the source code to ensure that.

Jint is distributed as a single dll you have to reference in your project. You just need that one. If you want to link to the source code, then you will need the Jint project, and the antlr dll, no executable at all. But the distributed dll is the recommended way.

Feb 9, 2011 at 1:56 AM

That was helpful.  Thank you. 

The documentation provided at http://jint.codeplex.com/documentation  - is that all of the documentation?  Is there a listing of the supported (built-in) methods or is that something that needs to be gleaned from the source?

 

Feb 9, 2011 at 2:16 AM
Edited Feb 9, 2011 at 12:37 PM

thank you

Feb 9, 2011 at 2:44 AM
Edited Feb 9, 2011 at 3:34 AM
Can you dynamically load the jint.dll
after startup of my main app,  during initialization?
and keep jint.dll in a subfolder?
 
Having "MyApp.exe.manifest" in my main folder would be truly abhorrent.