diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-16 11:45:35 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-17 08:59:23 +0000 |
commit | 552906b0f222c5d5dd11b9fd73829d510980461a (patch) | |
tree | 3a11e6ed0538a81dd83b20cf3a4783e297f26d91 /chromium/styleguide | |
parent | 1b05827804eaf047779b597718c03e7d38344261 (diff) | |
download | qtwebengine-chromium-552906b0f222c5d5dd11b9fd73829d510980461a.tar.gz |
BASELINE: Update Chromium to 83.0.4103.122
Change-Id: Ie3a82f5bb0076eec2a7c6a6162326b4301ee291e
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/styleguide')
-rw-r--r-- | chromium/styleguide/c++/blink-c++.md | 55 | ||||
-rw-r--r-- | chromium/styleguide/c++/c++-dos-and-donts.md | 2 | ||||
-rw-r--r-- | chromium/styleguide/c++/c++.md | 2 | ||||
-rw-r--r-- | chromium/styleguide/python/OWNERS | 1 | ||||
-rw-r--r-- | chromium/styleguide/python/blink-python.md | 2 | ||||
-rw-r--r-- | chromium/styleguide/python/python.md | 48 | ||||
-rw-r--r-- | chromium/styleguide/web/OWNERS | 1 | ||||
-rw-r--r-- | chromium/styleguide/web/es.md | 79 |
8 files changed, 128 insertions, 62 deletions
diff --git a/chromium/styleguide/c++/blink-c++.md b/chromium/styleguide/c++/blink-c++.md index 47db5ac9045..b67e0244b90 100644 --- a/chromium/styleguide/c++/blink-c++.md +++ b/chromium/styleguide/c++/blink-c++.md @@ -54,6 +54,61 @@ using appropriate smart pointers and handles (`std::unique_ptr`, `scoped_refptr` and strong Blink GC references, respectively). See [How Blink Works](https://docs.google.com/document/d/1aitSOucL0VHZa9Z2vbRJSyAIsAz24kX8LFByQ5xQnUg/edit#heading=h.ekwf97my4bgf) for more information. +## Don't mix Create() factory methods and public constructors in one class. + +A class only can have either Create() factory functions or public constructors. +In case you want to call MakeGarbageCollected<> from a Create() method, a +PassKey pattern can be used. Note that the auto-generated binding classes keep +using Create() methods consistently. + +**Good:** +```c++ +class HistoryItem { + public: + HistoryItem(); + ~HistoryItem(); + ... +} + +void DocumentLoader::SetHistoryItemStateForCommit() { + history_item_ = MakeGarbageCollected<HistoryItem>(); + ... +} +``` + +**Good:** +```c++ +class BodyStreamBuffer { + public: + using PassKey = util::PassKey<BodyStreamBuffer>; + static BodyStreamBuffer* Create(); + + BodyStreamBuffer(PassKey); + ... +} + +BodyStreamBuffer* BodyStreamBuffer::Create() { + auto* buffer = MakeGarbageCollected<BodyStreamBuffer>(PassKey()); + buffer->Init(); + return buffer; +} + +BodyStreamBuffer::BodyStreamBuffer(PassKey) {} +``` + +**Bad:** +```c++ +class HistoryItem { + public: + // Create() and a public constructor should not be mixed. + static HistoryItem* Create() { return MakeGarbageCollected<HistoryItem>(); } + + HistoryItem(); + ~HistoryItem(); + ... +} +``` + ## Naming ### Use `CamelCase` for all function names diff --git a/chromium/styleguide/c++/c++-dos-and-donts.md b/chromium/styleguide/c++/c++-dos-and-donts.md index f7906662224..28e432ee279 100644 --- a/chromium/styleguide/c++/c++-dos-and-donts.md +++ b/chromium/styleguide/c++/c++-dos-and-donts.md @@ -80,7 +80,7 @@ general rules: ```cpp MyClass c(1.7, false, "test"); - std::vector<double> v(500, 0.97); // Creates 50 copies of the provided initializer + std::vector<double> v(500, 0.97); // Creates 500 copies of the provided initializer ``` 3. Use C++11 "uniform init" syntax ("{}" without '=') only when neither of the above work: diff --git a/chromium/styleguide/c++/c++.md b/chromium/styleguide/c++/c++.md index a624a866130..5fec3c4349d 100644 --- a/chromium/styleguide/c++/c++.md +++ b/chromium/styleguide/c++/c++.md @@ -16,7 +16,7 @@ You can propose changes to this style guide by sending an email to request review for a change to this file. If there's no consensus, `src/styleguide/c++/OWNERS` get to decide. -Blink code in `third_party/WebKit` uses [Blink style](blink-c++.md). +Blink code in `third_party/blink` uses [Blink style](blink-c++.md). ## Modern C++ features diff --git a/chromium/styleguide/python/OWNERS b/chromium/styleguide/python/OWNERS index bf7129f19f0..3dd24727e2b 100644 --- a/chromium/styleguide/python/OWNERS +++ b/chromium/styleguide/python/OWNERS @@ -1,6 +1,5 @@ agrieve@chromium.org dpranke@chromium.org -estevenson@chromium.org jbudorick@chromium.org wnwen@chromium.org diff --git a/chromium/styleguide/python/blink-python.md b/chromium/styleguide/python/blink-python.md index f37dd42e7aa..931c4bc2caf 100644 --- a/chromium/styleguide/python/blink-python.md +++ b/chromium/styleguide/python/blink-python.md @@ -14,5 +14,3 @@ style recommendation is likely to change._ ## Differences from Chromium style * Line length limit is 132 -* Uses four-space indent -* Uses `function_name`, `method_name` rather than `FunctionName`, `MethodName` diff --git a/chromium/styleguide/python/python.md b/chromium/styleguide/python/python.md index 12f2c52aaba..f56902dbe85 100644 --- a/chromium/styleguide/python/python.md +++ b/chromium/styleguide/python/python.md @@ -1,34 +1,38 @@ -# Chromium Python style guide +# Chromium Python Style Guide _For other languages, please see the [Chromium style guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md)._ -Chromium follows [PEP-8](https://www.python.org/dev/peps/pep-0008/) unless an -exception is listed below. +Chromium follows [PEP-8](https://www.python.org/dev/peps/pep-0008/). -See also the [Chromium OS Python Style -Guidelines](https://sites.google.com/a/chromium.org/dev/chromium-os/python-style-guidelines). +It is also encouraged to follow advice from +[Google's Python Style Guide](https://google.github.io/styleguide/pyguide.html), +which is a superset of PEP-8. -You can propose changes to this style guide by sending an email to -`python@chromium.org`. Ideally, the list will arrive at some consensus and you -can request review for a change to this file. If there's no consensus, -[`//styleguide/python/OWNERS`](https://chromium.googlesource.com/chromium/src/+/master/styleguide/python/OWNERS) -get to decide. - -Blink code in `third_party/blink` uses [Blink style](blink-python.md). +See also: +* [Chromium OS Python Style Guide](https://sites.google.com/a/chromium.org/dev/chromium-os/python-style-guidelines) +* [Blink Python Style Guide](blink-python.md) [TOC] -## Differences from PEP-8 +## Our Previous Python Style +Chromium used to differ from PEP-8 in the following ways: * Use two-space indentation instead of four-space indentation. * Use `CamelCase()` method and function names instead of `unix_hacker_style()` names. +* 80 character line limits rather than 79. -(The rationale for these is mostly legacy: the code was originally written -following Google's internal style guideline, the cost of updating all of the -code to PEP-8 compliance was not small, and consistency was seen to be a -greater virtue than compliance.) +New scripts should not follow these deviations, but they should be followed when +making changes to files that follow them. + +## Making Style Guide Changes + +You can propose changes to this style guide by sending an email to +`python@chromium.org`. Ideally, the list will arrive at some consensus and you +can request review for a change to this file. If there's no consensus, +[`//styleguide/python/OWNERS`](https://chromium.googlesource.com/chromium/src/+/master/styleguide/python/OWNERS) +get to decide. ## Tools @@ -49,7 +53,7 @@ Directories can opt into enforcing auto-formatting by adding a `.style.yapf` file with the following contents: ``` [style] -based_on_style = chromium +based_on_style = pep8 ``` Entire files can be formatted (rather than just touched lines) via: @@ -57,6 +61,14 @@ Entire files can be formatted (rather than just touched lines) via: git cl format --python --full ``` +YAPF has gotchas. You should review its changes before submitting. Notably: + * It does not re-wrap comments. + * It won't insert characters in order wrap lines. You might need to add ()s + yourself in order to have to wrap long lines for you. + * It formats lists differently depending on whether or not they end with a + trailing comma. + + #### Bugs * Are tracked here: https://github.com/google/yapf/issues. * For Chromium-specific bugs, please discuss on `python@chromium.org`. diff --git a/chromium/styleguide/web/OWNERS b/chromium/styleguide/web/OWNERS index 6aad1e89052..d7e4f49972e 100644 --- a/chromium/styleguide/web/OWNERS +++ b/chromium/styleguide/web/OWNERS @@ -1,4 +1,3 @@ # Interested in helping maintain this? Let us know! -dbeam@chromium.org dpapad@chromium.org michaelpg@chromium.org diff --git a/chromium/styleguide/web/es.md b/chromium/styleguide/web/es.md index e1ef98ad06f..ab52d3fca29 100644 --- a/chromium/styleguide/web/es.md +++ b/chromium/styleguide/web/es.md @@ -588,6 +588,47 @@ section. --- +### Object Literal Extensions + +Convenient new ways for object property definition. + +**Usage Example:** + +```js +// Computed property name +const prop = 'foo'; +const o = { + [prop]: 'hey', + ['b' + 'ar']: 'there', +}; +console.log(o); // {foo: 'hey', bar: 'there'} + +// Shorthand property +const foo = 1; +const bar = 2; +const o = {foo, bar}; +console.log(o); // {foo: 1, bar: 2} + +// Method property +const clearSky = { + // Basically the same as clouds: function() { return 0; }. + clouds() { return 0; }, + color() { return 'blue'; }, +}; +console.log(clearSky.color()); // 'blue' +console.log(clearSky.clouds()); // 0 +``` + +**Documentation:** [link](https://tc39.github.io/ecma262/#sec-object-initialiser) +[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer) + +**Discussion Notes / Link to Thread:** +https://groups.google.com/a/chromium.org/d/msg/chromium-dev/RqOdTlxuGVg/M7I0CTryDQAJ + +Note: clang-format has some issues formatting complex computed property names. + +--- + ## Banned Features The following features are banned for Chromium development. @@ -655,44 +696,6 @@ hide(document.body, false); // Not animated. --- -### Object Literal Extensions - -Convenient new ways for object property definition. - -**Usage Example:** - -```js -// Computed property name -const prop = 'foo'; -const o = { - [prop]: 'hey', - ['b' + 'ar']: 'there', -}; -console.log(o); // {foo: 'hey', bar: 'there'} - -// Shorthand property -const foo = 1; -const bar = 2; -const o = {foo, bar}; -console.log(o); // {foo: 1, bar: 2} - -// Method property -const clearSky = { - // Basically the same as clouds: function() { return 0; }. - clouds() { return 0; }, - color() { return 'blue'; }, -}; -console.log(clearSky.color()); // 'blue' -console.log(clearSky.clouds()); // 0 -``` - -**Documentation:** [link](https://tc39.github.io/ecma262/#sec-object-initialiser) -[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer) - -**Discussion Notes / Link to Thread:** - ---- - ### Binary & Octal Literals **Usage Example:** |