Skip to content

Commit

Permalink
Core - Improve JavascriptObjectRepository.TryCallMethod Object Not Fo…
Browse files Browse the repository at this point in the history
…und error message

- Add method name and param count

Resolves #4209
  • Loading branch information
amaitland committed Aug 21, 2022
1 parent 0131024 commit 2ead423
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CefSharp.Test/JavascriptBinding/JavaScriptObjectRepositoryFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public void CanRegisterJavascriptObjectBindWhenNamespaceIsNull()
Assert.Equal("ok", result.ReturnValue.ToString());
}

[Fact]
public void ShouldReturnErrorMessageForObjectInvalidId()
{
IJavascriptObjectRepositoryInternal javascriptObjectRepository = new JavascriptObjectRepository();

var result = javascriptObjectRepository.TryCallMethod(100, "getExampleString", new object[0]);
Assert.False(result.Success);
Assert.StartsWith("Object Not Found Matching Id", result.Exception);
}

#if !NETCOREAPP
[Fact]
public void CanRegisterJavascriptObjectPropertyBindWhenNamespaceIsNull()
Expand Down
4 changes: 3 additions & 1 deletion CefSharp/Internals/JavascriptObjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ protected virtual TryCallMethodResult TryCallMethod(long objectId, string name,

if (!objects.TryGetValue(objectId, out obj))
{
return new TryCallMethodResult(false, result, "Object Not Found Matching Id:" + objectId);
var paramCount = parameters == null ? 0 : parameters.Length;

return new TryCallMethodResult(false, result, $"Object Not Found Matching Id:{objectId}, MethodName:{name}, ParamCount:{paramCount}");
}

var method = obj.Methods.FirstOrDefault(p => p.JavascriptName == name);
Expand Down

0 comments on commit 2ead423

Please sign in to comment.