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

New Post: Setting Decimal property of Object [V8]

$
0
0
Hello. I'm trying to set a value to a decimal property of an object. Setting integer values works but for decimals "Error: Invalid property assignment" error thrown.

Works Fine
MyObject.Price = 1
Invalid property assignment thrown
MyObject.Price = 1.5

New Post: Setting Decimal property of Object [V8]

$
0
0
Greetings!

JavaScript numbers are floating-point and therefore not implicitly convertible to decimal (see here for more information).

You can assign a decimal property as follows:
engine.AddHostObject("host", new HostFunctions());
engine.Execute("MyObject.Price = host.toDecimal(1.5)");
By the way, your first example works because ClearScript converts JavaScript numbers to managed integers when doing so results in no data loss, and integers are implicitly convertible to decimal.

Good luck!

Created Unassigned: Dubugging in V8 not working as expected [61]

$
0
0
I can connect with the debugger, which gives me source code but does not stop on breakpoints. It does yield the source code so I am sure I am connected, but the breakpoints do not work. I have followed the instructions in the readme and I have read a helpful blog from Satyendra Kumar Pandey http://pandeysk.wordpress.com/2014/05/25/debugging-with-clearscript/

Steps to reproduce
I have download the codebase and run the v8 setup script, I was able to get v8 up and running. I am just using the simple console application from you demo project. I can connect the the script engine using both eclipse and webstorm, neither one will stop at a break point. I have tried using the debugger key word and that does not stop debugging.





New Post: Setting Decimal property of Object [V8]

$
0
0
Thank you very much for the detailed explanation. That worked great.

Commented Unassigned: Dubugging in V8 not working as expected [61]

$
0
0
I can connect with the debugger, which gives me source code but does not stop on breakpoints. It does yield the source code so I am sure I am connected, but the breakpoints do not work. I have followed the instructions in the readme and I have read a helpful blog from Satyendra Kumar Pandey http://pandeysk.wordpress.com/2014/05/25/debugging-with-clearscript/

Steps to reproduce
I have download the codebase and run the v8 setup script, I was able to get v8 up and running. I am just using the simple console application from you demo project. I can connect the the script engine using both eclipse and webstorm, neither one will stop at a break point. I have tried using the debugger key word and that does not stop debugging.





Comments: Hello! Where in the code are you setting the breakpoint (and/or adding the `debugger` statement)?

New Post: Cannot use Linq Where and Select Extension Methods

$
0
0
I am trying to get ClearScript to work with my a Linq data access Layer. I have unit of work object that exposes IQueryable of my various database entities. E.g. IQueryable<Project>

I am trying to write a linq statement to select specific projects from the unit of work using the Where extension method but I get the following message Error: 'System.Linq.IQueryable' does not contain a definition for 'Where'. Similiar errors occur for other extension methods that require Func<> delegates. E.g. Select, OrderBy, etc. Any help on getting this scenario to work would be much appreciated.

Unit Of Work Definition
Public class MyUnitOfWork : UnitOfWorkBase
{
    public IQueryable<Project> Projects { get { return this.Query<Project>(); } }
}
Script Engine Setup
using (var engine = new V8ScriptEngine())
{
    var uow = ContextFactory.GetModuleRepo<MyUnitOfWork>(); //creates unit of work instance
    engine.AddHostType(typeof(Enumerable).FullName, typeof(Enumerable));
    engine.AddHostType(typeof(Queryable).FullName, typeof(Queryable));
    engine.AddHostObject("uow", uow);
    engine.Evaluate(txtScript.Text);
}
Javascript
result = uow.Projects.Where(function(w) {return w.Id == 100;}).ToList();

New Post: Cannot use Linq Where and Select Extension Methods

$
0
0
Hello!

ClearScript doesn't convert script functions to delegates automatically, but it provides an easy way to create a delegate that invokes a script function. Try something like this:
engine.AddHostType("Enumerable", typeof(Enumerable));
engine.AddHostType("ProjectPredicate", typeof(Func<Project, bool>));
engine.Execute(@"
    predicate = new ProjectPredicate(function (w) { return w.Id == 100; });
    result = uow.Projects.Where(predicate).ToList();
");
Please let us know if this doesn't work for you.

Thanks!

New Post: Cannot use Linq Where and Select Extension Methods

$
0
0
This approach worked. Thanks for the example.

The only problem with this approach is that it requires a priori knowledge of the predicates that will be used. This kind of defeats the purpose of providing a scripting component in an application. It means I would have to enumerate all possible predicate types for possible linq statements.

I'm not sure if it is possible, but and excellent feature would be to allow for automatic conversion of script functions to delegates (at least For Func and Action delegate types.) This would greatly simplify usage of the LINQ language features.

New Post: Reference one compiled script from another

$
0
0
I have a situation where I want a large static base script included with all the runtime scripts I wish to execute. I don't want to compile this large script with each small script if possible.

Is there any way of referencing one compiled script from another?

New Post: Reference one compiled script from another

$
0
0
Think I may have found my own answer...If I compile the common script and store it, then execute that compiled script each time before I execute the main script, that should do the trick right? I guess I'll find out soon enough.

New Post: Cannot use Linq Where and Select Extension Methods

$
0
0
Hi again,

Unfortunately ambiguity prevents automatic conversion of script functions to delegates, especially when generics are involved.

For example, examining a JavaScript function gets us, at best, a parameter count, and while that might be enough to select the correct overload of Where(), it can't help us bind to the intended specialization of something like Select(), where the delegate's return type plays a critical role in finding the right method. To invoke Select() successfully we must either have explicit type arguments or a strongly-typed delegate; lacking both it's just not possible.

However, there are things you can do to make LINQ easier for script code to use. For example, instead of exposing the standard Enumerable class, consider exposing your own extensions that are specifically designed for script code:
publicstaticclass ScriptWhere {
    publicstatic IEnumerable<T> Where<T>(this IEnumerable<T> source, dynamic predicate) {
        return source.Where(item => Convert.ToBoolean(predicate(item)));
    }
}
Then you could do this:
engine.AddHostType("ScriptWhere", typeof(ScriptWhere));
engine.Execute(@"
    result = uow.Projects.Where(function (w) { return w.Id == 100; }).ToList();
");
For Select() you can't get around having to specify the target type, but you could still make script code a bit happier:
publicstaticclass ScriptSelect {
    publicstatic IEnumerable<T> Select<T>(this IEnumerable<object> source, dynamic selector) {
        return source.Select(item => (T)selector(item));
    }
}
And then:
engine.AddHostType("ScriptSelect", typeof(ScriptSelect));
engine.AddHostType("Int32", typeof(int));
engine.Execute(@"
    result = uow.Projects.Select(Int32, function (w) { return w.Id; }).ToList();
");
We haven't explored all the possibilities; there are just a few ideas.

Good luck!

New Post: Reference one compiled script from another

$
0
0
Hi Eric,

Not sure what you mean by "referencing one script from another". As a script is executed, it may leave functions and/or data hanging somewhere off the global object, and subsequent scripts are free to access those artifacts.

Script compilation can provide a significant boost, but remember that a compiled script is bound to the runtime that created it. You can reuse it in other engines within the runtime, but not in other runtimes.

Good luck!

Commented Unassigned: Dubugging in V8 not working as expected [61]

$
0
0
I can connect with the debugger, which gives me source code but does not stop on breakpoints. It does yield the source code so I am sure I am connected, but the breakpoints do not work. I have followed the instructions in the readme and I have read a helpful blog from Satyendra Kumar Pandey http://pandeysk.wordpress.com/2014/05/25/debugging-with-clearscript/

Steps to reproduce
I have download the codebase and run the v8 setup script, I was able to get v8 up and running. I am just using the simple console application from you demo project. I can connect the the script engine using both eclipse and webstorm, neither one will stop at a break point. I have tried using the debugger key word and that does not stop debugging.





Comments: I have tried adding a debugger line, and I have tried adding a break point in the IDE. Nothing seemed to work.

New Post: Global window object

$
0
0
I just wanted to say THANKS for this amazing project. I am also working on a private, .NET-based DOM implementation and was previously using another .NET engine for JavaScript and have recently migrated my code to use ClearScript. The GlobalMembers flag is a godsend!

Commented Unassigned: Dubugging in V8 not working as expected [61]

$
0
0
I can connect with the debugger, which gives me source code but does not stop on breakpoints. It does yield the source code so I am sure I am connected, but the breakpoints do not work. I have followed the instructions in the readme and I have read a helpful blog from Satyendra Kumar Pandey http://pandeysk.wordpress.com/2014/05/25/debugging-with-clearscript/

Steps to reproduce
I have download the codebase and run the v8 setup script, I was able to get v8 up and running. I am just using the simple console application from you demo project. I can connect the the script engine using both eclipse and webstorm, neither one will stop at a break point. I have tried using the debugger key word and that does not stop debugging.





Comments: Are you still using just the unmodified ClearScriptConsole application? If so, where are you setting a breakpoint? That is, which line, of which script? If you're using another application or script, are you sure the script code with the breakpoint (or `debugger` statement) is being executed? So far we haven't been able to reproduce any issues, so any additional information you could provide might help.

New Post: Global window object

$
0
0
Thanks, krisoye!

GlobalMembers is an old Windows Script feature (see here) that ClearScript exposed early on when it supported only Windows Script engines, and then extended to V8 to achieve API parity.

The good news about GlobalMembers is that recent V8 drops have greatly reduced its performance impact, so if you're using it, stay tuned for the next ClearScript release :)

Cheers!

New Post: Using ClearScript. WebApplication problem

$
0
0
Hello,

I recently started using ClearScript. I have used ClearScript.Manager through Nuget package. I am using Visual Studio 2012. I could see 'ClearScriptV8-32'.dll', 'ClearScriptV8-64.dll', 'v8-ia32.dll' & 'v8-ia64.dll' added in the project. It got copied over to bin directory while running app. But I see below error:


Could not load file or assembly 'ClearScriptV8-32.dll' or one of its dependencies. The specified module could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'ClearScriptV8-32.dll' or one of its dependencies. The specified module could not be found.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[FileNotFoundException: Could not load file or assembly 'ClearScriptV8-32.dll' or one of its dependencies. The specified module could not be found.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'ClearScriptV8-32.dll' or one of its dependencies. The specified module could not be found.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): Could not load file or assembly 'ClearScriptV8-32.dll' or one of its dependencies. The specified module could not be found.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915300
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Am I missing anything here? I created a simple ASP.net application to test this. If you need, I can provide the source.

New Post: Using ClearScript. WebApplication problem

$
0
0
Update to above thread.

I am using Azure to deploy. It is working fine there.

New Post: Using ClearScript. WebApplication problem

$
0
0
Hi offshoredevpune,

A couple of suggestions:

  • Make sure that the "Copy to Output Directory" properties for those DLLs are set to "Do not copy". For some reason mixed-mode and native modules just don't work if copied to the bin directory. It appears to be an ASP.NET limitation.

  • Consider getting a newer version of ClearScript for more detailed error reporting in this specific scenario. If ClearScript fails to load any of those modules, it'll list the places it looked and the errors it encountered.
Thanks!

Commented Unassigned: Dubugging in V8 not working as expected [61]

$
0
0
I can connect with the debugger, which gives me source code but does not stop on breakpoints. It does yield the source code so I am sure I am connected, but the breakpoints do not work. I have followed the instructions in the readme and I have read a helpful blog from Satyendra Kumar Pandey http://pandeysk.wordpress.com/2014/05/25/debugging-with-clearscript/

Steps to reproduce
I have download the codebase and run the v8 setup script, I was able to get v8 up and running. I am just using the simple console application from you demo project. I can connect the the script engine using both eclipse and webstorm, neither one will stop at a break point. I have tried using the debugger key word and that does not stop debugging.





Comments: Ug, I guess it was user error. I modified the console app sample, to be a little different and I was able to get the debugging to work properly. I dont think the file was properly load the way I originally had it.
Viewing all 2297 articles
Browse latest View live




Latest Images