diff --git a/dom/docs/workersAndStorage/CodeStyle.rst b/dom/docs/workersAndStorage/CodeStyle.rst index 6de6ab828a51..316e5b976834 100644 --- a/dom/docs/workersAndStorage/CodeStyle.rst +++ b/dom/docs/workersAndStorage/CodeStyle.rst @@ -164,8 +164,11 @@ We extend this by some more encouragements and discouragements: which will make the type information available in searchfox. In consequence, the guidelines might be amended to promote a more widespread use of ``auto``. +Pointer types +------------- + Plain pointers --------------- +~~~~~~~~~~~~~~ The use of plain pointers is error-prone. Avoid using owning plain pointers. In particular, avoid using literal, non-placement new. There are various kinds @@ -186,6 +189,20 @@ factory functions: | ``std::shared_ptr`` | ``std::make_shared`` | ```` | +------------------------+-------------------------+------------------------+ +Also, to create an ``already_AddRefed<>`` to pass as a parameter or return from +a function without the need to dereference it, use ``MakeAndAddRef`` instead of +creating a dereferenceable ``RefPtr`` (or similar) first and then using +``.forget()``. + +Smart pointers +~~~~~~~~~~~~~~ + +In function signatures, prefer accepting or returning ``RefPtr`` instead of +``already_AddRefed`` in conjunction with regular ``std::move`` rather than +``.forget()``. This improves readability and code generation. Prevailing +legimitate uses of ``already_AddRefed`` are described in its +`documentation `_. + Evolution Process =================