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

New Post: Add functions and property from an Interface to a new API of the engine

$
0
0
Hello

Thanks, Perfect :-)

Sybaris

New Post: Praise and a couple questions

$
0
0
Wow, this is an awesome project! I wrote a home automation system and implemented a simple rules system in XML (essentially If-Then-Else statements). As I wanted to do more complex things in my rules, I decided to look around for a way to host a scripting language directly so that I don't end up writing one over time. ClearScript does this so easily that I am just amazed. Thank you for releasing the project and for all the support you give in these forums; they have been a great resource for me.

So, 2 questions:

1) I noticed that when calling (from .NET) a JavaScript function that talks to .NET objects, it seems to take about an extra 100ms on the first call. Is this because the proxies are set up on demand? Just curious.

2) I want to have an implementation of some XmlHttpRequest features. As discussed previously in some topics here, this can easily be done by wrapping WebClient and I see how to do this on both sides of the fence. Is there a performance or garbage collection contrast between these 2 approaches:
  • Expose WebClient and URI (for the async method) to JavaScript and write a JS wrapper that creates .NET objects, subscribes to events, and performs the callback.
  • Write a C# wrapper around WebClient and URI and expose that 1 object to JavaScript.
Really this is a specific example of a general question - is it better to do such work on the C# side and expose simpler objects and interfaces to JavaScript?

New Post: Script editor

$
0
0
Hello

I realize that my question is off topic limit, but this result from the using of ClearScript and Javascript.
Currently I use ScintillaNet to offer to my user an integrated interface in my soft.
This component seems pretty well, but do you know if some others components are better ?

I would be especially interested to offer a good intellisence. so if you have tips, I'm interested...

Thanks for advance.
Sybaris

New Post: Praise and a couple questions

$
0
0
Hi ScytaleZero,

First, thank you very much for your positive feedback!

Now, on to your questions:

I noticed that when calling (from .NET) a JavaScript function that talks to .NET objects, it seems to take about an extra 100ms on the first call. Is this because the proxies are set up on demand? Just curious.

Most likely it's because invoking a .NET method from script code involves an expensive step (called binding) that maps the method name to a unique method. For an overloaded method this step may require an examination of the argument types, and for a generic method it may require the on-demand construction of the specialized (closed generic) version of the method.

Once a given call signature has been bound successfully, ClearScript caches the binding to speed up subsequent calls. This is very similar to what happens at dynamic call sites emitted by the C# compiler.

Really this is a specific example of a general question - is it better to do such work on the C# side and expose simpler objects and interfaces to JavaScript?

If you're concerned about performance and/or wish to restrict the script's activities, then exposing a simple, custom API is probably the best approach. The key for performance is to design your API to minimize hops across the .NET-script boundary, especially if you're using V8. That script engine is remarkably fast but not as fast as JIT-compiled C#, and the overhead of invoking native code from .NET is significant.

Good luck!

Created Unassigned: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

New Post: Type argument : how to make a typeof

$
0
0
Hello,

I exposed DataTable type to my javascript code :
C# code :
scriptEngine.AddHostObject("DotNet", new HostTypeCollection("mscorlib", "System.Core", "System.Data"));
But for adding columns, the Add method require a Type Parameter.
My Javascript code :
var dt = new DotNet.System.Data.DataTable("testDataTable");
dt.Columns.Add("Col1",DotNet.System.Int32);
The last line does not run 'invalid argument.
In C#, I should write this :
dt.Columns.Add("Col1",typeof(System.Int32));
How can I do the same of typeof in ClearScript / Javascript ?

Thanks for advance
Sybaris
PS : I discover ClearScript for a few days, and I am very impressed by all the work made, and the power of this engine...

Commented Unassigned: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

