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

Commit 0dc4db5

Browse files
committed
meta: merge node/master into node-chakracore/master
Merge 1b0d979 as of 2018-01-17 This commit was automatically generated. For any problems, please contact jackhorton Reviewed-By: Jack Horton <jahorto@microsoft.com>
2 parents 2bc8958 + 1b0d979 commit 0dc4db5

File tree

117 files changed

+1501
-821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1501
-821
lines changed

CPP_STYLE_GUIDE.md

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
* [Others](#others)
2121
* [Type casting](#type-casting)
2222
* [Do not include `*.h` if `*-inl.h` has already been included](#do-not-include-h-if--inlh-has-already-been-included)
23-
* [Avoid throwing JavaScript errors in nested C++ methods](#avoid-throwing-javascript-errors-in-nested-c-methods)
23+
* [Avoid throwing JavaScript errors in C++ methods](#avoid-throwing-javascript-errors-in-c)
24+
* [Avoid throwing JavaScript errors in nested C++ methods](#avoid-throwing-javascript-errors-in-nested-c-methods)
2425

2526
Unfortunately, the C++ linter (based on
2627
[Google’s `cpplint`](https://github.com/google/styleguide)), which can be run
@@ -213,12 +214,65 @@ instead of
213214
#include "util-inl.h"
214215
```
215216

216-
## Avoid throwing JavaScript errors in nested C++ methods
217+
## Avoid throwing JavaScript errors in C++
217218

218-
If you need to throw JavaScript errors from a C++ binding method, try to do it
219-
at the top level and not inside of nested calls.
219+
When there is a need to throw errors from a C++ binding method, try to
220+
return the data necessary for constructing the errors to JavaScript,
221+
then construct and throw the errors [using `lib/internal/errors.js`][errors].
220222

221-
A lot of code inside Node.js is written so that typechecking etc. is performed
222-
in JavaScript.
223+
Note that in general, type-checks on arguments should be done in JavaScript
224+
before the arguments are passed into C++. Then in the C++ binding, simply using
225+
`CHECK` assertions to guard against invalid arguments should be enough.
226+
227+
If the return value of the binding cannot be used to signal failures or return
228+
the necessary data for constructing errors in JavaScript, pass a context object
229+
to the binding and put the necessary data inside in C++. For example:
230+
231+
```cpp
232+
void Foo(const FunctionCallbackInfo<Value>& args) {
233+
Environment* env = Environment::GetCurrent(args);
234+
// Let the JavaScript handle the actual type-checking,
235+
// only assertions are placed in C++
236+
CHECK_EQ(args.Length(), 2);
237+
CHECK(args[0]->IsString());
238+
CHECK(args[1]->IsObject());
239+
240+
int err = DoSomethingWith(args[0].As<String>());
241+
if (err) {
242+
// Put the data inside the error context
243+
Local<Object> ctx = args[1].As<Object>();
244+
Local<String> key = FIXED_ONE_BYTE_STRING(env->isolate(), "code");
245+
ctx->Set(env->context(), key, err).FromJust();
246+
} else {
247+
args.GetReturnValue().Set(something_to_return);
248+
}
249+
}
250+
251+
// In the initialize function
252+
env->SetMethod(target, "foo", Foo);
253+
```
254+
255+
```js
256+
exports.foo = function(str) {
257+
// Prefer doing the type-checks in JavaScript
258+
if (typeof str !== 'string') {
259+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'str', 'string');
260+
}
261+
262+
const ctx = {};
263+
const result = binding.foo(str, ctx);
264+
if (ctx.code !== undefined) {
265+
throw new errors.Error('ERR_ERROR_NAME', ctx.code);
266+
}
267+
return result;
268+
};
269+
```
270+
271+
### Avoid throwing JavaScript errors in nested C++ methods
272+
273+
When you have to throw the errors from C++, try to do it at the top level and
274+
not inside of nested calls.
223275

224276
Using C++ `throw` is not allowed.
277+
278+
[errors]: https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md

Makefile

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,57 +1020,13 @@ ifeq ($(XZ), 0)
10201020
ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz.done"
10211021
endif
10221022

1023-
.PHONY: bench-net
1024-
bench-net: all
1025-
@$(NODE) benchmark/run.js net
1026-
1027-
bench-crypto: all
1028-
@$(NODE) benchmark/run.js crypto
1029-
1030-
.PHONY: bench-tls
1031-
bench-tls: all
1032-
@$(NODE) benchmark/run.js tls
1033-
1034-
.PHONY: bench-http
1035-
bench-http: all
1036-
@$(NODE) benchmark/run.js http
1037-
1038-
.PHONY: bench-fs
1039-
bench-fs: all
1040-
@$(NODE) benchmark/run.js fs
1041-
1042-
.PHONY: bench-misc
1043-
bench-misc: benchmark/misc/function_call/build/Release/binding.node
1044-
@$(NODE) benchmark/run.js misc
1045-
1046-
.PHONY: bench-array
1047-
bench-array: all
1048-
@$(NODE) benchmark/run.js arrays
1049-
1050-
.PHONY: bench-buffer
1051-
bench-buffer: all
1052-
@$(NODE) benchmark/run.js buffers
1053-
1054-
bench-url: all
1055-
@$(NODE) benchmark/run.js url
1056-
1057-
bench-events: all
1058-
@$(NODE) benchmark/run.js events
1059-
1060-
bench-util: all
1061-
@$(NODE) benchmark/run.js util
1062-
1063-
bench-dgram: all
1064-
@$(NODE) benchmark/run.js dgram
1065-
10661023
.PHONY: bench-all
1067-
bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events bench-dgram bench-util
1024+
bench-all:
1025+
@echo "Please use benchmark/run.js or benchmark/compare.js to run the benchmarks."
10681026

10691027
.PHONY: bench
1070-
bench: bench-net bench-http bench-fs bench-tls
1071-
1072-
.PHONY: bench-ci
1073-
bench-ci: bench
1028+
bench:
1029+
@echo "Please use benchmark/run.js or benchmark/compare.js to run the benchmarks."
10741030

10751031
.PHONY: lint-md-clean
10761032
lint-md-clean:

configure

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,6 @@ def configure_node(o):
908908
configure_mips(o)
909909

910910
if flavor == 'aix':
911-
o['variables']['node_core_target_name'] = 'node_base'
912911
o['variables']['node_target_type'] = 'static_library'
913912

914913
if target_arch in ('x86', 'x64', 'ia32', 'x32'):
@@ -1018,6 +1017,13 @@ def configure_node(o):
10181017
else:
10191018
o['variables']['coverage'] = 'false'
10201019

1020+
if options.shared:
1021+
o['variables']['node_target_type'] = 'shared_library'
1022+
elif options.enable_static:
1023+
o['variables']['node_target_type'] = 'static_library'
1024+
else:
1025+
o['variables']['node_target_type'] = 'executable'
1026+
10211027
def configure_library(lib, output):
10221028
shared_lib = 'shared_' + lib
10231029
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1539,6 +1545,7 @@ config = {
15391545
'BUILDTYPE': 'Debug' if options.debug else 'Release',
15401546
'USE_XCODE': str(int(options.use_xcode or 0)),
15411547
'PYTHON': sys.executable,
1548+
'NODE_TARGET_TYPE': variables['node_target_type'],
15421549
}
15431550

15441551
if options.prefix:

doc/api/assert.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
645645
## assert.ok(value[, message])
646646
<!-- YAML
647647
added: v0.1.21
648+
changes:
649+
- version: REPLACEME
650+
pr-url: https://github.com/nodejs/node/pull/17581
651+
description: assert.ok() will throw a `ERR_MISSING_ARGS` error.
652+
Use assert.fail() instead.
648653
-->
649654
* `value` {any}
650655
* `message` {any}
@@ -658,19 +663,50 @@ parameter is `undefined`, a default error message is assigned. If the `message`
658663
parameter is an instance of an [`Error`][] then it will be thrown instead of the
659664
`AssertionError`.
660665

666+
Be aware that in the `repl` the error message will be different to the one
667+
thrown in a file! See below for further details.
668+
661669
```js
662670
const assert = require('assert').strict;
663671

664672
assert.ok(true);
665673
// OK
666674
assert.ok(1);
667675
// OK
668-
assert.ok(false);
669-
// throws "AssertionError: false == true"
670-
assert.ok(0);
671-
// throws "AssertionError: 0 == true"
676+
672677
assert.ok(false, 'it\'s false');
673678
// throws "AssertionError: it's false"
679+
680+
// In the repl:
681+
assert.ok(typeof 123 === 'string');
682+
// throws:
683+
// "AssertionError: false == true
684+
685+
// In a file (e.g. test.js):
686+
assert.ok(typeof 123 === 'string');
687+
// throws:
688+
// "AssertionError: The expression evaluated to a falsy value:
689+
//
690+
// assert.ok(typeof 123 === 'string')
691+
692+
assert.ok(false);
693+
// throws:
694+
// "AssertionError: The expression evaluated to a falsy value:
695+
//
696+
// assert.ok(false)
697+
698+
assert.ok(0);
699+
// throws:
700+
// "AssertionError: The expression evaluated to a falsy value:
701+
//
702+
// assert.ok(0)
703+
704+
// Using `assert()` works the same:
705+
assert(0);
706+
// throws:
707+
// "AssertionError: The expression evaluated to a falsy value:
708+
//
709+
// assert(0)
674710
```
675711

676712
## assert.strictEqual(actual, expected[, message])

doc/api/buffer.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,18 @@ console.log(buf2.toString());
511511
<!-- YAML
512512
added: v5.10.0
513513
changes:
514-
- version: v8.9.3
515-
pr-url: https://github.com/nodejs/node/pull/17428
516-
description: Specifying an invalid string for `fill` now results in a
517-
zero-filled buffer.
514+
- version: REPLACEME
515+
pr-url: https://github.com/nodejs/node/pull/18129
516+
description: Attempting to fill a non-zero length buffer with a zero length
517+
buffer triggers a thrown exception.
518518
- version: REPLACEME
519519
pr-url: https://github.com/nodejs/node/pull/17427
520520
description: Specifying an invalid string for `fill` triggers a thrown
521521
exception.
522+
- version: v8.9.3
523+
pr-url: https://github.com/nodejs/node/pull/17428
524+
description: Specifying an invalid string for `fill` now results in a
525+
zero-filled buffer.
522526
-->
523527

524528
* `size` {integer} The desired length of the new `Buffer`.
@@ -1224,13 +1228,17 @@ console.log(buf1.equals(buf3));
12241228
<!-- YAML
12251229
added: v0.5.0
12261230
changes:
1227-
- version: v5.7.0
1228-
pr-url: https://github.com/nodejs/node/pull/4935
1229-
description: The `encoding` parameter is supported now.
1231+
- version: REPLACEME
1232+
pr-url: https://github.com/nodejs/node/pull/18129
1233+
description: Attempting to fill a non-zero length buffer with a zero length
1234+
buffer triggers a thrown exception.
12301235
- version: REPLACEME
12311236
pr-url: https://github.com/nodejs/node/pull/17427
12321237
description: Specifying an invalid string for `value` triggers a thrown
12331238
exception.
1239+
- version: v5.7.0
1240+
pr-url: https://github.com/nodejs/node/pull/4935
1241+
description: The `encoding` parameter is supported now.
12341242
-->
12351243

12361244
* `value` {string|Buffer|integer} The value to fill `buf` with.

doc/api/deprecations.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ The AsyncHooks Sensitive API was never documented and had various of minor
788788
issues, see https://github.com/nodejs/node/issues/15572. Use the `AsyncResource`
789789
API instead.
790790
791-
792791
<a id="DEP0086"></a>
793792
### DEP0086: Remove runInAsyncIdScope
794793

doc/api/errors.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,18 @@ While using `N-API`, `Constructor.prototype` was not an object.
13281328
While calling `napi_create_dataview()`, a given `offset` was outside the bounds
13291329
of the dataview or `offset + length` was larger than a length of given `buffer`.
13301330

1331+
<a id="ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT"></a>
1332+
### ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT
1333+
1334+
While calling `napi_create_typedarray()`, the provided `offset` was not a
1335+
multiple of the element size.
1336+
1337+
<a id="ERR_NAPI_INVALID_TYPEDARRAY_LENGTH"></a>
1338+
### ERR_NAPI_INVALID_TYPEDARRAY_LENGTH
1339+
1340+
While calling `napi_create_typedarray()`, `(length * size_of_element) +
1341+
byte_offset` was larger than the length of given `buffer`.
1342+
13311343
<a id="ERR_NO_CRYPTO"></a>
13321344
### ERR_NO_CRYPTO
13331345

@@ -1530,6 +1542,12 @@ a hostname in the first parameter.
15301542
An excessive amount of TLS renegotiations is detected, which is a potential
15311543
vector for denial-of-service attacks.
15321544

1545+
<a id="ERR_TLS_SNI_FROM_SERVER"></a>
1546+
### ERR_TLS_SNI_FROM_SERVER
1547+
1548+
An attempt was made to issue Server Name Indication from a TLS server-side
1549+
socket, which is only valid from a client.
1550+
15331551
<a id="ERR_TLS_RENEGOTIATION_DISABLED"></a>
15341552
### ERR_TLS_RENEGOTIATION_DISABLED
15351553

doc/api/http2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ added: v8.4.0
919919
-->
920920

921921
* code {number} Unsigned 32-bit integer identifying the error code. **Default:**
922-
`http2.constant.NGHTTP2_NO_ERROR` (`0x00`)
922+
`http2.constants.NGHTTP2_NO_ERROR` (`0x00`)
923923
* `callback` {Function} An optional function registered to listen for the
924924
`'close'` event.
925925
* Returns: {undefined}

doc/api/stream.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ added: v8.0.0
15051505
argument.
15061506

15071507
The `_destroy()` method is called by [`writable.destroy()`][writable-destroy].
1508-
It can be overriden by child classes but it **must not** be called directly.
1508+
It can be overridden by child classes but it **must not** be called directly.
15091509

15101510
#### writable.\_final(callback)
15111511
<!-- YAML
@@ -1727,7 +1727,7 @@ added: v8.0.0
17271727
argument.
17281728

17291729
The `_destroy()` method is called by [`readable.destroy()`][readable-destroy].
1730-
It can be overriden by child classes but it **must not** be called directly.
1730+
It can be overridden by child classes but it **must not** be called directly.
17311731

17321732
#### readable.push(chunk[, encoding])
17331733
<!-- YAML

doc/guides/maintaining-the-build-files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ There are three main build files that may be directly run when building Node.js:
1515
Makefile mentioned below is maintained separately by humans). For a detailed
1616
guide on this script, see [configure](#configure).
1717
- `vcbuild.bat`: A Windows Batch Script that locates build tools, provides a
18-
subset of the targets avilable in the [Makefile](#makefile), and a few targets
18+
subset of the targets available in the [Makefile](#makefile), and a few targets
1919
of its own. For a detailed guide on this script, see
2020
[vcbuild.bat](#vcbuild.bat).
2121
- `Makefile`: A Makefile that can be run with GNU Make. It provides a set of

0 commit comments

Comments
 (0)