I've landed the last bits of bug 514280 which will help to enforce this.

Examples:

nsCOMPtr<MyRunnable> runnable = new MyRunnable();
NS_DispatchToMainThread(runnable);

This now fails to compile in debug builds. For simple cases like this just use nsCOMPtr<nsIRunnable> here. For more complex cases (calling non-interface methods) use nsRefPtr instead of nsCOMPtr, but note that this creates extra templating overhead for the compiler and linker.

nsCOMPtr<MyClass> instance = do_QueryInterface(aParam);

This was always incorrect code and will now fail to compile. I have filed bugs and landed workarounds for the instances we have of this in the current codebase. If you have a parameter of a base class of your class, and you can guarantee that it's an instance of your class, then you should simply static_cast the parameter into an nsRefPtr variable. If you can't guarantee that it's an instance of your class, then either give your class an CID (see nsStandardURL for an example) or give your class an IID and use do_QueryObject.

--
Warning: May contain traces of nuts.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to