mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 19:25:01 +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:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user