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 | .... | 34 | 35 | (Page 36) | 37 | 38 | .... | 115 | newer

    0 0

    In which language? Please be specific.

    0 0

    After we provided a suitable Console object, this code worked perfectly with ClearScript 5.3.11. Are you using an older version?

    0 0

    i use the latest version

    and the Console object is a firebug-console implementation

    0 0

    in js in clearscript

    0 0

    All JavaScript functions can take any number of arguments. Please see here.

    0 0

    Can you provide more information? Which script engine are you using? How are you exposing XmlHttpRequest to the script engine? How are you loading and executing the JavaScript code?

    0 0

    i use JScriptEngine

    se.AddHostObject("XmlHttpRequest", new XmlHttpRequest());

    i execute with: js.Evaluate(Properties.Resources.Run);
    i also tried with execute, but same error

    0 0

    in c# works the code correctly

    0 0

    Hi furesoft,

    You're exposing an object - an instance of the XmlHttpRequest class. For the new operator to work, you need to expose the class itself:
    se.AddHostType("XmlHttpRequest", typeof(XmlHttpRequest));
    Good luck!

    0 0

    oh, my bad

    thanks

    0 0

    So I know you can't do what the subject suggests.

    What I'd like is the next best thing.

    I'm trying to save as much of the running engine instance as possible so that I can re-instantiate it later and begin invoking functions. I recognize that I'm going to have to be doing something like scrapping the engine instance's root objects, saving them somehow, and then reinjecting them into the engine before resuming execution of script. So, I'm looking for two things:

    1) How do I get access to all root objects from inside the CLR?
    2) Any advice on things to look out for? I recognize I'm going to have it tricky with regards to tracking down and persisting references, and especially things like 'this' references in JavaScript, and function instances.

    What I'm basically implementing is a W3C user agent for XForms. Imagine it as an actual web browser. Except I need to save my engine state and resume it where its left off. My implementation is basically done, except I'm looking for a suitable JavaScript engine to add into it. ClearScript is nice, but I need to be able to accomplish this.

    https://github.com/nxkit/nxkit

    0 0

    Hello!

    1) How do I get access to all root objects from inside the CLR?

    You can do something like this:
    foreach (var name in engine.Script.GetDynamicMemberNames()) {
        var obj = engine.Script[name];
        // do something with obj
    }
    This should return all global properties that aren't standard JavaScript built-ins.

    2) Any advice on things to look out for?

    Not knowing what kind of objects might be in your script environment, it's difficult to say. Would you expect many .NET objects, and if so, what types? What about script functions? Some script functions may be serializable, but some may not (e.g., those created via bind()). One thing you should definitely avoid is using JSON.stringify() to serialize .NET objects.

    Good luck, and please let us know if you encounter any specific issues!

    0 0

    i know i would know too how can i use

    0 0

    hi,
    how can i get a list of all functions?
    • found

    0 0

    One way could be to add a host type and pass it to the generic method ?

    0 0
  • 05/28/14--05:29: New Post: using typescript
  • Hello furesoft,

    The TypeScript compiler generates JavaScript code, which ClearScript should be able to execute. If you'd like use ClearScript to run the TypeScript compiler itself, take a look here.

    Good luck!

    0 0

    Hello maicalal,

    One way could be to add a host type and pass it to the generic method ?

    That's correct. Many generic methods don't require explicit type arguments because their type arguments can be inferred from their other arguments. In this case there are no other arguments, so type inference is impossible and an explicit type argument is required.

    Here's a simple example:
    publicclass Factory {
        public T Create<T>() where T : new() {
            returnnew T();
        }
    }
    publicclass SomeClass {
        // ...
    }
    and then:
    engine.AddHostObject("factory", new Factory());
    engine.AddHostType("SomeClass", typeof(SomeClass));
    engine.Execute("obj = factory.Create(SomeClass)");
    In general, to invoke a method that requires explicit type arguments, place the required number of host types at the beginning of the argument list.

    Cheers!

    0 0

    This issue seems a bit of an epic. I've read through and tried a lot of things here, but I'm still unable to run my website.
    • Installed via NuGet package (bear with me, I don't think that's the issue -- I even updated this morning)
    • Works fine in VS 2013 express on development machine
    • Works fine in IIS7 on development machine
    • ClearScript v5.3.11.0
    • Doesn't run on the server after using web deploy to deploy (debug or release)
    • Server is Windows 2008 R2 Datacenter w/ Web Server Role (IIS7)
    Actual error is
    Cannot load V8 interface assembly. Load failure information for v8-x64.dll:
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\d007e065\a07c7d1b\assembly\dl3\3b1d0932\880b1e76_0e75cf01\v8-x64.dll: The specified module could not be found
    C:\inetpub\mysite.com\beta\v8-x64.dll: The specified module could not be found
    C:\inetpub\mysite.com\beta\bin\v8-x64.dll: The specified module could not be found
    • The files do not exist in the paths mentioned. They do exist in /bin/ClearScript.V8/
    • The dll ClearScript.dll does exist in /bin/
    I did try quite a few things:
    • Copying the requested dlls into the requested paths also generated errors (mentioned in other, older posts)
    • Turning off shadow copy only removed the line about Temporary ASP.NET
    Please help, I've spent a whole day on this so far.

    0 0

    Hi willeyams,

    you can use the AssemblyResolve event to point your application to the correct binaries. I've deployed successfully my ASP.NET application to Azure with this technique. First, you register the event handler in the Application_Start method of your website like this:
            void Application_Start(object sender, EventArgs e)
            {
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            }
    This is the way I'm handling the loading:
            Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
            {
                if (args.Name.Contains("ClearScript"))
                {
                    var rootPath = HostingEnvironment.MapPath("/Dependencies");
    
                    try
                    {
                        _log.Info("Looking for ClearScript in " + Path.Combine(rootPath, "ClearScriptV8-64.dll"));
                        return Assembly.LoadFile(Path.Combine(rootPath, "ClearScriptV8-64.dll"));
                    }
                    catch (Exception e)
                    {
                        _log.Error("Cannot load ClearScript64", e);
                        return Assembly.LoadFile(Path.Combine(rootPath, "ClearScriptV8-32.dll"));
                    }
                }
    
                return null;
            }
    Clearly, my /Dependencies directory contains ClearScriptV8-xx.dll as well as v8-xxx.dll (which is probably needed only if you are using V8).

    Let me know if this helps! Also, note that the assembly resolve event is probably not handled by the NuGet version (which is not officially supported by the developers) - you'll have to get a version from Codeplex.
    Best regards,
    Andrea

    edit: since this is my first post, I'd like to thank the developers of ClearScript for providing such an amazing package. Keep up the good work :-)

    0 0

    Hello andrea_schirru!

    Thank you very much for posting that sample, and for your kind words!

    Cheers!

older | 1 | .... | 34 | 35 | (Page 36) | 37 | 38 | .... | 115 | newer