Jonas Sicking writes:

> On Sun, Aug 2, 2015 at 3:47 AM, Xidorn Quan <quanxunz...@gmail.com> wrote:
>> Probably we should generally avoid using constructor directly for
>> those cases. Instead, use helper functions like MakeUnique() or
>> MakeAndAddRef(), which is much safer.
>
> We used to have NS_NewFoo() objects all over the codebase. A lot of
> those were removed as part of deCOMtamination efforts.
>
> Personally I think being able to directly call the constructor has
> made for much easier to read code. Definitely worth the risk of
> refcount errors.

Definitely easier to read than

  nsresult NS_NewFoo(getter_AddRefs(foo))

and perhaps arguably easier to read than

  already_AddRefed<T> MakeAndAddRef<Foo>()

but I don't see much advantage of public constructors over
something like

  static already_AddRefed<Foo> Foo::Create()

or

  static nsRefPtr<Foo> Foo::Make()

Constructors also have the potentially awkward feature of never
failing, and hence the abundance of separate Init() methods.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to