Quantcast
Channel: ClearScript
Viewing all 2297 articles
Browse latest View live

New Post: What is correct option to use ClearScript.V8 as NuGet package?

$
0
0
Hello Ciget!

It sounds like you've set everything up correctly. You're just trying to run your project in IIS Express on your VS 2013 machine, right?

Please make sure that copies of those DLL files do not appear in your bin directory. The NuGet package sets up build steps to copy them there, but that unfortunately doesn't work for ASP.NET projects. In such projects those files must be deleted from the bin directory, and those build steps should be disabled.

Please let us know if this helps. Thanks!

New Post: Calling VBScript function by dispatchId

$
0
0
Hello!

ClearScript does not support invocation of script items via dispatch ID.

However, the VBScript functions have names, right? Why not use them? We're guessing that the Delphi application had no choice but to deal with dispatch IDs because no higher-level interface to VBScript code existed at the time.

Internally all JScript/VBScript invocation involves dispatch IDs, but ClearScript is designed to shield developers from engine-specific details like that. We'll gladly consider exposing them, but first we'd like to get a better understanding of the use case.

Thanks!

New Post: Calling VBScript function by dispatchId

$
0
0
This application wrote before years. I think dispatch id is used for performance reason. The application allows to customize specific business model, extend and interact with application, it uses VBScript is very extensive.
Additional question about thead-safe.
Is the VB scripter thread-safe?

New Post: Cannot get property of a derived class

$
0
0
Consider I have the following classes
    public class Element
    {
        public Location Location { get; set; }
    }

    public class Location
    {
        public string Name { get; set; }
    }

    public class LocationPoint : Location
    {
        public string Point { get; set; }
    }
var e = new Element
{
    Location = new LocationPoint
    {
        Name = "N",
        Point = "X"
    }
};

var engine = new V8ScriptEngine();
engine.AddHostObject("e", e);
Console.WriteLine(engine.Evaluate("e.Location.Point"));
Point value will be undefined. It seems like Clearscript uses reflection to get the property for "Element" but in this case, the property "Location" is not a "Location" but it is a derived class "LocationPoint".

New Post: Cannot get property of a derived class

$
0
0
Here's a quick hack, in HostItem class, change
target.Type.GetScriptableProperty(name, invokeFlags, bindArgs); 
to
target.Target.GetType().GetScriptableProperty(name, invokeFlags, bindArgs);
That way, it will get the property from the derived class instead.

New Post: Cannot get property of a derived class

$
0
0
Hi ravetam!

Great question. This may be an example of ClearScript behaving a little too much like C# :)

The expression you're evaluating, e.Location.Point, doesn't compile in C#, and it doesn't work in script code for the same reason. You need to cast e.Location to LocationPoint.

Here's how to do the cast in script code:
engine.AddHostObject("host", new HostFunctions());
engine.AddHostType("LocationPoint", typeof(LocationPoint));

engine.AddHostObject("e", e);
Console.WriteLine(engine.Evaluate("host.cast(LocationPoint, e.Location).Point"));
If you're wondering why ClearScript exposes the declared type of the property instead of the runtime type of its value, it has to do with preserving static type information in order to provide C#-like method binding. Without this behavior, some things might be easier to do in script code, but you'd lose the ability to access .NET members in many scenarios. Your proposed fix, for example, breaks 47 ClearScript tests :)

Nevertheless, ClearScript does provide a way to override its default behavior:
publicclass Element
{
    [ScriptMember(ScriptMemberFlags.ExposeRuntimeType)]
    public Location Location { get; set; }
}
With the Element class defined this way, no cast is necessary in script code.

Thanks, and good luck!

New Post: Cannot get property of a derived class

$
0
0
Thanks for the detailed explanation. I should have run the unit test first.

The second solution seems to work but the problem is, the class library has to reference Clearscript. If I were to disable this check at all (IsRestrictedForScript always returns false), would I run into any issue? I ran all the unit test and there's no error at all. And it seems to ran a lot faster because it is not reading the attribute from the property.

New Post: Cannot get property of a derived class

$
0
0
If I were to disable this check at all (IsRestrictedForScript always returns false), would I run into any issue?

It depends on the design of the .NET API you're calling from script code. In general you'll probably be OK.

The default behavior is aligned with C#. Where C# requires a cast, so does script code. Your change will allow you to avoid casting in some situations, but it may also force you to cast in places where C# doesn't.

I ran all the unit test and there's no error at all.

You're right, and that's something we need to fix.

Cheers!

Commented Issue: [V8 bug] Issue with memory leaking scripts: 5.3.9 vs 5.3.10 [32]

