Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebinding external function in JS causes #21

Open
oconnor663 opened this issue Apr 30, 2012 · 3 comments
Open

Rebinding external function in JS causes #21

oconnor663 opened this issue Apr 30, 2012 · 3 comments

Comments

@oconnor663
Copy link

I did the following by accident:

  • Expose a C# object using CEF.RegisterJSObject.
  • In JS, bind a function from that object onto a different, ordinary JS object.
  • Call the function in that context.
  • Crash!

This is obviously unsupported behavior, but it probably should just cause a JS error, instead of crashing the whole app. Here's the exception.

System.NullReferenceException was unhandled
Message: Object reference not set to an instance of an object.

    CefSharp.dll!gcroot<System::Object ^>::operator System::Object ^() Line 113 C++
    CefSharp.dll!CefSharp::BindingData::Get() Line 22 + 0xc bytes   C++
    CefSharp.dll!CefSharp::BindingHandler::Execute(CefStringBase<CefStringTraitsUTF16>& name, CefRefPtr<CefV8Value>* object, std::vector<CefRefPtr<CefV8Value>,std::allocator<CefRefPtr<CefV8Value> > >& arguments, CefRefPtr<CefV8Value>& retval, CefStringBase<CefStringTraitsUTF16>& exception) Line 130 + 0x1e bytes    C++
    [External Code] 
@ataranto
Copy link
Owner

Good find, will take a look throwing an exception for this case.

@ataranto
Copy link
Owner

ataranto commented May 1, 2012

Not clear on what you mean by "that object" and "the function". Can you clarify of post a small code example?

@oconnor663
Copy link
Author

Sure, I should've done that from the beginning:

/*
 * Instantiate a WebView and register a simple JS object
 */
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        CEF.RegisterJsObject("test", new Test());
        WebView v = new WebView(
            @"C:\Users\jacko\Desktop\test.html",
            new CefSharp.BrowserSettings());
        v.Parent = this;
        v.Dock = DockStyle.Fill;
    }
}

class Test
{
    public int returnThree()
    {
        return 3;
    }
}
<!-- test.html: This causes the app to crash! -->
<html><body><script>
var regularObject = {};
// bind the native method to the JS object
regularObject.returnThree = test.returnThree;
// call it from the JS object
regularObject.returnThree();
// CRASH!!!
</script></body></html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants