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 | .... | 99 | 100 | (Page 101) | 102 | 103 | .... | 115 | newer

    0 0

    Version 5.4.6: Expanded canonical reference support to all equatable value types; fixed a bug preventing assembly-qualified type names from being used with ScriptEngine.AddHostType(); fixed double execution of exception-throwing code via C# dynamic (Issue #105); added IScriptEngineException.ExecutionStarted; fixed cross-engine double execution of exception-throwing code (Issue #108); tweaked V8 debug protocol implementation to support non-Eclipse debuggers; added tests for bug fixes and new APIs. Tested with V8 5.1.281.50.

    0 0

    5.4.6
    • Expanded canonical reference support to all equatable value types.
    • Fixed host-side and cross-engine assignment of VBScript class object properties (Issue #104).
    • Fixed a bug preventing assembly-qualified type names from being used with ScriptEngine.AddHostType().
    • Fixed double execution of exception-throwing code via C# dynamic (Issue #105).
    • Added IScriptEngineException.ExecutionStarted.
    • Fixed memory leak with shared V8 runtimes (Issue #107).
    • Fixed cross-engine double execution of exception-throwing code (Issue #108).
    • Tweaked V8 debug protocol implementation to support non-Eclipse debuggers.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 5.1.281.50.

    5.4.5
    • Breaking Change: Added strongly-typed indexing support for IList<T>. Because IList<T> takes precedence over IList, array and list elements retrieved by index are now correctly type-restricted. Use the new propertyScriptEngine.DisableListIndexTypeRestriction to restore the previous behavior, orScriptEngine.DisableTypeRestriction to control type restriction globally.
    • Added V8ScriptEngine.SuppressExtensionMethodEnumeration (Issue #101).
    • Fixed native property hiding on V8 (Issue #98).
    • Fixed host method clobbering on V8.
    • Reduced V8 stack overflow detection false positives.
    • Added HostItemFlags.DirectAccess.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 4.9.385.30.

    5.4.4
    • Added fast data transfer between host arrays and JavaScript typed arrays (and other ArrayBuffer views) (Issue #83).
    • IEnumerable instances now supportES6 iteration andfor...of when exposed inV8ScriptEngine.
    • Added fully dynamic treatment for exposed IDispatchEx instances (Issue #96).
    • Fixed host member enumeration and deletion on JScript with Standards Mode (Issue #94).
    • Improved numeric argument conversion and matching (Issue #95).
    • Fixed nested termination behavior on V8.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 4.7.80.25.

    5.4.3
    • Added support for Visual Studio 2015.
    • Changed V8Update to use installed Python 2.x.
    • Fixed hangs in V8 proxy finalizers during script execution (Issue #86).
    • Fixed V8 weak handle callback context leak (Issue #90).
    • Fixed dynamic method invocation with value-typed arguments (Issue #89).
    • Improved V8ScriptEngine.Interrupt() latency and reliability.
    • Added tests for bug fixes.
    • Tested with V8 4.4.63.29.

    5.4.2.1
    • Fixed unnecessary assembly table construction (Issue #84).

    5.4.2
    • Updated ClearScriptBenchmarks to use SunSpider 1.0.2.
    • Host methods and delegates in V8ScriptEngine now supporttoFunction(), which creates a native JavaScript function wrapper.
    • Fixed syntax error reporting in nested WindowsScriptEngine invocations.
    • Added defensive code to tolerate IProcessDebugManager::AddApplication() failure (Issue #76).
    • Added ScriptEngine.AddHostType() overloads that derive the script item name from the type name.
    • Implemented host item data sharing and other optimizations, boosting memory efficiency in many scenarios.
    • Added default ScriptAccess settings at the type, assembly, and engine levels.
    • Enhanced support for default properties, fixing Issue #74.
    • Added IHostWindow and WindowsScriptEngine.HostWindow (Issue #73).
    • V8RuntimeConstraints limits are now specified inMiB. For compatibility with hosts that predate an inadvertent breaking change in Version 5.4.1, values greater than 1048576 (1TiB) are still interpreted as bytes.
    • Fixed V8 debug agent in ASP.NET and eliminated excessive thread usage (Issue #75).
    • Added ScriptMemberFlags.WrapNullResult, ScriptEngine.EnableNullResultWrapping, and HostFunctions.isNull() (Issue #72).
    • Added enforcement of restricted access to non-public accessors of public properties (Issue #71).
    • (Andrey Taritsyn) Switched assembly targets to .NET 4 Client Profile.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 4.2.77.18.

    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.6
    • Expanded canonical reference support to all equatable value types.
    • Fixed host-side and cross-engine assignment of VBScript class object properties (Issue #104).
    • Fixed a bug preventing assembly-qualified type names from being used with ScriptEngine.AddHostType().
    • Fixed double execution of exception-throwing code via C# dynamic (Issue #105).
    • Added IScriptEngineException.ExecutionStarted.
    • Fixed memory leak with shared V8 runtimes (Issue #107).
    • Fixed cross-engine double execution of exception-throwing code (Issue #108).
    • Tweaked V8 debug protocol implementation to support non-Eclipse debuggers.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 5.1.281.50.

    5.4.5
    • Breaking Change: Added strongly-typed indexing support for IList<T>. Because IList<T> takes precedence over IList, array and list elements retrieved by index are now correctly type-restricted. Use the new property ScriptEngine.DisableListIndexTypeRestriction to restore the previous behavior, or ScriptEngine.DisableTypeRestriction to control type restriction globally.
    • Added V8ScriptEngine.SuppressExtensionMethodEnumeration (Issue #101).
    • Fixed native property hiding on V8 (Issue #98).
    • Fixed host method clobbering on V8.
    • Reduced V8 stack overflow detection false positives.
    • Added HostItemFlags.DirectAccess.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 4.9.385.30.

    5.4.4
    • Added fast data transfer between host arrays and JavaScript typed arrays (and other ArrayBuffer views) (Issue #83).
    • IEnumerable instances now support ES6 iteration and for...of when exposed in V8ScriptEngine.
    • Added fully dynamic treatment for exposed IDispatchEx instances (Issue #96).
    • Fixed host member enumeration and deletion on JScript with Standards Mode (Issue #94).
    • Improved numeric argument conversion and matching (Issue #95).
    • Fixed nested termination behavior on V8.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 4.7.80.25.

    5.4.3
    • Added support for Visual Studio 2015.
    • Changed V8Update to use installed Python 2.x.
    • Fixed hangs in V8 proxy finalizers during script execution (Issue #86).
    • Fixed V8 weak handle callback context leak (Issue #90).
    • Fixed dynamic method invocation with value-typed arguments (Issue #89).
    • Improved V8ScriptEngine.Interrupt() latency and reliability.
    • Added tests for bug fixes.
    • Tested with V8 4.4.63.29.

    5.4.2.1
    • Fixed unnecessary assembly table construction (Issue #84).

    5.4.2
    • Updated ClearScriptBenchmarks to use SunSpider 1.0.2.
    • Host methods and delegates in V8ScriptEngine now support toFunction(), which creates a native JavaScript function wrapper.
    • Fixed syntax error reporting in nested WindowsScriptEngine invocations.
    • Added defensive code to tolerate IProcessDebugManager::AddApplication() failure (Issue #76).
    • Added ScriptEngine.AddHostType() overloads that derive the script item name from the type name.
    • Implemented host item data sharing and other optimizations, boosting memory efficiency in many scenarios.
    • Added default ScriptAccess settings at the type, assembly, and engine levels.
    • Enhanced support for default properties, fixing Issue #74.
    • Added IHostWindow and WindowsScriptEngine.HostWindow (Issue #73).
    • V8RuntimeConstraints limits are now specified in MiB. For compatibility with hosts that predate an inadvertent breaking change in Version 5.4.1, values greater than 1048576 (1 TiB) are still interpreted as bytes.
    • Fixed V8 debug agent in ASP.NET and eliminated excessive thread usage (Issue #75).
    • Added ScriptMemberFlags.WrapNullResult, ScriptEngine.EnableNullResultWrapping, and HostFunctions.isNull() (Issue #72).
    • Added enforcement of restricted access to non-public accessors of public properties (Issue #71).
    • (Andrey Taritsyn) Switched assembly targets to .NET 4 Client Profile.
    • Added tests for bug fixes and new APIs.
    • Tested with V8 4.2.77.18.

    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
  • 05/29/16--13:46: Updated Wiki: Announcements
  • 5/29/2016: Version 5.4.6 released.

    View the release notes and download the source code here.

    3/10/2016: Version 5.4.5 released.

    View the release notes and download the source code here.

    12/8/2015: Version 5.4.4 released.

    View the release notes and download the source code here.

    8/17/2015: Version 5.4.3 released.

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

    6/30/2015: Version 5.4.2.1 released.

    View the release notes and download the source code here. This is a bug fix release only.

    5/10/2015: Version 5.4.2 released.

    View the release notes and download the source code here.

    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
  • 05/29/16--13:48: 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
  • 05/29/16--13:48: 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

    It looks like calling a JavaScript function from c# with an implicit this object will be executed twice if an exception ist thrown during execution.

    It is possible to work around this issue via explicit this.

    Consider the following test code:

    ```
    var engine = new V8ScriptEngine( "Test", V8ScriptEngineFlags.DisableGlobalMembers );
    dynamic funcObj = engine.Evaluate( "({ func: function(counter) { counter.val = counter.val + 1; throw new Error('Counter was ' + counter.val); } })" );
    dynamic counter1 = engine.Evaluate( "({val: 0})" );
    dynamic counter2 = engine.Evaluate( "({val: 0})" );
    try
    {
    funcObj.func( counter1 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 1: " + counter1.val );
    // Counter 1: 2
    }

    try
    {
    var func = funcObj.func;
    func.call( funcObj, counter2 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 2: " + counter2.val );
    // Counter 2: 1
    }
    ```

    Am I doing something wrong here?

    0 0

    It looks like calling a JavaScript function from c# with an implicit this object will be executed twice if an exception ist thrown during execution.

    It is possible to work around this issue via explicit this.

    Consider the following test code:

    ```
    var engine = new V8ScriptEngine( "Test", V8ScriptEngineFlags.DisableGlobalMembers );
    dynamic funcObj = engine.Evaluate( "({ func: function(counter) { counter.val = counter.val + 1; throw new Error('Counter was ' + counter.val); } })" );
    dynamic counter1 = engine.Evaluate( "({val: 0})" );
    dynamic counter2 = engine.Evaluate( "({val: 0})" );
    try
    {
    funcObj.func( counter1 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 1: " + counter1.val );
    // Counter 1: 2
    }

    try
    {
    var func = funcObj.func;
    func.call( funcObj, counter2 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 2: " + counter2.val );
    // Counter 2: 1
    }
    ```

    Am I doing something wrong here?
    Comments: Fixed in [Version 5.4.6](https://clearscript.codeplex.com/SourceControl/changeset/a453fe935c7f30b8285ca6d9a34bf2165b4b7805).

    0 0

    got one more cross-engine issue.

    an error raised by scriptengine (b) which was invoked by another scriptengine (a), doesn't make it to scriptengine (a) and properly back to the origin calle in the stack scriptengine (b). which means the script execution error occurred as such in scriptengine (b) cant be catched by a try-catch on the host side.

    on more weird issue happening along side is that the code block (function|sub) where the error was raised gets executed from the very beginning.

    in short the call chain looks like this:
    ```
    engineA.someMethod(
    engineB.anotherMethod(
    engineA.errorOccuringMethod(
    - firstLineCode -
    someErrorCode -> causing a rerun of engineA.errorOccuringmethod() then throwing COMException in WindowsScriptEngine.ThrowHostException()
    )
    )
    )
    ```

    here a sample code:

    ```
    var seA = new VBScriptEngine();
    seA.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seA.Execute(@"
    class aclass

    function binvoke(bobj)
    bobj.bmethod()
    end function

    end class
    dim avar : set avar = new aclass
    ");

    var seB = new VBScriptEngine();
    seB.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seB.Execute(@"
    class bclass

    function bmethod()
    WriteLine(""begin-bmethod"")
    err.raise 1, ""source"", ""errdescr""
    bmethod = ""retval""
    WriteLine(""end-bmethod"")
    end function

    function go(seA, bobj)
    dim i
    'for i = 0 to 5
    seA.binvoke(bobj)
    'next
    end function

    end class
    dim bvar : set bvar = new bclass
    ");


    try
    {
    seB.Script.bvar.go(seA.Script.avar, seB.Script.bvar);
    }
    catch (System.Runtime.InteropServices.COMException)
    {
    throw;
    }
    catch (Exception)
    {
    throw;
    }
    ```

    you should see 2xtimes "begin-bmethod" in the console output before the debugger stop at WindowsScriptEngine.ThrowHostException()

    the expected behaviour would be 1xtime "begin-bmethod" in the console output and break of the debugger in the try-catch block

    0 0

    got one more cross-engine issue.

    an error raised by scriptengine (b) which was invoked by another scriptengine (a), doesn't make it to scriptengine (a) and properly back to the origin calle in the stack scriptengine (b). which means the script execution error occurred as such in scriptengine (b) cant be catched by a try-catch on the host side.

    on more weird issue happening along side is that the code block (function|sub) where the error was raised gets executed from the very beginning.

    in short the call chain looks like this:
    ```
    engineA.someMethod(
    engineB.anotherMethod(
    engineA.errorOccuringMethod(
    - firstLineCode -
    someErrorCode -> causing a rerun of engineA.errorOccuringmethod() then throwing COMException in WindowsScriptEngine.ThrowHostException()
    )
    )
    )
    ```

    here a sample code:

    ```
    var seA = new VBScriptEngine();
    seA.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seA.Execute(@"
    class aclass

    function binvoke(bobj)
    bobj.bmethod()
    end function

    end class
    dim avar : set avar = new aclass
    ");

    var seB = new VBScriptEngine();
    seB.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seB.Execute(@"
    class bclass

    function bmethod()
    WriteLine(""begin-bmethod"")
    err.raise 1, ""source"", ""errdescr""
    bmethod = ""retval""
    WriteLine(""end-bmethod"")
    end function

    function go(seA, bobj)
    dim i
    'for i = 0 to 5
    seA.binvoke(bobj)
    'next
    end function

    end class
    dim bvar : set bvar = new bclass
    ");


    try
    {
    seB.Script.bvar.go(seA.Script.avar, seB.Script.bvar);
    }
    catch (System.Runtime.InteropServices.COMException)
    {
    throw;
    }
    catch (Exception)
    {
    throw;
    }
    ```

    you should see 2xtimes "begin-bmethod" in the console output before the debugger stop at WindowsScriptEngine.ThrowHostException()

    the expected behaviour would be 1xtime "begin-bmethod" in the console output and break of the debugger in the try-catch block
    Comments: Fixed in [Version 5.4.6](https://clearscript.codeplex.com/SourceControl/changeset/a453fe935c7f30b8285ca6d9a34bf2165b4b7805).

    0 0

    got one more cross-engine issue.

    an error raised by scriptengine (b) which was invoked by another scriptengine (a), doesn't make it to scriptengine (a) and properly back to the origin calle in the stack scriptengine (b). which means the script execution error occurred as such in scriptengine (b) cant be catched by a try-catch on the host side.

    on more weird issue happening along side is that the code block (function|sub) where the error was raised gets executed from the very beginning.

    in short the call chain looks like this:
    ```
    engineA.someMethod(
    engineB.anotherMethod(
    engineA.errorOccuringMethod(
    - firstLineCode -
    someErrorCode -> causing a rerun of engineA.errorOccuringmethod() then throwing COMException in WindowsScriptEngine.ThrowHostException()
    )
    )
    )
    ```

    here a sample code:

    ```
    var seA = new VBScriptEngine();
    seA.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seA.Execute(@"
    class aclass

    function binvoke(bobj)
    bobj.bmethod()
    end function

    end class
    dim avar : set avar = new aclass
    ");

    var seB = new VBScriptEngine();
    seB.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seB.Execute(@"
    class bclass

    function bmethod()
    WriteLine(""begin-bmethod"")
    err.raise 1, ""source"", ""errdescr""
    bmethod = ""retval""
    WriteLine(""end-bmethod"")
    end function

    function go(seA, bobj)
    dim i
    'for i = 0 to 5
    seA.binvoke(bobj)
    'next
    end function

    end class
    dim bvar : set bvar = new bclass
    ");


    try
    {
    seB.Script.bvar.go(seA.Script.avar, seB.Script.bvar);
    }
    catch (System.Runtime.InteropServices.COMException)
    {
    throw;
    }
    catch (Exception)
    {
    throw;
    }
    ```

    you should see 2xtimes "begin-bmethod" in the console output before the debugger stop at WindowsScriptEngine.ThrowHostException()

    the expected behaviour would be 1xtime "begin-bmethod" in the console output and break of the debugger in the try-catch block

    0 0

    It looks like calling a JavaScript function from c# with an implicit this object will be executed twice if an exception ist thrown during execution.

    It is possible to work around this issue via explicit this.

    Consider the following test code:

    ```
    var engine = new V8ScriptEngine( "Test", V8ScriptEngineFlags.DisableGlobalMembers );
    dynamic funcObj = engine.Evaluate( "({ func: function(counter) { counter.val = counter.val + 1; throw new Error('Counter was ' + counter.val); } })" );
    dynamic counter1 = engine.Evaluate( "({val: 0})" );
    dynamic counter2 = engine.Evaluate( "({val: 0})" );
    try
    {
    funcObj.func( counter1 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 1: " + counter1.val );
    // Counter 1: 2
    }

    try
    {
    var func = funcObj.func;
    func.call( funcObj, counter2 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 2: " + counter2.val );
    // Counter 2: 1
    }
    ```

    Am I doing something wrong here?

    0 0

    Repeated calls to `V8Runtime.CreateScriptEngine` make the runtime's heap grow even if the engine instances are disposed immediately. This is because the `V8ContextImpl` destructor neglects to to dispose the termination exception.

    0 0

    Setting a Value to Put Property outside the Script execution context fails, saying member not found.

    here is a simple demonstration code:

    ```
    var e = new VBScriptEngine();
    e.Execute(@"
    class test
    private var_

    public property get var
    var = var_
    end property
    public property let var(val)
    var_ = val
    end property

    Private Sub Class_Initialize()
    var_ = ""value""
    End Sub

    end class
    dim mytest : set mytest = new test
    ");
    dynamic a = e.Script.mytest;
    Console.WriteLine(a.var);

    a.var = "adad"; // !! this used to fail also, but found a quick workaround. see code below
    Console.WriteLine(a.var);

    var e2 = new VBScriptEngine();
    e2.Execute("dim mytest, tyna");
    e2.Script.mytest = a;

    e2.Execute("tyna = typename(mytest)");
    e2.Execute("mytest.var = \"sad\""); // !! this fails !!
    ```


    the quick fix is achived in COMDispatchHelper.cs inside the SetProperty(..) method, simply trying next DispatchFlags:

    ```
    Marshal.ThrowExceptionForHR(result);
    using (var argVariantArrayBlock = new CoTaskMemVariantArgsBlock(args))
    {
    using (var namedArgDispidBlock = new CoTaskMemBlock(sizeof(int)))
    {
    EXCEPINFO excepInfo;
    Marshal.WriteInt32(namedArgDispidBlock.Addr, SpecialDispIDs.PropertyPut);
    var dispArgs = new DISPPARAMS { cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 1, rgdispidNamedArgs = namedArgDispidBlock.Addr };
    try
    {
    dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPut | DispatchFlags.PropertyPutRef, ref dispArgs, IntPtr.Zero, out excepInfo);
    return true;
    }
    catch (COMException)
    {
    try
    {
    dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPut, ref dispArgs, IntPtr.Zero, out excepInfo);
    return true;
    }
    catch (COMException)
    {
    try
    {
    dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPutRef, ref dispArgs, IntPtr.Zero, out excepInfo);
    return true;
    }
    catch (COMException) { }
    }
    }
    return false;
    }
    }
    ```

    any ideas of why this happens at all?

    0 0
  • 05/29/16--13:56: Updated Wiki: Home
  • InfoIcon.jpgVersion 5.4.6 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.JavaScript;
    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);
    
        // read a JavaScript typed array
        engine.Execute("values = new Int32Array([1, 2, 3, 4, 5])");
        var values = (ITypedArray<int>)engine.Script.values;
        Console.WriteLine(string.Join(", ", values.ToArray()));
    }

    0 0

    It looks like calling a JavaScript function from c# with an implicit this object will be executed twice if an exception ist thrown during execution.

    It is possible to work around this issue via explicit this.

    Consider the following test code:

    ```
    var engine = new V8ScriptEngine( "Test", V8ScriptEngineFlags.DisableGlobalMembers );
    dynamic funcObj = engine.Evaluate( "({ func: function(counter) { counter.val = counter.val + 1; throw new Error('Counter was ' + counter.val); } })" );
    dynamic counter1 = engine.Evaluate( "({val: 0})" );
    dynamic counter2 = engine.Evaluate( "({val: 0})" );
    try
    {
    funcObj.func( counter1 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 1: " + counter1.val );
    // Counter 1: 2
    }

    try
    {
    var func = funcObj.func;
    func.call( funcObj, counter2 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 2: " + counter2.val );
    // Counter 2: 1
    }
    ```

    Am I doing something wrong here?
    Comments: Thanks! :)

    0 0

    got one more cross-engine issue.

    an error raised by scriptengine (b) which was invoked by another scriptengine (a), doesn't make it to scriptengine (a) and properly back to the origin calle in the stack scriptengine (b). which means the script execution error occurred as such in scriptengine (b) cant be catched by a try-catch on the host side.

    on more weird issue happening along side is that the code block (function|sub) where the error was raised gets executed from the very beginning.

    in short the call chain looks like this:
    ```
    engineA.someMethod(
    engineB.anotherMethod(
    engineA.errorOccuringMethod(
    - firstLineCode -
    someErrorCode -> causing a rerun of engineA.errorOccuringmethod() then throwing COMException in WindowsScriptEngine.ThrowHostException()
    )
    )
    )
    ```

    here a sample code:

    ```
    var seA = new VBScriptEngine();
    seA.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seA.Execute(@"
    class aclass

    function binvoke(bobj)
    bobj.bmethod()
    end function

    end class
    dim avar : set avar = new aclass
    ");

    var seB = new VBScriptEngine();
    seB.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seB.Execute(@"
    class bclass

    function bmethod()
    WriteLine(""begin-bmethod"")
    err.raise 1, ""source"", ""errdescr""
    bmethod = ""retval""
    WriteLine(""end-bmethod"")
    end function

    function go(seA, bobj)
    dim i
    'for i = 0 to 5
    seA.binvoke(bobj)
    'next
    end function

    end class
    dim bvar : set bvar = new bclass
    ");


    try
    {
    seB.Script.bvar.go(seA.Script.avar, seB.Script.bvar);
    }
    catch (System.Runtime.InteropServices.COMException)
    {
    throw;
    }
    catch (Exception)
    {
    throw;
    }
    ```

    you should see 2xtimes "begin-bmethod" in the console output before the debugger stop at WindowsScriptEngine.ThrowHostException()

    the expected behaviour would be 1xtime "begin-bmethod" in the console output and break of the debugger in the try-catch block
    Comments: great Thanks!

    0 0

    got one more cross-engine issue.

    an error raised by scriptengine (b) which was invoked by another scriptengine (a), doesn't make it to scriptengine (a) and properly back to the origin calle in the stack scriptengine (b). which means the script execution error occurred as such in scriptengine (b) cant be catched by a try-catch on the host side.

    on more weird issue happening along side is that the code block (function|sub) where the error was raised gets executed from the very beginning.

    in short the call chain looks like this:
    ```
    engineA.someMethod(
    engineB.anotherMethod(
    engineA.errorOccuringMethod(
    - firstLineCode -
    someErrorCode -> causing a rerun of engineA.errorOccuringmethod() then throwing COMException in WindowsScriptEngine.ThrowHostException()
    )
    )
    )
    ```

    here a sample code:

    ```
    var seA = new VBScriptEngine();
    seA.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seA.Execute(@"
    class aclass

    function binvoke(bobj)
    bobj.bmethod()
    end function

    end class
    dim avar : set avar = new aclass
    ");

    var seB = new VBScriptEngine();
    seB.Script.WriteLine = new Action<string>((text) => Console.WriteLine(text));
    seB.Execute(@"
    class bclass

    function bmethod()
    WriteLine(""begin-bmethod"")
    err.raise 1, ""source"", ""errdescr""
    bmethod = ""retval""
    WriteLine(""end-bmethod"")
    end function

    function go(seA, bobj)
    dim i
    'for i = 0 to 5
    seA.binvoke(bobj)
    'next
    end function

    end class
    dim bvar : set bvar = new bclass
    ");


    try
    {
    seB.Script.bvar.go(seA.Script.avar, seB.Script.bvar);
    }
    catch (System.Runtime.InteropServices.COMException)
    {
    throw;
    }
    catch (Exception)
    {
    throw;
    }
    ```

    you should see 2xtimes "begin-bmethod" in the console output before the debugger stop at WindowsScriptEngine.ThrowHostException()

    the expected behaviour would be 1xtime "begin-bmethod" in the console output and break of the debugger in the try-catch block

    0 0

    It looks like calling a JavaScript function from c# with an implicit this object will be executed twice if an exception ist thrown during execution.

    It is possible to work around this issue via explicit this.

    Consider the following test code:

    ```
    var engine = new V8ScriptEngine( "Test", V8ScriptEngineFlags.DisableGlobalMembers );
    dynamic funcObj = engine.Evaluate( "({ func: function(counter) { counter.val = counter.val + 1; throw new Error('Counter was ' + counter.val); } })" );
    dynamic counter1 = engine.Evaluate( "({val: 0})" );
    dynamic counter2 = engine.Evaluate( "({val: 0})" );
    try
    {
    funcObj.func( counter1 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 1: " + counter1.val );
    // Counter 1: 2
    }

    try
    {
    var func = funcObj.func;
    func.call( funcObj, counter2 );
    }
    catch( Exception ex )
    {
    System.Console.WriteLine( "Counter 2: " + counter2.val );
    // Counter 2: 1
    }
    ```

    Am I doing something wrong here?

    0 0

    Setting a Value to Put Property outside the Script execution context fails, saying member not found.

    here is a simple demonstration code:

    ```
    var e = new VBScriptEngine();
    e.Execute(@"
    class test
    private var_

    public property get var
    var = var_
    end property
    public property let var(val)
    var_ = val
    end property

    Private Sub Class_Initialize()
    var_ = ""value""
    End Sub

    end class
    dim mytest : set mytest = new test
    ");
    dynamic a = e.Script.mytest;
    Console.WriteLine(a.var);

    a.var = "adad"; // !! this used to fail also, but found a quick workaround. see code below
    Console.WriteLine(a.var);

    var e2 = new VBScriptEngine();
    e2.Execute("dim mytest, tyna");
    e2.Script.mytest = a;

    e2.Execute("tyna = typename(mytest)");
    e2.Execute("mytest.var = \"sad\""); // !! this fails !!
    ```


    the quick fix is achived in COMDispatchHelper.cs inside the SetProperty(..) method, simply trying next DispatchFlags:

    ```
    Marshal.ThrowExceptionForHR(result);
    using (var argVariantArrayBlock = new CoTaskMemVariantArgsBlock(args))
    {
    using (var namedArgDispidBlock = new CoTaskMemBlock(sizeof(int)))
    {
    EXCEPINFO excepInfo;
    Marshal.WriteInt32(namedArgDispidBlock.Addr, SpecialDispIDs.PropertyPut);
    var dispArgs = new DISPPARAMS { cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 1, rgdispidNamedArgs = namedArgDispidBlock.Addr };
    try
    {
    dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPut | DispatchFlags.PropertyPutRef, ref dispArgs, IntPtr.Zero, out excepInfo);
    return true;
    }
    catch (COMException)
    {
    try
    {
    dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPut, ref dispArgs, IntPtr.Zero, out excepInfo);
    return true;
    }
    catch (COMException)
    {
    try
    {
    dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPutRef, ref dispArgs, IntPtr.Zero, out excepInfo);
    return true;
    }
    catch (COMException) { }
    }
    }
    return false;
    }
    }
    ```

    any ideas of why this happens at all?

older | 1 | .... | 99 | 100 | (Page 101) | 102 | 103 | .... | 115 | newer