Are you the publisher? Claim or contact us about this channel


Embed this content in your HTML

Search

Report adult content:

click to rate:

Account: (login)

More Channels


Showcase


Channel Catalog


Channel Description:

ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.

older | 1 | .... | 62 | 63 | (Page 64) | 65 | 66 | .... | 115 | newer

    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!
    Comments: This appears to be a bug in ClearScript, possibly related to COM interface inheritance. Thanks for reporting it!

    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, you noticed it right. The snippet I provided is a part of big javascript code. < I can't put the complete code here :( > Also, it is interesting to know that not all users have this problem. ( We ship the same file for every one ). This is what I do to load the js file: ``` string jsContents = File.ReadAllText(jsFilePath); //jsFilePath is javascript file name. var _v8Engine = new V8ScriptEngine(V8ScriptEngineFlags.None); _v8Engine.Execute(jsContents); ``` The last line throws exception.

    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!
    Comments: Clarification: Once this bug is fixed (in the next ClearScript point release), the correct VBScript syntax for setting the field will be: ``` VBScript RS.Fields.Item("Name").Value = "Ok" ``` Note that that the `Item` property is a COM interop artifact. VBScript and JScript can also interface _directly_ with COM objects (without ClearScript's involvement), in which case the above syntax might work.

    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: This looks like a COM interop bug - an interesting one. When you call `AddHostObject()`, ClearScript asks for the object's imported type. At this point the CLR fails to detect that the relevant interop assembly is already loaded. Then it fails to look it up and load it manually. Finally, as a last resort, the CLR generates the interop assembly _on the fly_. For Excel's gigantic type library, this is the step that can take minutes. We'll have a workaround in the next ClearScript release. Thanks for reporting this issue!

    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!

    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, any thought on this issue please?

    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 now run several tests, each evaluating the expression above thousands of times, on both ClearScript 5.4.0 and 5.3.11, without any issues. Inspecting the code path between `ScriptEngine.Execute()` and V8 didn't reveal any obvious string handling issues. With no reproducible case, no representative test script, and no ability to debug the failure where it occurred, all we have are wild guesses. We can't rule out a bug in ClearScript, but at this point it could be in V8, the host, or some other library you're using. Some questions that might yield a clue (or not): 1. Do the users who have this problem see it all the time? Or is it intermittent? 1. Are affected users seeing any other issues that might suggest memory corruption? 1. Does the host execute the script once, or many times within a given engine instance? 1. What is the text encoding of the file from which you're loading the script? 1. Does the script contain any non-ASCII characters? 1. Do affected users have anything in common in their system setup (e.g., regional settings)? 1. Does your application use any other external native-code libraries? 1. Can you confirm that the script was undamaged when you passed it into ClearScript? Good luck!

    0 0

    Hello!

    In general we don't recommend passing script objects from one engine to another, even if those engines are in the same V8 runtime. ClearScript has some support for this, and even some unit tests, but it doesn't leverage V8's one-shared-heap-per-runtime architecture. That is, an engine may hold a foreign script object, but its access to that object will always be proxied through the managed ClearScript layer, and that involves a lot of overhead. Note that this doesn't apply to host objects, which you can expose in multiple engines without additional overhead.

    As for securing your script platform against untrusted scripts, there are things you can do, especially if you're using V8. Some suggestions:
    1. Instead of executing untrusted scripts directly within the global context, consider wrapping them within anonymous functions that internally enable strict mode.
    2. Use Object.defineProperty() and Object.freeze() to harden your service objects.
    Cheers!

    0 0

    Hi there,

    I just downloaded ClearScript-5.4.0.zip directly from CodePlex and tried to build it in order to run it with V8 support. However, I couldn't get past the point of building 32-bit version of V8. I've proceeded to analyze where it is breaking exactly, and it appears it is happening when this line is executed in V8Update.cmd:

    ```
    msbuild /p:Configuration=%mode% /p:Platform=Win32 /t:v8 tools\gyp\v8.sln >build.log
    ```

    Build log it-self revealed that I have some files missing that affect the build the process. see below:

    ```
    ...
    ClCompile:
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\CL.exe /c /I..\..\src /Zi /nologo /W3 /WX /O2 /Ob2 /Oi /Oy- /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D V8_TARGET_ARCH_IA32 /D WIN32 /D V8_DEPRECATION_WARNINGS /D V8_USE_DEFAULT_PLATFORM /D BUILDING_V8_SHARED /D V8_SHARED /D _UNICODE /D UNICODE /GF /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /GR- /Fo"..\..\build\Release\obj\v8_nosnapshot.ia32\\" /Fd"..\..\build\Release\obj\v8_nosnapshot.ia32\vc110.pdb" /Gd /TP /wd4355 /wd4800 /analyze- /errorReport:queue /MP ..\..\build\Release\obj\global_intermediate\libraries.cc "..\..\build\Release\obj\global_intermediate\experimental-libraries.cc" "..\..\build\Release\obj\global_intermediate\trig-table.cc" "..\..\src\snapshot-empty.cc"
    libraries.cc
    experimental-libraries.cc
    trig-table.cc
    snapshot-empty.cc
    c1xx : fatal error C1083: Cannot open source file: '..\..\build\Release\obj\global_intermediate\libraries.cc': No such file or directory [c:\ClearScript\ClearScript\V8\V8\build\v8-ia32\tools\gyp\v8_nosnapshot.ia32.vcxproj]
    c1xx : fatal error C1083: Cannot open source file: '..\..\build\Release\obj\global_intermediate\experimental-libraries.cc': No such file or directory [c:\ClearScript\ClearScript\V8\V8\build\v8-ia32\tools\gyp\v8_nosnapshot.ia32.vcxproj]
    c1xx : fatal error C1083: Cannot open source file: '..\..\build\Release\obj\global_intermediate\trig-table.cc': No such file or directory [c:\ClearScript\ClearScript\V8\V8\build\v8-ia32\tools\gyp\v8_nosnapshot.ia32.vcxproj]
    Done Building Project "c:\ClearScript\ClearScript\V8\V8\build\v8-ia32\tools\gyp\v8_nosnapshot.ia32.vcxproj" (default targets) -- FAILED.
    Done Building Project "c:\ClearScript\ClearScript\V8\V8\build\v8-ia32\tools\gyp\v8_nosnapshot.ia32.vcxproj.metaproj" (default targets) -- FAILED.
    Done Building Project "c:\ClearScript\ClearScript\V8\V8\build\v8-ia32\tools\gyp\v8.vcxproj.metaproj" (default targets) -- FAILED.
    Done Building Project "c:\ClearScript\ClearScript\V8\V8\build\v8-ia32\tools\gyp\v8.sln" (v8 target(s)) -- FAILED.
    ...
    ```
    After inspecting above error paths in the explorer, I can confirm that above files are indeed missing, so I'm not 100% sure what could've led to it. Is there any help you could provide on this build issue?

    Additional Info:
    * Windows 7 Enterprise with SP1 installed, 64-bit.
    * Visual Studio(s) installed: 2010/2012/2013
    * ClearScript built by using Developer Command Prompt for VS2012
    * Downloaded ClearScript API 5.4.0 as zip from [https://clearscript.codeplex.com/releases/view/135637](https://clearscript.codeplex.com/releases/view/135637)
    * Build.log is attached for your reference
    Comments: I was able to build V8 by the following command in regular Command Prompt: ``` C:\ClearScript> "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" C:\ClearScript> V8Update.cmd Release Latest ```

    0 0

    is there any build in functions or classes in V8?

    0 0

    Hi furesoft,

    You can see a list of JavaScript built-ins here.

    Cheers!

    0 0
  • 02/08/15--19:01: Updated Wiki: Announcements
  • 2/8/2015: Version 5.4.1 released.

    View the release notes and download the source code here. Note: This release removes support for Visual Studio 2012 and updates the procedure for downloading and building V8. See the ClearScript ReadMe for the latest information.

    10/22/2014: ClearScript 5.4 released.

    View the release notes and download the source code here.

    1/16/2014: Version 5.3.11 released.

    View the release notes and download the source code here.

    11/28/2013: Version 5.3.10 released.

    View the release notes and download the source code here.

    10/29/2013: Version 5.3.9 released.

    View the release notes and download the source code here.

    10/14/2013: Version 5.3.8 released.

    View the release notes and download the source code here.

    8/22/2013: Version 5.3.7 released.

    View the release notes and download the source code here.

    8/14/2013: Version 5.3.6 released.

    View the release notes and download the source code here.

    8/2/2013: Version 5.3.5 released.

    View the release notes and download the source code here.

    7/10/2013: Version 5.3.4 released.

    View the release notes and download the source code here.

    7/2/2013: Version 5.3.3 released.

    View the release notes and download the source code here.

    6/6/2013: Version 5.3.2 released.

    View the release notes and download the source code here. Due to issues with several recent V8 trunk releases (build failures, breaking API changes, etc.), and because more breaking changes are coming soon, this release modifies V8Update so that it fetches a tested, known-good V8 revision by default. See the ClearScript ReadMe for more information.

    5/31/2013: Version 5.3.1 released.

    View the release notes and download the source code here.

    5/21/2013: ClearScript 5.3 released.

    View the release notes and download the source code here.

    5/15/2013: Version 5.2.2 released.

    View the release notes and download the source code here. This release addresses the build issue reported yesterday and can be used with the latest V8 version. Here's how to update your copy of V8:
    C:\ClearScript> set V8REV=
    C:\ClearScript> V8Update
    

    5/14/2013: ClearScript build failure due to API deprecation in V8 3.19.1.

    We are aware of a ClearScript build issue with the latest version of V8. Until this issue is resolved we recommend that you explicitly use V8 3.19.0:
    C:\ClearScript> set V8REV=14604
    C:\ClearScript> V8Update
    

    5/2/2013: Version 5.2.1 released.

    View the release notes and download the source code here.

    4/18/2013: V8Update failure resolved by V8 3.18.1.

    The V8Update issue reported yesterday has been fixed by a new version of V8 released today. Here's how to update to the latest V8 version:
    C:\ClearScript> set V8REV=
    C:\ClearScript> V8Update
    

    4/17/2013: V8Update failure with V8 3.18.0.

    We are aware of a V8Update issue with the latest version of V8. Until this issue is resolved we recommend that you explicitly use V8 3.17.16:
    C:\ClearScript> set V8REV=14138
    C:\ClearScript> V8Update
    

    3/27/2013: ClearScript 5.2 released.

    View the release notes and download the source code here.

    3/8/2013: Version 5.1.3 released.

    View the release notes and download the source code here.

    3/4/2013: V8Update failure resolved by V8 3.17.7.

    The V8Update issue reported earlier has been fixed by a new version of V8 released today. Here's how to update to the latest V8 version:
    C:\ClearScript> set V8REV=
    C:\ClearScript> V8Update
    

    3/4/2013: V8Update failure with V8 3.17.6.

    We are aware of a V8Update issue with the latest version of V8. The issue affects the "Building 64-bit V8" step. The V8 team appears to have already submitted a fix, but the fix has not yet been merged into the trunk. In the meantime, we recommend that you explicitly use V8 3.17.5:
    C:\ClearScript> set V8REV=13745
    C:\ClearScript> V8Update
    

    0 0

    5.4.1
    • Fixed several issues affecting GlobalMembers on V8.
    • Implemented a V8 debug agent to compensate for removed V8 API.
    • V8Update now fetches V8 source and dependencies from Git repositories.
    • Fixed V8 assembly unloading and patched V8 to tolerate redundant initialization (Issue #60).
    • Added ScriptEngine.EnableAutoHostVariables.
    • Fixed by-reference arguments to VBScript functions (Issue #58).
    • Removed support for Visual Studio 2012 (V8 build now requires at least Visual Studio 2013).
    • Added explicit loading of primary interop assemblies to fix Issue #68.
    • Added host exception marshaling for V8.
    • Fixed V8ScriptEngine crash when script code calls theHostObject constructor.
    • Fixed host item caching for host variables.
    • Added non-generic overloads of newArr() andfunc() to HostFunctions.
    • Added ScriptEngine.Current.
    • HostFunctions instances can now be exposed in multiple script engines.
    • Added a GetDynamicMemberNames() override toMetaScriptItem (Issue #64).
    • Fixed indexed property binding ambiguity for inherited interfaces (Issue #69).
    • Added tests for bug fixes and new APIs.
    • Tested with V8 3.30.33.16.

    5.4.0
    • Added COM object projection (Issue #38):
      • New ScriptEngine methods: AddCOMObject() and AddCOMType().
      • New ExtendedHostFunctions methods: newComObj() and comType().
    • Improved performance and memory usage:
      • Host methods, events, and const/readonly fields are now cached as direct V8 object properties.
      • Added shared bind cache for improved performance and enhanced binder leak mitigation.
      • Made V8ScriptEngine.CollectGarbage() much more aggressive.
      • Switched to weak context/isolate bindings for V8 script objects and compiled scripts, fixingIssue #44.
      • Bypassed reflection for Windows script item property and method access, fixingIssue #47.
      • Added explicit disposal of cached V8 objects to fix Issue #48.
    • Enhanced support for legacy scripts:
      • Added null, decimal, and array marshaling options to WindowsScriptEngine.
      • Added ScriptEngine.UseReflectionBindFallback.
      • VBScript's For Each ... Next and JScript's Enumerator now operate on IEnumerable instances.
    • Other enhancements:
      • Added optional heap size monitoring to V8ScriptEngine andV8Runtime (experimental).
      • Added HostFunctions.tryCatch().
      • Added ScriptEngine.Invoke() and V8ScriptEngine.Execute(V8Script).
      • Added ScriptEngine.DisableTypeRestriction.
      • Enhanced error reporting for V8 assembly load failures (Issue #39).
      • V8Update now supports branched V8 revisions.
    • Miscellaneous fixes:
      • Added a V8 array buffer allocator, fixing Issue #46.
      • Overhauled ClearScriptV8 string usage to fix Issue #42 and improve performance.
      • Hardened ClearScriptV8 smart pointers.
      • Changed ActiveScript sites to return the current thread culture.
      • Added defensive code to make V8-related API objects resurrection-safe, fixingIssue #51.
      • Fixed exception when using WindowsScriptEngineFlags.EnableDebugging with no suitable script debugger installed (Issue #36).
    • Updates for breaking V8 API changes.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 3.26.31.15.

    0 0

    5.4.1
    • Fixed several issues affecting GlobalMembers on V8.
    • Implemented a V8 debug agent to compensate for removed V8 API.
    • V8Update now fetches V8 source and dependencies from Git repositories.
    • Fixed V8 assembly unloading and patched V8 to tolerate redundant initialization (Issue #60).
    • Added ScriptEngine.EnableAutoHostVariables.
    • Fixed by-reference arguments to VBScript functions (Issue #58).
    • Removed support for Visual Studio 2012 (V8 build now requires at least Visual Studio 2013).
    • Added explicit loading of primary interop assemblies to fix Issue #68.
    • Added host exception marshaling for V8.
    • Fixed V8ScriptEngine crash when script code calls the HostObject constructor.
    • Fixed host item caching for host variables.
    • Added non-generic overloads of newArr() and func() to HostFunctions.
    • Added ScriptEngine.Current.
    • HostFunctions instances can now be exposed in multiple script engines.
    • Added a GetDynamicMemberNames() override to MetaScriptItem (Issue #64).
    • Fixed indexed property binding ambiguity for inherited interfaces (Issue #69).
    • Added tests for bug fixes and new APIs.
    • Tested with V8 3.30.33.16.

    5.4.0
    • Added COM object projection (Issue #38):
      • New ScriptEngine methods: AddCOMObject() and AddCOMType().
      • New ExtendedHostFunctions methods: newComObj() and comType().
    • Improved performance and memory usage:
      • Host methods, events, and const/readonly fields are now cached as direct V8 object properties.
      • Added shared bind cache for improved performance and enhanced binder leak mitigation.
      • Made V8ScriptEngine.CollectGarbage() much more aggressive.
      • Switched to weak context/isolate bindings for V8 script objects and compiled scripts, fixing Issue #44.
      • Bypassed reflection for Windows script item property and method access, fixing Issue #47.
      • Added explicit disposal of cached V8 objects to fix Issue #48.
    • Enhanced support for legacy scripts:
      • Added null, decimal, and array marshaling options to WindowsScriptEngine.
      • Added ScriptEngine.UseReflectionBindFallback.
      • VBScript's For Each ... Next and JScript's Enumerator now operate on IEnumerable instances.
    • Other enhancements:
      • Added optional heap size monitoring to V8ScriptEngine and V8Runtime (experimental).
      • Added HostFunctions.tryCatch().
      • Added ScriptEngine.Invoke() and V8ScriptEngine.Execute(V8Script).
      • Added ScriptEngine.DisableTypeRestriction.
      • Enhanced error reporting for V8 assembly load failures (Issue #39).
      • V8Update now supports branched V8 revisions.
    • Miscellaneous fixes:
      • Added a V8 array buffer allocator, fixing Issue #46.
      • Overhauled ClearScriptV8 string usage to fix Issue #42 and improve performance.
      • Hardened ClearScriptV8 smart pointers.
      • Changed ActiveScript sites to return the current thread culture.
      • Added defensive code to make V8-related API objects resurrection-safe, fixing Issue #51.
      • Fixed exception when using WindowsScriptEngineFlags.EnableDebugging with no suitable script debugger installed (Issue #36).
    • Updates for breaking V8 API changes.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 3.26.31.15.

    0 0
  • 02/08/15--19:11: Updated Wiki: Documentation
  • Documentation

    To learn more about ClearScript:
    • Check out the ClearScript tutorial: [Word], [PDF].
    • Browse the ClearScript Library Reference: [Cannot resolve file macro, invalid file name or id.]. Save this file before opening it. If you get a security warning when you open it, uncheck "Always ask before opening this file".
    • View the latest information in the ClearScript ReadMe.
    • Take a look at our latest Announcements.

    0 0
  • 02/08/15--19:12: Updated Wiki: Documentation
  • Documentation

    To learn more about ClearScript:
    • Check out the ClearScript tutorial: [Word], [PDF].
    • Browse the ClearScript Library Reference: [Reference.chm]. Save this file before opening it. If you get a security warning when you open it, uncheck "Always ask before opening this file".
    • View the latest information in the ClearScript ReadMe.
    • Take a look at our latest Announcements.

    0 0
  • 02/08/15--19:14: Updated Wiki: Home
  • InfoIcon.jpgVersion 5.4.1 released. More...

    Description

    ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.

    Features

    • Simple usage; create a script engine, add your objects and/or types, run scripts
    • Support for several script engines: Google's V8, Microsoft's JScript and VBScript
    • Exposed resources require no modification, decoration, or special coding of any kind
    • Scripts get simple access to most of the features of exposed objects and types:
      • Methods, properties, fields, events
      • (Objects) Indexers, extension methods, conversion operators, explicitly implemented interfaces
      • (Types) Constructors, nested types
    • Full support for generic types and methods, including C#-like type inference and explicit type arguments
    • Scripts can invoke methods with output parameters, optional parameters, and parameter arrays
    • Script delegates enable callbacks into script code
    • Support for exposing all the types defined in one or more assemblies in one step
    • Optional support for importing types and assemblies from script code
    • The host can invoke script functions and access script objects directly
    • Full support for script debugging

    Examples

    using System;
    using Microsoft.ClearScript;
    using Microsoft.ClearScript.V8;
    
    // create a script engineusing (var engine = new V8ScriptEngine())
    {
        // expose a host type
        engine.AddHostType("Console", typeof(Console));
        engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)");
    
        // expose a host object
        engine.AddHostObject("random", new Random());
        engine.Execute("Console.WriteLine(random.NextDouble())");
    
        // expose entire assemblies
        engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core"));
        engine.Execute("Console.WriteLine(lib.System.DateTime.Now)");
    
        // create a host object from script
        engine.Execute(@"
            birthday = new lib.System.DateTime(2007, 5, 22);
            Console.WriteLine(birthday.ToLongDateString());
        ");
    
        // use a generic class from script
        engine.Execute(@"
            Dictionary = lib.System.Collections.Generic.Dictionary;
            dict = new Dictionary(lib.System.String, lib.System.Int32);
            dict.Add('foo', 123);
        ");
    
        // call a host method with an output parameter
        engine.AddHostObject("host", new HostFunctions());
        engine.Execute(@"
            intVar = host.newVar(lib.System.Int32);
            found = dict.TryGetValue('foo', intVar.out);
            Console.WriteLine('{0} {1}', found, intVar);
        ");
    
        // create and populate a host array
        engine.Execute(@"
            numbers = host.newArr(lib.System.Int32, 20);
            for (var i = 0; i < numbers.Length; i++) { numbers[i] = i; }
            Console.WriteLine(lib.System.String.Join(', ', numbers));
        ");
    
        // create a script delegate
        engine.Execute(@"
            Filter = lib.System.Func(lib.System.Int32, lib.System.Boolean);
            oddFilter = new Filter(function(value) {
                return (value & 1) ? true : false;
            });
        ");
    
        // use LINQ from script
        engine.Execute(@"
            oddNumbers = numbers.Where(oddFilter);
            Console.WriteLine(lib.System.String.Join(', ', oddNumbers));
        ");
    
        // use a dynamic host object
        engine.Execute(@"
            expando = new lib.System.Dynamic.ExpandoObject();
            expando.foo = 123;
            expando.bar = 'qux';
            delete expando.foo;
        ");
    
        // call a script function
        engine.Execute("function print(x) { Console.WriteLine(x); }");
        engine.Script.print(DateTime.Now.DayOfWeek);
    
        // examine a script object
        engine.Execute("person = { name: 'Fred', age: 5 }");
        Console.WriteLine(engine.Script.person.name);
    }

    0 0

    Whenever I try to run a test under xUnit using the built in Visual Studio Test Runner (with xUnit plugin) containing the V8Runtime, I get either an AccessViolation or an SEHException. The strange thing is the exception does not occur if I debug the test (with/without break points).

    Environment: Visual 2013 Update 4 Test Runner, xUnit 1.9.2.1705, code to recreate:

    [Fact]
    public void TestAccessException() {
    var runtime = new V8Runtime("Test Context");
    }

    Stack trace:

    System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
    ---- System.Runtime.InteropServices.SEHException : External component has thrown an exception.
    Result StackTrace:
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
    at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
    at System.Activator.CreateInstance(Type type, Object[] args)
    at Microsoft.ClearScript.V8.V8Proxy.CreateImpl[T](Object[] args) in c:\dev\ClearScript\ClearScript\V8\V8Proxy.cs:line 93
    at Microsoft.ClearScript.V8.V8IsolateProxy.Create(String name, V8RuntimeConstraints constraints, Boolean enableDebugging, Int32 debugPort) in c:\dev\ClearScript\ClearScript\V8\V8IsolateProxy.cs:line 70
    at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort) in c:\dev\ClearScript\ClearScript\V8\V8Runtime.cs:line 204
    at Microsoft.ClearScript.V8.V8Runtime..ctor(String name) in c:\dev\ClearScript\ClearScript\V8\V8Runtime.cs:line 98
    at FlowAPI.Scripting.JavascriptRunner..ctor() in c:\dev\FlowAPI\FlowAPI.Scripting\JavascriptRunner.cs:line 20
    at FlowAPI.Server.Tests.Scripting.TestScripting.TestV8ScriptingMultiCall() in c:\dev\FlowAPI\FlowAPI.Server.Tests\Scripting\TestScripting.cs:line 20
    ----- Inner Stack Trace -----
    at V8Isolate.Create(StdString* , V8IsolateConstraints* , Boolean , Int32 )
    at Microsoft.ClearScript.V8.V8IsolateProxyImpl..ctor(String gcName, V8RuntimeConstraints gcConstraints, Boolean enableDebugging, Int32 debugPort) in c:\dev\clearscript\clearscript\v8\clearscriptv8\v8isolateproxyimpl.cpp:line 86



    0 0

    Whenever I try to run a test under xUnit using the built in Visual Studio Test Runner (with xUnit plugin) containing the V8Runtime, I get either an AccessViolation or an SEHException. The strange thing is the exception does not occur if I debug the test (with/without break points).

    Environment: Visual 2013 Update 4 Test Runner, xUnit 1.9.2.1705, code to recreate:

    [Fact]
    public void TestAccessException() {
    var runtime = new V8Runtime("Test Context");
    }

    Stack trace:

    System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
    ---- System.Runtime.InteropServices.SEHException : External component has thrown an exception.
    Result StackTrace:
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
    at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
    at System.Activator.CreateInstance(Type type, Object[] args)
    at Microsoft.ClearScript.V8.V8Proxy.CreateImpl[T](Object[] args) in c:\dev\ClearScript\ClearScript\V8\V8Proxy.cs:line 93
    at Microsoft.ClearScript.V8.V8IsolateProxy.Create(String name, V8RuntimeConstraints constraints, Boolean enableDebugging, Int32 debugPort) in c:\dev\ClearScript\ClearScript\V8\V8IsolateProxy.cs:line 70
    at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort) in c:\dev\ClearScript\ClearScript\V8\V8Runtime.cs:line 204
    at Microsoft.ClearScript.V8.V8Runtime..ctor(String name) in c:\dev\ClearScript\ClearScript\V8\V8Runtime.cs:line 98
    at FlowAPI.Scripting.JavascriptRunner..ctor() in c:\dev\FlowAPI\FlowAPI.Scripting\JavascriptRunner.cs:line 20
    at FlowAPI.Server.Tests.Scripting.TestScripting.TestV8ScriptingMultiCall() in c:\dev\FlowAPI\FlowAPI.Server.Tests\Scripting\TestScripting.cs:line 20
    ----- Inner Stack Trace -----
    at V8Isolate.Create(StdString* , V8IsolateConstraints* , Boolean , Int32 )
    at Microsoft.ClearScript.V8.V8IsolateProxyImpl..ctor(String gcName, V8RuntimeConstraints gcConstraints, Boolean enableDebugging, Int32 debugPort) in c:\dev\clearscript\clearscript\v8\clearscriptv8\v8isolateproxyimpl.cpp:line 86


    Comments: Fixed in [Version 5.4.1](https://clearscript.codeplex.com/SourceControl/changeset/c2200cbd6b77300484927906517035caef3ae323).

    0 0


    Great Library, really helpful!

    I ran into one situation where we have some existing VBScripts, the have subroutines and functions that take ByRef scalar types such as ints, double and the values are being changed in the function.


    Here is the code I tested:

    VBScriptEngine scriptEngine = new VBScriptEngine(WindowsScriptEngineFlags.EnableDebugging);
    double byRefValue = 10.0;
    scriptEngine.Execute(@"sub TestSub(ByRef MyParam) : MyParam=20.0 : end sub");
    scriptEngine.Script.TestSub(ref byRefValue);


    Basically what I was trying to accomplish , was the double values should end up being set to 20.0 , but it always remains at 10.0

    I tried changing the double to an object and dynamic and it didn't make a difference.

    Any thoughts on how to support this scenario.

    Thanks!


older | 1 | .... | 62 | 63 | (Page 64) | 65 | 66 | .... | 115 | newer