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

New Post: Line numbers in stacktraces

$
0
0
Well, it works pretty similar to what node.js does, so lets have a look at that:
https://github.com/nodejs/node/blob/master/lib/internal/bootstrap_node.js

Starting with line 386 a minimal module system is implemented.
The interesting part is the compile function in line 473. The given source is basically spliced into a function declaration (pretty much as you suggested) to ensure that everything is local to the function end not in the global context. Note how there is no line break after the header. This is done so that line numbers of errors encountered will still be correct after the splicing. However, any errors in the first line of source will be very strange to the user.
The next step is to run the resulting function declaration through the engine. In my case I have defined the runInThisContext function as follows in c#:
privateobject RunInThisContext( string source, dynamic settings )
{
    string filename = _GetFileName(settings);

    var moduleLoader = Engine.Evaluate( filename, false, source );
    return moduleLoader;
}
What I would like to do now is wrap source like this:
'(function (exports, require, module, __filename, __dirname) {\n',
+ source +
'\n});'
And then tell the engine to offset all line positionsi n error messages by -1. Then errors in the first line of source could produce good error messages as well.

New Post: C# Constructor

$
0
0
Hello.

I have two class definitions in c# like this:
publicclass Foo
{
    public Foobar(int x)
    {
    ...
    }
}
publicclass Bar : Foo
{
    public Bar(int x) : base(x)
    {
    ...
    }
}
Now I would like to make the constructors available to the JavaScript Engine. However, not as global functions but as functions of some object. Something like this:
var engine = new V8ScriptEngine( name, flags, debugPort );
engine.Script.SomeObject.Foo = engine.CompileConstructor(typeof(Foo));
engine.Script.SomeObject.Bar = engine.CompileConstructor(typeof(Bar));
Is there a way to accomplish this? Any chance that this would even work with JavaScript's instanceof operator?

Created Feature: [FEATURE] Add support for script line/column offsets [110]

$
0
0
This feature would permit accurate line/column error information for scripts embedded within HTML or other formats. Ideally it would be possible to specify negative offsets for situations where the executed script includes boilerplate that is not to be considered part of the script.

New Post: Line numbers in stacktraces

$
0
0
Hi again,

V8 does allow you to specify where a given script begins within its containing file, presumably to accommodate scripts embedded in HTML and other file formats. It also appears to permit negative line and column offsets, enabling exactly the behavior you're looking for.

Unfortunately ClearScript doesn't provide access to this feature, as it only supports script document names. We've added a feature request here.

Cheers!

New Post: C# Constructor

$
0
0
Hi ZoneRunner,

There are several ways to do this. One is to use ClearScript's ExtendedHostFunctions class:
var xHost = new ExtendedHostFunctions();
engine.Script.SomeObject.Foo = xHost.type(typeof(Foo));
engine.Script.SomeObject.Bar = xHost.type(typeof(Bar));
engine.Execute("bar = new SomeObject.Bar(123)");
You can't use instanceof to examine a host object's type information. If that's a requirement, consider defining native JavaScript types that wrap your host types as necessary.

Good luck!

New Post: C# Constructor

Source code checked in, #26ec250ac354b63f5a97722841389cadba30e6f3

$
0
0
Version 5.4.7: Added ImmutableValueAttribute and fixed canonical reference support; fixed nested V8 syntax error reporting; added tests for bug fixes and new APIs. Tested with V8 5.3.332.45.

Released: ClearScript 5.4 (Oct 22, 2014)

$
0
0
5.4.7
  • Added ImmutableValueAttribute and fixed canonical reference support.
  • Hardened native timers and V8 background tasks, fixing intermittent V8 crashes.
  • Fixed nested V8 syntax error reporting.
  • Added tests for bug fixes and new APIs.
  • Tested with V8 5.3.332.45.

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 debugg

Updated Release: ClearScript 5.4 (Oct 22, 2014)

$
0
0
5.4.7
  • Added ImmutableValueAttribute and fixed canonical reference support.
  • Hardened native timers and V8 background tasks, fixing intermittent V8 crashes.
  • Fixed nested V8 syntax error reporting.
  • Added tests for bug fixes and new APIs.
  • Tested with V8 5.3.332.45.

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 debugg

