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

New Post: Call known method by name

0
0
OK the issue has been resolved.

In a VWG application with CLR Exception Breaking on, the error is thrown multiple times, but you can continue past them.

It also appears that creating a ScriptEngine in a VWG form constructor is bad.

Thanks for the help and sorry to bother you.

New Post: Call known method by name

0
0
You're absolutely right! The C# Runtime Binder throws exceptions and handles them internally. This is all by design and happens on "normal" .NET as well.

Thanks!

Created Unassigned: Property with modifier [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you

Commented Unassigned: Property with modifier [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you
Comments: And also, I found out that, ClearScript is trying to load all of the assemblies inside .net framework installation directory at the first launching. The case here is that, I have a lot of websites/wcf services in my local IIS. "Temporary ASP.NET Files" folder contains a lot of temporary dlls. Then the first loading almost spent me more than 10 mins. Thought that it got crashed...

Edited Unassigned: Property with modifier [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you

Commented Unassigned: Property with modifier [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you
Comments: Hello! The issue with the private setter is indeed a ClearScript bug, and we'll use this report to track it. In the meantime, if you're the developer of `SomeObject`, you can use ClearScript's `ScriptMemberAttribute` to make properties read-only for scripting: ``` C# [ScriptMember(ScriptAccess.ReadOnly)] public string Name { get { return this._name; } private set { this._name = value; } } ``` About the interface issue, here's what you want to do: ``` C# IInterface obj = new SomeObject(); engine.AddRestrictedHostObject("O", obj); ``` Finally, the assembly loading issue you're seeing is probably related to a ClearScript feature that is optional. Are you by any chance exposing assemblies by specifying their short names? Here's how that might look in your code: ``` C# new HostTypeCollection("mscorlib") ``` If you can reproduce this issue, can you break in while it's happening and post a stack? Thanks!

Edited Unassigned: Restricted access to non-public property accessors is not enforced [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you

Edited Unassigned: Non-public accessors of public properties are not correctly restricted [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you

Edited Issue: Non-public accessors of public properties are not correctly restricted [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you

Edited Issue: Non-public accessors of public properties is not enforced [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you

Edited Issue: Restricted access to non-public accessors of public properties is not enforced [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you

Commented Issue: Restricted access to non-public accessors of public properties is not enforced [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you
Comments: Hi, thank you so much. I was thinking that I can introduce a proxy pattern to expose an interface. It also can limit the access of non-public properties. Talking about the assembly loading issue. I did break into ClearScript source code. Microsoft.ClearScript.Util.AssemblyHelpers is trying to load every assembly at the first launching if "AssemblyTable.bin" doesn't exist. You may check out AssemblyHelpers.BuildAssemblyTable(). But anyway, it's not a bug. It's just not that responsive with my computer which has a lot of dlls in "Temporary ASP.NET Files". Thank you for you helping.

Created Unassigned: Passing null to overloaded methods. [72]

0
0
Hi, I'm having another issue with passing null to overloaded methods. Here's code sample.
```

public class SimpleObject
{
public string Name { get; set; }
}

public static class LogWriter
{
public static void WriteLine(string message)
{
Console.WriteLine(message);
}

public static void WriteLine(Exception e)
{
if (e == null) Console.WriteLine(string.Empty);
else Console.WriteLine(string.Format("Exception: {0}\n{1}", e.Message, e.StackTrace));
}
}

```
Exposing "SimpleObject" and "LogWriter"
```
Engine.AddHostObject("SimpleObject", new SimpleObject());
Engine.AddHostType("Logger", typeof(LogWriter));
```
Then I will get error by scripting "Logger.WriteLine(SimpleObject.Name)".

The call is ambiguous between the following methods or properties:
'ConsoleApplication1.LogWriter.WriteLine(string)' and 'ConsoleApplication1.LogWr
iter.WriteLine(System.Exception)'

Is that missing converting the value of the property to property type? In this case, it should be (string)null.

Thank you!

Edited Unassigned: Passing null to overloaded methods. [72]

0
0
Hi, I'm having another issue with passing null to overloaded methods. Here's code sample.
```

public class SimpleObject
{
public string Name { get; set; }
public string GetName()
{
return null;
}
}

public static class LogWriter
{
public static void WriteLine(string message)
{
Console.WriteLine(message);
}

public static void WriteLine(Exception e)
{
if (e == null) Console.WriteLine(string.Empty);
else Console.WriteLine(string.Format("Exception: {0}\n{1}", e.Message, e.StackTrace));
}
}

```
Exposing "SimpleObject" and "LogWriter"
```
Engine.AddHostObject("SimpleObject", new SimpleObject());
Engine.AddHostType("Logger", typeof(LogWriter));
```
Then I will get error by scripting "Logger.WriteLine(SimpleObject.Name)" or "Logger.WriteLine(SimpleObject.GetName())".

The call is ambiguous between the following methods or properties:
'ConsoleApplication1.LogWriter.WriteLine(string)' and 'ConsoleApplication1.LogWr
iter.WriteLine(System.Exception)'

Is that missing converting the value of the property/return value of the method to property type/method return type? In this case, it should be (string)null.

Thank you!

Commented Issue: Restricted access to non-public accessors of public properties is not enforced [71]

0
0
Hi, I'm having an issue with exposed host object which has a property with public getter and private setter.
For example, I can put a script like "SomeObject.Name = ...". Is there a way to prevent this?

```
public class SomeObject
{
private string _name;
public string Name
{
get { return this._name; }
private set { this._name = value; }
}
}
```

And also, If I try to expose an object instance as interface, I still be able to access to the object's members.
For example,
```
public class SomeObject : IInterface
{
private string _name;
public string Name
{
get { return this.Name; }
private set { this._name = value; }
}

public string ToSomeString()
{
return this._name;
}
}

public interface IInterface
{
string ToSomeString();
}
```
```
IInterface obj = new SomeObject();
Engine.AddHostObject("O", obj);
```

I can put script like O.Name = “A”.

Thank you
Comments: Hi again, ​ >I was thinking that I can introduce a proxy pattern to expose an interface. It also can limit the access of non-public properties. ​ Yes, that's certainly an option, but we'll fix the non-public getter/setter issue anyway :) ​ >Microsoft.ClearScript.Util.AssemblyHelpers is trying to load every assembly at the first launching if "AssemblyTable.bin" doesn't exist. ​ Yes, but it should only do that if you're loading or exposing one or more assemblies by name. There are several ways to do that in ClearScript, but you can always avoid it by specifying preloaded assemblies instead. In fact, that's our recommendation for web applications. Thanks again, and good luck!

New Post: Retrieving javascript line index during execution

0
0
Slight update in case anyone experiences same problem,

It turns out the problem wasn't in supporting code, but rather with the 5.4.0 version.

In 5.4.0 V8ScriptEngine.Script.getStackTrace() throws
RuntimeBinderException: 'Microsoft.ClearScript.V8.V8ScriptItem' does not contain a definition for 'EngineInternal'
In 5.4.1 it works properly. Something related to V8 debugging has changed in this version though so beware when upgrading (our custom debugger which was working fine on 5.4.0 doesn't work anymore)

P.S.
We are using assemblies from the ClearScript.Install NuGet package.

New Post: Retrieving javascript line index during execution

0
0
Hi again,

In 5.4.0 V8ScriptEngine.Script.getStackTrace() throws
RuntimeBinderException: 'Microsoft.ClearScript.V8.V8ScriptItem' does not contain a definition for 'EngineInternal'

Actually exceptions like that are often thrown and handled internally during C# dynamic operations, with or without ClearScript's involvement. If you see an exception like that in the debugger, you should be able to continue safely.

Something related to V8 debugging has changed in this version though so beware when upgrading (our custom debugger which was working fine on 5.4.0 doesn't work anymore)

ClearScript 5.4.1 does have a new V8 debug agent. The old one was built into V8, but the V8 team removed it a while back. If you're encountering issues with the new one, we'd love to hear the details.

Thanks!

Commented Unassigned: Passing null to overloaded methods. [72]

0
0
Hi, I'm having another issue with passing null to overloaded methods. Here's code sample.
```

public class SimpleObject
{
public string Name { get; set; }
public string GetName()
{
return null;
}
}

public static class LogWriter
{
public static void WriteLine(string message)
{
Console.WriteLine(message);
}

public static void WriteLine(Exception e)
{
if (e == null) Console.WriteLine(string.Empty);
else Console.WriteLine(string.Format("Exception: {0}\n{1}", e.Message, e.StackTrace));
}
}

```
Exposing "SimpleObject" and "LogWriter"
```
Engine.AddHostObject("SimpleObject", new SimpleObject());
Engine.AddHostType("Logger", typeof(LogWriter));
```
Then I will get error by scripting "Logger.WriteLine(SimpleObject.Name)" or "Logger.WriteLine(SimpleObject.GetName())".

The call is ambiguous between the following methods or properties:
'ConsoleApplication1.LogWriter.WriteLine(string)' and 'ConsoleApplication1.LogWr
iter.WriteLine(System.Exception)'

Is that missing converting the value of the property/return value of the method to property type/method return type? In this case, it should be (string)null.

Thank you!
Comments: Ah, you found one of ClearScript's dark corners :) ​ >Is that missing converting the value of the property/return value of the method to property type/method return type? ​ Not exactly. It's simply that `null`'s runtime type is ambiguous. C# can use static typing to select the correct `WriteLine` overload, but that's not an option here. Note that this isn't unique to `null`. Any managed object can match a parameter of the same type, one of its base types, or one of its interfaces. ClearScript normally deals with this by packaging return values with their declared types when they're different from their runtime types. The problem is that ClearScript does __not__ do this for `null`, and that's by design. The reason is that doing so would make `null` results [_truthy_](http://www.codeproject.com/Articles/713894/Truthy-Vs-Falsy-Values-in-JavaScript) and not easily recognizable on the JavaScript side. We'll take another look at this issue; thanks for reporting it. In the meantime, it's not elegant, but you can use a _host variable_ to invoke the correct method: ``` C# engine.AddHostObject("host", new HostFunctions()); engine.AddHostType("CLRString", typeof(string)); // don't hide JS String engine.Execute(@" Logger.WriteLine(host.newVar(CLRString, SimpleObject.Name)) "); ``` Good luck!

Edited Issue: Ambiguity when passing null to overloaded methods [72]

0
0
Hi, I'm having another issue with passing null to overloaded methods. Here's code sample.
```

public class SimpleObject
{
public string Name { get; set; }
public string GetName()
{
return null;
}
}

public static class LogWriter
{
public static void WriteLine(string message)
{
Console.WriteLine(message);
}

public static void WriteLine(Exception e)
{
if (e == null) Console.WriteLine(string.Empty);
else Console.WriteLine(string.Format("Exception: {0}\n{1}", e.Message, e.StackTrace));
}
}

```
Exposing "SimpleObject" and "LogWriter"
```
Engine.AddHostObject("SimpleObject", new SimpleObject());
Engine.AddHostType("Logger", typeof(LogWriter));
```
Then I will get error by scripting "Logger.WriteLine(SimpleObject.Name)" or "Logger.WriteLine(SimpleObject.GetName())".

The call is ambiguous between the following methods or properties:
'ConsoleApplication1.LogWriter.WriteLine(string)' and 'ConsoleApplication1.LogWr
iter.WriteLine(System.Exception)'

Is that missing converting the value of the property/return value of the method to property type/method return type? In this case, it should be (string)null.

Thank you!

New Post: ClearScript build error

0
0
Hi,
I'm unable to build ClearScript with V8. I have VS 2013 on Windows Server 2012.
I have run the V8Update command using VS2013 Command Prompt (x64 Cross Tools).

On trying to build ClearScript solution, I run into this error:
Error 102 error MSB6006: "cmd.exe" exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets 170 5 ClearScriptV8-32
Error 103 error MSB6006: "cmd.exe" exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets 170 5 ClearScriptV8-64

What am I missing here?
Thanks.
Viewing all 2297 articles
Browse latest View live




Latest Images