Quantcast
Channel: Jint - Javascript Interpreter for .NET
Viewing all 425 articles
Browse latest View live

New Post: How debug in Jint 2.0.0?

$
0
0
I think it's not possible yet. But I also like the feature in Jint 0.9 But I that version isn't working with my requirements.

New Post: Method “params” Keyword not supported

$
0
0
Method “params” Keyword not supported

class test{
public void demo( params object[] ss)
{
    this.log(string.Join(", ", ss));
}
}


var tt = new test();


tt.demo(55,66,77,88,99 );

No public methods with the specified arguments were found.

Closed Issue: Lexer errors are ignored [6922]

$
0
0
Javascript syntax errors (e.g., typos) that cause the text to fail the first, "lexing" stage of parsing are simply ignored, silently... This means, for example, if you type ")(---" in the middle of your JavaScript program, it will do nothing, but not tell you an error. This is a known problem with the way that Jint uses Antlr.

Comments: 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/

Closed Issue: Problem with milliseconds in JS date [6918]

$
0
0
Hi,

I found out a little problem with JS date and milliseconds in Jint 0.9.0

If you assign a milliseconds value to a JS date, it's set with a discrepancy of 2 milliseconds.

I'm using this unit test:

-----------------------------

[TestMethod]
public void Test_Jint_DateMilliseconds()
{
var jint = new JintEngine();
object result = null;

string script = @"
var dd = new Date(2010, 10, 17, 19, 01, 01);
dd.setMilliseconds(123);
return dd.getMilliseconds();
";

result = jint.Run(script);
Assert.AreEqual(123, result);
}

-----------------------------

Above test returns 121 as result (any setting will always return 2 milliseconds before).
Comments: 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/

Closed Issue: Can't use "CallFunction". :\ [5657]

$
0
0
Okay.. So, I don't know if I'm doing it wrong or what.. But I can't get CallFunction to work..

i have:
JintEngine Engine = new JintEngine();
Engine.Run(@"function MyTest(num) { return 'hello world ' + num; }");

for(int i=0; i<10; i++)
Console.WriteLine(Engine.CallFunction("MyTest", i));


---

Error:
'Jint.JintEngine' does not contain a definition for 'CallFunction' and no extension method 'CallFunction' accepting a first argument of type 'Jint.JintEngine' could be found (are you missing a using directive or an assembly reference?)
Comments: 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/

Closed Issue: Returning JavaScript objects to the Clr [6861]

$
0
0
It is normally not possible to pass JavaScript objects to the Clr. The only ways to do this are to use the JintEngine.Run(..., false) function, or to use the ExecutionVisitor class directly. In all other cases, trying to pass a JavaScript object will result in a null value, which is completely useless.

I would like to be able to transparently pass JS objects using return, property setters and function call arguments. I suggest to simply return the raw JsObject object instead, without any conversion. This will at least provide a more flexible way to pass objects. A better solution may be to use a wrapper class, which converts the JsObject values on-demand.

Other than that, I really like Jint. It's great to have lightweight C-style scripting support in .Net! Thank you!
Comments: 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/

Closed Issue: Compatibility with .Net4 [6878]

$
0
0
When compiling Jint for .Net4, we get some error messages caused by conflicting names for the delegates redeclared in JintEngine.cs :
Names "Action" and "Func" are conflicting with .Net names from System namespace.

It's easy to resolve, it would be great to check how to deal with different versions of Framework.
Comments: 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/

Closed Issue: Trouble testing isNaN [6916]

$
0
0
Hi. I've tried out Jint for a few hours and finally banged my head against the wall trying to figure out testing a callback from our method.

This works:


[TestMethod]
public void BasicTest()
{
string expectedValue = "http://restservices.localhost";

var jint = new JintEngine();
var returnVal = jint.Run(File.ReadAllText("api.js") &#43; "return $api.getRestHost();");

Assert.AreEqual(expectedValue, returnVal);
}


which is great.



However - when I try to test our Person.get function the internal Javascript function isNaN doesn't work the way I expect.

First the Javascript function:




$api.Person.get = function (id, callback) {
if (isNaN(id)) {
callback({ code: 400, message: "Invalid ID" });
return;
}
//Do stuff and call external service
};




...and the C# test


[TestMethod]
public void Test3()
{
var jint = new JintEngine();
jint.SetFunction("callback", new Action(() => {}));
jint.SetDebugMode(true);
var returnVal = jint.Run(File.ReadAllText("api.js") &#43; "return $api.Person.get(abc, callback);");
//Assert not implemented - should test that I get JSON back with a 'code' property set to 400
}The if-statement in $api.Person.get doesn't evaluate to true - so my callback with code 400 isn't invoked and I later on get an error and a huge stacktrace because the "Do stuff" section at some point depends on the Javascript 'window' object (which obviously isn't there).How should the test be written in order for isNaN to work like expected?
Comments: 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/

Closed Issue: Bug at the Marshaller.MarshalJsFunctionHelper [6904]

$
0
0
The AllowClr Property bug:

object MarshalJsFunctionHelper(JsFunction func, Type delegateType)
{
// create independent visitor
ExecutionVisitor visitor = new ExecutionVisitor(m_global, new JsScope((JsObject)m_global));
var v = ((ExecutionVisitor)m_global.Visitor);
visitor.AllowClr = v.AllowClr;
visitor.PermissionSet = v.PermissionSet;
JsFunctionDelegate wrapper = new JsFunctionDelegate(visitor, func, JsNull.Instance, delegateType);
return wrapper.GetDelegate();
}
Comments: 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/

Closed Issue: Exception error description return nothing [6910]

$
0
0
When an exception is caught in javascript in the code below, the error message can be retrieved through the local variable in step event handler. But err.description return nothing.

try
{
//some code here throw exception
}
catch(err)
{
var errMessage = err.description;
alert(errMessage);
}

Comments: 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/

Closed Issue: How support import? [6903]

$
0
0
var list = new System.Collections.Generic.List{System.Int32}(5);
list.Add(1);
list.Add(15);
for(var i in list)
{
show(i);
}

It's long....
Comments: 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/

Closed Issue: delete Operator is Not Implemented [6883]

$
0
0
Please implement the delete operator, which is part of the EMCA-262 (JavaScript 1.2) recommendation. Here is a simple test case that was done with the shell project that comes in the latest source download.

jint > var a = 3;


jint > delete a;

delete
Line: 1 Char: 0
No source code available.

jint >
Comments: 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/

Closed Issue: Exposing COM objects [6900]

$
0
0
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.
Comments: 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/

Closed Issue: undefined and null can be modified [6898]

$
0
0
The following code:

var x;
x.a = "b";

succeeds in Jint but should fail with something like:
"Unable to set value of the property 'a': object is null or undefined"

ECMAScript doesn't allow you to do this.

I added the following to Jint.Native.JsUndefined:
public override void DefineOwnProperty(Descriptor currentDescriptor) {
throw new JintException(String.Format("Unable to define property '{0}': object is undefined", currentDescriptor.Name));
}

and a similar exception for the same method in Jint.Native.JsNull.

Comments: 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/

Closed Issue: JintEngine.Run(Program, bool) discards root exception when processing catch(Exception e) [6879]

$
0
0
In the catch(Exception e) block of JintEngine.Run(), a new JintException() is generated which is:
throw new JintException(e.Message + source + stackTrace, e.InnerException);
but this throws away 'e' and makes e.InnerException the inner exception for the new JintException. This should be:
throw new JintException(e.Message + source + stackTrace, e);

Comments: 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/

Closed Issue: Function/variable redeclaration bug, different between same context or between contexts [6870]

$
0
0
Hello,

This is a three part problem.
If one re-declares a function one will not get any warning by the jint engine.
The problem gets more complicated when depending on how you execute the code either the first or the second declaration of the function will be executed.

I found this second problem, because I treat the code slightly differently when running from when debugging.

In the normal run case, it will go through a list of files and run each of them, basically doing something like:
// simplified pseudo code for clarity
JintEngine().Run(file1);
JintEngine().Run(file2);

Below is sample code for the two files, where test1() is declared three times.

// File 1
// first one
function test1()
{
// This function will not be called since the function is redefined in the next source file
Echo("test1");
}

// File 2
// second one
function test1()
{
// This definition is what will be executed
Echo("test2");
}

// third one
function test1()
{
// This is hidden due to that above definition takes priority
// If the engine should be consistent then this should take priority
// That is how variable definitions work.
Echo("You will not see this!");
}

test1();

When debugging, I need to merge all the files in memory and keep track line numbers and calculate the right offset to which file should be shown during debug (as well as recalculating this offset for any exception).

So it will basically run:
code = file1+file;
JintEngine().Run(code);

However in this scenario it will call the first declaration (in "file1" which is now merged with the second one into one big code string).
One would expect it to always chose the last re-declaration. I'm guessing this behavior is because it will build some tree or something similar where it will pick the first found function declaration
and this tree is re-init between jintEngine.Run states differently than when finding the re-declaration in the same context.

The best would be to get some sort of warning in both scenarios :)

This got pretty long, I hope the explanation was clear enough :)

Best regards







Comments: 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/

Closed Feature: Implementing import keyword [5529]

$
0
0
I looked up on Google that "import" is a Javascript reserved keyword. Now, even though it isn't an ECMAScript reserved keyword and that is the primary focus of Jint, wouldn't it be practical though to get import implemented sooner rather than later so that there doesn't have to be so much ridiculous keyboard typing going on to reference .Net classes?

I hope the overwhelming majority of people here would say...YES!
Comments: 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/

Closed Issue: Javascript set fields [6131]

$
0
0
At the moment, js code interacting with .net classes can only set properties, and not set fields. I think setting fields would be a good idea, and easy to impliment.
Comments: 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/

Closed Issue: Classes that implements IEnumerable are not introspected [5878]

$
0
0
I have .Net classes implemented in C# that inherits IDictionary. Since IDictionary inherits IEnumerable all the methods and properties are ignored when JsClr class wrapps an instance of these classes.

When exposing IDictionary objects to jint it would be nice if the the IDictionary interface is checked first (TryGetValue) and then check the members of the class.

My workaround is to just comment out the check in JsClr for IEnumerable that prevents introspection(dosent seem to break any of tests - 3 failing before and after in trunk). Another is to implement delegating calls from the IDictionary methods to the correct class member.
Comments: 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/

Closed Issue: Overloaded CLR indexers not supported ("Item" property) [5872]

$
0
0
When having multiple indexers in a class, Jint just selects the one that happens to come first when enumerating available properties. The proposed patch fixes this by first attempting to let the runtime resolve the property directly using the Type.GetProperty() method (CachedReflectionPropertyGetter.cs). Also included is a change to ExecutionVisitor.cs that adds support for renamed default members (i.e. when the indexer property name is not "Item").

Example broken code:

using System;
using System.Text;
using Jint;

namespace jinttest
{
public enum TestEnum
{
One = 1,
Two = 2,
Three = 3
}

public class Test
{
public string this[string str]
{
get { return "StringIndexer - " + str; }
}

public string this[TestEnum num]
{
get { return "EnumIndexer - " + num.ToString(); }
}
}

class Program
{
static void Main(string[] args)
{
object result;

JintEngine engine = new JintEngine();
engine.AllowClr = true;
engine.DisableSecurity();

StringBuilder program = new StringBuilder();

program.AppendLine("var o = new jinttest.Test();");
program.AppendLine("return o[jinttest.TestEnum.Two];");

result = engine.Run(program.ToString());

Console.WriteLine(result.ToString());
Console.ReadKey();
}
}
}
Comments: 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/
Viewing all 425 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>