Quantcast
Channel: ClearScript
Mark channel Not-Safe-For-Work? cancel confirm NSFW Votes: (0 votes)
Are you the publisher? Claim or contact us about this channel.
0

New Post: Problem building the 5.4.7 in the v8 32 bit step

0
0
Updating VS to update 5 seems to have solved the problem, and I encountered no problems when compiling with the updated version.

Seems a little strange to me, that the update could have such a big impact on the compilation, and it works now, and I am happy :)

Thank you very much for the help.

New Post: Calling a JS Function from a script that has been exectued

0
0
It is the same instance, but I think I've found the issue. The prior execute is failing, because for some reason it's throwing a missing ; error during the execute (compiling pretty common JS code, jquery.js... guess I need to sort out what's going on there.

New Post: Problem building the 5.4.7 in the v8 32 bit step

0
0
That's great to hear. Thanks!

New Post: V8 Null Pointer crash when using "for (let a of hostObj)"

0
0
In my application, the following code works for two successive calls but then causes a null pointer crash in v8-x64.dll during the third call:
function volumeOperation(choiceResults) {
    for (let c of choiceResults) {
        // anything here
     }
}
where choiceResults is a Dictionary<string, List<object>> passed in via a callback call. If I change this code to the following:
function volumeOperation(choiceResults) {
    const results = choiceResults.GetEnumerator();
    while (results.MoveNext()) {
        const c = results.Current;
        // anything here
    }
}
it does not crash. I've tried to reproduce this in C# Interactive but I was not successful. Hopefully this is useful anyway, but let me know if there's any additional information or experimenting I can provide to help narrow it down (or if I've done something wrong).

I'm using the NuGet ClearScript.V8 5.4.6 package, and here's the crash dialog in case it is helpful: crash dialog

Thanks,
Mike.

New Post: Clearscript support for ES6

0
0
Does Clearscript V8 script engine support javascript ES6.

Thanks
Praveen

Created Unassigned: Doesn't Run on Linux [111]

0
0
I recently installed Mono and tried to get ClearScript to run. It doesn't. The CLR ends up looking for "kernel32," which is a native DLL and not available on Mono.

For other libraries, the prescribed fix for this is to remove P/Invoke calls. I don't know how feasible that is here. I would like to see ClearScript running on Linux.

New Post: V8 Null Pointer crash when using "for (let a of hostObj)"

0
0
Hi Mike,

Thanks for reporting this. It appears to be due to a bug in V8's optimization or JIT compilation logic. Luckily it's easy to work around. We'll post a fix shortly.

Thanks again!

New Post: Clearscript support for ES6

0
0
Hi Praveen,

We don't test ClearScript's JavaScript engines for full ES6 support. However, according to this blog post, V8 supports ES6 and ES7 as of stable version 5.2. ClearScript's latest release (version 5.4.7) is paired with V8 5.3, so it should support ES6 and ES7.

Good luck!

Commented Unassigned: Doesn't Run on Linux [111]

0
0
I recently installed Mono and tried to get ClearScript to run. It doesn't. The CLR ends up looking for "kernel32," which is a native DLL and not available on Mono.

For other libraries, the prescribed fix for this is to remove P/Invoke calls. I don't know how feasible that is here. I would like to see ClearScript running on Linux.
Comments: Unfortunately ClearScript depends on a number of Windows-only components. The first of these are JScript and VBScript, legacy script engines that aren't likely to be ported to Linux. Then there's the .NET Framework, as ClearScript doesn't support Mono or .NET Core. Finally there's ClearScript's V8 embedding layer, which combines native and managed code in "mixed-mode" assemblies that are only supported on Windows. We have no plan to reimplement ClearScript's V8 host, but we'd like to support both .NET Core and Chakra Core in the future. That combination should eventually enable Linux support, but we're still very far from making it a reality. In the meantime, consider a Mono-friendly alternative such as [V8.NET](https://v8dotnet.codeplex.com/) or [VroomJS](https://github.com/fogzot/vroomjs).

Edited Feature: Doesn't Run on Linux [111]

0
0
I recently installed Mono and tried to get ClearScript to run. It doesn't. The CLR ends up looking for "kernel32," which is a native DLL and not available on Mono.

For other libraries, the prescribed fix for this is to remove P/Invoke calls. I don't know how feasible that is here. I would like to see ClearScript running on Linux.

Closed Feature: Doesn't Run on Linux [111]

0
0
I recently installed Mono and tried to get ClearScript to run. It doesn't. The CLR ends up looking for "kernel32," which is a native DLL and not available on Mono.

For other libraries, the prescribed fix for this is to remove P/Invoke calls. I don't know how feasible that is here. I would like to see ClearScript running on Linux.

New Post: Host Function that returns dynamic object

0
0
Dear,

I am trying to access properties from a dynamic object that is returned from a c# call.
Example JS:
var xml = api.MyHostFunction();
var productId = xml.ProductId;
This is the prototype for MyHostFunction():
dynamic MyHostFunction();
ClearScript is throwing an exception when trying to access the ProductId property.
Debugging I can see that the property actually exists and can be accessed from any Host code. But its not possible to access it from JS:

TypeError: Cannot read property 'ProductId' of undefined

Am I doing anything wrong or ClearScript does not support this yet?

Thank you!

New Post: Host Function that returns dynamic object

0
0
Hello!

What kind of object does MyHostFunction actually return? Also, are you using V8 or JScript?

Thanks!

New Post: Host Function that returns dynamic object

0
0
Hi!

Thank you for the prompt reply.

The object is typeof(dynamic).
That function makes a call to my WebServer and retrieves a XML document. This XML document can be a lot of different things, so to ease parsing, I am converting it to a dynamic object as described here: https://www.captechconsulting.com/blogs/fluent-xml-parsing-using-cs-dynamic-type-part-1
Then, my JS code should be able to access the XML document elements and attributes as dynamic C# properties.

Basically it is an object that inherits from the DynamicObject class.

I am running V8 engine.

New Post: Host Function that returns dynamic object

0
0
Hi again,

For this to work, your object must implement GetDynamicMemberNames in addition to TryGetMember et al.

Good luck!

New Post: Host Function that returns dynamic object

0
0
Great!

Implementing this method worked.
I will paste it here for future reference:
public class DynamicXml : DynamicObject, IEnumerable
    {
        private readonly List<XElement> _elements;

        public DynamicXml(string text)
        {
            var doc = XDocument.Parse(text);
            _elements = new List<XElement> { doc.Root };
        }

        protected DynamicXml(XElement element)
        {
            _elements = new List<XElement> { element };
        }

        protected DynamicXml(IEnumerable<XElement> elements)
        {
            _elements = new List<XElement>(elements);
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;
            var attr = _elements[0].Attribute(XName.Get(binder.Name));
            if (attr != null)
                result = attr.Value;
            else
            {
                var items = _elements.Descendants(XName.Get(binder.Name));
                if (items == null || items.Count() == 0) 
                    return false;
                result = new DynamicXml(items);
            }
            return true;
        }

        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            int ndx = (int)indexes[0];
            result = new DynamicXml(_elements[ndx]);
            return true;
        }

        public override IEnumerable<string> GetDynamicMemberNames()
        {
            List<String> memberNames = new List<String>();
            foreach (XAttribute attr in _elements[0].Attributes())
            {
                memberNames.Add(attr.Name.LocalName);
            }
            foreach (XElement child in _elements[0].Descendants())
            {
                memberNames.Add(child.Name.LocalName);
            }
            return memberNames;
        }

        public IEnumerator GetEnumerator()
        {
            foreach (var element in _elements)
                yield return new DynamicXml(element);
        }
    }

Created Unassigned: Crash when calling Interrupt() at bad time [112]

0
0
Hello,

we are having issues with a portion of code that basically provokes an exception in user code called by clearscript, and then calls Interrupt on the V8 engine.

It always crashes. Isn't this scenario supposed to function properly ? (I mean, Interrupt should not crash... ?)

Should I explicitely wait before Interrupting in this case ? (but this would be some sort of workaround?)

Cdlt,
Julien.

btw: reproduced on ClearScript 5.4.6 (Nuget version)

```
[Test]
public virtual void TestScriptTerminateCrash()
{
var ctx = new PropertyBag();
using (var engine = new V8ScriptEngine("CrashScript"))
{
engine.AddHostObject("context", ctx);

var eventW = new ManualResetEventSlim(initialState: false);
var tokenSource = new CancellationTokenSource();

// start notification only
var startEvent = new ManualResetEventSlim(false);

ThreadStart main = () =>
{
try
{

ctx["waitCode"] = new Action(() =>
{
// Waiting in the C# code : a cancel exception is generated here
eventW.Wait(tokenSource.Token);

});
ctx["startEvent"] = startEvent;
ctx["counter"] = 0;
try
{
System.DateTime dtRun = System.DateTime.UtcNow;
engine.Execute("dummyDocument.js", @"
// Start
context.counter = 1;

context.startEvent.Set();

context.counter = 2;

context.waitCode();

context.counter = 3;


");
Assert.Inconclusive();
}
catch (Microsoft.ClearScript.ScriptInterruptedException si)
{
Assert.That(si.Message.Contains("interrupted"));
}
catch (Microsoft.ClearScript.ScriptEngineException segx)
{
if (segx.InnerException is System.Reflection.TargetInvocationException &&
segx.InnerException.InnerException != null)
throw segx.InnerException.InnerException;
Assert.Fail();
}
}
catch (OperationCanceledException)
{
}
catch (Exception)
{
Assert.Fail();
}

};

var t = new Thread(main);
t.Start();
Assert.That(startEvent.Wait(5000));

// Cancel + interrupt
tokenSource.Cancel();
//Thread.Sleep(1000); // won't fail if we interrupt later
engine.Interrupt();

t.Join();

Assert.AreEqual(2, (Int32)ctx["counter"]);
}
}

```

Edited Issue: [BUG] Crash when calling Interrupt() at bad time [112]

0
0
Hello,

we are having issues with a portion of code that basically provokes an exception in user code called by clearscript, and then calls Interrupt on the V8 engine.

It always crashes. Isn't this scenario supposed to function properly ? (I mean, Interrupt should not crash... ?)

Should I explicitely wait before Interrupting in this case ? (but this would be some sort of workaround?)

Cdlt,
Julien.

btw: reproduced on ClearScript 5.4.6 (Nuget version)

```
[Test]
public virtual void TestScriptTerminateCrash()
{
var ctx = new PropertyBag();
using (var engine = new V8ScriptEngine("CrashScript"))
{
engine.AddHostObject("context", ctx);

var eventW = new ManualResetEventSlim(initialState: false);
var tokenSource = new CancellationTokenSource();

// start notification only
var startEvent = new ManualResetEventSlim(false);

ThreadStart main = () =>
{
try
{

ctx["waitCode"] = new Action(() =>
{
// Waiting in the C# code : a cancel exception is generated here
eventW.Wait(tokenSource.Token);

});
ctx["startEvent"] = startEvent;
ctx["counter"] = 0;
try
{
System.DateTime dtRun = System.DateTime.UtcNow;
engine.Execute("dummyDocument.js", @"
// Start
context.counter = 1;

context.startEvent.Set();

context.counter = 2;

context.waitCode();

context.counter = 3;


");
Assert.Inconclusive();
}
catch (Microsoft.ClearScript.ScriptInterruptedException si)
{
Assert.That(si.Message.Contains("interrupted"));
}
catch (Microsoft.ClearScript.ScriptEngineException segx)
{
if (segx.InnerException is System.Reflection.TargetInvocationException &&
segx.InnerException.InnerException != null)
throw segx.InnerException.InnerException;
Assert.Fail();
}
}
catch (OperationCanceledException)
{
}
catch (Exception)
{
Assert.Fail();
}

};

var t = new Thread(main);
t.Start();
Assert.That(startEvent.Wait(5000));

// Cancel + interrupt
tokenSource.Cancel();
//Thread.Sleep(1000); // won't fail if we interrupt later
engine.Interrupt();

t.Join();

Assert.AreEqual(2, (Int32)ctx["counter"]);
}
}

```

Commented Issue: [BUG] Crash when calling Interrupt() at bad time [112]

0
0
Hello,

we are having issues with a portion of code that basically provokes an exception in user code called by clearscript, and then calls Interrupt on the V8 engine.

It always crashes. Isn't this scenario supposed to function properly ? (I mean, Interrupt should not crash... ?)

Should I explicitely wait before Interrupting in this case ? (but this would be some sort of workaround?)

Cdlt,
Julien.

btw: reproduced on ClearScript 5.4.6 (Nuget version)

```
[Test]
public virtual void TestScriptTerminateCrash()
{
var ctx = new PropertyBag();
using (var engine = new V8ScriptEngine("CrashScript"))
{
engine.AddHostObject("context", ctx);

var eventW = new ManualResetEventSlim(initialState: false);
var tokenSource = new CancellationTokenSource();

// start notification only
var startEvent = new ManualResetEventSlim(false);

ThreadStart main = () =>
{
try
{

ctx["waitCode"] = new Action(() =>
{
// Waiting in the C# code : a cancel exception is generated here
eventW.Wait(tokenSource.Token);

});
ctx["startEvent"] = startEvent;
ctx["counter"] = 0;
try
{
System.DateTime dtRun = System.DateTime.UtcNow;
engine.Execute("dummyDocument.js", @"
// Start
context.counter = 1;

context.startEvent.Set();

context.counter = 2;

context.waitCode();

context.counter = 3;


");
Assert.Inconclusive();
}
catch (Microsoft.ClearScript.ScriptInterruptedException si)
{
Assert.That(si.Message.Contains("interrupted"));
}
catch (Microsoft.ClearScript.ScriptEngineException segx)
{
if (segx.InnerException is System.Reflection.TargetInvocationException &&
segx.InnerException.InnerException != null)
throw segx.InnerException.InnerException;
Assert.Fail();
}
}
catch (OperationCanceledException)
{
}
catch (Exception)
{
Assert.Fail();
}

};

var t = new Thread(main);
t.Start();
Assert.That(startEvent.Wait(5000));

// Cancel + interrupt
tokenSource.Cancel();
//Thread.Sleep(1000); // won't fail if we interrupt later
engine.Interrupt();

t.Join();

Assert.AreEqual(2, (Int32)ctx["counter"]);
}
}

```

Comments: Thanks for reporting this. The root cause is that script interruption in V8 is an asynchronous process during which the script continues to run but many V8 APIs fail. ClearScript defends against these failures in most cases, but you've found another one. We'll have a fix up shortly. One thing to note is that your `context.waitCode()` script line is guaranteed to raise a managed exception, since your main thread cancels the wait rather than setting the event. This is a particularly problematic scenario; the cancellation exception is raised during script interruption and may therefore end up with empty or invalid properties. Unfortunately that's unavoidable given V8's design.

Commented Feature: [FEATURE] Support for .Net CoreClr [99]

0
0
I'm not sure how feasible this is considering dependencies like V8 but it would be great to have even partial support for [.Net CoreClr](https://github.com/dotnet/coreclr)
Comments: It would be great :)