Commit cf4f2dd4 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

Blink style: Make mutable reference arguments optional and link to thread.

Per blink-dev thread:
https://groups.google.com/a/chromium.org/d/msg/blink-dev/O7R4YwyPIHc/1SXD1UCOCAAJ

Change-Id: I2d1d7079394449d369f6520de0fa73f98ee2e239
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1530501Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658789}
parent 005d0c60
......@@ -8,43 +8,20 @@ differs from Google style.
[TOC]
## Use references for all non-null pointer arguments
Pointer arguments that can never be null should be passed as a reference, even
if this results in a mutable reference argument.
## May use mutable reference arguments
> Note: Even though Google style prohibits mutable reference arguments, Blink
style explicitly permits their use.
Mutable reference arguments are permitted in Blink, in contrast to Google style.
**Good:**
> Note: This rule is under [discussion](https://groups.google.com/a/chromium.org/d/msg/blink-dev/O7R4YwyPIHc/mJyEyJs-EAAJ).
**OK:**
```c++
// Passed by mutable reference since |frame| is assumed to be non-null.
// May be passed by mutable reference since |frame| is assumed to be non-null.
FrameLoader::FrameLoader(LocalFrame& frame)
: frame_(&frame),
progress_tracker_(ProgressTracker::Create(frame)) {
// ...
}
// Optional arguments should still be passed by pointer.
void LocalFrame::SetDOMWindow(LocalDOMWindow* dom_window) {
if (dom_window)
GetScriptController().ClearWindowProxy();
if (this->DomWindow())
this->DomWindow()->Reset();
dom_window_ = dom_window;
}
```
**Bad:**
```c++
// Since the constructor assumes that |frame| is never null, it should be
// passed as a mutable reference.
FrameLoader::FrameLoader(LocalFrame* frame)
: frame_(frame),
progress_tracker_(ProgressTracker::Create(frame)) {
DCHECK(frame_);
// ...
}
```
## Prefer WTF types over STL and base types
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment