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

New Post: SignalR in ClearScript

$
0
0
I've not dug into the details but I don't believe SignalR needs the DOM for anything however the JavaScript SignalR client is based upon jQuery. In fact it is in the file name (jquery.signalR-2.1.1.js). And so when I try to execute jQuery followed by the SignalR script it fails because jQuery references the window object from the web API provided by the browser. I don't know what else jQuery needs but it seems to be the sticking point when it comes to SignalR without outside of a browser.

There is a Nodejs SignalR client script that does not require jQuery but it only supports the websockets transport and that doesn't work when the SignalR server is running on any Windows OS below Windows 8 or Server 2012. I actually got this part installed and working to the point that the server sent back a message saying it did not support websockets. After a little reasearch I learned about the Windows OS limitations with websockets.

I think I have found an alternate solution. I created my own .NET class that handles the client side SignalR interface. I then add this type to the V8 engine. The JavaScript then interfaces with SignalR through my .NET host environment. It was a little tricky getting all the async callbacks working but the answers you have for other discussion threads gave me what I needed to get it working. Its actually pretty cool once it gets working. Data starts pouring in very rapidly in my test environment - multiple updates every second - and it seems to be working well enough.

Right now I am just prototyping and figuring out how to solve some of these interface problems and marshalling data back and forth between ClearScript and Host. I'm nearly done with that and then I have to design the applications structure. A user will have mutiple instances of a v8Engine running at the same time and each one will have a separate SignalR connection with real-time (every half second) data updates. I'm curious to see how well it performs when it is loaded up with 10 scripts and a thousand SignalR data subscriptions. Is there anything you can think of that I should look out for?

New Post: User Edit of Script without reloading entirely

$
0
0
If I have a JavaScript function like the one below, I understand that I must call Engine.Execute(ScriptText) from the Host to both load and execute the code.
function foo() {
  console.log("some message");
}  
What happens if I call Engine.Execute(ScriptText) a second time on the same engine with a different string in console.log()? Is there a duplicate foo() function in my script?

