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 | .... | 20 | 21 | (Page 22) | 23 | 24 | .... | 115 | newer

    0 0

    Thank you for the workaround. For those that may run into this issue I was able to change the long to a double:
            JScriptEngine engine = new JScriptEngine();
    
            engine.Script.bigNumber = (double)1400000000000;
            var result = engine.Evaluate( "'BigNumber: ' + bigNumber" );
    
            Console.WriteLine( "Result: " + result.ToString() );
    
    The number was output correctly.

    Thank you!

    0 0
  • 02/10/14--08:16: New Post: Date marshalling
  • JavaScript comparisons can't be redefined or overloaded to operate meaningfully on host objects.
    This is good to know. I wont waste any more time trying to find a way to manipulate the JavaScript operators to perform this task.

    The simplification provided I think will be my best option.

    Thank you!

    0 0

    Hi,
    Thanks ! What is the flag I need to enable to use this feature ?

    0 0

    any feedback,

    have you reproduced and, finally, solved the problems?

    Thanks a lot.

    0 0

    Hi niconico49,

    Sorry we didn't make this clear. Yes, we reproduced the issue, and in our case the problem was permissions. The assemblies were in the right place but the application pool identity couldn't access them.

    Because we can't provide a universal fix for deployment issues like this, we're working on enhanced error reporting. Instead of the unhelpful message you currently see, the next version of ClearScript will list the directories it searched for the V8 assemblies and the error encountered in each one.

    Cheers!

    0 0

    Hello!

    The new flag is WindowsScriptEngineFlags.EnableStandardsMode. It enables the JSON object as well as other, less prominent standards compliance improvements.

    Good luck!

    0 0

    Hi,

    Thanks for creating this excellent library. I am attempting to get the requirejs implemententation to work.

    My code is as follows.
    engine.Script.moduleLoader = new ModuleLoader(engine);
    string currentDir = FileOperations.GetCurrentlyExecutingAssemblyLocation();
    engine.Execute(File.ReadAllText(currentDir + @"\Scripts\require.js"));
    engine.Execute(@"require.load = function (context, name, url) {
    moduleLoader.LoadModuleAsync(context, name, url);
    }");
    The following exception is thrown when I execute "engine.Script.moduleLoader = new ModuleLoader(engine);"

    First Chance Exception: RuntimeBinderException
    Message: 'System.Dynamic.DynamicObject' does not contain a definition for 'moduleLoader'

    The requirejs file is loaded and the objects it creates are visible in the engine.Script

    Do you have any ideas why this exception is thrown? I am not 100% clear what the context variable is, how is context accessed or created. What does context mean?

    I did find the following articles but I can't work out if they have relevance to the problem I am facing.

    Adding properties or Dynamic objects in ClearScript
    https://clearscript.codeplex.com/discussions/433131

    https://stackoverflow.com/questions/2630370/c-sharp-dynamic-cannot-access-properties-from-anonymous-types-declared-in-anot

    http://www.solutionevangelist.com/post/14

    Due to the fact that V8 does not implement a DOM, loading libraries like jQuery can prove difficult since there are no window or document objects in the engine. I noticed the test projects have a class called MockDOM but this is a very barebones implementation. For something more fully featured I've been looking at using jsdom http://lab.arc90.com/2010/11/22/jsdom/ . jsdom seems to be developed specifically for node but I am hoping it will work in ClearScript also. Do you know of any techniques that will enable me to load jQuery or other libraries that require the DOM to load and execute in ClearScript?

    Any help or suggestions you have in realation to these matters is appreciated.

    0 0

    I think I may have found a solution for

    First Chance Exception: RuntimeBinderException
    Message: 'System.Dynamic.DynamicObject' does not contain a definition for 'moduleLoader'

    http://www.codeproject.com/Articles/62839/Adventures-with-C-4-0-dynamic-ExpandoObject-Elasti
    Type t = typeof (ModuleLoader);
    dynamic moduleLoaderDefinedInClassLib = Activator.CreateInstance(t, engine);
    engine.Script.moduleLoader = moduleLoaderDefinedInClassLib;
    string currentDir = FileOperations.GetCurrentlyExecutingAssemblyLocation();
    engine.Execute(File.ReadAllText(currentDir + @"\Scripts\require.js"));
    engine.Execute(@"require.load = function (context, name, url) {
    moduleLoader.LoadModuleAsync(context, name, url);
    }");
    In my case the ModuleLoader was defined in a class library project that the main executable referenced, so I think this was the reason the exception was thrown.

    Still not clear what the context variable is though!

    0 0

    Hello AustinDimmer!

    We can't reproduce the exception you're seeing. Can you tell us more about your environment?

    • What version of Windows are you using, including the SKU, x64 vs. x86, etc.?
    • What version of Visual Studio are you using? Is it Visual Studio Express?
    • What version of ClearScript are you using? Did you build it, or are you using a NuGet package? Have you made any modifications?
    • What kind of project are you building - web, console, WPF, etc.?
    • What version of the .NET framework is your project targeting?
    • Is your ModuleLoader class defined exactly as above?
    • Can you share more of your code? We'd like to see how you're creating the script engine, what other objects you're exposing, etc.
    • How are you getting to the line that executes require.js if you're hitting an exception two lines before?
    As for JSDOM, we haven't tried it but it looks like it might be exactly what you're looking for.

    Good luck!

    0 0

    Hi again,

    In my case the ModuleLoader was defined in a class library project that the main executable referenced, so I think this was the reason the exception was thrown.

    That doesn't seem likely. If you can successfully compile expressions such as typeof(ModuleLoader) and new ModuleLoader(engine), then you have a compile-time reference to ModuleLoader, and instantiation via Activator should be unnecessary. Indeed, the exception indicates a problem with dynamic property assignment rather than ModuleLoader instantiation. We'd like to understand the issue, but we can't reproduce it, so please provide any additional information you can.

    Still not clear what the context variable is though!

    The context object is just a JavaScript object that RequireJS passes to its load function. Among other things, context contains a completeLoad function that must be called to report that the requested resource has been loaded.

    0 0

    Thanks for the quick answer.

    What version of Windows are you using, including the SKU, x64 vs. x86, etc.? Windows 8.1 x64
    What version of Visual Studio are you using? Is it Visual Studio Express? VS2013 Ultimate
    What version of ClearScript are you using? Did you build it, or are you using a NuGet package? Have you made any modifications? Nuget <package id="ClearScript.V8" version="5.3.10.0" targetFramework="net45" />
    What kind of project are you building - web, console, WPF, etc.? WPF Application
    What version of the .NET framework is your project targeting? 4.5
    Is your ModuleLoader class defined exactly as above? Yes
    Can you share more of your code? We'd like to see how you're creating the script engine, what other objects you're exposing, etc.

    Trying to load in jQuery or other libs that require a DOM, I am following the sample starter code given at http://lab.arc90.com/2010/11/22/jsdom/

    Here is the code I have so far, more or less.
    var engine = new V8ScriptEngine("engine", V8ScriptEngineFlags.EnableDebugging);
    var typeCollection = new HostTypeCollection("mscorlib", "System", "System.Core");
    engine.AddHostObject("clr", typeCollection);
    //Now all the types defined in the standard mscorlib, System, and System.Core assemblies are exposed. Host type collections are hierarchical data structures where leaf nodes represent host types and parent nodes represent namespaces:
    engine.Execute(@"var guid = clr.System.Guid.NewGuid();");
    engine.Execute(@"var today = clr.System.DayOfWeek.Friday;");
    //Note that, unlike C# types and namespaces, the nodes of a host type collection are objects. A script can copy them to the root level for more convenient access:
    engine.Execute(@"var System = clr.System;");
    engine.Execute(@"var System = clr.System;");
    engine.Execute(@"var Guid = System.Guid;");
    engine.Execute(@"var String = System.String;");
    engine.AddHostType("Console", typeof(Console));
    Type t = typeof (ModuleLoader);
    dynamic moduleLoaderDefinedInClassLib = Activator.CreateInstance(t, engine);
    engine.Script.moduleLoader = moduleLoaderDefinedInClassLib;
    string currentDir = FileOperations.GetCurrentlyExecutingAssemblyLocation();
    engine.Execute(File.ReadAllText(currentDir + @"\Scripts\require.js"));
    engine.Execute(@"require.load = function (context, name, url) {
    moduleLoader.LoadModuleAsync(context, name, url);
    }");
    string htmlTest = "<html><head></head><body><h1>Hello World</h1><p>This is a <em>stupid simple</em> example</p></body></html>";
    engine.Script.htmlTest = htmlTest;
    engine.Execute(@"var html = htmlTest");
    
    // create a new window, with the above markupstring jsdomPath = currentDir + @"\Scripts\jsdom" + ".js";;
    engine.Script.jsdomPath = jsdomPath;
    engine.Execute(@"moduleLoader.LoadModuleAsync(this, 'jsdom', jsdomPath);");
    engine.Execute(@"var window = require(jsdomPath).jsdom(html).createWindow();");
    
    // create a new script tag to load up jQuery
    engine.Execute(@"script = window.document.createElement('script');");
    
    engine.Execute(@"script.src = 'http://code.jquery.com/jquery-1.4.2.js';");
    
    // when jQuery finishes loading
    engine.Execute(@"script.onload = function() {
    // Since this is not a browser we need to specify the window that jQuery has
    // been added to
    // Output: 'H1 Contents: Hello World'
    Console.WriteLine(window.jQuery('h1').text());
    
    // do a simple replace on the `em` text above
    window.jQuery('p em').text('silly');
    
    // Output: 'P Contents: This is a silly example'
    Console.WriteLine(window.jQuery('p').text());}}"
    );
    // Append the element to the head element of the document
    engine.Execute(@"window.document.head.appendChild(script);");
    
    How are you getting to the line that executes require.js if you're hitting an exception two lines before? I have a first chance exception handler, code still runs. Not 100% sure why the code behaves like this!

    0 0

    Hi AustinDimmer!

    You code looks fine, although you shouldn't need this line:
    engine.Execute(@"moduleLoader.LoadModuleAsync(this, 'jsdom', jsdomPath);");
    You shouldn't need that because the require call on the next line should call the module loader internally. Also, be careful with this:
    engine.Execute(@"var String = System.String;");
    That replaces the built-in JavaScript String function, which could affect subsequent scripts.

    I have a first chance exception handler, code still runs. Not 100% sure why the code behaves like this!

    How are you setting up this handler? It's not in the code above. We're glad you found a way forward, but we'd really like to understand your original issue, and we still can't reproduce it with ModuleLoader defined in a separate class library. Would it by any chance be possible for you to share your project?

    Thanks!

    0 0

    I've been looking into the context thing and I am having some progress. I found a decent example at the following url

    https://stackoverflow.com/questions/19279196/context-and-nested-modules-in-requirejs

    I should mention that ClearScript is being set up in a seperate AppDomain. My thinking is that this makes things a little bit more secure in that code executing in the child AppDomain can't execute more sensitive code in the ParentApp domain. The AppDomain that I am loading ClearScript into is isolated. Not sure if this may be the root cause for my observations. I suspect not.

    I am setting up handlers in the AppDomain as follows.
    AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
    And the handler method is just printing to the console.
    privatestaticvoid CurrentDomain_FirstChanceException(object sender, FirstChanceExceptionEventArgs e)
    {
    Debug.WriteLine(String.Format("First Chance Exception: {0}\r\nMessage: {1}\r\n", e.Exception.GetType()
    .Name, e.Exception.Message));
    }
    I can't share the whole codebase, but if you want to investigate further. I'll try and provide as much info as possible to enable you to replicate things at your end.

    I've made some progress today and I am hoping that I will soon find the secret sauce that enables me to load jsdom into ClearScript using requirejs.

    Thanks again!

    0 0

    Hello again!

    We've investigated this some more, and it turns out that the RuntimeBinderException is absolutely not a concern. It is thrown and handled internally within the C# Runtime Binder.

    In other words, the exception doesn't make it out of .NET code, and that's why your code continues to run. Your AppDomain.FirstChanceException handler has nothing to do with it. From MSDN: "This event is only a notification. Handling this event does not handle the exception or affect subsequent exception handling in any way."

    At first we thought we couldn't reproduce the exception because we didn't see it in the debugger, but that was because Visual Studio is configured to ignore RuntimeBinderException by default. Once we set up a logging handler similar to yours, we saw it.

    The bottom line is that you can use the original simple form:
    engine.Script.moduleLoader = new ModuleLoader(engine);
    This is recommended over Activator.CreateInstance() and should perform much better.

    Thanks for all your help!

    0 0

    Hello,

    I didn't known jsdom :)

    The sound nicer than using phantomJS in order to generate page for SEO.

    https://github.com/ithkuil/angular-on-server/wiki/Running-AngularJS-on-the-server-with-Node.js-and-jsdom

    Do you know an easy way of implement XMLHttpRequest interface on the server C# side?

    In order to make :
    AngularJS
    JSDom
    JQuery

    Work on with cleascript on serveur side?

    Regards,

    Guillaume Chervet.

    0 0

    hello, i have this script:
    engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core"));
    this script will be ok in a ConsoleApplication.exe. but if i write this code in mvc and deploy to iis7.5/win2008r2, this will throw an exception:
    The type initializer for 'Microsoft.ClearScript.Util.AssemblyHelpers' threw an exception.
    
    System.String GetFullAssemblyName(System.String)
    at Microsoft.ClearScript.Util.AssemblyHelpers.GetFullAssemblyName(String name) at Microsoft.ClearScript.HostTypeCollection.AddAssembly(String assemblyName) at System.Array.ForEach[T](T[] array, Action`1 action) at MyEngine.InitScriptEngin() in MyEngine.cs:line 80
    
    
    It maybe something about "access right" or can't find the system dll problem, but i don't know how to fix it, please help.

    best&regards

    0 0

    Hi Guillaume,

    If you need to run existing JavaScript code that requires XMLHttpRequest, the best available option is to implement (the required portions of) XMLHttpRequest on top of something like System.Net.HttpWebRequest and expose it to the script engine.

    Windows provides a COM implementation of XMLHttpRequest, and the next version of ClearScript will allow you to expose it for scripting. However, this solution may not support asynchronous operation and may therefore be of limited use on the server.

    Cheers!

    0 0

    Greetings zestyzeng!

    We believe this issue is fixed in ClearScript 5.3.11. Can you give that version a try?

    If not, you can work around this issue (and slightly improve your application's performance) by specifying preloaded assemblies when constructing your host type collection:
    var mscorlib = typeof(System.String).Assembly;
    var systemCore = typeof(System.Linq.Enumerable).Assembly;
    engine.AddHostObject("lib", new HostTypeCollection(mscorlib, systemCore));
    Good luck!

    0 0

    It turns out that the jsdom dependencies on Node are going to make it impractical for me to use jsdom to get the functionality that I need. I could not get jsdom to load into ClearScript so I will now look for alternatives.

    Thanks again for the help yesterday and keep up the good work!

    0 0

    AustinDimmer, thank you for your kind words and for giving ClearScript a try!

older | 1 | .... | 20 | 21 | (Page 22) | 23 | 24 | .... | 115 | newer