ataranto / CefSharp

.Net binding for the Chromium Embedded Framework
Other
62 stars 34 forks source link

Rebinding external function in JS causes #21

Open oconnor663 opened 12 years ago

oconnor663 commented 12 years ago

I did the following by accident:

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 commented 12 years ago

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

ataranto commented 12 years ago

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

oconnor663 commented 12 years ago

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>