mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
Javascript Binding - Allow binding to classes in the global namespace (#3467)
* fix IsComplexType NullReferenceException Sometimes, the registered Javascript object does not have a namespace, at this time this function will throw a ```NullReferenceException```. * add unit test for IsComplexType * Simplify and remove useless code * Update CefSharp/Internals/JavascriptObjectRepository.cs Co-authored-by: campersau <buchholz.bastian@googlemail.com> Co-authored-by: Alex Maitland <amaitland@users.noreply.github.com> Co-authored-by: campersau <buchholz.bastian@googlemail.com>
This commit is contained in:
@@ -163,6 +163,7 @@
|
||||
<Compile Include="Framework\RequestContextFacts.cs" />
|
||||
<Compile Include="Framework\TestMemberInfo.cs" />
|
||||
<Compile Include="JavascriptBinding\IntegrationTestFacts.cs" />
|
||||
<Compile Include="JavascriptBinding\JavaScriptObjectRepositoryFacts.cs" />
|
||||
<Compile Include="OffScreen\OffScreenBrowserBasicFacts.cs" />
|
||||
<Compile Include="CefSharpXunitTestFramework.cs" />
|
||||
<Compile Include="CefSharpFixture.cs" />
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using CefSharp.Internals;
|
||||
using Xunit;
|
||||
|
||||
internal class NoNamespaceClass
|
||||
{
|
||||
public SomeElseClass SomeElseClass { get; set; }
|
||||
public int Year { get; set; }
|
||||
|
||||
public string GetExampleString()
|
||||
{
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
internal class SomeElseClass
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace CefSharp.Test.JavascriptBinding
|
||||
{
|
||||
public class JavaScriptObjectRepositoryFacts
|
||||
{
|
||||
[Fact]
|
||||
public void CanRegisterJavascriptObjectBindWhenNamespaceIsNull()
|
||||
{
|
||||
var javascriptObjectRepository = new JavascriptObjectRepository();
|
||||
var name = nameof(NoNamespaceClass);
|
||||
javascriptObjectRepository.Register(name, new NoNamespaceClass(), false, new BindingOptions() { });
|
||||
Assert.True(javascriptObjectRepository.IsBound(name));
|
||||
|
||||
var result = ((IJavascriptObjectRepositoryInternal)javascriptObjectRepository).TryCallMethod(1, "getExampleString", new object[0]);
|
||||
Assert.True(result.Success);
|
||||
Assert.Equal("ok", result.ReturnValue.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,7 +738,7 @@ namespace CefSharp.Internals
|
||||
baseType = Nullable.GetUnderlyingType(type);
|
||||
}
|
||||
|
||||
if (baseType == null || baseType.IsArray || baseType.Namespace.StartsWith("System"))
|
||||
if (baseType == null || baseType.IsArray || baseType.Namespace?.StartsWith("System") == true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user