The reason I am asking is that my app will include a bunch of host object loaded into an engine then one (or more) user written scripts. All are loaded into the same engine using Execute. The user then develops their script and presses a Run button to load and execute their piece of the puzzle. After executing, the user may want to edit the script and update the engine with the changes but without reloading the entire engine (don't want to reload all the host objects and other support scripts etc.). The executed (executing) script is very stateful and updates itself and its variables through callbacks and interfacing with other dynamic systems so I want to preserve state as much as possible.

How can I let the user edit a script that has been executed without reloading the entire script and host objects?

Created Unassigned: Double quote replaced by some other "junk" character [67]

$
0
0
Hi,
I am noticing v8Engine.Execute() fails with :
_
SyntaxError: Unexpected identifier
at Script Document xx..xxx.... -> -----------------------_
exception.

I see that normally one of the Double quotes ( " ) in the javascript text is replaced with some other characters and hence the syntax error. This seems to be intermittent issue as it doesnt happen all the time and not on all the machines the application runs.

Can you please have a look? I am using version 5.3.

thanks
Pandey

New Post: SignalR in ClearScript

$
0
0
Hi again,

And so when I try to execute jQuery followed by the SignalR script it fails because jQuery references the window object from the web API provided by the browser.

OK, well, you could start by pre-executing a simple script such as window = this to provide a window alias for the global object. Then run the jQuery/SignalR script again to see what else it needs. If it really does need the HTML DOM, you might be out of luck, but if it only needs a tiny subset, you might be able to accommodate it by providing a handful of simple mock objects.

I think I have found an alternate solution. I created my own .NET class that handles the client side SignalR interface. I then add this type to the V8 engine. The JavaScript then interfaces with SignalR through my .NET host environment.

That sounds even better!

I'm curious to see how well it performs when it is loaded up with 10 scripts and a thousand SignalR data subscriptions. Is there anything you can think of that I should look out for?

For all performance-sensitive applications that use ClearScript with V8, we recommend that you (a) use the latest version of ClearScript (currently 5.4.0), (b) disable the GlobalMembers feature by using V8ScriptEngineFlags.DisableGlobalMembers (unless you really need it), and (c) compensate for V8's lazy garbage collector by calling ScriptEngine.CollectGarbage() once in a while (e.g., periodically or when your application is idle).

Good luck!

New Post: User Edit of Script without reloading entirely

$
0
0
Hello!

What happens if I call Engine.Execute(ScriptText) a second time on the same engine with a different string in console.log()? Is there a duplicate foo() function in my script?

No. The first invocation creates a global property foo whose value is a function. The second simply assigns a new value to foo. The original function is eventually cleaned up by the garbage collector.

If on the other hand the second invocation changed the function name, then yes, you'd end up with two functions.

How can I let the user edit a script that has been executed without reloading the entire script and host objects?

You can re-execute scripts with or without modifications as many times as you'd like, but you need to understand the potential consequences.

Scripts can easily change or delete objects set up by the host or by other scripts. They can mess up the environment by replacing or deleting JavaScript built-ins and host objects (depending on how the host objects were set up).

The question is, what capabilities do the user scripts in your application require? Do they need to be able to install global functions and overwrite global data directly (as opposed to via some API that you provide for them)? Your description makes it sound as if they do, and if so, then there's really no way to restrict them.

If not, then there are things you can do. For example, when the Run button is clicked, instead of executing the user script directly, you could wrap it within an anonymous function that internally enables strict mode, thus preventing any damage to the global environment.

Good luck!

Commented Unassigned: Double quote replaced by some other "junk" character [67]

$
0
0
Hi,
I am noticing v8Engine.Execute() fails with :
_
SyntaxError: Unexpected identifier
at Script Document xx..xxx.... -> -----------------------_
exception.

I see that normally one of the Double quotes ( " ) in the javascript text is replaced with some other characters and hence the syntax error. This seems to be intermittent issue as it doesnt happen all the time and not on all the machines the application runs.

Can you please have a look? I am using version 5.3.

thanks
Pandey

Comments: Hi Pandey, First, we strongly recommend that you switch to ClearScript 5.4, which overhauled string usage within the V8 interface. Second, we need more information to reproduce this. Can you attach (the relevant portion of) a specific script that fails? Thanks!

New Post: User Edit of Script without reloading entirely

$
0
0
That is good to know.

The nature of the application is such that they are not likely to mess up the global environment but if they do, we can tell them not to do that. The app won't have wide distribution - it will only be used people who work with me and a few select customers.

I like the idea of wrapping in an anonymous function with strict mode but I'll need to see how that impacts the rest of the application and it's interaction with the Host. In general, I think if I just document the behaviour you described that should be sufficient. The user will have the option to reload a clean environment or keep editing the existing environment. I'll give them something like a Reload button that will recreate a new clean script engine and reload everthing including their latest user script. They can choose to Run their dirty script or Reload a clean script.

Thanks for your answer.

Commented Unassigned: Double quote replaced by some other "junk" character [67]

$
0
0
Hi,
I am noticing v8Engine.Execute() fails with :
_
SyntaxError: Unexpected identifier
at Script Document xx..xxx.... -> -----------------------_
exception.

I see that normally one of the Double quotes ( " ) in the javascript text is replaced with some other characters and hence the syntax error. This seems to be intermittent issue as it doesnt happen all the time and not on all the machines the application runs.

Can you please have a look? I am using version 5.3.

thanks
Pandey

Comments: Hi, Thanks for your response. Below is one example : The exception on execute i get is - _SyntaxError: Unexpected identifier at Script Document:320:69 -> "{"mimeĭtypť":"x-apŰlicštioŮ/ponHelp","ref":"n20","source":"ps"Ž}]}}}]}Ž, _ the actual code is : _{"mime-type":"x-application/ponHelp","ref":"n20","source":"ps"}}]}}}]}},_ In this situation, actually many characters are replaced with some other chars. On upgrading to version 5.4, I am afraid we cant do this soon as we are in middle of business season and this big-bang change wont be allowed. Is there anything else that I can take care to prevent this without update? Would highly appreciate any help on this. regards pandey PS: can you provide a link on what string changes are gone in V8?

Created Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!

Commented Unassigned: Double quote replaced by some other "junk" character [67]

$
0
0
Hi,
I am noticing v8Engine.Execute() fails with :
_
SyntaxError: Unexpected identifier
at Script Document xx..xxx.... -> -----------------------_
exception.

I see that normally one of the Double quotes ( " ) in the javascript text is replaced with some other characters and hence the syntax error. This seems to be intermittent issue as it doesnt happen all the time and not on all the machines the application runs.

Can you please have a look? I am using version 5.3.

thanks
Pandey

Comments: Hi Pandey, We've run a test that evaluates this expression 1,000,000 times in a loop with no errors: ``` JavaScript ({"mime-type":"x-application/ponHelp","ref":"n20","source":"ps"}) ``` On the other hand, the trailing brackets and braces in your snippet above suggest that in your case this is part of a much larger expression. Can you provide more context? Also, it's interesting that each clobbered character is the result of extending the original ASCII character to UTF-16 and then changing the upper byte from zero to one (e.g., 'a' 0x0061 -> 'š' 0x0161). That might suggest some kind of text encoding error. Where is the script coming from? How are you loading it into memory? Thanks!

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: Hello! By any chance, are you seeing this in a "cross-architecture" interop scenario? That is, is your test app 64-bit and your Office installation 32-bit (or vice-versa)? Thanks!

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: Hello! No, test 32-bit app and Office 32-bit Thanks!

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: OK, and when you say that the call takes too long, how long do you mean, approximately?

New Post: Locking Javascript objects

$
0
0
Hi!

Basically I work on a platform in C# that distributes content. Sometimes that content has custom actions that the platform needs to support (Like installing things in specific places, or providing some extra functionality etc)

I had the idea of using the ClearScript Engine (or something similar) to allow content to provide scripts for our platform to carry out, rather than us hard coding support in for specific content and releasing platform updates.

The general idea is:
  • Platform (C#)
  • Protected Services (C#) (Provides IO operations etc...)
  • Content Services (TS->JS)
  • Content Scripts (TS->JS)
The Platform would load content scripts with the content and then hand off the required services to those scripts.

The problem I forsee is that when a content script gets hold of a service object it also has the ability to rewrite the functions in that script and carry out malicious actions. The same could be said if one Content Script gets a hold of another.

My current idea was to proxy JS objects through C# between engines on the same runtime so that the prototypes of the JS objects would remain protected. One issue with this though is that I'd have to proxy the function calls too since I'd also need to protect any object passed between the two JS objects, and so on. It becomes recursive.

I was wondering if there is an easy way to protect the prototypes of JS Objects between Engines. So inside one engine the object is manipulable but if it was passed to another engine it becomes protected so that functions can't be rewritten maliciously.

Thanks!

Commented Unassigned: Double quote replaced by some other "junk" character [67]

$
0
0
Hi,
I am noticing v8Engine.Execute() fails with :
_
SyntaxError: Unexpected identifier
at Script Document xx..xxx.... -> -----------------------_
exception.

I see that normally one of the Double quotes ( " ) in the javascript text is replaced with some other characters and hence the syntax error. This seems to be intermittent issue as it doesnt happen all the time and not on all the machines the application runs.

Can you please have a look? I am using version 5.3.

thanks
Pandey

Comments: Oh, and the string changes in ClearScript 5.4 have to do with the way strings are passed around within the V8 interface. Instead of simple character pointers, the library now uses std::wstring references everywhere. This change was motivated by the need to support strings with embedded null characters.

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: About 1-2 minutes

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: Thanks. One more question: Are you using ClearScript 5.4, or an older version?

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: I'm using version 5.4. OS: Windows 8.1 (x64) Enterprise. Office 2013

Created Unassigned: Using ADODB recordsets [69]

$
0
0
HI!
How to properly add ADODB.Recordset? Is it possible?
```
static void Main(string[] args)
{
ADODB.Recordset _recordset = new ADODB.Recordset();
_recordset.Fields.Append("Id", ADODB.DataTypeEnum.adInteger);
_recordset.Fields.Append("Name", ADODB.DataTypeEnum.adVarChar, 20);
_recordset.Open(System.Reflection.Missing.Value
, System.Reflection.Missing.Value
, ADODB.CursorTypeEnum.adOpenStatic
, ADODB.LockTypeEnum.adLockOptimistic, 0);
_recordset.AddNew(Type.Missing, Type.Missing);
_recordset.Fields["Name"].Value = "Test";
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AllowReflection = true;
engine.AddHostObject("RS", _recordset);
engine.Execute("RS.MoveFirst"); // Ok
engine.Execute("RS.Fields(\"Name\").Value = \"Ok\""); // Error
}
```
Thanks!

Edited Issue: Using ADODB recordsets [69]

$
0
0
HI!
How to properly add ADODB.Recordset? Is it possible?
```
static void Main(string[] args)
{
ADODB.Recordset _recordset = new ADODB.Recordset();
_recordset.Fields.Append("Id", ADODB.DataTypeEnum.adInteger);
_recordset.Fields.Append("Name", ADODB.DataTypeEnum.adVarChar, 20);
_recordset.Open(System.Reflection.Missing.Value
, System.Reflection.Missing.Value
, ADODB.CursorTypeEnum.adOpenStatic
, ADODB.LockTypeEnum.adLockOptimistic, 0);
_recordset.AddNew(Type.Missing, Type.Missing);
_recordset.Fields["Name"].Value = "Test";
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AllowReflection = true;
engine.AddHostObject("RS", _recordset);
engine.Execute("RS.MoveFirst"); // Ok
engine.Execute("RS.Fields(\"Name\").Value = \"Ok\""); // Error
}
```
Thanks!
Viewing all 2297 articles
Browse latest View live




Latest Images