Bug 43735 - C++ DOM binding classes with private structs need operator= overload
Summary: C++ DOM binding classes with private structs need operator= overload
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: Wx
Depends on:
Blocks:
 
Reported: 2010-08-09 11:35 PDT by Kevin Ollivier
Modified: 2010-08-11 05:31 PDT (History)
2 users (show)

See Also:


Attachments
Add operator= overloads to C++ DOM binding classes with private structs. (3.20 KB, patch)
2010-08-09 11:38 PDT, Kevin Ollivier
no flags Details | Formatted Diff | Diff
Patch updated with bindings test outputs updated. (7.79 KB, patch)
2010-08-09 21:48 PDT, Kevin Ollivier
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Ollivier 2010-08-09 11:35:13 PDT
C++ DOM binding classes which have a private struct that manages the WebCore pointer already have a copy constructor defined that passes the pointer properly, but they do not define operator= so outside of construction, assignment leads to a crash, since it does a simple copy of the private structure rather than creating a new one and assigning the pointer.
Comment 1 Kevin Ollivier 2010-08-09 11:38:30 PDT
Created attachment 63912 [details]
Add operator= overloads to C++ DOM binding classes with private structs.
Comment 2 Geoffrey Garen 2010-08-09 11:40:45 PDT
Are there cases where assignment is used like this? If so, you should be able to write a layout test.

If assignment is not used like this, I suggest just forbidding assignment, in the same way the Noncopyable class does.
Comment 3 Geoffrey Garen 2010-08-09 11:41:50 PDT
Comment on attachment 63912 [details]
Add operator= overloads to C++ DOM binding classes with private structs.

r- because the new code in this patch does not include a test.
Comment 4 Kevin Ollivier 2010-08-09 11:52:17 PDT
(In reply to comment #2)
> Are there cases where assignment is used like this? If so, you should be able to write a layout test.

Yes, I ran into this problem when generating Python wrappers for these bindings. The SWIG tool does something along these lines (code simplified to show the relevant bits):

WebDOMNode result;

{
    result = range->startContainer();
}
 
swigptr = new WebDOMNode(result);

The block assigning result has some extra error handling code, etc. which is why they isolate it in a code block.

As for the LayoutTest part, does WebDOM* have a test suite yet? If so I'll be happy to add a case for it.

> If assignment is not used like this, I suggest just forbidding assignment, in the same way the Noncopyable class does.

For a public API like the WebDOM* classes, I'm concerned that making the objects non-copyable would be pretty restrictive. (And, of course, it would really set me back on trying to get Python bindings working.)
Comment 5 Geoffrey Garen 2010-08-09 15:33:27 PDT
Comment on attachment 63912 [details]
Add operator= overloads to C++ DOM binding classes with private structs.

Okeedokee.

I don't think WebDOM* has a test suite yet. That's a shame, but it's not the fault of this patch.

r=me
Comment 6 Darin Adler 2010-08-09 16:12:20 PDT
Comment on attachment 63912 [details]
Add operator= overloads to C++ DOM binding classes with private structs.

You’ll need to update the test results checked in at the directory WebCore/bindings/cpp as well.
Comment 7 Kevin Ollivier 2010-08-09 21:48:47 PDT
Created attachment 63974 [details]
Patch updated with bindings test outputs updated.

Thanks for catching the bindings test updates! I didn't realize these were in the tree. New patch up now with them added.

Note that there are a couple other changes (with the ENABLE(Conditional)) in one of the test headers as well, this is from a change in a previous commit (the C++ DOM bindings wasn't enclosing the function definitions with the conditional #if, only their implementations) and the results are correct.
Comment 8 Adam Barth 2010-08-10 23:26:02 PDT
Comment on attachment 63974 [details]
Patch updated with bindings test outputs updated.

Forwarding ggaren's r+.
Comment 9 WebKit Commit Bot 2010-08-11 05:31:11 PDT
Comment on attachment 63974 [details]
Patch updated with bindings test outputs updated.

Clearing flags on attachment: 63974

Committed r65147: <http://trac.webkit.org/changeset/65147>
Comment 10 WebKit Commit Bot 2010-08-11 05:31:16 PDT
All reviewed patches have been landed.  Closing bug.