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

New Post: Does ClearScript use CodeDom

$
0
0
Thank you for all your help and support!

I will use JScript/VBScript in 64-bit mode and as you said I can't use it asynchronously, I won't need to as I don't use WebSockets, AJAX, etc. I use simple form post, process values by running the form action page from start to finish, then return control back to user with response.write.

Anyways, its been a pleasure. :-)

New Post: Add variables

$
0
0
Imports System.Xml
Imports Microsoft.ClearScript

Public Class WebForm1
Inherits System.Web.UI.Page

Private xml As XmlDocument = New XmlDocument
Private documentid As Integer = New Integer
Private cs_engine As Windows.JScriptEngine = New Windows.JScriptEngine

Public Sub Initialize()
    cs_engine.AddHostObject("xml", xml)
    cs_engine.AddHostObject("me", Me)

    Try
        cs_engine.Execute("xml.LoadXml('<sales id=""123""/>');")
        cs_engine.Execute("me.documentid = me.documentid + 1;")

    Catch e As Microsoft.ClearScript.ScriptEngineException
        Response.Write(e.GetBaseException)
    End Try

    If xml.InnerXml.ToString <> "" Then
        Response.Write(xml.SelectSingleNode("//sales").Attributes.GetNamedItem("id").InnerText & "<BR><BR>")
    Else
        Response.Write("No XML Detected!<br><br>")
    End If

    Response.Write(documentid)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
End Class

Loading an XML object or database connection in clearscript with AddObject method is no problem. But how can I add a integer or string variable so when I manipulate it in script I can refer it outside script in VB or vice versa ?

New Post: Add variables

$
0
0
Hi shripaldalal,

In your code above the script can't access documentid because it's a private field. To fix the problem, either make it public or expose Me like this:
cs_engine.AddRestrictedHostObject("me", HostItemFlags.PrivateAccess, Me)
Cheers!

New Post: Add variables

$
0
0
Hey,

Thanks a ton for the quick reply. Worked like a charm. Though I did this, so all the objects of the class get added in script global. Which is exactly what I need. As I mentioned in the other thread, I will be having one web class = 1 script engine! If you feel this is wrong please let me know or I will go ahead using this.

Imports System.Xml
Imports Microsoft.ClearScript

Public Class WebForm1
Inherits System.Web.UI.Page

Public xml As XmlDocument = New XmlDocument
Public documentid As Integer = New Integer
Public cs_engine As Windows.JScriptEngine = New Windows.JScriptEngine

Public Sub Initialize()
documentid = 1
cs_engine.AddRestrictedHostObject("me", HostItemFlags.GlobalMembers, Me)

Try
    cs_engine.Execute("xml.LoadXml('<sales id=""123""/>');")
    cs_engine.Execute("documentid = documentid + 1;")

Catch e As Microsoft.ClearScript.ScriptEngineException
    Response.Write(e.GetBaseException)
End Try

If xml.InnerXml.ToString <> "" Then
    Response.Write(xml.SelectSingleNode("//sales").Attributes.GetNamedItem("id").InnerText & "<BR><BR>")
Else
    Response.Write("No XML Detected!<br><br>")
End If

Response.Write(documentid)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
End Class

New Post: Performance Improvements

$
0
0
Hello Libor,

Thanks for sharing your optimizations. We particularly like your idea of having host items partially share their cached type information. This is definitely something we'll explore further.

By the way, if you're using V8 in a performance-critical application, we recommend using V8ScriptEngineFlags.DisableGlobalMembers if possible.

Also, if you're comfortable sharing it, we'd love to hear more about your application, specifically the aspects that require large numbers of exposed objects.

Thanks again!

New Post: Some basic compiled script questions

$
0
0
Hey guys, a few questions regarding the V8 script compilation:
  • Why are compiled scripts available to evaluate but not to execute?
  • Are executed scripts always compiled internally?
  • Is there any advantage to adding host objects/types before script compilation or is that a runtime only thing?

New Post: Some basic compiled script questions

$
0
0
Hi Eric,

Why are compiled scripts available to evaluate but not to execute?

Script compilation is a V8-specific feature, and since in JavaScript evaluation and execution are the same thing, there's no need for two sets of methods. Evaluation and execution are currently different only in VBScript; V8ScriptEngine has some execution methods only because it inherits them from ScriptEngine.

Are executed scripts always compiled internally?

In V8ScriptEngine, all execution and evaluation methods that accept script code in string format internally perform a compilation step followed by an execution step.

Is there any advantage to adding host objects/types before script compilation or is that a runtime only thing?

Our understanding is that script compilation is not affected by the execution environment, which includes the global object hierarchy. In fact, compiled scripts are reusable across V8ScriptEngine instances that share the same V8 runtime.

Cheers!

New Post: Some basic compiled script questions

$
0
0
Thanks for the fast answer...that was leading to a second question:

I would like to cache my compiled scripts, but it seems from what I've read in the discussions that the compiled scripts are associated with a particular V8 runtime instance. Is that simply a V8 limitation?

In that case I would have to create a managed V8 engine pool with each engine having an associated script cache (which obviously detracts from the benefits of the cache). In my case, I'm going to have a large number of scripts that are user created/edited, so I'm not sure if it's worth the effort. Would that be the suggested approach if I wanted to tackle that?

New Post: Performance Improvements

$
0
0
Hi,

the application is used for virtualization of services (SOAP, REST, JDBC, MQ, ...) generaly for testing of distributed systems (QA can test the system before all the neccessary services are ready and also can easily change behavior of the services and test, how the tested system works with different conditions).
Very simply said our application recieves request message and have to generate and send response message. One of the ways, how the application can modify the response is to modify or partially create it in using JavaScript. And here is the place, where ClearScript is used. The message is stored in a tree structure and user can modify or change any value in the tree and I have to know, what exactly did the user set in the tree not only what did he changed, I have also to know, if user sets some value that was already there. Thas why the simple diff of the original tree and the result of the script execution is not good enought. I have to map the tree to the ClearScript and trace all the objects set into it.
Some scripts are fast (run few ms) but not all of them. We have also script, where millisons of objects are created and added to the tree in for-cycle.

I've already tried to use V8ScriptEngineFlags.DisableGlobalMembers but it did wasn;t faster. In what cases should it help?

After fixing the performance issues I've found in ClearScript, profiler shows me weak places in my app. Is some better way, how can I do this calls faster?


1) Getting property names from object created in JavaScript:
dynamicObject.GetDynamicMemberNames()
2) Check if the object is an array:
..just once:
  isArrayFunction = clearScriptEngine.V8ScriptEngine.Evaluate("(function (x) { return x instanceof Array; })");
..and than use lot of times:
isArrayFunction(dynamicObject)
3) Getting the property value:
dynamicObject.TryGetMember(new Binder(propertyName, false), out propertyValue)
I've also tried to get property value using CallSite. But it was slower even when I was chaching the CallSites.

Thanks, Libor.

New Post: Some basic compiled script questions

$
0
0
Hello Eric,

I would like to cache my compiled scripts, but it seems from what I've read in the discussions that the compiled scripts are associated with a particular V8 runtime instance. Is that simply a V8 limitation?

Yes. A compiled script is bound to the V8 runtime that created it. There's no cross-runtime script representation that performs better than plain-text JavaScript.

Well, actually, there could be. V8 also supports precompilation, which generates reusable offline data that speeds up compilation, but (a) ClearScript currently doesn't support it, and (b) it would still require per-runtime compilation.

In that case I would have to create a managed V8 engine pool with each engine having an associated script cache (which obviously detracts from the benefits of the cache).

A couple of points: The main benefit of a compiled script is enhanced performance for repeated execution. If a script is likely to be run multiple times in multiple runtimes, it makes sense to compile and cache it for each runtime unless you're memory-constrained. Also, depending on your requirements, it might make sense to share runtimes across engine instances, which would greatly reduce memory usage and enable compiled script sharing at the cost of reduced concurrency.

Good luck!

New Post: Some basic compiled script questions

$
0
0
Good info, thanks. I'm implementing a runtime pool w/ caching as discussed.

New Post: Performance Improvements

$
0
0
Hi Libor,

Thanks for describing your application. It sounds like you have things well in hand, having profiled your application. We've been focusing mostly on ease of use, but we expect performance to occupy more of our cycles as we hear more real-world feedback like yours. In the meantime, you can see most of our current performance-oriented recommendations in this thread.

I've already tried to use V8ScriptEngineFlags.DisableGlobalMembers but it did wasn;t faster. In what cases should it help?

It helps in scenarios where script code frequently accesses the global object. Check out the ClearScriptBenchmarks application; Sunspider performs much better with that flag than without.

Cheers!

New Post: Replace Existing Event Handler

$
0
0
I can use the connect() function to add a Javascript event handler to an event but is there a way to remove an existing handler that's defined in my C# code so that my new Javascript handler replaces the existing C# handler?

Neil

(I'm using V8)

New Post: languages

$
0
0
it is possible to implement new scripting languages?

New Post: Calling VBScript function by dispatchId

$
0
0
Yes, our legacy application has a host implementation.
It use with clone method in case if there is access to script engine from thread that not is base thread.
The our site implementation maintain a list of the active scripts created from different threads.
Is there any plans to support clone option?

Thanks.

New Post: Replace Existing Event Handler

$
0
0
Hi Neil,

ClearScript does not provide this capability. Handlers for a given event generally aren't aware of each other, and the only way to do what you want in .NET is via reflection. With ClearScript you can of course allow the script to use reflection, or provide an alternate event connection API that does what you want behind the scenes.

However, some events are naturally "single-cast". That is, the semantics of the event are such that only one handler should ever be connected. If you're developing the event source, consider if that applies to the event in question. If it does, you can use custom event accessors to provide the required behavior in an elegant manner. This article demonstrates the technique.

Thanks for your question, and good luck!

New Post: languages

$
0
0
Hello furesoft!

If you're asking whether ClearScript provides a framework, or API, for developing script language interpreters, the answer is no. ClearScript is only a .NET interop layer for specific existing interpreters.

If on the other hand you've developed a script language interpreter and you'd like ClearScript to support it, then yes, this is certainly possible. For example, V8 support was added long after ClearScript was originally developed. However, doing so would require some modification of ClearScript source code, as ClearScript currently does not have a public plug-in API.

Cheers!

New Post: Calling VBScript function by dispatchId

$
0
0
Greetings!

We would definitely like to add support for cloning. Originally we thought it would "just work", but we've found some complications that we're still investigating. Unfortunately full support for cloning may require significant work, so we can't say when it'll be available.

Cheers!

New Post: Script timeout

New Post: Script timeout

$
0
0
You can use ScriptEngine.Interrupt() to abort script execution based on a timeout or any other criteria.
Viewing all 2297 articles
Browse latest View live




Latest Images