$
0
0
Hi everybody,

I just noticed a behavior that differs between ClearScript v 5.3.9 and 5.3.10, and it's about limiting memory for a script execution. Consider following faulty script (it emulates a memory leak) being executed inside the 64 bit console application:
```
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;

for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;

return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.WriteLine("Sorted Array:", sample_arr);
```
as well as following ClearScript's V8 engine configuration:
```
Using engine As New V8ScriptEngine("V8Engine", New V8RuntimeConstraints() With {.MaxOldSpaceSize = 209715200}, V8ScriptEngineFlags.EnableDebugging, 9222)
```
You'll notice that after running above code in 5.3.9 it gracefully ends up with an exception that indicates a memory limit being exceeded (see attachment). However, in 5.3.10 it doesn't result in exception and rather hard-crashes with a message in the console (see attachment). Could you test it on your end and provide some follow-up?

System used for testing: Window 7, 64 bit.

Thanks for your work,
Max

Comments: Feedback from V8's team on the bug doesn't sound too promising...

New Post: Calling VBScript function by dispatchId

$
0
0
So at startup the application looks up dispatch IDs by name and caches them for invocation purposes. Is that correct? Again, we're not sure it makes sense to expose dispatch IDs in ClearScript. The performance hit of invoking by name is likely to be negligible in a modern .NET environment.

As for your other question, no, VBScript has never been thread-safe. Not only that, its thread affinity means that you can only use a given VBScript instance on the thread that created it. ClearScript enforces this rule.

New Post: Calling VBScript function by dispatchId

$
0
0
Thanks for your answers.
Can you more explain why for .NET application calling by name to be negligible?

About thread-safe I know, that a reason why in our legacy code there is a logic that check thread id and clone scripter in case of calling from a different thread.
Is there some work around in ClearScript?

Thanks.

Commented Issue: [V8 bug] Issue with memory leaking scripts: 5.3.9 vs 5.3.10 [32]

$
0
0
Hi everybody,

I just noticed a behavior that differs between ClearScript v 5.3.9 and 5.3.10, and it's about limiting memory for a script execution. Consider following faulty script (it emulates a memory leak) being executed inside the 64 bit console application:
```
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;

for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;

return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.WriteLine("Sorted Array:", sample_arr);
```
as well as following ClearScript's V8 engine configuration:
```
Using engine As New V8ScriptEngine("V8Engine", New V8RuntimeConstraints() With {.MaxOldSpaceSize = 209715200}, V8ScriptEngineFlags.EnableDebugging, 9222)
```
You'll notice that after running above code in 5.3.9 it gracefully ends up with an exception that indicates a memory limit being exceeded (see attachment). However, in 5.3.10 it doesn't result in exception and rather hard-crashes with a message in the console (see attachment). Could you test it on your end and provide some follow-up?

System used for testing: Window 7, 64 bit.

Thanks for your work,
Max

Comments: No, unfortunately it doesn't, but it's their project, so it makes sense that they're evolving it according to their needs. They've generously made the code available for anyone to fork; we just don't have the resources for that. We might make one final plea for them to fix it, but that's it.

Commented Issue: [V8 bug] Issue with memory leaking scripts: 5.3.9 vs 5.3.10 [32]

$
0
0
Hi everybody,

I just noticed a behavior that differs between ClearScript v 5.3.9 and 5.3.10, and it's about limiting memory for a script execution. Consider following faulty script (it emulates a memory leak) being executed inside the 64 bit console application:
```
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;

for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;

return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.WriteLine("Sorted Array:", sample_arr);
```
as well as following ClearScript's V8 engine configuration:
```
Using engine As New V8ScriptEngine("V8Engine", New V8RuntimeConstraints() With {.MaxOldSpaceSize = 209715200}, V8ScriptEngineFlags.EnableDebugging, 9222)
```
You'll notice that after running above code in 5.3.9 it gracefully ends up with an exception that indicates a memory limit being exceeded (see attachment). However, in 5.3.10 it doesn't result in exception and rather hard-crashes with a message in the console (see attachment). Could you test it on your end and provide some follow-up?

System used for testing: Window 7, 64 bit.

Thanks for your work,
Max

Comments: Could you suggest any theoretical workaround for this given that V8 doesn't do anything about this issue? It looks like the only exit strategy here is to create and monitor a new process to host ClearScript/V8 within, which by it-self is not a trivial task - for one I wanted to be able to run these libraries in conjunction with ASP.NET, process being killed is not something I can afford.

New Post: Calling VBScript function by dispatchId

