[webkit-dev] Lets use PassRefPtr for arguments less; lets use RefPtr for locals and data members more
ap at webkit.org
Sat Jun 18 22:47:55 PDT 2011
18.06.2011, в 22:15, Maciej Stachowiak написал(а):
> - I think having a rule for using PassRefPtr for arguments that depends on how callers use the function is likely to be hard to use in practice, since it requires global knowledge of all callers to pick the right function signature. The rule I prefer is that if a function takes ownership of the argument, whether or not we currently have a caller that gives away ownership, the function should take PassRefPtr. If it does not take ownership, it should take a raw pointer. That way you can decide the right thing to do based solely on the definition of the function itself.
Using PassRefPtr for arguments is a fairly common source of bugs. The way it's zeroed out after being used has caused crashes in code paths that weren't tested before commit for some reason (see e.g. <https://bugs.webkit.org/show_bug.cgi?id=52981>). Another example that we've just seen (<https://bugs.webkit.org/show_bug.cgi?id=62836>) was when a different compiler had a different order of evaluation, so building with it suddenly exposed a crash that we didn't need to have.
Looking at either bug, using PassRefPtr is pointless. For trace(), we could theoretically pass ownership from jsConsolePrototypeFunctionTrace(), but we do not, and micro-optimizing Console functions for performance isn't worth the cost of having had this crasher bug in my opinion. For bug 62836, it's quite clearly impossible to pass ownership to HTMLTableRowsCollection.
- WBR, Alexey Proskuryakov
More information about the webkit-dev