Updated Wiki: Documentation

$
0
0

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.

Updated Wiki: Documentation

$
0
0

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.

Updated Wiki: Announcements

$
0
0

9/13/2016: Version 5.4.7 released.

View the release notes and download the source code here.

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

Updated Wiki: Home

$
0
0
InfoIcon.jpgVersion 5.4.7 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()));
}

New Post: Problem building the 5.4.7 in the v8 32 bit step

$
0
0
I am getting this error when trying to build the v8 engine using the 5.4.7 ClearScript package.

"C:\ClearScript\ClearScript\V8\V8\build\v8-ia32\src\v8.sln" (v8 target) (1) ->
"C:\ClearScript\ClearScript\V8\V8\build\v8-ia32\src\v8.vcxproj.metaproj" (default target) (2) ->
"C:\ClearScript\ClearScript\V8\V8\build\v8-ia32\src\v8.vcxproj" (default target) (14) ->
(Link target) ->
v8_base_3.lib(bytecode-register-optimizer.obj) : error LNK2005: "private: static unsigned int const v8::internal::interpreter::BytecodeRegisterOptimizer::kInvalidEquivalenceId" (?kInvalidEquivalenceId@BytecodeRegisterOptimizer@interpreter@internal@v8@@0IB) already defined in v8_base_2.lib(bytecode-array-builder.obj) [C:\ClearScript\ClearScript\V8\V8\build\v8-ia32\src\v8.vcxproj]
..\build\Release\v8-ia32.dll : fatal error LNK1169: one or more multiply defined symbols found [C:\ClearScript\ClearScript\V8\V8\build\v8-ia32\src\v8.vcxproj

The build proces goes fint up to the buidling v8 32bit step.

To me it looks like that something is wrong in the code.

I have been able to build ClearScript before on this computer.

New Post: Calling a JS Function from a script that has been exectued

$
0
0
So the issue is this, I need to load a script and execute the script, and keep it's state, for a subsequent call to a function within the script based upon a UI event.

For example:

A script:

var hello = "hello";

function spanishHello() { hello = "hola"; }
function englishHello() { hello = "hello"; }
function newyorkHello() { hello = "screw you"; }

spanishHello();

Console.WriteLine(hello);


That script is executed in the engine:

scriptEngine.Execute(script);

that works fine.

At a later point I need to call spanishHello(). It appears that the answer is scriptEngine.Invoke("spanishHello", null); but that throws a not found exception.

I suspect I'm making this harder than it needs to be. Your thoughts and suggestions?

New Post: Calling a JS Function from a script that has been exectued

$
0
0
Hi dru_satori,

scriptEngine.Invoke("spanishHello") should work; another possibility is scriptEngine.Script.spanishHello().

Are you sure you're using the same engine instance that executed the script? Is it possible that you're deleting the functions somehow? What exactly does the exception say? Could you provide a minimal code sample that reproduces the issue?

Thanks!

New Post: Calling a JS Function from a script that has been exectued

$
0
0
I'll have to see if I can pull it apart and give you a test case. The error I'm getting is 'Invalid object or property access' thrown as Microsoft.ClearScript.ScriptingEngineException.

New Post: Calling a JS Function from a script that has been exectued

$
0
0
Hi again,

That message would be expected if you used different JScriptEngine instances to run the script and invoke the function. Are you sure that's not the case?

Cheers!

New Post: Problem building the 5.4.7 in the v8 32 bit step

$
0
0
Hello dennisdc,

We cannot reproduce this on the following configurations:
  • Windows 10 64-bit, Visual Studio 2015 with Updates 2 and 3
  • Windows 7 32-bit, Visual Studio 2013 with Update 5
Can you describe your configuration?

Thanks!

New Post: Problem building the 5.4.7 in the v8 32 bit step

$
0
0
Windows 7 64-bit, Visual Studio 2013 with no updates.

I am currently in the process of updating my VS 2013 now to Update 5, and will report back if it changes anything.
Viewing all 2297 articles
Browse latest View live




Latest Images