$
0
0
Can you more explain why for .NET application calling by name to be negligible?

Invoking a VBScript function from .NET is relatively expensive, as the ClearScript and COM interop layers incur a lot of overhead. Adding a string lookup shouldn't affect it significantly. This is all speculation, of course, until we compare some actual performance measurements. We'll take a closer look at this.

About thread-safe I know, that a reason why in our legacy code there is a logic that check thread id and clone scripter in case of calling from a different thread. Is there some work around in ClearScript?

No, ClearScript throws an exception if you attempt to use a VBScriptEngine instance from the wrong thread, but nothing stops you from implementing an engine cloning scheme like the one in your legacy application.

Good luck!

Commented Issue: [V8 bug] Issue with memory leaking scripts: 5.3.9 vs 5.3.10 [32]

$
0
0
Hi everybody,

I just noticed a behavior that differs between ClearScript v 5.3.9 and 5.3.10, and it's about limiting memory for a script execution. Consider following faulty script (it emulates a memory leak) being executed inside the 64 bit console application:
```
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;

for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;

return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.WriteLine("Sorted Array:", sample_arr);
```
as well as following ClearScript's V8 engine configuration:
```
Using engine As New V8ScriptEngine("V8Engine", New V8RuntimeConstraints() With {.MaxOldSpaceSize = 209715200}, V8ScriptEngineFlags.EnableDebugging, 9222)
```
You'll notice that after running above code in 5.3.9 it gracefully ends up with an exception that indicates a memory limit being exceeded (see attachment). However, in 5.3.10 it doesn't result in exception and rather hard-crashes with a message in the console (see attachment). Could you test it on your end and provide some follow-up?

System used for testing: Window 7, 64 bit.

Thanks for your work,
Max

Comments: I wonder if we could make a feature request for ClearScript to handle the multi-process architecture or if that is out of scope for the project. I would say that the concept of running untrusted scripts, possibly in a server environment, is a valid use case.

New Post: Cannot get property of a derived class

$
0
0
Actually, I wanted it to look more "Javascript" coding style. Anyway, from my unit test, my script still works after the changes.

Thanks again. I'll keep "the casting issue" in mind.

New Post: Cannot get property of a derived class

$
0
0
Right, automatic type restriction is a relatively new feature in ClearScript, designed to facilitate access to esoteric .NET APIs. We agree that for simple APIs that rely on polymorphism, turning it off may make sense. Maybe we'll add a flag for that, but in the meantime, your IsRestrictedForScript patch should be perfectly safe.

Commented Issue: [V8 bug] Issue with memory leaking scripts: 5.3.9 vs 5.3.10 [32]

$
0
0
Hi everybody,

I just noticed a behavior that differs between ClearScript v 5.3.9 and 5.3.10, and it's about limiting memory for a script execution. Consider following faulty script (it emulates a memory leak) being executed inside the 64 bit console application:
```
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;

for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;

return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.WriteLine("Sorted Array:", sample_arr);
```
as well as following ClearScript's V8 engine configuration:
```
Using engine As New V8ScriptEngine("V8Engine", New V8RuntimeConstraints() With {.MaxOldSpaceSize = 209715200}, V8ScriptEngineFlags.EnableDebugging, 9222)
```
You'll notice that after running above code in 5.3.9 it gracefully ends up with an exception that indicates a memory limit being exceeded (see attachment). However, in 5.3.10 it doesn't result in exception and rather hard-crashes with a message in the console (see attachment). Could you test it on your end and provide some follow-up?

System used for testing: Window 7, 64 bit.

Thanks for your work,
Max

Comments: Max, we're investigating workarounds that include ClearScript changes, V8 patches, and switching to an older, branched V8 build that functions better in this area. This will take some time, however. A simple code fix appears unlikely, as everything we've tried so far to fake out unmodified V8 has been thwarted by the unusual stack environment set up by V8's JIT compiler. @jbrantly, extending ClearScript's API across process boundaries is probably not practical. Each exposed .NET object - and each imported script object - would have to be marshaled across the boundary via some sort of live proxy, and we don't know of any generic means of doing so. Even if that could be accomplished, it would be extremely inefficient, as the overhead of crossing the host-to-script boundary - already high - would go up by several additional orders of magnitude. A multi-process design at the host application level - as in Chrome - would be much better, but it would of course be application-specific.

New Post: Cannot get property of a derived class

New Post: How to change the Global Object to another object?

$
0
0
Just like in Chrome,the Global object is "window".the code:
var i=100;
if(window.i==100) //this is true
{
.....
}
Viewing all 2297 articles
Browse latest View live


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