Comments: Hello! It looks like your ClearScriptV8 projects were somehow converted to use an old Visual Studio toolset. We cannot reproduce this and recommend that you [download](https://clearscript.codeplex.com/releases) the latest ClearScript source code into a new directory and start over. Please follow the build procedure in the ClearScript [ReadMe](https://clearscript.codeplex.com/SourceControl/latest).

New Post: Script editor

$
0
0
Hi Sybaris,

Unfortunately we don't have any specific recommendations for an embeddable JavaScript editor. StackOverflow has several similar questions; take a look here for an example.

Good luck!

New Post: Type argument : how to make a typeof

$
0
0
Hi Sybaris,

ClearScript's HostFunctions class provides a number of utility methods for situations like this, including typeOf(). The only other thing to be aware of is that ClearScript blocks reflection by default, but you can easily enable it:
scriptEngine.AddHostObject("host", new HostFunctions());
scriptEngine.AllowReflection = true;
scriptEngine.Execute(@"
    var dt = new DotNet.System.Data.DataTable('testDataTable');
    dt.Columns.Add('Col1', host.typeOf(DotNet.System.Int32));
");
Cheers!

New Post: Type argument : how to make a typeof

Commented Unassigned: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

Comments: I get the same results. The download and build of V8 seems to work fine but the ClearScriptV8 projects just won't compile for me.

Commented Unassigned: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

Comments: Please paste or attach your copy of the following file: >[ClearScriptRoot]\ClearScript\V8\ClearScriptV8\64\ClearScriptV8-64.vcxproj

Commented Unassigned: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

Comments: It turns out I did not have the VC++ 2013 redistributables installed. I had VC++ installed with Visual Studio 2013 but for some reason did not have the redistributable. So it now compiles. Thank you.

Created Unassigned: setTimeout fails after upgrade [93]

$
0
0
I just upgraded from version 5.4.2 to 5.4.3 and script code that once worked now fails with the error "Object doesn't support this property or method". I am using V8.

I added a host object that is a Timer
```
Engine.AddHostType("ScriptTimer", GetType(ScriptTimer))
```

My ScriptTimer looks like this (VB.Net)
```
Public Module ScriptTimer
Public Function Create(func As Object, delay As Double, period As Double, args As Object)
Try
Dim callback As System.Threading.TimerCallback = New System.Threading.TimerCallback(
Sub()
Try
func.apply(Nothing, args)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub)
Return New System.Threading.Timer(callback, Nothing, Convert.ToInt64(delay), Convert.ToInt64(period))
Catch ex As Exception
Console.WriteLine(ex.Message)
Return ex
End Try
End Function
End Module
```

And this is the script that fails.
```
function createTimer(periodic, func, delay) {
var period = periodic ? delay : -1;
var args = Array.prototype.slice.call(arguments, 3);
return ScriptTimer.Create(func, delay, period, args);
}

setTimeout = createTimer.bind(null, false);
```

Commented Unassigned: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

Comments: Glad to hear it. Thanks!

Edited Issue: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

Closed Issue: Building with VS 2013 [92]

$
0
0
I successfully ran V8Update downloading the latest version of V8. However, when I try to build the solution in VS2013, I get two errors and it fails to compile ClearScriptV8-32 and ClearScriptV8-64. Do I need to have Visual Studio 2010 installed on my machine?

Here are the two errors.

Error 1 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-32 (Visual Studio 2010)

Error 2 error MSB8020: The builds tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2010 to build using the Visual Studio 2010 build tools. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets 42 5 ClearScriptV8-64 (Visual Studio 2010)

Commented Unassigned: setTimeout fails after upgrade [93]

$
0
0
I just upgraded from version 5.4.2 to 5.4.3 and script code that once worked now fails with the error "Object doesn't support this property or method". I am using V8.

I added a host object that is a Timer
```
Engine.AddHostType("ScriptTimer", GetType(ScriptTimer))
```

My ScriptTimer looks like this (VB.Net)
```
Public Module ScriptTimer
Public Function Create(func As Object, delay As Double, period As Double, args As Object)
Try
Dim callback As System.Threading.TimerCallback = New System.Threading.TimerCallback(
Sub()
Try
func.apply(Nothing, args)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub)
Return New System.Threading.Timer(callback, Nothing, Convert.ToInt64(delay), Convert.ToInt64(period))
Catch ex As Exception
Console.WriteLine(ex.Message)
Return ex
End Try
End Function
End Module
```

And this is the script that fails.
```
function createTimer(periodic, func, delay) {
var period = periodic ? delay : -1;
var args = Array.prototype.slice.call(arguments, 3);
return ScriptTimer.Create(func, delay, period, args);
}

setTimeout = createTimer.bind(null, false);
```
Comments: Hello! Hmm, we can't reproduce this. Can you post a call stack? Here's the full program we ran without encountering any issues: ``` VB.NET Imports Microsoft.ClearScript.V8 Public Module ScriptTimer Public Function Create(func As Object, delay As Double, period As Double, args As Object) Try Dim callback As Threading.TimerCallback = New System.Threading.TimerCallback( Sub() Try func.apply(Nothing, args) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub) Return New Threading.Timer(callback, Nothing, Convert.ToInt64(delay), Convert.ToInt64(period)) Catch ex As Exception Console.WriteLine(ex.Message) Return ex End Try End Function End Module Module Module1 Sub Main() Using engine As New V8ScriptEngine engine.AddHostType("ScriptTimer", GetType(ScriptTimer)) engine.Execute( <![CDATA[ function createTimer(periodic, func, delay) { var period = periodic ? delay : -1; var args = Array.prototype.slice.call(arguments, 3); return ScriptTimer.Create(func, delay, period, args); } setTimeout = createTimer.bind(null, false); ]]>.Value) End Using End Sub End Module ``` Thanks!

New Post: Using Compile with Execute and Script

$
0
0
I have an application (with V8ClearScript) where the user occasionally loads a collection of script libraries. They then develop a Main script that can call those library scripts. The Main script will execute on a timer that may scan anywhere from once every 1 second to once every 10 seconds - most likely closer to 1 second.

It sounds like my best bet is to precompile the scripts. Generally the user may reload everything if they make changes to the library scripts. The user may just reload the main script if they make changes to just the main script. The user then can put the main script on scan or take it off scan before reloading.

Do first compile the script then execute the script?
ThisScript = Engine.Compile(scriptFile)
Engine.Execute(ThisScript)
When the timer is on I use the Script method to call a specific function name in the main script. The user understands that if they want to run a script every scan it must be in the main script and a function named Main() must exist in that script.

Commented Unassigned: setTimeout fails after upgrade [93]

$
0
0
I just upgraded from version 5.4.2 to 5.4.3 and script code that once worked now fails with the error "Object doesn't support this property or method". I am using V8.

I added a host object that is a Timer
```
Engine.AddHostType("ScriptTimer", GetType(ScriptTimer))
```

My ScriptTimer looks like this (VB.Net)
```
Public Module ScriptTimer
Public Function Create(func As Object, delay As Double, period As Double, args As Object)
Try
Dim callback As System.Threading.TimerCallback = New System.Threading.TimerCallback(
Sub()
Try
func.apply(Nothing, args)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub)
Return New System.Threading.Timer(callback, Nothing, Convert.ToInt64(delay), Convert.ToInt64(period))
Catch ex As Exception
Console.WriteLine(ex.Message)
Return ex
End Try
End Function
End Module
```

And this is the script that fails.
```
function createTimer(periodic, func, delay) {
var period = periodic ? delay : -1;
var args = Array.prototype.slice.call(arguments, 3);
return ScriptTimer.Create(func, delay, period, args);
}

setTimeout = createTimer.bind(null, false);
```
Comments: I have it solved. I had changed my code to use JScript instead of V8. When I put it back to V8 everything worked fine. Sorry for the confusion. BTW: Should this same setTimeout function work in the ClearScript JScript engine?
Viewing all 2297 articles
Browse latest View live




Latest Images