Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 4a19a9b

Browse files
committed
meta: merge node/master into node-chakracore/master
Merge fff4272 as of 2017-12-03 This commit was automatically generated. For any problems, please contact jackhorton Reviewed-By: Taylor Woll <taylor.woll@microsoft.com>
2 parents a1eb4f9 + fff4272 commit 4a19a9b

File tree

2 files changed

+71
-68
lines changed

2 files changed

+71
-68
lines changed

CPP_STYLE_GUIDE.md

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,33 @@
22

33
## Table of Contents
44

5-
* [Left-leaning (C++ style) asterisks for pointer declarations](#left-leaning-c-style-asterisks-for-pointer-declarations)
6-
* [2 spaces of indentation for blocks or bodies of conditionals](#2-spaces-of-indentation-for-blocks-or-bodies-of-conditionals)
7-
* [4 spaces of indentation for statement continuations](#4-spaces-of-indentation-for-statement-continuations)
8-
* [Align function arguments vertically](#align-function-arguments-vertically)
9-
* [Initialization lists](#initialization-lists)
10-
* [CamelCase for methods, functions, and classes](#camelcase-for-methods-functions-and-classes)
11-
* [snake\_case for local variables and parameters](#snake_case-for-local-variables-and-parameters)
12-
* [snake\_case\_ for private class fields](#snake_case_-for-private-class-fields)
13-
* [Space after `template`](#space-after-template)
14-
* [Type casting](#type-casting)
15-
* [Memory allocation](#memory-allocation)
16-
* [`nullptr` instead of `NULL` or `0`](#nullptr-instead-of-null-or-0)
17-
* [Do not include `*.h` if `*-inl.h` has already been included](#do-not-include-h-if--inlh-has-already-been-included)
18-
* [Avoid throwing JavaScript errors in nested C++ methods](#avoid-throwing-javascript-errors-in-nested-c-methods)
19-
* [Ownership and Smart Pointers](#ownership-and-smart-pointers)
5+
* [Formatting](#formatting)
6+
* [Left-leaning (C++ style) asterisks for pointer declarations](#left-leaning-c-style-asterisks-for-pointer-declarations)
7+
* [2 spaces of indentation for blocks or bodies of conditionals](#2-spaces-of-indentation-for-blocks-or-bodies-of-conditionals)
8+
* [4 spaces of indentation for statement continuations](#4-spaces-of-indentation-for-statement-continuations)
9+
* [Align function arguments vertically](#align-function-arguments-vertically)
10+
* [Initialization lists](#initialization-lists)
11+
* [CamelCase for methods, functions and classes](#camelcase-for-methods-functions-and-classes)
12+
* [snake\_case for local variables and parameters](#snake_case-for-local-variables-and-parameters)
13+
* [snake\_case\_ for private class fields](#snake_case_-for-private-class-fields)
14+
* [Space after `template`](#space-after-template)
15+
* [Memory Management](#memory-management)
16+
* [Memory allocation](#memory-allocation)
17+
* [Use `nullptr` instead of `NULL` or `0`](#use-nullptr-instead-of-null-or-0)
18+
* [Ownership and Smart Pointers](#ownership-and-smart-pointers)
19+
* [Others](#others)
20+
* [Type casting](#type-casting)
21+
* [Do not include `*.h` if `*-inl.h` has already been included](#do-not-include-h-if--inlh-has-already-been-included)
22+
* [Avoid throwing JavaScript errors in nested C++ methods](#avoid-throwing-javascript-errors-in-nested-c-methods)
2023

2124
Unfortunately, the C++ linter (based on
2225
[Google’s `cpplint`](https://github.com/google/styleguide)), which can be run
2326
explicitly via `make lint-cpp`, does not currently catch a lot of rules that are
2427
specific to the Node.js C++ code base. This document explains the most common of
2528
these rules:
2629

30+
## Formatting
31+
2732
## Left-leaning (C++ style) asterisks for pointer declarations
2833

2934
`char* buffer;` instead of `char *buffer;`
@@ -128,23 +133,50 @@ class FancyContainer {
128133
...
129134
}
130135
```
131-
132-
## Type casting
133-
134-
- Always avoid C-style casts (`(type)value`)
135-
- `dynamic_cast` does not work because RTTI is not enabled
136-
- Use `static_cast` for casting whenever it works
137-
- `reinterpret_cast` is okay if `static_cast` is not appropriate
136+
## Memory Management
138137
139138
## Memory allocation
140139
141140
- `Malloc()`, `Calloc()`, etc. from `util.h` abort in Out-of-Memory situations
142141
- `UncheckedMalloc()`, etc. return `nullptr` in OOM situations
143142
144-
## `nullptr` instead of `NULL` or `0`
143+
## Use `nullptr` instead of `NULL` or `0`
145144
146145
What it says in the title.
147146
147+
## Ownership and Smart Pointers
148+
149+
"Smart" pointers are classes that act like pointers, e.g.
150+
by overloading the `*` and `->` operators. Some smart pointer types can be
151+
used to automate ownership bookkeeping, to ensure these responsibilities are
152+
met. `std::unique_ptr` is a smart pointer type introduced in C++11, which
153+
expresses exclusive ownership of a dynamically allocated object; the object
154+
is deleted when the `std::unique_ptr` goes out of scope. It cannot be
155+
copied, but can be moved to represent ownership transfer.
156+
`std::shared_ptr` is a smart pointer type that expresses shared ownership of a
157+
dynamically allocated object. `std::shared_ptr`s can be copied; ownership
158+
of the object is shared among all copies, and the object
159+
is deleted when the last `std::shared_ptr` is destroyed.
160+
161+
Prefer to use `std::unique_ptr` to make ownership
162+
transfer explicit. For example:
163+
164+
```cpp
165+
std::unique_ptr<Foo> FooFactory();
166+
void FooConsumer(std::unique_ptr<Foo> ptr);
167+
```
168+
169+
Never use `std::auto_ptr`. Instead, use `std::unique_ptr`.
170+
171+
## Others
172+
173+
## Type casting
174+
175+
- Always avoid C-style casts (`(type)value`)
176+
- `dynamic_cast` does not work because RTTI is not enabled
177+
- Use `static_cast` for casting whenever it works
178+
- `reinterpret_cast` is okay if `static_cast` is not appropriate
179+
148180
## Do not include `*.h` if `*-inl.h` has already been included
149181

150182
Do
@@ -169,27 +201,3 @@ A lot of code inside Node.js is written so that typechecking etc. is performed
169201
in JavaScript.
170202

171203
Using C++ `throw` is not allowed.
172-
173-
## Ownership and Smart Pointers
174-
175-
"Smart" pointers are classes that act like pointers, e.g.
176-
by overloading the `*` and `->` operators. Some smart pointer types can be
177-
used to automate ownership bookkeeping, to ensure these responsibilities are
178-
met. `std::unique_ptr` is a smart pointer type introduced in C++11, which
179-
expresses exclusive ownership of a dynamically allocated object; the object
180-
is deleted when the `std::unique_ptr` goes out of scope. It cannot be
181-
copied, but can be moved to represent ownership transfer.
182-
`std::shared_ptr` is a smart pointer type that expresses shared ownership of a
183-
dynamically allocated object. `std::shared_ptr`s can be copied; ownership
184-
of the object is shared among all copies, and the object
185-
is deleted when the last `std::shared_ptr` is destroyed.
186-
187-
Prefer to use `std::unique_ptr` to make ownership
188-
transfer explicit. For example:
189-
190-
```cpp
191-
std::unique_ptr<Foo> FooFactory();
192-
void FooConsumer(std::unique_ptr<Foo> ptr);
193-
```
194-
195-
Never use `std::auto_ptr`. Instead, use `std::unique_ptr`.

vcbuild.bat

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ if /i "%1"=="upload" set upload=1&goto arg-ok
109109
if /i "%1"=="small-icu" set i18n_arg=%1&goto arg-ok
110110
if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok
111111
if /i "%1"=="intl-none" set i18n_arg=%1&goto arg-ok
112-
if /i "%1"=="without-intl" set i18n_arg=%1&goto arg-ok
112+
if /i "%1"=="without-intl" set i18n_arg=intl-none&goto arg-ok
113113
if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok
114114
if /i "%1"=="ignore-flaky" set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok
115115
if /i "%1"=="enable-vtune" set enable_vtune_arg=1&goto arg-ok
@@ -153,25 +153,19 @@ set "node_gyp_exe="%node_exe%" deps\npm\node_modules\node-gyp\bin\node-gyp"
153153
if "%target_env%"=="vs2015" set "node_gyp_exe=%node_gyp_exe% --msvs_version=2015"
154154
if "%target_env%"=="vs2017" set "node_gyp_exe=%node_gyp_exe% --msvs_version=2017"
155155

156-
if "%config%"=="Debug" set configure_flags=%configure_flags% --debug
156+
if "%config%"=="Debug" set configure_flags=%configure_flags% --debug
157157
if "%chakracore_test_build%"=="1" set configure_flags=%configure_flags% --chakracore-test-build
158-
if defined nosnapshot set configure_flags=%configure_flags% --without-snapshot
159-
if defined noetw set configure_flags=%configure_flags% --without-etw& set noetw_msi_arg=/p:NoETW=1
160-
if defined noperfctr set configure_flags=%configure_flags% --without-perfctr& set noperfctr_msi_arg=/p:NoPerfCtr=1
161-
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
162-
if defined download_arg set configure_flags=%configure_flags% %download_arg%
158+
if defined nosnapshot set configure_flags=%configure_flags% --without-snapshot
159+
if defined noetw set configure_flags=%configure_flags% --without-etw& set noetw_msi_arg=/p:NoETW=1
160+
if defined noperfctr set configure_flags=%configure_flags% --without-perfctr& set noperfctr_msi_arg=/p:NoPerfCtr=1
161+
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
162+
if defined download_arg set configure_flags=%configure_flags% %download_arg%
163163
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
164-
if defined dll set configure_flags=%configure_flags% --shared
165-
if defined enable_static set configure_flags=%configure_flags% --enable-static
166-
if defined no_NODE_OPTIONS set configure_flags=%configure_flags% --without-node-options
167-
168-
REM if defined debug_http2 set configure_flags=%configure_flags% --debug-http2
169-
REM if defined debug_nghttp2 set configure_flags=%configure_flags% --debug-nghttp2
170-
171-
if "%i18n_arg%"=="full-icu" set configure_flags=%configure_flags% --with-intl=full-icu
172-
if "%i18n_arg%"=="small-icu" set configure_flags=%configure_flags% --with-intl=small-icu
173-
if "%i18n_arg%"=="intl-none" set configure_flags=%configure_flags% --with-intl=none
174-
if "%i18n_arg%"=="without-intl" set configure_flags=%configure_flags% --without-intl
164+
if defined dll set configure_flags=%configure_flags% --shared
165+
if defined enable_static set configure_flags=%configure_flags% --enable-static
166+
if defined no_NODE_OPTIONS set configure_flags=%configure_flags% --without-node-options
167+
if defined link_module set configure_flags=%configure_flags% %link_module%
168+
if defined i18n_arg set configure_flags=%configure_flags% --with-intl=%i18n_arg%
175169

176170
if "%engine%"=="chakracore" (
177171
set configure_flags=%configure_flags% --without-bundled-v8
@@ -185,8 +179,9 @@ if "%target_arch%"=="arm" (
185179
set configure_flags=%configure_flags% --without-intl
186180
)
187181
)
188-
189-
if defined config_flags set configure_flags=%configure_flags% %config_flags%
182+
if defined config_flags set configure_flags=%configure_flags% %config_flags%
183+
if defined target_arch set configure_flags=%configure_flags% --dest-cpu=%target_arch%
184+
if defined TAG set configure_flags=%configure_flags% --tag=%TAG%
190185

191186
if not exist "%~dp0deps\icu" goto no-depsicu
192187
if "%target%"=="Clean" echo deleting %~dp0deps\icu
@@ -287,7 +282,7 @@ goto run
287282
if defined noprojgen goto msbuild
288283

289284
@rem Generate the VS project.
290-
call :run-python configure %configure_flags% --engine=%engine% --dest-cpu=%target_arch% --tag=%TAG% %link_module%
285+
call :run-python configure %configure_flags% --engine=%engine%
291286
if errorlevel 1 goto create-msvs-files-failed
292287
if not exist node.sln goto create-msvs-files-failed
293288
echo Project files generated.

0 commit comments

Comments
 (0)