From 3c54f8199c80fbc5b5d710938e1eaf3c8b84019e Mon Sep 17 00:00:00 2001 From: Ben Schmidt Date: Tue, 19 Jul 2016 13:50:27 +1000 Subject: [PATCH 01/49] tty: add ref() so process.stdin.ref() etc. work Also squashed from: * test: move tty-wrap isrefed test to pseudo-tty/ * test: test tty-wrap handle isrefed properly * test: improve failure messages in isrefed tests PR-URL: https://github.com/nodejs/node/pull/7360 Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- src/tty_wrap.cc | 1 + test/README.md | 5 + test/parallel/test-handle-wrap-isrefed-tty.js | 33 ----- test/parallel/test-handle-wrap-isrefed.js | 129 +++++++++++------- test/pseudo-tty/ref_keeps_node_running.js | 27 ++++ test/pseudo-tty/ref_keeps_node_running.out | 0 .../test-handle-wrap-isrefed-tty.js | 23 ++++ .../test-handle-wrap-isrefed-tty.out | 0 8 files changed, 135 insertions(+), 83 deletions(-) delete mode 100644 test/parallel/test-handle-wrap-isrefed-tty.js create mode 100644 test/pseudo-tty/ref_keeps_node_running.js create mode 100644 test/pseudo-tty/ref_keeps_node_running.out create mode 100644 test/pseudo-tty/test-handle-wrap-isrefed-tty.js create mode 100644 test/pseudo-tty/test-handle-wrap-isrefed-tty.out diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 26f061b99b34e8..5b7518324773ae 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -34,6 +34,7 @@ void TTYWrap::Initialize(Local target, env->SetProtoMethod(t, "close", HandleWrap::Close); env->SetProtoMethod(t, "unref", HandleWrap::Unref); + env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown); diff --git a/test/README.md b/test/README.md index 949a275792abb0..653f78cc6d2eb5 100644 --- a/test/README.md +++ b/test/README.md @@ -105,6 +105,11 @@ On how to run tests in this direcotry, see Yes Various tests that are able to be run in parallel. + + pseudo-tty + Yes + Tests that require stdin/stdout/stderr to be a TTY. + pummel No diff --git a/test/parallel/test-handle-wrap-isrefed-tty.js b/test/parallel/test-handle-wrap-isrefed-tty.js deleted file mode 100644 index ad312be1f77862..00000000000000 --- a/test/parallel/test-handle-wrap-isrefed-tty.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -const common = require('../common'); -const strictEqual = require('assert').strictEqual; -const spawn = require('child_process').spawn; - -function makeAssert(message) { - return function(actual, expected) { - strictEqual(actual, expected, message); - }; -} -const assert = makeAssert('hasRef() not working on tty_wrap'); - -if (process.argv[2] === 'child') { - // Test tty_wrap in piped child to guarentee stdin being a TTY. - const ReadStream = require('tty').ReadStream; - const tty = new ReadStream(0); - assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), true); - assert(tty._handle.hasRef(), true); - tty.unref(); - assert(tty._handle.hasRef(), false); - tty._handle.close( - common.mustCall(() => assert(tty._handle.hasRef(), false))); - return; -} - -// Use spawn so that we can be sure that stdin has a _handle property. -// Refs: https://github.com/nodejs/node/pull/5916 -const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' }); -proc.stderr.pipe(process.stderr); -proc.on('exit', common.mustCall(function(exitCode) { - process.exitCode = exitCode; -})); diff --git a/test/parallel/test-handle-wrap-isrefed.js b/test/parallel/test-handle-wrap-isrefed.js index b5dbeb23bfd63a..66353fcc0362b3 100644 --- a/test/parallel/test-handle-wrap-isrefed.js +++ b/test/parallel/test-handle-wrap-isrefed.js @@ -3,99 +3,128 @@ const common = require('../common'); const strictEqual = require('assert').strictEqual; -function makeAssert(message) { - return function(actual, expected) { - strictEqual(actual, expected, message); - }; -} - - // child_process { - const assert = makeAssert('hasRef() not working on process_wrap'); const spawn = require('child_process').spawn; const cmd = common.isWindows ? 'rundll32' : 'ls'; const cp = spawn(cmd); - assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('hasRef'), true); - assert(cp._handle.hasRef(), true); + strictEqual(Object.getPrototypeOf(cp._handle).hasOwnProperty('hasRef'), + true, 'process_wrap: hasRef() missing'); + strictEqual(cp._handle.hasRef(), + true, 'process_wrap: not initially refed'); cp.unref(); - assert(cp._handle.hasRef(), false); + strictEqual(cp._handle.hasRef(), + false, 'process_wrap: unref() ineffective'); cp.ref(); - assert(cp._handle.hasRef(), true); - cp._handle.close(common.mustCall(() => assert(cp._handle.hasRef(), false))); + strictEqual(cp._handle.hasRef(), + true, 'process_wrap: ref() ineffective'); + cp._handle.close(common.mustCall(() => + strictEqual(cp._handle.hasRef(), + false, 'process_wrap: not unrefed on close'))); } -// dgram +// dgram ipv4 { - const assert = makeAssert('hasRef() not working on udp_wrap'); const dgram = require('dgram'); - const sock4 = dgram.createSocket('udp4'); - assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('hasRef'), true); - assert(sock4._handle.hasRef(), true); + strictEqual(Object.getPrototypeOf(sock4._handle).hasOwnProperty('hasRef'), + true, 'udp_wrap: ipv4: hasRef() missing'); + strictEqual(sock4._handle.hasRef(), + true, 'udp_wrap: ipv4: not initially refed'); sock4.unref(); - assert(sock4._handle.hasRef(), false); + strictEqual(sock4._handle.hasRef(), + false, 'udp_wrap: ipv4: unref() ineffective'); sock4.ref(); - assert(sock4._handle.hasRef(), true); - sock4._handle.close( - common.mustCall(() => assert(sock4._handle.hasRef(), false))); + strictEqual(sock4._handle.hasRef(), + true, 'udp_wrap: ipv4: ref() ineffective'); + sock4._handle.close(common.mustCall(() => + strictEqual(sock4._handle.hasRef(), + false, 'udp_wrap: ipv4: not unrefed on close'))); +} + +// dgram ipv6 +{ + const dgram = require('dgram'); const sock6 = dgram.createSocket('udp6'); - assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('hasRef'), true); - assert(sock6._handle.hasRef(), true); + strictEqual(Object.getPrototypeOf(sock6._handle).hasOwnProperty('hasRef'), + true, 'udp_wrap: ipv6: hasRef() missing'); + strictEqual(sock6._handle.hasRef(), + true, 'udp_wrap: ipv6: not initially refed'); sock6.unref(); - assert(sock6._handle.hasRef(), false); + strictEqual(sock6._handle.hasRef(), + false, 'udp_wrap: ipv6: unref() ineffective'); sock6.ref(); - assert(sock6._handle.hasRef(), true); - sock6._handle.close( - common.mustCall(() => assert(sock6._handle.hasRef(), false))); + strictEqual(sock6._handle.hasRef(), + true, 'udp_wrap: ipv6: ref() ineffective'); + sock6._handle.close(common.mustCall(() => + strictEqual(sock6._handle.hasRef(), + false, 'udp_wrap: ipv6: not unrefed on close'))); } // pipe { - const assert = makeAssert('hasRef() not working on pipe_wrap'); const Pipe = process.binding('pipe_wrap').Pipe; const handle = new Pipe(); - assert(Object.getPrototypeOf(handle).hasOwnProperty('hasRef'), true); - assert(handle.hasRef(), true); + strictEqual(Object.getPrototypeOf(handle).hasOwnProperty('hasRef'), + true, 'pipe_wrap: hasRef() missing'); + strictEqual(handle.hasRef(), + true, 'pipe_wrap: not initially refed'); handle.unref(); - assert(handle.hasRef(), false); + strictEqual(handle.hasRef(), + false, 'pipe_wrap: unref() ineffective'); handle.ref(); - assert(handle.hasRef(), true); - handle.close(common.mustCall(() => assert(handle.hasRef(), false))); + strictEqual(handle.hasRef(), + true, 'pipe_wrap: ref() ineffective'); + handle.close(common.mustCall(() => + strictEqual(handle.hasRef(), + false, 'pipe_wrap: not unrefed on close'))); } // tcp { - const assert = makeAssert('hasRef() not working on tcp_wrap'); const net = require('net'); const server = net.createServer(() => {}).listen(0); - assert(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'), true); - assert(server._handle.hasRef(), true); - assert(server._unref, false); + strictEqual(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'), + true, 'tcp_wrap: hasRef() missing'); + strictEqual(server._handle.hasRef(), + true, 'tcp_wrap: not initially refed'); + strictEqual(server._unref, + false, 'tcp_wrap: _unref initially incorrect'); server.unref(); - assert(server._handle.hasRef(), false); - assert(server._unref, true); + strictEqual(server._handle.hasRef(), + false, 'tcp_wrap: unref() ineffective'); + strictEqual(server._unref, + true, 'tcp_wrap: _unref not updated on unref()'); server.ref(); - assert(server._handle.hasRef(), true); - assert(server._unref, false); - server._handle.close( - common.mustCall(() => assert(server._handle.hasRef(), false))); + strictEqual(server._handle.hasRef(), + true, 'tcp_wrap: ref() ineffective'); + strictEqual(server._unref, + false, 'tcp_wrap: _unref not updated on ref()'); + server._handle.close(common.mustCall(() => + strictEqual(server._handle.hasRef(), + false, 'tcp_wrap: not unrefed on close'))); } // timers { - const assert = makeAssert('hasRef() not working on timer_wrap'); const timer = setTimeout(() => {}, 500); timer.unref(); - assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'), true); - assert(timer._handle.hasRef(), false); + strictEqual(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'), + true, 'timer_wrap: hasRef() missing'); + strictEqual(timer._handle.hasRef(), + false, 'timer_wrap: unref() ineffective'); timer.ref(); - assert(timer._handle.hasRef(), true); - timer._handle.close( - common.mustCall(() => assert(timer._handle.hasRef(), false))); + strictEqual(timer._handle.hasRef(), + true, 'timer_wrap: ref() ineffective'); + timer._handle.close(common.mustCall(() => + strictEqual(timer._handle.hasRef(), + false, 'timer_wrap: not unrefed on close'))); } + + +// see also test/pseudo-tty/test-handle-wrap-isrefed-tty.js diff --git a/test/pseudo-tty/ref_keeps_node_running.js b/test/pseudo-tty/ref_keeps_node_running.js new file mode 100644 index 00000000000000..de3c6531ef6924 --- /dev/null +++ b/test/pseudo-tty/ref_keeps_node_running.js @@ -0,0 +1,27 @@ +'use strict'; +require('../common'); + +const { TTY, isTTY } = process.binding('tty_wrap'); +const strictEqual = require('assert').strictEqual; + +strictEqual(isTTY(0), true, 'fd 0 is not a TTY'); + +const handle = new TTY(0); +handle.readStart(); +handle.onread = () => {}; + +function isHandleActive(handle) { + return process._getActiveHandles().some((active) => active === handle); +} + +strictEqual(isHandleActive(handle), true, 'TTY handle not initially active'); + +handle.unref(); + +strictEqual(isHandleActive(handle), false, 'TTY handle active after unref()'); + +handle.ref(); + +strictEqual(isHandleActive(handle), true, 'TTY handle inactive after ref()'); + +handle.unref(); diff --git a/test/pseudo-tty/ref_keeps_node_running.out b/test/pseudo-tty/ref_keeps_node_running.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/pseudo-tty/test-handle-wrap-isrefed-tty.js b/test/pseudo-tty/test-handle-wrap-isrefed-tty.js new file mode 100644 index 00000000000000..4baf6200962cc3 --- /dev/null +++ b/test/pseudo-tty/test-handle-wrap-isrefed-tty.js @@ -0,0 +1,23 @@ +'use strict'; + +// see also test/parallel/test-handle-wrap-isrefed.js + +const common = require('../common'); +const strictEqual = require('assert').strictEqual; +const ReadStream = require('tty').ReadStream; +const tty = new ReadStream(0); +const isTTY = process.binding('tty_wrap').isTTY; +strictEqual(isTTY(0), true, 'tty_wrap: stdin is not a TTY'); +strictEqual(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), + true, 'tty_wrap: hasRef() missing'); +strictEqual(tty._handle.hasRef(), + true, 'tty_wrap: not initially refed'); +tty.unref(); +strictEqual(tty._handle.hasRef(), + false, 'tty_wrap: unref() ineffective'); +tty.ref(); +strictEqual(tty._handle.hasRef(), + true, 'tty_wrap: ref() ineffective'); +tty._handle.close(common.mustCall(() => + strictEqual(tty._handle.hasRef(), + false, 'tty_wrap: not unrefed on close'))); diff --git a/test/pseudo-tty/test-handle-wrap-isrefed-tty.out b/test/pseudo-tty/test-handle-wrap-isrefed-tty.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 From 11aea2662ff9fd605a04cdd7ee74c2932e610fa4 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Tue, 28 Feb 2017 19:59:59 +0200 Subject: [PATCH 02/49] doc: fix typo in STYLE_GUIDE.md PR-URL: https://github.com/nodejs/node/pull/11615 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig --- doc/STYLE_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/STYLE_GUIDE.md b/doc/STYLE_GUIDE.md index 10f26421a4ceb5..f087718a6754fd 100644 --- a/doc/STYLE_GUIDE.md +++ b/doc/STYLE_GUIDE.md @@ -57,7 +57,7 @@ * When using underscores, asterisks and backticks please use proper escaping (**\\\_**, **\\\*** and **\\\`** instead of **\_**, **\*** and **\`**) * References to constructor functions should use PascalCase * References to constructor instances should be camelCased -* References to methods should be used with parenthesis: `socket.end()` instead of `socket.end` +* References to methods should be used with parentheses: `socket.end()` instead of `socket.end` [plugin]: http://editorconfig.org/#download [Oxford comma]: https://en.wikipedia.org/wiki/Serial_comma From d329abf1c6ef7470ef5e7cd611bba71bdc182a77 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Thu, 23 Feb 2017 11:02:39 -0500 Subject: [PATCH 03/49] doc: use common malformed instead of misformatted PR-URL: https://github.com/nodejs/node/pull/11518 Reviewed-By: James M Snell Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig --- doc/api/cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 538b1e06afdb12..89879cdc532937 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -382,7 +382,7 @@ When set, the well known "root" CAs (like VeriSign) will be extended with the extra certificates in `file`. The file should consist of one or more trusted certificates in PEM format. A message will be emitted (once) with [`process.emitWarning()`][emit_warning] if the file is missing or -misformatted, but any errors are otherwise ignored. +malformed, but any errors are otherwise ignored. Note that neither the well known nor extra certificates are used when the `ca` options property is explicitly specified for a TLS or HTTPS client or server. From 1b6ba9effbd4094359cf7bacfc174f9b8c774c75 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Fri, 24 Feb 2017 17:57:45 -0800 Subject: [PATCH 04/49] src: do not ignore IDNA conversion error Old behavior can be restored using a special `lenient` mode, as used in the legacy URL parser. PR-URL: https://github.com/nodejs/node/pull/11549 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- lib/url.js | 5 ++++- src/node_i18n.cc | 20 ++++++++++++++------ src/node_i18n.h | 6 ++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/url.js b/lib/url.js index 845f22a44447d6..42853e346c474f 100644 --- a/lib/url.js +++ b/lib/url.js @@ -319,7 +319,10 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { // It only converts parts of the domain name that // have non-ASCII characters, i.e. it doesn't matter if // you call it with a domain that already is ASCII-only. - this.hostname = toASCII(this.hostname); + + // Use lenient mode (`true`) to try to support even non-compliant + // URLs. + this.hostname = toASCII(this.hostname, true); } var p = this.port ? ':' + this.port : ''; diff --git a/src/node_i18n.cc b/src/node_i18n.cc index ae14aed7c6b4c2..b337456c639318 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -410,7 +410,8 @@ bool InitializeICUDirectory(const std::string& path) { int32_t ToUnicode(MaybeStackBuffer* buf, const char* input, - size_t length) { + size_t length, + bool lenient) { UErrorCode status = U_ZERO_ERROR; uint32_t options = UIDNA_DEFAULT; options |= UIDNA_NONTRANSITIONAL_TO_UNICODE; @@ -435,7 +436,7 @@ int32_t ToUnicode(MaybeStackBuffer* buf, &status); } - if (U_FAILURE(status)) { + if (U_FAILURE(status) || (!lenient && info.errors != 0)) { len = -1; buf->SetLength(0); } else { @@ -448,7 +449,8 @@ int32_t ToUnicode(MaybeStackBuffer* buf, int32_t ToASCII(MaybeStackBuffer* buf, const char* input, - size_t length) { + size_t length, + bool lenient) { UErrorCode status = U_ZERO_ERROR; uint32_t options = UIDNA_DEFAULT; options |= UIDNA_NONTRANSITIONAL_TO_ASCII; @@ -473,7 +475,7 @@ int32_t ToASCII(MaybeStackBuffer* buf, &status); } - if (U_FAILURE(status)) { + if (U_FAILURE(status) || (!lenient && info.errors != 0)) { len = -1; buf->SetLength(0); } else { @@ -489,8 +491,11 @@ static void ToUnicode(const FunctionCallbackInfo& args) { CHECK_GE(args.Length(), 1); CHECK(args[0]->IsString()); Utf8Value val(env->isolate(), args[0]); + // optional arg + bool lenient = args[1]->BooleanValue(env->context()).FromJust(); + MaybeStackBuffer buf; - int32_t len = ToUnicode(&buf, *val, val.length()); + int32_t len = ToUnicode(&buf, *val, val.length(), lenient); if (len < 0) { return env->ThrowError("Cannot convert name to Unicode"); @@ -508,8 +513,11 @@ static void ToASCII(const FunctionCallbackInfo& args) { CHECK_GE(args.Length(), 1); CHECK(args[0]->IsString()); Utf8Value val(env->isolate(), args[0]); + // optional arg + bool lenient = args[1]->BooleanValue(env->context()).FromJust(); + MaybeStackBuffer buf; - int32_t len = ToASCII(&buf, *val, val.length()); + int32_t len = ToASCII(&buf, *val, val.length(), lenient); if (len < 0) { return env->ThrowError("Cannot convert name to ASCII"); diff --git a/src/node_i18n.h b/src/node_i18n.h index 21567eeb3ec38f..270eb1f3d1bc46 100644 --- a/src/node_i18n.h +++ b/src/node_i18n.h @@ -18,10 +18,12 @@ bool InitializeICUDirectory(const std::string& path); int32_t ToASCII(MaybeStackBuffer* buf, const char* input, - size_t length); + size_t length, + bool lenient = false); int32_t ToUnicode(MaybeStackBuffer* buf, const char* input, - size_t length); + size_t length, + bool lenient = false); } // namespace i18n } // namespace node From 6a5d96164a42feaa03f0e654f8c74934b7d65dc7 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Fri, 24 Feb 2017 18:00:17 -0800 Subject: [PATCH 05/49] test: more comprehensive IDNA test cases - Split the tests out to a separate file - Add invalid cases - Add tests for url.domainTo*() - Re-enable previously broken WPT URL parsing tests PR-URL: https://github.com/nodejs/node/pull/11549 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- test/fixtures/url-idna.js | 217 ++++++++++++++++++++++ test/fixtures/url-tests.js | 62 +++---- test/parallel/test-icu-punycode.js | 85 +++------ test/parallel/test-whatwg-url-domainto.js | 36 ++++ 4 files changed, 311 insertions(+), 89 deletions(-) create mode 100644 test/fixtures/url-idna.js create mode 100644 test/parallel/test-whatwg-url-domainto.js diff --git a/test/fixtures/url-idna.js b/test/fixtures/url-idna.js new file mode 100644 index 00000000000000..af169bb04a8736 --- /dev/null +++ b/test/fixtures/url-idna.js @@ -0,0 +1,217 @@ +'use strict'; + +// Credit for list: http://www.i18nguy.com/markup/idna-examples.html +module.exports = { + valid: [ + { ascii: 'xn--mgbaal8b0b9b2b.icom.museum', + unicode: 'افغانستا.icom.museum' + }, + { + ascii: 'xn--lgbbat1ad8j.icom.museum', + unicode: 'الجزائر.icom.museum' + }, + { + ascii: 'xn--sterreich-z7a.icom.museum', + unicode: 'österreich.icom.museum' + }, + { + ascii: 'xn--54b6eqazv8bc7e.icom.museum', + unicode: 'বাংলাদেশ.icom.museum' + }, + { + ascii: 'xn--80abmy0agn7e.icom.museum', + unicode: 'беларусь.icom.museum' + }, + { + ascii: 'xn--belgi-rsa.icom.museum', + unicode: 'belgië.icom.museum' + }, + { + ascii: 'xn--80abgvm6a7d2b.icom.museum', + unicode: 'българия.icom.museum' + }, + { + ascii: 'xn--mgbfqim.icom.museum', + unicode: 'تشادر.icom.museum' + }, + { + ascii: 'xn--fiqs8s.icom.museum', + unicode: '中国.icom.museum' + }, + { + ascii: 'xn--mgbu4chg.icom.museum', + unicode: 'القمر.icom.museum' + }, + { + ascii: 'xn--vxakcego.icom.museum', + unicode: 'κυπρος.icom.museum' + }, + { + ascii: 'xn--eskrepublika-ebb62d.icom.museum', + unicode: 'českárepublika.icom.museum' + }, + { + ascii: 'xn--wgbh1c.icom.museum', + unicode: 'مصر.icom.museum' + }, + { + ascii: 'xn--hxakic4aa.icom.museum', + unicode: 'ελλάδα.icom.museum' + }, + { + ascii: 'xn--magyarorszg-t7a.icom.museum', + unicode: 'magyarország.icom.museum' + }, + { + ascii: 'xn--sland-ysa.icom.museum', + unicode: 'ísland.icom.museum' + }, + { + ascii: 'xn--h2brj9c.icom.museum', + unicode: 'भारत.icom.museum' + }, + { + ascii: 'xn--mgba3a4fra.icom.museum', + unicode: 'ايران.icom.museum' + }, + { + ascii: 'xn--ire-9la.icom.museum', + unicode: 'éire.icom.museum' + }, + { + ascii: 'xn--4dbklr2c8d.xn--4dbrk0ce.museum', + unicode: 'איקו״ם.ישראל.museum' + }, + { + ascii: 'xn--wgv71a.icom.museum', + unicode: '日本.icom.museum' + }, + { + ascii: 'xn--igbhzh7gpa.icom.museum', + unicode: 'الأردن.icom.museum' + }, + { + ascii: 'xn--80aaa0a6awh12ed.icom.museum', + unicode: 'қазақстан.icom.museum' + }, + { + ascii: 'xn--3e0b707e.icom.museum', + unicode: '한국.icom.museum' + }, + { + ascii: 'xn--80afmksoji0fc.icom.museum', + unicode: 'кыргызстан.icom.museum' + }, + { + ascii: 'xn--q7ce6a.icom.museum', + unicode: 'ລາວ.icom.museum' + }, + { + ascii: 'xn--mgbb7fjb.icom.museum', + unicode: 'لبنان.icom.museum' + }, + { + ascii: 'xn--80aaldqjmmi6x.icom.museum', + unicode: 'македонија.icom.museum' + }, + { + ascii: 'xn--mgbah1a3hjkrd.icom.museum', + unicode: 'موريتانيا.icom.museum' + }, + { + ascii: 'xn--mxico-bsa.icom.museum', + unicode: 'méxico.icom.museum' + }, + { + ascii: 'xn--c1aqabffc0aq.icom.museum', + unicode: 'монголулс.icom.museum' + }, + { + ascii: 'xn--mgbc0a9azcg.icom.museum', + unicode: 'المغرب.icom.museum' + }, + { + ascii: 'xn--l2bey1c2b.icom.museum', + unicode: 'नेपाल.icom.museum' + }, + { + ascii: 'xn--mgb9awbf.icom.museum', + unicode: 'عمان.icom.museum' + }, + { + ascii: 'xn--wgbl6a.icom.museum', + unicode: 'قطر.icom.museum' + }, + { + ascii: 'xn--romnia-yta.icom.museum', + unicode: 'românia.icom.museum' + }, + { + ascii: 'xn--h1alffa9f.xn--h1aegh.museum', + unicode: 'россия.иком.museum' + }, + { + ascii: 'xn--80aaabm1ab4blmeec9e7n.xn--h1aegh.museum', + unicode: 'србијаицрнагора.иком.museum' + }, + { + ascii: 'xn--xkc2al3hye2a.icom.museum', + unicode: 'இலங்கை.icom.museum' + }, + { + ascii: 'xn--espaa-rta.icom.museum', + unicode: 'españa.icom.museum' + }, + { + ascii: 'xn--o3cw4h.icom.museum', + unicode: 'ไทย.icom.museum' + }, + { + ascii: 'xn--pgbs0dh.icom.museum', + unicode: 'تونس.icom.museum' + }, + { + ascii: 'xn--trkiye-3ya.icom.museum', + unicode: 'türkiye.icom.museum' + }, + { + ascii: 'xn--80aaxgrpt.icom.museum', + unicode: 'украина.icom.museum' + }, + { + ascii: 'xn--vitnam-jk8b.icom.museum', + unicode: 'việtnam.icom.museum' + }, + // long URL + { + ascii: `${`${'a'.repeat(63)}.`.repeat(3)}com`, + unicode: `${`${'a'.repeat(63)}.`.repeat(3)}com` + } + ], + invalid: [ + // long label + { + url: `${'a'.repeat(64)}.com`, + mode: 'ascii' + }, + // long URL + { + url: `${`${'a'.repeat(63)}.`.repeat(4)}com`, + mode: 'ascii' + }, + // invalid character + { + url: '\ufffd.com', + mode: 'ascii' + }, + { + url: '\ufffd.com', + mode: 'unicode' + }, + // invalid Punycode + { + url: 'xn---abc.com', + mode: 'unicode' + } + ] +} diff --git a/test/fixtures/url-tests.js b/test/fixtures/url-tests.js index 3b162391cd2ef5..3e303910ca6e19 100644 --- a/test/fixtures/url-tests.js +++ b/test/fixtures/url-tests.js @@ -3589,17 +3589,17 @@ module.exports = "base": "http://other.com/", "failure": true }, - // "U+FFFD", - // { - // "input": "https://\ufffd", - // "base": "about:blank", - // "failure": true - // }, - // { - // "input": "https://%EF%BF%BD", - // "base": "about:blank", - // "failure": true - // }, + "U+FFFD", + { + "input": "https://\ufffd", + "base": "about:blank", + "failure": true + }, + { + "input": "https://%EF%BF%BD", + "base": "about:blank", + "failure": true + }, { "input": "https://x/\ufffd?\ufffd#\ufffd", "base": "about:blank", @@ -4497,26 +4497,26 @@ module.exports = "hash": "" }, "# Hosts and percent-encoding", - // { - // "input": "ftp://example.com%80/", - // "base": "about:blank", - // "failure": true - // }, - // { - // "input": "ftp://example.com%A0/", - // "base": "about:blank", - // "failure": true - // }, - // { - // "input": "https://example.com%80/", - // "base": "about:blank", - // "failure": true - // }, - // { - // "input": "https://example.com%A0/", - // "base": "about:blank", - // "failure": true - // }, + { + "input": "ftp://example.com%80/", + "base": "about:blank", + "failure": true + }, + { + "input": "ftp://example.com%A0/", + "base": "about:blank", + "failure": true + }, + { + "input": "https://example.com%80/", + "base": "about:blank", + "failure": true + }, + { + "input": "https://example.com%A0/", + "base": "about:blank", + "failure": true + }, { "input": "ftp://%e2%98%83", "base": "about:blank", diff --git a/test/parallel/test-icu-punycode.js b/test/parallel/test-icu-punycode.js index 62508bc9f78f49..411704bb8f4477 100644 --- a/test/parallel/test-icu-punycode.js +++ b/test/parallel/test-icu-punycode.js @@ -6,67 +6,36 @@ if (!common.hasIntl) { return; } -const icu = getPunycode(); +const icu = process.binding('icu'); const assert = require('assert'); -function getPunycode() { - try { - return process.binding('icu'); - } catch (err) { - return undefined; +const tests = require('../fixtures/url-idna.js'); + +{ + for (const [i, { ascii, unicode }] of tests.valid.entries()) { + assert.strictEqual(ascii, icu.toASCII(unicode), `toASCII(${i + 1})`); + assert.strictEqual(unicode, icu.toUnicode(ascii), `toUnicode(${i + 1})`); + assert.strictEqual(ascii, icu.toASCII(icu.toUnicode(ascii)), + `toASCII(toUnicode(${i + 1}))`); + assert.strictEqual(unicode, icu.toUnicode(icu.toASCII(unicode)), + `toUnicode(toASCII(${i + 1}))`); } } -// Credit for list: http://www.i18nguy.com/markup/idna-examples.html -const tests = [ - 'افغانستا.icom.museum', - 'الجزائر.icom.museum', - 'österreich.icom.museum', - 'বাংলাদেশ.icom.museum', - 'беларусь.icom.museum', - 'belgië.icom.museum', - 'българия.icom.museum', - 'تشادر.icom.museum', - '中国.icom.museum', - 'القمر.icom.museum', - 'κυπρος.icom.museum', - 'českárepublika.icom.museum', - 'مصر.icom.museum', - 'ελλάδα.icom.museum', - 'magyarország.icom.museum', - 'ísland.icom.museum', - 'भारत.icom.museum', - 'ايران.icom.museum', - 'éire.icom.museum', - 'איקו״ם.ישראל.museum', - '日本.icom.museum', - 'الأردن.icom.museum', - 'қазақстан.icom.museum', - '한국.icom.museum', - 'кыргызстан.icom.museum', - 'ລາວ.icom.museum', - 'لبنان.icom.museum', - 'македонија.icom.museum', - 'موريتانيا.icom.museum', - 'méxico.icom.museum', - 'монголулс.icom.museum', - 'المغرب.icom.museum', - 'नेपाल.icom.museum', - 'عمان.icom.museum', - 'قطر.icom.museum', - 'românia.icom.museum', - 'россия.иком.museum', - 'србијаицрнагора.иком.museum', - 'இலங்கை.icom.museum', - 'españa.icom.museum', - 'ไทย.icom.museum', - 'تونس.icom.museum', - 'türkiye.icom.museum', - 'украина.icom.museum', - 'việtnam.icom.museum' -]; +{ + const errorRe = { + ascii: /^Error: Cannot convert name to ASCII$/, + unicode: /^Error: Cannot convert name to Unicode$/ + }; + const convertFunc = { + ascii: icu.toASCII, + unicode: icu.toUnicode + }; -// Testing the roundtrip -tests.forEach((i) => { - assert.strictEqual(i, icu.toUnicode(icu.toASCII(i))); -}); + for (const [i, { url, mode }] of tests.invalid.entries()) { + assert.throws(() => convertFunc[mode](url), errorRe[mode], + `Invalid case ${i + 1}`); + assert.doesNotThrow(() => convertFunc[mode](url, true), + `Invalid case ${i + 1} in lenient mode`); + } +} diff --git a/test/parallel/test-whatwg-url-domainto.js b/test/parallel/test-whatwg-url-domainto.js new file mode 100644 index 00000000000000..f891f95a19cd3b --- /dev/null +++ b/test/parallel/test-whatwg-url-domainto.js @@ -0,0 +1,36 @@ +'use strict'; +const common = require('../common'); + +if (!common.hasIntl) { + common.skip('missing Intl'); + return; +} + +const assert = require('assert'); +const { domainToASCII, domainToUnicode } = require('url'); + +// Tests below are not from WPT. +const tests = require('../fixtures/url-idna.js'); + +{ + for (const [i, { ascii, unicode }] of tests.valid.entries()) { + assert.strictEqual(ascii, domainToASCII(unicode), + `domainToASCII(${i + 1})`); + assert.strictEqual(unicode, domainToUnicode(ascii), + `domainToUnicode(${i + 1})`); + assert.strictEqual(ascii, domainToASCII(domainToUnicode(ascii)), + `domainToASCII(domainToUnicode(${i + 1}))`); + assert.strictEqual(unicode, domainToUnicode(domainToASCII(unicode)), + `domainToUnicode(domainToASCII(${i + 1}))`); + } +} + +{ + const convertFunc = { + ascii: domainToASCII, + unicode: domainToUnicode + }; + + for (const [i, { url, mode }] of tests.invalid.entries()) + assert.strictEqual(convertFunc[mode](url), '', `Invalid case ${i + 1}`); +} From b968491dc26983fed5c688b2c7534d45746174cf Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sat, 25 Feb 2017 00:25:11 -0800 Subject: [PATCH 06/49] doc: document WHATWG IDNA methods' error handling PR-URL: https://github.com/nodejs/node/pull/11549 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- doc/api/url.md | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/doc/api/url.md b/doc/api/url.md index c7bc6d5dbbe2f1..637616364b54dc 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -876,14 +876,27 @@ for (const [name, value] of params) { // xyz baz ``` -### require('url').domainToAscii(domain) +### require('url').domainToASCII(domain) * `domain` {String} * Returns: {String} -Returns the [Punycode][] ASCII serialization of the `domain`. +Returns the [Punycode][] ASCII serialization of the `domain`. If `domain` is an +invalid domain, the empty string is returned. -*Note*: The `require('url').domainToAscii()` method is introduced as part of +It performs the inverse operation to [`require('url').domainToUnicode()`][]. + +```js +const url = require('url'); +console.log(url.domainToASCII('español.com')); + // Prints xn--espaol-zwa.com +console.log(url.domainToASCII('中文.com')); + // Prints xn--fiq228c.com +console.log(url.domainToASCII('xn--iñvalid.com')); + // Prints an empty string +``` + +*Note*: The `require('url').domainToASCII()` method is introduced as part of the new `URL` implementation but is not part of the WHATWG URL standard. ### require('url').domainToUnicode(domain) @@ -891,7 +904,20 @@ the new `URL` implementation but is not part of the WHATWG URL standard. * `domain` {String} * Returns: {String} -Returns the Unicode serialization of the `domain`. +Returns the Unicode serialization of the `domain`. If `domain` is an invalid +domain, the empty string is returned. + +It performs the inverse operation to [`require('url').domainToASCII()`][]. + +```js +const url = require('url'); +console.log(url.domainToUnicode('xn--espaol-zwa.com')); + // Prints español.com +console.log(url.domainToUnicode('xn--fiq228c.com')); + // Prints 中文.com +console.log(url.domainToUnicode('xn--iñvalid.com')); + // Prints an empty string +``` *Note*: The `require('url').domainToUnicode()` API is introduced as part of the the new `URL` implementation but is not part of the WHATWG URL standard. @@ -956,6 +982,8 @@ console.log(myURL.origin); [`URLSearchParams`]: #url_class_urlsearchparams [`urlSearchParams.entries()`]: #url_urlsearchparams_entries [`urlSearchParams@@iterator()`]: #url_urlsearchparams_iterator +[`require('url').domainToASCII()`]: #url_require_url_domaintoascii_domain +[`require('url').domainToUnicode()`]: #url_require_url_domaintounicode_domain [stable sorting algorithm]: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability [`JSON.stringify()`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify [`url.toJSON()`]: #url_url_tojson From b116830d648b9b723b8b25dc14ac85f94c934883 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 1 Mar 2017 11:35:23 +0800 Subject: [PATCH 07/49] doc: add link to references in net.Socket PR-URL: https://github.com/nodejs/node/pull/11625 Reviewed-By: Rich Trott Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- doc/api/net.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/net.md b/doc/api/net.md index f4669449ee0107..fe55ff486f6b19 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -340,7 +340,7 @@ Construct a new socket object. `fd` allows you to specify the existing file descriptor of socket. Set `readable` and/or `writable` to `true` to allow reads and/or writes on this socket (NOTE: Works only when `fd` is passed). -About `allowHalfOpen`, refer to `createServer()` and `'end'` event. +About `allowHalfOpen`, refer to [`net.createServer()`][] and [`'end'`][] event. `net.Socket` instances are [`EventEmitter`][] with the following events: @@ -952,6 +952,7 @@ Returns true if input is a version 6 IP address, otherwise returns false. [`dns.lookup()` hints]: dns.html#dns_supported_getaddrinfo_flags [`end()`]: #net_socket_end_data_encoding [`EventEmitter`]: events.html#events_class_eventemitter +[`net.createServer()`]: #net_net_createserver_options_connectionlistener [`net.Socket`]: #net_class_net_socket [`pause()`]: #net_socket_pause [`resume()`]: #net_socket_resume From 2601c064863d35b653aaaf4dd6e6a2481a66ec4c Mon Sep 17 00:00:00 2001 From: "Sakthipriyan Vairamani (thefourtheye)" Date: Tue, 28 Feb 2017 00:24:03 +0530 Subject: [PATCH 08/49] test: skip tests with common.skip The `common.skip` function adds proper message in TAP format to skipped tests. It is better not to have the message rewritten in the tests. PR-URL: https://github.com/nodejs/node/pull/11585 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Luigi Pinca Reviewed-By: Yuta Hiroto --- test/parallel/test-crypto-authenticated.js | 2 +- test/parallel/test-tls-empty-sni-context.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js index 245783fb1b4275..1a628023b5c46e 100644 --- a/test/parallel/test-crypto-authenticated.js +++ b/test/parallel/test-crypto-authenticated.js @@ -318,7 +318,7 @@ for (const i in TEST_CASES) { } if (common.hasFipsCrypto && test.iv.length < 24) { - console.log('1..0 # Skipped: IV len < 12 bytes unsupported in FIPS mode'); + common.skip('IV len < 12 bytes unsupported in FIPS mode'); continue; } diff --git a/test/parallel/test-tls-empty-sni-context.js b/test/parallel/test-tls-empty-sni-context.js index 994a81e9ea9e6d..e68378fb4eac50 100644 --- a/test/parallel/test-tls-empty-sni-context.js +++ b/test/parallel/test-tls-empty-sni-context.js @@ -3,16 +3,14 @@ const common = require('../common'); if (!process.features.tls_sni) { - console.log('1..0 # Skipped: node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); + common.skip('node compiled without OpenSSL or with old OpenSSL version.'); return; } const assert = require('assert'); if (!common.hasCrypto) { - console.log('1..0 # Skipped: missing crypto'); - return; + return common.skip('missing crypto'); } const tls = require('tls'); From a0c117ba953d3cc9bc43eee69010a38f7aef18b5 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 17:49:25 +0200 Subject: [PATCH 09/49] doc: fixup errors.md * add semicolons in examples * fix indentation in code example * add spaces in code examples * console.log() -> console.error() * fix level of headings * update comment code example * delete obsolete info and example Fixes: https://github.com/nodejs/node/issues/11558 PR-URL: https://github.com/nodejs/node/pull/11566 Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- doc/api/errors.md | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 640935da35e460..e0e0f06ac5900f 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -141,15 +141,15 @@ the first argument will be passed as `null`. const fs = require('fs'); function nodeStyleCallback(err, data) { - if (err) { - console.error('There was an error', err); - return; - } - console.log(data); + if (err) { + console.error('There was an error', err); + return; + } + console.log(data); } fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback); -fs.readFile('/some/file/that/does-exist', nodeStyleCallback) +fs.readFile('/some/file/that/does-exist', nodeStyleCallback); ``` The JavaScript `try / catch` mechanism **cannot** be used to intercept errors @@ -167,15 +167,15 @@ try { throw err; } }); -} catch(err) { +} catch (err) { // This will not catch the throw! - console.log(err); + console.error(err); } ``` This will not work because the callback function passed to `fs.readFile()` is called asynchronously. By the time the callback has been called, the -surrounding code (including the `try { } catch(err) { }` block will have +surrounding code (including the `try { } catch (err) { }` block will have already exited. Throwing an error inside the callback **can crash the Node.js process** in most cases. If [domains][] are enabled, or a handler has been registered with `process.on('uncaughtException')`, such errors can be @@ -217,7 +217,7 @@ a string representing the location in the code at which ```js const myObject = {}; Error.captureStackTrace(myObject); -myObject.stack // similar to `new Error().stack` +myObject.stack; // similar to `new Error().stack` ``` The first line of the trace, instead of being prefixed with `ErrorType: @@ -238,7 +238,7 @@ function MyError() { // Without passing MyError to captureStackTrace, the MyError // frame would show up in the .stack property. By passing // the constructor, we omit that frame and all frames above it. -new MyError().stack +new MyError().stack; ``` ### Error.stackTraceLimit @@ -255,7 +255,7 @@ will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. -#### error.message +### error.message * {String} @@ -267,11 +267,11 @@ the stack trace of the `Error`, however changing this property after the ```js const err = new Error('The message'); -console.log(err.message); +console.error(err.message); // Prints: The message ``` -#### error.stack +### error.stack * {String} @@ -359,7 +359,7 @@ For example: ```js require('net').connect(-1); - // throws RangeError, port should be > 0 && < 65536 + // throws "RangeError: "port" option should be >= 0 and < 65536: -1" ``` Node.js will generate and throw `RangeError` instances *immediately* as a form @@ -379,19 +379,6 @@ doesNotExist; // throws ReferenceError, doesNotExist is not a variable in this program. ``` -`ReferenceError` instances will have an `error.arguments` property whose value -is an array containing a single element: a string representing the variable -that was not defined. - -```js -const assert = require('assert'); -try { - doesNotExist; -} catch(err) { - assert(err.arguments[0], 'doesNotExist'); -} -``` - Unless an application is dynamically generating and running code, `ReferenceError` instances should always be considered a bug in the code or its dependencies. @@ -407,7 +394,7 @@ program. ```js try { require('vm').runInThisContext('binary ! isNotOk'); -} catch(err) { +} catch (err) { // err will be a SyntaxError } ``` From 13cb8a69e4704922646720aaa6e8be5acd4e076c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 27 Feb 2017 05:24:11 +0100 Subject: [PATCH 10/49] net: remove misleading comment The allowHalfOpen comment was added in commit 8a3befa ("net: Refactor to use streams2") from 2012 but it wasn't true even then as far as I can tell: Node.js simply always does a shutdown(2) first. It is true that streams2 withholds the 'end' event when allowHalfOpen is true but the comment is about a callback that hangs off the 'finish' event that is emitted after calling `socket.end()`. PR-URL: https://github.com/nodejs/node/pull/11573 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- lib/net.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/net.js b/lib/net.js index 2528daedc84ef5..f3f8bb1a984ea8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -208,10 +208,6 @@ Socket.prototype._unrefTimer = function _unrefTimer() { // the user has called .end(), and all the bytes have been // sent out to the other side. -// If allowHalfOpen is false, or if the readable side has -// ended already, then destroy. -// If allowHalfOpen is true, then we need to do a shutdown, -// so that only the writable side will be cleaned up. function onSocketFinish() { // If still connecting - defer handling 'finish' until 'connect' will happen if (this.connecting) { From 4f9253686d683b40e9f2ef072e2d5473a60e8265 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 26 Feb 2017 22:39:55 -0800 Subject: [PATCH 11/49] test: apply strict mode in test-repl Strict mode for the test will not automatically enable strict mode in the REPL object. Enable strict mode in the test. PR-URL: https://github.com/nodejs/node/pull/11575 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Anna Henningsen Reviewed-By: Santiago Gimeno --- test/parallel/test-repl.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 70aac915f6b594..420010e1a3d6c9 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -1,4 +1,6 @@ -/* eslint-disable max-len, strict */ +/* eslint-disable max-len */ +'use strict'; + const common = require('../common'); const assert = require('assert'); From 83c7b245e27ffe90d1c2cbea7e2387c051e9c7b6 Mon Sep 17 00:00:00 2001 From: Bradley Curran Date: Sun, 26 Feb 2017 00:33:13 +0000 Subject: [PATCH 12/49] doc: fix typo in stream doc Use the plural instead of the possessive for developers PR-URL: https://github.com/nodejs/node/pull/11560 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson --- doc/api/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 0e12e76c810c17..b1b14f4f93b992 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -21,7 +21,7 @@ const stream = require('stream'); While it is important for all Node.js users to understand how streams work, the `stream` module itself is most useful for developers that are creating new -types of stream instances. Developer's who are primarily *consuming* stream +types of stream instances. Developers who are primarily *consuming* stream objects will rarely (if ever) have need to use the `stream` module directly. ## Organization of this Document From 5963566367328fa8020ed10af3ec070049b6d30b Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 25 Feb 2017 11:23:41 -0800 Subject: [PATCH 13/49] meta: remove out of date ROADMAP.md file The ROADMAP.md file has not been updated in a while. It serves no useful purpose that cannot be handled better in other docs (contrib guidelines, etc). Just remove it. PR-URL: https://github.com/nodejs/node/pull/11556 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: Jeremiah Senkpiel Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- ROADMAP.md | 84 ------------------------------------------------------ 1 file changed, 84 deletions(-) delete mode 100644 ROADMAP.md diff --git a/ROADMAP.md b/ROADMAP.md deleted file mode 100644 index da8e47941916cc..00000000000000 --- a/ROADMAP.md +++ /dev/null @@ -1,84 +0,0 @@ -# Node.js Roadmap - -***This is a living document, it describes the policy and priorities as they exist today but can evolve over time.*** - -## Stability Policy - -The most important consideration in every code change is the impact it will have, positive or negative, on the ecosystem (modules and applications). - -Node.js does not remove stdlib JS API. - -Shipping with current and well supported dependencies is the best way to ensure long term stability of the platform. - -Node.js will continue to adopt new V8 releases. -* When V8 ships a breaking change to their C++ API that can be handled by [`nan`](https://github.com/nodejs/nan) -the *minor* version of Node.js will be increased. -* When V8 ships a breaking change to their C++ API that can NOT be handled by [`nan`](https://github.com/nodejs/nan) -the *major* version of Node.js will be increased. -* When new features in the JavaScript language are introduced by V8 the -*minor* version number will be increased. TC39 has stated clearly that no -backwards incompatible changes will be made to the language so it is -appropriate to increase the minor rather than major. - -No new API will be added in *patch* releases. - -Any API addition will cause an increase in the *minor* version. - -## Channels - -Channels are points of collaboration with the broader community and are not strictly scoped to a repository or branch. - -* Release - Stable production ready builds. Unique version numbers following semver. -* Canary - Nightly builds w/ V8 version in Chrome Canary + changes landing to Node.js. No version designation. -* NG - "Next Generation." No version designation. - -## NG (Next Generation) - -In order for Node.js to stay competitive we need to work on the next generation of the platform which will more accurately integrate and reflect the advancements in the language and the ecosystem. - -While this constitutes a great leap forward for the platform we will be making this leap without breaking backwards compatibility with the existing ecosystem of modules. - -## Immediate Priorities - -### Debugging and Tracing - -Debugging is one of the first things from everyone's mouth, both developer and enterprise, when describing trouble they've had with Node.js. - -The goal of Node.js' effort is to build a healthy debugging and tracing ecosystem and not to try and build any "silver bullet" features for core (like the domains debacle). - -The [Tracing WG](https://github.com/nodejs/tracing-wg) is driving this effort: - -* AsyncWrap improvements - basically just iterations based on feedback from people using it. -* async-listener - userland module that will dogfood AsyncWrap as well as provide many often requested debugging features. -* Tracing - * Add tracing support for more platforms (LTTng, etc). - * [Unify the Tracing endpoint](https://github.com/nodejs/node/issues/729). - * New Chrome Debugger - Google is working on a version of Chrome's debugger that is without Chrome and can be used with Node.js. - -### Ecosystem Automation - -In order to maintain a good release cadence without harming compatibility we must do a better job of understanding exactly what impact a particular change or release will have on the ecosystem. This requires new automation. - -The initial goals for this automation are relatively simple but will create a baseline toolchain we can continue to improve upon. - -* Produce a list of modules that no longer build between two release versions. -* Produce a list of modules that use a particular core API. -* Produce detailed code coverage data for the tests in core. - -### Improve Installation and Upgrades - -* Host and maintain registry endpoints (Homebrew, apt, etc). -* Document installation and upgrade procedures with an emphasis on using nvm or nave for development and our registry endpoints for traditional package managers and production. - -### Streams - -* Fix all existing compatibility issues. -* Simplify stream creation to avoid user error. -* Explore and identify compatibility issues with [WHATWG Streams](https://github.com/whatwg/streams). -* Improve stream performance. - -### Internationalization / Localization - -* Build documentation tooling with localization support built in. -* Reduce size of ICU and ship with it by default. -* Continue growth of our i18n community. From e468cd3ee79e51e7306d86731106e4ac80ab2d22 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Sat, 25 Feb 2017 09:31:35 -0800 Subject: [PATCH 14/49] doc: argument types for console methods Refs: https://github.com/nodejs/node/issues/9399 PR-URL: https://github.com/nodejs/node/pull/11554 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung --- doc/api/console.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/api/console.md b/doc/api/console.md index 45566a9cdf586d..cd538d73328615 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -66,6 +66,8 @@ const Console = console.Console; ``` ### new Console(stdout[, stderr]) +* `stdout` {Writable} +* `stderr` {Writable} Creates a new `Console` by passing one or two writable stream instances. `stdout` is a writable stream to print log or info output. `stderr` @@ -94,6 +96,9 @@ new Console(process.stdout, process.stderr); +* `value` {any} +* `message` {any} +* `...args` {any} A simple assertion test that verifies whether `value` is truthy. If it is not, an `AssertionError` is thrown. If provided, the error `message` is formatted @@ -155,6 +160,11 @@ console.log('this will also print'); +* `obj` {any} +* `options` {Object} + * `showHidden` {Boolean} + * `depth` {Number} + * `colors` {Boolean} Uses [`util.inspect()`][] on `obj` and prints the resulting string to `stdout`. This function bypasses any custom `inspect()` function defined on `obj`. An @@ -176,6 +186,8 @@ Defaults to `false`. Colors are customizable; see +* `data` {any} +* `...args` {any} Prints to `stderr` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution @@ -198,6 +210,8 @@ values are concatenated. See [`util.format()`][] for more information. +* `data` {any} +* `...args` {any} The `console.info()` function is an alias for [`console.log()`][]. @@ -205,6 +219,8 @@ The `console.info()` function is an alias for [`console.log()`][]. +* `data` {any} +* `...args` {any} Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution @@ -227,6 +243,7 @@ values are concatenated. See [`util.format()`][] for more information. +* `label` {String} Starts a timer that can be used to compute the duration of an operation. Timers are identified by a unique `label`. Use the same `label` when you call @@ -242,6 +259,7 @@ changes: description: This method no longer supports multiple calls that don’t map to individual `console.time()` calls; see below for details. --> +* `label` {String} Stops a timer that was previously started by calling [`console.time()`][] and prints the result to `stdout`: @@ -260,10 +278,12 @@ leaking it. On older versions, the timer persisted. This allowed `console.timeEnd()` to be called multiple times for the same label. This functionality was unintended and is no longer supported.* -### console.trace(message[, ...args]) +### console.trace([message][, ...args]) +* `message` {any} +* `...args` {any} Prints to `stderr` the string `'Trace :'`, followed by the [`util.format()`][] formatted message and stack trace to the current position in the code. @@ -288,6 +308,8 @@ console.trace('Show me'); +* `data` {any} +* `...args` {any} The `console.warn()` function is an alias for [`console.error()`][]. From cdee945307aae3b0a7366dd06afb7c157c67e0a2 Mon Sep 17 00:00:00 2001 From: chiaki-yokoo Date: Fri, 17 Feb 2017 12:55:27 +0900 Subject: [PATCH 15/49] test: improve https coverage to check create connection PR-URL: https://github.com/nodejs/node/pull/11435 Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- .../test-https-agent-create-connection.js | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 test/parallel/test-https-agent-create-connection.js diff --git a/test/parallel/test-https-agent-create-connection.js b/test/parallel/test-https-agent-create-connection.js new file mode 100644 index 00000000000000..f593700081a88f --- /dev/null +++ b/test/parallel/test-https-agent-create-connection.js @@ -0,0 +1,124 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) { + common.skip('missing crypto'); + return; +} + +const assert = require('assert'); +const https = require('https'); + +const agent = new https.Agent(); + +const fs = require('fs'); + +const options = { + key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), + cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), +}; + +const server = https.createServer(options, (req, res) => { + res.end('hello world\n'); +}); + +const expectedHeader = /^HTTP\/1.1 200 OK/; +const expectedBody = /hello world\n/; +const expectCertError = /^Error: unable to verify the first certificate$/; + +const checkRequest = (socket, server) => { + let result = ''; + socket.on('connect', common.mustCall((data) => { + socket.write('GET / HTTP/1.1\r\n\r\n'); + socket.end(); + })); + socket.on('data', common.mustCall((chunk) => { + result += chunk; + })); + socket.on('end', common.mustCall(() => { + assert(expectedHeader.test(result)); + assert(expectedBody.test(result)); + server.close(); + })); +}; + +// use option connect +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + port: port, + host: host, + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + + const socket = agent.createConnection(options); + checkRequest(socket, server); +})); + +// use port and option connect +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, options); + checkRequest(socket, server); +})); + +// use port and host and option connect +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); +})); + +// use port and host and option does not have agentKey +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); +})); + +// options is null +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = null; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + })); +})); + +// options is undefined +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = undefined; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + })); +})); From 163d2d1624f387c4b034dafe82b228768cc4d333 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 27 Feb 2017 07:32:23 -0800 Subject: [PATCH 16/49] timers: unlock the timers API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the Stability Index on timers from Locked to Stable. Note that this is not intended to encourage changes to the timers API, but to allow it when its useful for Node.js (as has happened in violation of the documented stability level), and possibly to simplify the stability levels by removing Locked altogether. PR-URL: https://github.com/nodejs/node/pull/11580 Ref: https://github.com/nodejs/node/issues/11200 Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell Reviewed-By: Michaël Zasso Reviewed-By: Colin Ihrig --- doc/api/timers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/timers.md b/doc/api/timers.md index 75d6a36737b7d9..09c43bfeaa3532 100644 --- a/doc/api/timers.md +++ b/doc/api/timers.md @@ -1,6 +1,6 @@ # Timers -> Stability: 3 - Locked +> Stability: 2 - Stable The `timer` module exposes a global API for scheduling functions to be called at some future period of time. Because the timer functions are From 924b785d509e3d308fd0f211182b49d3c2aecbad Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 28 Feb 2017 20:33:12 +0100 Subject: [PATCH 17/49] test: fix test-internal-util-assertCrypto regex When building --without-ssl and then running: out/Release/node --expose-internals test/parallel/test-internal-util-assertCrypto.js The following error is displayed: assert.js:420 throw actual; ^ Error: Node.js is not compiled with openssl crypto support at Object.exports.assertCrypto (internal/util.js:82:11) at assert.throws (/Users/danielbevenius/work/nodejs/node/test/parallel/test-internal-util-assertCrypto.js:8:28) at _tryBlock (assert.js:379:5) at _throws (assert.js:398:12) at Function.throws (assert.js:428:3) at Object. (/Users/danielbevenius/work/nodejs/node/test/parallel/test-internal-util-assertCrypto.js:8:10) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) It looks like the regex is not taking into account the 'Error: ' hence the failure to match it. PR-URL: https://github.com/nodejs/node/pull/11620 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Yuta Hiroto Reviewed-By: Santiago Gimeno Reviewed-By: Colin Ihrig --- test/parallel/test-internal-util-assertCrypto.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-internal-util-assertCrypto.js b/test/parallel/test-internal-util-assertCrypto.js index f3003a2fee04e9..3a7acdb65c6b89 100644 --- a/test/parallel/test-internal-util-assertCrypto.js +++ b/test/parallel/test-internal-util-assertCrypto.js @@ -6,7 +6,7 @@ const util = require('internal/util'); if (!process.versions.openssl) { assert.throws(() => util.assertCrypto(), - /^Node.js is not compiled with openssl crypto support$/); + /^Error: Node.js is not compiled with openssl crypto support$/); } else { assert.doesNotThrow(() => util.assertCrypto()); } From 91a222de9903ba77c14d54ccd60908646837dc80 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 25 Feb 2017 16:23:49 -0800 Subject: [PATCH 18/49] test: enable max-len for test-repl Instead of disabling max-len (ESLint's line-length rule) for the entire file, reformat to avoid exceeding length restrictions in most cases and disable the rule only on specific lines where exceeding the length restriction may be a better choice than conforming to it. PR-URL: https://github.com/nodejs/node/pull/11559 Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- test/parallel/test-repl.js | 69 +++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 420010e1a3d6c9..3cf1b52e6179f2 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -1,4 +1,3 @@ -/* eslint-disable max-len */ 'use strict'; const common = require('../common'); @@ -168,18 +167,32 @@ function error_test() { { client: client_unix, send: 'new RegExp("foo", "wrong modifier");', expect: /\bSyntaxError: Invalid flags supplied to RegExp constructor/ }, // strict mode syntax errors should be caught (GH-5178) - { client: client_unix, send: '(function() { "use strict"; return 0755; })()', + { client: client_unix, + send: '(function() { "use strict"; return 0755; })()', expect: /\bSyntaxError: Octal literals are not allowed in strict mode/ }, - { client: client_unix, send: '(function(a, a, b) { "use strict"; return a + b + c; })()', - expect: /\bSyntaxError: Duplicate parameter name not allowed in this context/ }, - { client: client_unix, send: '(function() { "use strict"; with (this) {} })()', - expect: /\bSyntaxError: Strict mode code may not include a with statement/ }, - { client: client_unix, send: '(function() { "use strict"; var x; delete x; })()', - expect: /\bSyntaxError: Delete of an unqualified identifier in strict mode/ }, - { client: client_unix, send: '(function() { "use strict"; eval = 17; })()', + { + client: client_unix, + send: '(function(a, a, b) { "use strict"; return a + b + c; })()', + expect: /\bSyntaxError: Duplicate parameter name not allowed in this context/ // eslint-disable-line max-len + }, + { + client: client_unix, + send: '(function() { "use strict"; with (this) {} })()', + expect: /\bSyntaxError: Strict mode code may not include a with statement/ + }, + { + client: client_unix, + send: '(function() { "use strict"; var x; delete x; })()', + expect: /\bSyntaxError: Delete of an unqualified identifier in strict mode/ // eslint-disable-line max-len + }, + { client: client_unix, + send: '(function() { "use strict"; eval = 17; })()', expect: /\bSyntaxError: Unexpected eval or arguments in strict mode/ }, - { client: client_unix, send: '(function() { "use strict"; if (true) function f() { } })()', - expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block./ }, + { + client: client_unix, + send: '(function() { "use strict"; if (true) function f() { } })()', + expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block./ // eslint-disable-line max-len + }, // Named functions can be used: { client: client_unix, send: 'function blah() { return 1; }', expect: prompt_unix }, @@ -312,16 +325,20 @@ function error_test() { { client: client_unix, send: 'require("internal/repl")', expect: /^Error: Cannot find module 'internal\/repl'/ }, // REPL should handle quotes within regexp literal in multiline mode - { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", + { client: client_unix, + send: "function x(s) {\nreturn s.replace(/'/,'');\n}", expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", + { client: client_unix, + send: "function x(s) {\nreturn s.replace(/'/,'');\n}", expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - { client: client_unix, send: 'function x(s) {\nreturn s.replace(/"/,"");\n}', + { client: client_unix, + send: 'function x(s) {\nreturn s.replace(/"/,"");\n}', expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - { client: client_unix, send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}', + { client: client_unix, + send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}', expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, { client: client_unix, send: '{ var x = 4; }', @@ -356,14 +373,20 @@ function error_test() { expect: '{ value: undefined, done: true }' }, // https://github.com/nodejs/node/issues/9300 - { client: client_unix, send: 'function foo() {\nvar bar = 1 / 1; // "/"\n}', - expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - - { client: client_unix, send: '(function() {\nreturn /foo/ / /bar/;\n}())', - expect: prompt_multiline + prompt_multiline + 'NaN\n' + prompt_unix }, - - { client: client_unix, send: '(function() {\nif (false) {} /bar"/;\n}())', - expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix } + { + client: client_unix, send: 'function foo() {\nvar bar = 1 / 1; // "/"\n}', + expect: `${prompt_multiline}${prompt_multiline}undefined\n${prompt_unix}` + }, + + { + client: client_unix, send: '(function() {\nreturn /foo/ / /bar/;\n}())', + expect: prompt_multiline + prompt_multiline + 'NaN\n' + prompt_unix + }, + + { + client: client_unix, send: '(function() {\nif (false) {} /bar"/;\n}())', + expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix + } ]); } From 00dd20c173800bb579982a9980513101fe30955e Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 2 Mar 2017 12:34:07 +0100 Subject: [PATCH 19/49] test: fix flaky test-https-agent-create-connection Use a different server instance for every test to avoid that they reuse the same port. PR-URL: https://github.com/nodejs/node/pull/11649 Fixes: https://github.com/nodejs/node/issues/11644 Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Rich Trott Reviewed-By: Gibson Fahnestock --- .../test-https-agent-create-connection.js | 158 ++++++++++-------- 1 file changed, 90 insertions(+), 68 deletions(-) diff --git a/test/parallel/test-https-agent-create-connection.js b/test/parallel/test-https-agent-create-connection.js index f593700081a88f..6bd86fe166d3f2 100644 --- a/test/parallel/test-https-agent-create-connection.js +++ b/test/parallel/test-https-agent-create-connection.js @@ -18,10 +18,6 @@ const options = { cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), }; -const server = https.createServer(options, (req, res) => { - res.end('hello world\n'); -}); - const expectedHeader = /^HTTP\/1.1 200 OK/; const expectedBody = /hello world\n/; const expectCertError = /^Error: unable to verify the first certificate$/; @@ -42,83 +38,109 @@ const checkRequest = (socket, server) => { })); }; +function createServer() { + return https.createServer(options, (req, res) => { + res.end('hello world\n'); + }); +} + // use option connect -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - port: port, - host: host, - rejectUnauthorized: false, - _agentKey: agent.getName({ +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { port: port, host: host, - }), - }; + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; - const socket = agent.createConnection(options); - checkRequest(socket, server); -})); + const socket = agent.createConnection(options); + checkRequest(socket, server); + })); +} // use port and option connect -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - rejectUnauthorized: false, - _agentKey: agent.getName({ - port: port, - host: host, - }), - }; - const socket = agent.createConnection(port, options); - checkRequest(socket, server); -})); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, options); + checkRequest(socket, server); + })); +} // use port and host and option connect -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - rejectUnauthorized: false, - _agentKey: agent.getName({ - port: port, - host: host, - }), - }; - const socket = agent.createConnection(port, host, options); - checkRequest(socket, server); -})); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); + })); +} // use port and host and option does not have agentKey -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - rejectUnauthorized: false, - }; - const socket = agent.createConnection(port, host, options); - checkRequest(socket, server); -})); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); + })); +} // options is null -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = null; - const socket = agent.createConnection(port, host, options); - socket.on('error', common.mustCall((e) => { - assert(expectCertError.test(e.toString())); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = null; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + server.close(); + })); })); -})); +} // options is undefined -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = undefined; - const socket = agent.createConnection(port, host, options); - socket.on('error', common.mustCall((e) => { - assert(expectCertError.test(e.toString())); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = undefined; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + server.close(); + })); })); -})); +} From 3e79dffd2c0b11f9cd5f2b2b56557c858fe1ad43 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Thu, 2 Mar 2017 05:36:29 +0000 Subject: [PATCH 20/49] doc: fix WHATWG URL url.protocol example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Protocol of `https://example.org` is `https:` not `http:`. PR-URL: https://github.com/nodejs/node/pull/11647 Reviewed-By: James M Snell Reviewed-By: Timothy Gu Reviewed-By: Michaël Zasso Reviewed-By: Colin Ihrig --- doc/api/url.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/url.md b/doc/api/url.md index 637616364b54dc..5104c575396853 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -599,7 +599,7 @@ Gets and sets the protocol portion of the URL. ```js const myURL = new URL('https://example.org'); console.log(myURL.protocol); - // Prints http: + // Prints https: myURL.protocol = 'ftp'; console.log(myURL.href); From 1445e282c3f42069faf2f9b6469a25808cb72c76 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 27 Feb 2017 23:56:39 -0800 Subject: [PATCH 21/49] test: add test-buffer-prototype-inspect lib/buffer.js defines Buffer.prototype.inspect() to override how buffers are presented by util.inspect(). Add basic tests for it. PR-URL: https://github.com/nodejs/node/pull/11600 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Luigi Pinca --- .../parallel/test-buffer-prototype-inspect.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/parallel/test-buffer-prototype-inspect.js diff --git a/test/parallel/test-buffer-prototype-inspect.js b/test/parallel/test-buffer-prototype-inspect.js new file mode 100644 index 00000000000000..5f65a9bb288f16 --- /dev/null +++ b/test/parallel/test-buffer-prototype-inspect.js @@ -0,0 +1,23 @@ +'use strict'; +require('../common'); + +// lib/buffer.js defines Buffer.prototype.inspect() to override how buffers are +// presented by util.inspect(). + +const assert = require('assert'); +const util = require('util'); + +{ + const buf = Buffer.from('fhqwhgads'); + assert.strictEqual(util.inspect(buf), ''); +} + +{ + const buf = Buffer.from(''); + assert.strictEqual(util.inspect(buf), ''); +} + +{ + const buf = Buffer.from('x'.repeat(51)); + assert.ok(/^$/.test(util.inspect(buf))); +} From 02dbae6b3fed82f70c26732c309b76a54ceed913 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 28 Feb 2017 00:15:07 -0800 Subject: [PATCH 22/49] buffer: refactor Buffer.prototype.inspect() Replace toString().match().join() with toString().replace().trim(). This enables the elimination of a length check becuase replace() will return empty string if Buffer is empty whereas match() returns null. PR-URL: https://github.com/nodejs/node/pull/11600 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Luigi Pinca --- lib/buffer.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 21e24c2980f5e6..27e2b5393e7de0 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -521,12 +521,10 @@ Buffer.prototype.equals = function equals(b) { Buffer.prototype[internalUtil.customInspectSymbol] = function inspect() { var str = ''; var max = exports.INSPECT_MAX_BYTES; - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' '); - if (this.length > max) - str += ' ... '; - } - return '<' + this.constructor.name + ' ' + str + '>'; + str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); + if (this.length > max) + str += ' ... '; + return `<${this.constructor.name} ${str}>`; }; Buffer.prototype.inspect = Buffer.prototype[internalUtil.customInspectSymbol]; From ac3deb14812c170d6a7b53c4ed566862386bc23e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 28 Feb 2017 07:46:52 -0800 Subject: [PATCH 23/49] tools: remove NODE_PATH from environment for tests Unset NODE_PATH environment variable when running tests. On Ubuntu 16.04, some users experience test failures due to internal libraries being installed in /usr/lib/nodejs/internal and NODE_PATH including /usr/lib/nodejs. Tests that expect internal libraries to be off limits without the --expose-internals flag will fail in this situation. Currently, those tests are test/parallel/test-repl.js and test/parallel/test-internal-modules.js. This situation seems to (probably) be caused by some not-entirely-uncommon package that gets installed. Regardless, tests should ignore the user's NODE_PATH. (NODE_PATH is tested in test/parallel/test-module-globalpaths-nodepath.js and test/parallel/test-require-dot.js.) PR-URL: https://github.com/nodejs/node/pull/11612 Reviewed-By: James M Snell Reviewed-By: Bryan English Reviewed-By: Santiago Gimeno Refs: https://twitter.com/trott/status/835729396900061184 --- tools/test.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/test.py b/tools/test.py index f46b13fa30a66a..d6715937b60da3 100755 --- a/tools/test.py +++ b/tools/test.py @@ -702,8 +702,13 @@ def Execute(args, context, timeout=None, env={}, faketty=False): fd_in = 0 pty_out = None - # Extend environment env_copy = os.environ.copy() + + # Remove NODE_PATH + if "NODE_PATH" in env_copy: + del env_copy["NODE_PATH"] + + # Extend environment for key, value in env.iteritems(): env_copy[key] = value From e2133f3e572d62a97a3ea80cf181e32775e60499 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sat, 25 Feb 2017 23:40:39 -0500 Subject: [PATCH 24/49] os: improve cpus() performance PR-URL: https://github.com/nodejs/node/pull/11564 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Jackson Tian --- benchmark/os/cpus.js | 17 +++++++++++++ lib/os.js | 23 +++++++++++++++++- src/node_os.cc | 58 ++++++++++++++++++++++++++------------------ src/node_util.cc | 6 +++++ 4 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 benchmark/os/cpus.js diff --git a/benchmark/os/cpus.js b/benchmark/os/cpus.js new file mode 100644 index 00000000000000..2a8535113c207a --- /dev/null +++ b/benchmark/os/cpus.js @@ -0,0 +1,17 @@ +'use strict'; + +const common = require('../common.js'); +const cpus = require('os').cpus; + +const bench = common.createBenchmark(main, { + n: [3e4] +}); + +function main(conf) { + const n = +conf.n; + + bench.start(); + for (var i = 0; i < n; ++i) + cpus(); + bench.end(n); +} diff --git a/lib/os.js b/lib/os.js index 6d8ebd1ca55659..b2b960ea63d029 100644 --- a/lib/os.js +++ b/lib/os.js @@ -1,7 +1,9 @@ 'use strict'; const binding = process.binding('os'); +const getCPUs = binding.getCPUs; const getLoadAvg = binding.getLoadAvg; +const pushValToArrayMax = process.binding('util').pushValToArrayMax; const constants = process.binding('constants').os; const internalUtil = require('internal/util'); const isWindows = process.platform === 'win32'; @@ -10,7 +12,6 @@ exports.hostname = binding.getHostname; exports.uptime = binding.getUptime; exports.freemem = binding.getFreeMem; exports.totalmem = binding.getTotalMem; -exports.cpus = binding.getCPUs; exports.type = binding.getOSType; exports.release = binding.getOSRelease; exports.networkInterfaces = binding.getInterfaceAddresses; @@ -23,6 +24,26 @@ exports.loadavg = function loadavg() { return [avgValues[0], avgValues[1], avgValues[2]]; }; +const cpuValues = new Float64Array(6 * pushValToArrayMax); +function addCPUInfo() { + for (var i = 0, c = 0; i < arguments.length; ++i, c += 6) { + this[this.length] = { + model: arguments[i], + speed: cpuValues[c], + times: { + user: cpuValues[c + 1], + nice: cpuValues[c + 2], + sys: cpuValues[c + 3], + idle: cpuValues[c + 4], + irq: cpuValues[c + 5] + } + }; + } +} +exports.cpus = function cpus() { + return getCPUs(addCPUInfo, cpuValues, []); +}; + Object.defineProperty(exports, 'constants', { configurable: false, enumerable: true, diff --git a/src/node_os.cc b/src/node_os.cc index 211ac3d01dd8b2..c3f3ed75ab7d5d 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -32,6 +32,7 @@ using v8::ArrayBuffer; using v8::Boolean; using v8::Context; using v8::Float64Array; +using v8::Function; using v8::FunctionCallbackInfo; using v8::Integer; using v8::Local; @@ -122,36 +123,47 @@ static void GetOSRelease(const FunctionCallbackInfo& args) { static void GetCPUInfo(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); uv_cpu_info_t* cpu_infos; - int count, i; + int count, i, field_idx; int err = uv_cpu_info(&cpu_infos, &count); if (err) return; - Local cpus = Array::New(env->isolate()); - for (i = 0; i < count; i++) { + CHECK(args[0]->IsFunction()); + Local addfn = args[0].As(); + + CHECK(args[1]->IsFloat64Array()); + Local array = args[1].As(); + CHECK_EQ(array->Length(), 6 * NODE_PUSH_VAL_TO_ARRAY_MAX); + Local ab = array->Buffer(); + double* fields = static_cast(ab->GetContents().Data()); + + CHECK(args[2]->IsArray()); + Local cpus = args[2].As(); + + Local model_argv[NODE_PUSH_VAL_TO_ARRAY_MAX]; + int model_idx = 0; + + for (i = 0, field_idx = 0; i < count; i++) { uv_cpu_info_t* ci = cpu_infos + i; - Local times_info = Object::New(env->isolate()); - times_info->Set(env->user_string(), - Number::New(env->isolate(), ci->cpu_times.user)); - times_info->Set(env->nice_string(), - Number::New(env->isolate(), ci->cpu_times.nice)); - times_info->Set(env->sys_string(), - Number::New(env->isolate(), ci->cpu_times.sys)); - times_info->Set(env->idle_string(), - Number::New(env->isolate(), ci->cpu_times.idle)); - times_info->Set(env->irq_string(), - Number::New(env->isolate(), ci->cpu_times.irq)); - - Local cpu_info = Object::New(env->isolate()); - cpu_info->Set(env->model_string(), - OneByteString(env->isolate(), ci->model)); - cpu_info->Set(env->speed_string(), - Number::New(env->isolate(), ci->speed)); - cpu_info->Set(env->times_string(), times_info); - - (*cpus)->Set(i, cpu_info); + fields[field_idx++] = ci->speed; + fields[field_idx++] = ci->cpu_times.user; + fields[field_idx++] = ci->cpu_times.nice; + fields[field_idx++] = ci->cpu_times.sys; + fields[field_idx++] = ci->cpu_times.idle; + fields[field_idx++] = ci->cpu_times.irq; + model_argv[model_idx++] = OneByteString(env->isolate(), ci->model); + + if (model_idx >= NODE_PUSH_VAL_TO_ARRAY_MAX) { + addfn->Call(env->context(), cpus, model_idx, model_argv).ToLocalChecked(); + model_idx = 0; + field_idx = 0; + } + } + + if (model_idx > 0) { + addfn->Call(env->context(), cpus, model_idx, model_argv).ToLocalChecked(); } uv_free_cpu_info(cpu_infos, count); diff --git a/src/node_util.cc b/src/node_util.cc index a1387353e3d9a5..8279a787d7d1ac 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -141,6 +141,12 @@ void Initialize(Local target, } #undef V + target->DefineOwnProperty( + env->context(), + OneByteString(env->isolate(), "pushValToArrayMax"), + Integer::NewFromUnsigned(env->isolate(), NODE_PUSH_VAL_TO_ARRAY_MAX), + v8::ReadOnly).FromJust(); + env->SetMethod(target, "getHiddenValue", GetHiddenValue); env->SetMethod(target, "setHiddenValue", SetHiddenValue); env->SetMethod(target, "getProxyDetails", GetProxyDetails); From d6ac192fa32e88d599a202043e279c04a66d4280 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Thu, 2 Mar 2017 23:13:19 +0900 Subject: [PATCH 25/49] tls: fix macro to check NPN feature In order to check if NPN feature is enabled, use `#ifndef OPENSSL_NO_NEXTPROTONEG` rather than `#ifdef OPENSSL_NPN_NEGOTIATED` because the former is used in ssl.h. Fixes: https://github.com/nodejs/node/issues/11650 PR-URL: https://github.com/nodejs/node/pull/11655 Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Ben Noordhuis Reviewed-By: Fedor Indutny --- src/node.cc | 2 +- src/node_constants.cc | 2 +- src/node_crypto.cc | 16 ++++++++-------- src/node_crypto.h | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/node.cc b/src/node.cc index 25cd87defcf9e1..e6d37d8f44fcdf 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2892,7 +2892,7 @@ static Local GetFeatures(Environment* env) { // TODO(bnoordhuis) ping libuv obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate())); -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG Local tls_npn = True(env->isolate()); #else Local tls_npn = False(env->isolate()); diff --git a/src/node_constants.cc b/src/node_constants.cc index 8aa65ee7e23c35..a7c2d89906cced 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -942,7 +942,7 @@ void DefineOpenSSLConstants(Local target) { NODE_DEFINE_CONSTANT(target, DH_NOT_SUITABLE_GENERATOR); #endif -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG #define NPN_ENABLED 1 NODE_DEFINE_CONSTANT(target, NPN_ENABLED); #endif diff --git a/src/node_crypto.cc b/src/node_crypto.cc index d9f056682013b5..b5710e455c568d 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -147,7 +147,7 @@ template void SSLWrap::OnClientHello( void* arg, const ClientHelloParser::ClientHello& hello); -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG template int SSLWrap::AdvertiseNextProtoCallback( SSL* s, const unsigned char** data, @@ -1314,11 +1314,11 @@ void SSLWrap::AddMethods(Environment* env, Local t) { env->SetProtoMethod(t, "setMaxSendFragment", SetMaxSendFragment); #endif // SSL_set_max_send_fragment -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG env->SetProtoMethod(t, "getNegotiatedProtocol", GetNegotiatedProto); -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG env->SetProtoMethod(t, "setNPNProtocols", SetNPNProtocols); #endif @@ -1338,7 +1338,7 @@ void SSLWrap::AddMethods(Environment* env, Local t) { template void SSLWrap::InitNPN(SecureContext* sc) { -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG // Server should advertise NPN protocols SSL_CTX_set_next_protos_advertised_cb(sc->ctx_, AdvertiseNextProtoCallback, @@ -1346,7 +1346,7 @@ void SSLWrap::InitNPN(SecureContext* sc) { // Client should select protocol from list of advertised // If server supports NPN SSL_CTX_set_next_proto_select_cb(sc->ctx_, SelectNextProtoCallback, nullptr); -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG #ifdef NODE__HAVE_TLSEXT_STATUS_CB // OCSP stapling @@ -2091,7 +2091,7 @@ void SSLWrap::GetProtocol(const FunctionCallbackInfo& args) { } -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG template int SSLWrap::AdvertiseNextProtoCallback(SSL* s, const unsigned char** data, @@ -2231,7 +2231,7 @@ void SSLWrap::SetNPNProtocols(const FunctionCallbackInfo& args) { env->npn_buffer_private_symbol(), args[0]).FromJust()); } -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation template diff --git a/src/node_crypto.h b/src/node_crypto.h index 175206c40df586..38f49ba5a05063 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -249,7 +249,7 @@ class SSLWrap { const v8::FunctionCallbackInfo& args); #endif // SSL_set_max_send_fragment -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG static void GetNegotiatedProto( const v8::FunctionCallbackInfo& args); static void SetNPNProtocols(const v8::FunctionCallbackInfo& args); @@ -263,7 +263,7 @@ class SSLWrap { const unsigned char* in, unsigned int inlen, void* arg); -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG static void GetALPNNegotiatedProto( const v8::FunctionCallbackInfo& args); @@ -328,7 +328,7 @@ class Connection : public AsyncWrap, public SSLWrap { static void Initialize(Environment* env, v8::Local target); void NewSessionDoneCb(); -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG v8::Persistent npnProtos_; v8::Persistent selectedNPNProto_; #endif From 8377374754e0be64250146c5d24107642b0449c3 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Thu, 2 Mar 2017 23:19:49 +0900 Subject: [PATCH 26/49] test: fix tests when npn feature is disabled. ALPN test needs NPN feature to run. It also change the messages when ALPN and NPN tests are skipped. Fixes: https://github.com/nodejs/node/issues/11650 PR-URL: https://github.com/nodejs/node/pull/11655 Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Ben Noordhuis Reviewed-By: Fedor Indutny --- test/parallel/test-tls-alpn-server-client.js | 8 ++++---- test/parallel/test-tls-npn-server-client.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-tls-alpn-server-client.js b/test/parallel/test-tls-alpn-server-client.js index ca5785b09ac05a..9199d946791084 100644 --- a/test/parallel/test-tls-alpn-server-client.js +++ b/test/parallel/test-tls-alpn-server-client.js @@ -6,10 +6,10 @@ if (!common.hasCrypto) { return; } -if (!process.features.tls_alpn) { - console.error('Skipping because node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); - process.exit(0); +if (!process.features.tls_alpn || !process.features.tls_npn) { + common.skip('Skipping because node compiled without NPN or ALPN' + + ' feature of OpenSSL.'); + return; } const assert = require('assert'); diff --git a/test/parallel/test-tls-npn-server-client.js b/test/parallel/test-tls-npn-server-client.js index 3c69204d680d7c..c12fddb55bfab0 100644 --- a/test/parallel/test-tls-npn-server-client.js +++ b/test/parallel/test-tls-npn-server-client.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); if (!process.features.tls_npn) { - common.skip('node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); + common.skip('Skipping because node compiled without NPN feature of' + + ' OpenSSL.'); return; } From a4d14363a91dca6205184ae6488685fa93d94346 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Fri, 3 Mar 2017 16:09:43 +0200 Subject: [PATCH 27/49] test: fix args in parallel/test-fs-null-bytes.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The functions `fs.appendFile()` and `fs.writeFile()` were being called without the required `data` argument. Refs: https://github.com/nodejs/node/issues/11595 PR-URL: https://github.com/nodejs/node/pull/11601 Reviewed-By: Michaël Zasso Reviewed-By: Nikolai Vavilov Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- test/parallel/test-fs-null-bytes.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-fs-null-bytes.js b/test/parallel/test-fs-null-bytes.js index c56c8ff7cea4ff..522a1591e63962 100644 --- a/test/parallel/test-fs-null-bytes.js +++ b/test/parallel/test-fs-null-bytes.js @@ -23,7 +23,7 @@ function check(async, sync) { check(fs.access, fs.accessSync, 'foo\u0000bar'); check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK); -check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar'); +check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar', 'abc'); check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644'); check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34); check(fs.link, fs.linkSync, 'foo\u0000bar', 'foobar'); @@ -47,14 +47,14 @@ check(null, fs.unwatchFile, 'foo\u0000bar', common.mustNotCall()); check(fs.utimes, fs.utimesSync, 'foo\u0000bar', 0, 0); check(null, fs.watch, 'foo\u0000bar', common.mustNotCall()); check(null, fs.watchFile, 'foo\u0000bar', common.mustNotCall()); -check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar'); +check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar', 'abc'); const fileUrl = new URL('file:///C:/foo\u0000bar'); const fileUrl2 = new URL('file:///C:/foo%00bar'); check(fs.access, fs.accessSync, fileUrl); check(fs.access, fs.accessSync, fileUrl, fs.F_OK); -check(fs.appendFile, fs.appendFileSync, fileUrl); +check(fs.appendFile, fs.appendFileSync, fileUrl, 'abc'); check(fs.chmod, fs.chmodSync, fileUrl, '0644'); check(fs.chown, fs.chownSync, fileUrl, 12, 34); check(fs.link, fs.linkSync, fileUrl, 'foobar'); @@ -78,11 +78,11 @@ check(null, fs.unwatchFile, fileUrl, common.fail); check(fs.utimes, fs.utimesSync, fileUrl, 0, 0); check(null, fs.watch, fileUrl, common.fail); check(null, fs.watchFile, fileUrl, common.fail); -check(fs.writeFile, fs.writeFileSync, fileUrl); +check(fs.writeFile, fs.writeFileSync, fileUrl, 'abc'); check(fs.access, fs.accessSync, fileUrl2); check(fs.access, fs.accessSync, fileUrl2, fs.F_OK); -check(fs.appendFile, fs.appendFileSync, fileUrl2); +check(fs.appendFile, fs.appendFileSync, fileUrl2, 'abc'); check(fs.chmod, fs.chmodSync, fileUrl2, '0644'); check(fs.chown, fs.chownSync, fileUrl2, 12, 34); check(fs.link, fs.linkSync, fileUrl2, 'foobar'); @@ -106,7 +106,7 @@ check(null, fs.unwatchFile, fileUrl2, common.fail); check(fs.utimes, fs.utimesSync, fileUrl2, 0, 0); check(null, fs.watch, fileUrl2, common.fail); check(null, fs.watchFile, fileUrl2, common.fail); -check(fs.writeFile, fs.writeFileSync, fileUrl2); +check(fs.writeFile, fs.writeFileSync, fileUrl2, 'abc'); // an 'error' for exists means that it doesn't exist. // one of many reasons why this file is the absolute worst. From 98d33282d92d09c4e535c3b81ee8e3caf20bd6ae Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Fri, 3 Mar 2017 18:17:24 +0100 Subject: [PATCH 28/49] doc: add `Daijiro Wachi` to collaborators PR-URL: https://github.com/nodejs/node/pull/11676 Reviewed-By: Evan Lucas --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7fe05e05e27ad0..87e73ffb441cc8 100644 --- a/README.md +++ b/README.md @@ -337,6 +337,8 @@ more information about the governance of the Node.js project, see **Mike Tunnicliffe** <m.j.tunnicliffe@gmail.com> * [vkurchatkin](https://github.com/vkurchatkin) - **Vladimir Kurchatkin** <vladimir.kurchatkin@gmail.com> +* [watilde](https://github.com/watilde) - +**Daijiro Wachi** <daijiro.wachi@gmail.com> (he/him) * [whitlockjc](https://github.com/whitlockjc) - **Jeremy Whitlock** <jwhitlock@apache.org> * [yorkie](https://github.com/yorkie) - From f972bd81c677782c0439b63cafa436f91eeffd78 Mon Sep 17 00:00:00 2001 From: Eugene Ostroukhov Date: Thu, 16 Feb 2017 14:45:56 -0800 Subject: [PATCH 29/49] inspector: libuv notification on incoming message Currently Inspector posts a V8 "task" when a message is incoming. To make sure messages are processed even when no JS is executed (e.g. while waiting for I/O or timer), inspector will now post a libuv request. Fixes: https://github.com/nodejs/node/issues/11589 PR-URL: https://github.com/nodejs/node/pull/11617 Reviewed-By: Ben Noordhuis --- src/inspector_agent.cc | 17 +++++++++++++---- test/inspector/inspector-helper.js | 21 ++++++++++++++++++--- test/inspector/test-not-blocked-on-idle.js | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 test/inspector/test-not-blocked-on-idle.js diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index ae2e666384b5af..229bdfa36c6f55 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -159,6 +159,7 @@ class AgentImpl { static void ThreadCbIO(void* agent); static void WriteCbIO(uv_async_t* async); + static void MainThreadAsyncCb(uv_async_t* req); void InstallInspectorOnProcess(); @@ -190,6 +191,7 @@ class AgentImpl { node::Environment* parent_env_; uv_async_t io_thread_req_; + uv_async_t main_thread_req_; V8NodeInspector* inspector_; v8::Platform* platform_; MessageQueue incoming_message_queue_; @@ -334,6 +336,9 @@ AgentImpl::AgentImpl(Environment* env) : delegate_(nullptr), dispatching_messages_(false), session_id_(0), server_(nullptr) { + CHECK_EQ(0, uv_async_init(env->event_loop(), &main_thread_req_, + AgentImpl::MainThreadAsyncCb)); + uv_unref(reinterpret_cast(&main_thread_req_)); CHECK_EQ(0, uv_sem_init(&start_sem_, 0)); memset(&io_thread_req_, 0, sizeof(io_thread_req_)); } @@ -416,10 +421,7 @@ bool AgentImpl::Start(v8::Platform* platform, const char* path, InstallInspectorOnProcess(); - int err = uv_loop_init(&child_loop_); - CHECK_EQ(err, 0); - - err = uv_thread_create(&thread_, AgentImpl::ThreadCbIO, this); + int err = uv_thread_create(&thread_, AgentImpl::ThreadCbIO, this); CHECK_EQ(err, 0); uv_sem_wait(&start_sem_); @@ -606,6 +608,7 @@ void AgentImpl::PostIncomingMessage(InspectorAction action, int session_id, platform_->CallOnForegroundThread(isolate, new DispatchOnInspectorBackendTask(this)); isolate->RequestInterrupt(InterruptCallback, this); + CHECK_EQ(0, uv_async_send(&main_thread_req_)); } NotifyMessageReceived(); } @@ -662,6 +665,12 @@ void AgentImpl::DispatchMessages() { dispatching_messages_ = false; } +// static +void AgentImpl::MainThreadAsyncCb(uv_async_t* req) { + AgentImpl* agent = node::ContainerOf(&AgentImpl::main_thread_req_, req); + agent->DispatchMessages(); +} + void AgentImpl::Write(TransportAction action, int session_id, const StringView& inspector_message) { AppendMessage(&outgoing_message_queue_, action, session_id, diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index 3f3fe17e2e043e..beaf1a8aa1a3fd 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -427,9 +427,24 @@ Harness.prototype.expectShutDown = function(errorCode) { }); }; -exports.startNodeForInspectorTest = function(callback) { - const child = spawn(process.execPath, - [ '--inspect-brk', mainScript ]); +Harness.prototype.kill = function() { + return this.enqueue_((callback) => { + this.process_.kill(); + callback(); + }); +}; + +exports.startNodeForInspectorTest = function(callback, + inspectorFlag = '--inspect-brk', + opt_script_contents) { + const args = [inspectorFlag]; + if (opt_script_contents) { + args.push('-e', opt_script_contents); + } else { + args.push(mainScript); + } + + const child = spawn(process.execPath, args); const timeoutId = timeout('Child process did not start properly', 4); diff --git a/test/inspector/test-not-blocked-on-idle.js b/test/inspector/test-not-blocked-on-idle.js new file mode 100644 index 00000000000000..6d32888b44b802 --- /dev/null +++ b/test/inspector/test-not-blocked-on-idle.js @@ -0,0 +1,20 @@ +'use strict'; +require('../common'); +const helper = require('./inspector-helper.js'); + +function shouldShutDown(session) { + session + .sendInspectorCommands([ + { 'method': 'Debugger.enable' }, + { 'method': 'Debugger.pause' }, + ]) + .disconnect(true); +} + +function runTests(harness) { + // 1 second wait to make sure the inferior began running the script + setTimeout(() => harness.runFrontendSession([shouldShutDown]).kill(), 1000); +} + +const script = 'setInterval(() => {debugger;}, 60000);'; +helper.startNodeForInspectorTest(runTests, '--inspect', script); From f56ca30bf05d558b6475ae800e096c69ce4ec04a Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Sun, 5 Feb 2017 19:18:46 -0600 Subject: [PATCH 30/49] benchmark,build,doc,lib,src,test: correct typos PR-URL: https://github.com/nodejs/node/pull/11189 Reviewed-By: Brian White Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Sakthipriyan Vairamani --- benchmark/compare.R | 2 +- benchmark/compare.js | 2 +- configure | 2 +- doc/api_assets/dnt_helper.js | 2 +- doc/changelogs/CHANGELOG_ARCHIVE.md | 2 +- doc/changelogs/CHANGELOG_V5.md | 2 +- src/debug-agent.cc | 2 +- src/node.cc | 2 +- src/node_crypto.cc | 2 +- src/string_search.h | 12 ++++++------ src/tls_wrap.cc | 2 +- test/internet/test-dgram-broadcast-multi-process.js | 2 +- test/parallel/test-child-process-fork-dgram.js | 2 +- test/parallel/test-cluster-message.js | 2 +- test/parallel/test-cluster-setup-master-multiple.js | 2 +- test/parallel/test-crypto-binary-default.js | 4 ++-- test/parallel/test-crypto-cipheriv-decipheriv.js | 4 ++-- test/parallel/test-event-emitter-add-listeners.js | 12 ++++++------ test/parallel/test-fs-access.js | 4 ++-- test/parallel/test-process-no-deprecation.js | 2 +- test/parallel/test-stream-readable-needReadable.js | 2 +- ...ocket-timeout-removes-other-socket-unref-timer.js | 2 +- test/parallel/test-tls-check-server-identity.js | 2 +- 23 files changed, 36 insertions(+), 36 deletions(-) diff --git a/benchmark/compare.R b/benchmark/compare.R index 3f37cad74ad847..5085f4ea73b71a 100644 --- a/benchmark/compare.R +++ b/benchmark/compare.R @@ -47,7 +47,7 @@ statistics = ddply(dat, "name", function(subdat) { p.value = NA; confidence = 'NA'; - # Check if there is enough data to calulate the calculate the p-value + # Check if there is enough data to calculate the calculate the p-value if (length(old.rate) > 1 && length(new.rate) > 1) { # Perform a statistics test to see of there actually is a difference in # performance. diff --git a/benchmark/compare.js b/benchmark/compare.js index af36d1c4239edf..a671bc9f3d7be6 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -9,7 +9,7 @@ const BenchmarkProgress = require('./_benchmark_progress.js'); // Parse arguments // const cli = CLI(`usage: ./node compare.js [options] [--] ... - Run each benchmark in the directory many times using two diffrent + Run each benchmark in the directory many times using two different node versions. More than one directory can be specified. The output is formatted as csv, which can be processed using for example 'compare.R'. diff --git a/configure b/configure index 50078df43a9ed5..866d095e2e74a9 100755 --- a/configure +++ b/configure @@ -503,7 +503,7 @@ def warn(msg): prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING' print('%s: %s' % (prefix, msg)) -# track if warnings occured +# track if warnings occurred warn.warned = False def b(value): diff --git a/doc/api_assets/dnt_helper.js b/doc/api_assets/dnt_helper.js index f255d916c2df32..9906db4f276cd7 100644 --- a/doc/api_assets/dnt_helper.js +++ b/doc/api_assets/dnt_helper.js @@ -26,7 +26,7 @@ function _dntEnabled(dnt, userAgent) { var fxMatch = ua.match(/Firefox\/(\d+)/); var ieRegEx = /MSIE|Trident/i; var isIE = ieRegEx.test(ua); - // Matches from Windows up to the first occurance of ; un-greedily + // Matches from Windows up to the first occurrence of ; un-greedily // http://www.regexr.com/3c2el var platform = ua.match(/Windows.+?(?=;)/g); diff --git a/doc/changelogs/CHANGELOG_ARCHIVE.md b/doc/changelogs/CHANGELOG_ARCHIVE.md index 797317ea43fe81..7a643ca5c3a397 100644 --- a/doc/changelogs/CHANGELOG_ARCHIVE.md +++ b/doc/changelogs/CHANGELOG_ARCHIVE.md @@ -3025,7 +3025,7 @@ https://github.com/nodejs/node/commit/311d7dee19034ff1c6bc9098c36973b8d687eaba * After V8 heap is compact, don't use a timer every 2 seconds. * Improve nextTick implementation. - * Add primative support for Upgrading HTTP connections. + * Add primitive support for Upgrading HTTP connections. (See commit log for docs 760bba5) * Add timeout and maxBuffer options to child_process.exec diff --git a/doc/changelogs/CHANGELOG_V5.md b/doc/changelogs/CHANGELOG_V5.md index aa69d93f7ce180..5fefbcc81a6b85 100644 --- a/doc/changelogs/CHANGELOG_V5.md +++ b/doc/changelogs/CHANGELOG_V5.md @@ -215,7 +215,7 @@ This is a security release. All Node.js users should consult the security releas ### Notable changes **http**: - * Enclose IPv6 Host header in square brackets. This will enable proper separation of the host adress from any port reference (Mihai Potra) [#5314](https://github.com/nodejs/node/pull/5314) + * Enclose IPv6 Host header in square brackets. This will enable proper separation of the host address from any port reference (Mihai Potra) [#5314](https://github.com/nodejs/node/pull/5314) **path**: * Make win32.isAbsolute more consistent (Brian White) [#6028](https://github.com/nodejs/node/pull/6028) diff --git a/src/debug-agent.cc b/src/debug-agent.cc index 2d8ed8afc980ec..2ce8381fc51462 100644 --- a/src/debug-agent.cc +++ b/src/debug-agent.cc @@ -182,7 +182,7 @@ void Agent::WorkerRun() { CHECK_EQ(&child_loop_, env.event_loop()); uv_run(&child_loop_, UV_RUN_DEFAULT); - // Clean-up peristent + // Clean-up persistent api_.Reset(); } isolate->Dispose(); diff --git a/src/node.cc b/src/node.cc index e6d37d8f44fcdf..35d29bda93eea8 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3444,7 +3444,7 @@ void LoadEnvironment(Environment* env) { // (FatalException(), break on uncaught exception in debugger) // // This is not strictly necessary since it's almost impossible - // to attach the debugger fast enought to break on exception + // to attach the debugger fast enough to break on exception // thrown during process startup. try_catch.SetVerbose(true); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index b5710e455c568d..dec89b151171bf 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -913,7 +913,7 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo& args) { (void) &clear_error_on_return; // Silence compiler warning. // Auto DH is not supported in openssl 1.0.1, so dhparam needs - // to be specifed explicitly + // to be specified explicitly if (args.Length() != 1) return env->ThrowTypeError("DH argument is mandatory"); diff --git a/src/string_search.h b/src/string_search.h index abc69edb87621d..6040888110c2ec 100644 --- a/src/string_search.h +++ b/src/string_search.h @@ -238,7 +238,7 @@ inline const void* MemrchrFill(const void* haystack, uint8_t needle, } -// Finds the first occurence of *two-byte* character pattern[0] in the string +// Finds the first occurrence of *two-byte* character pattern[0] in the string // `subject`. Does not check that the whole pattern matches. template inline size_t FindFirstCharacter(Vector pattern, @@ -284,7 +284,7 @@ inline size_t FindFirstCharacter(Vector pattern, } -// Finds the first occurance of the byte pattern[0] in string `subject`. +// Finds the first occurrence of the byte pattern[0] in string `subject`. // Does not verify that the whole pattern matches. template <> inline size_t FindFirstCharacter(Vector pattern, @@ -373,7 +373,7 @@ size_t StringSearch::BoyerMooreSearch( // Only preprocess at most kBMMaxShift last characters of pattern. size_t start = search->start_; - int* bad_char_occurence = search->bad_char_table(); + int* bad_char_occurrence = search->bad_char_table(); int* good_suffix_shift = search->good_suffix_shift_table(); Char last_char = pattern[pattern_length - 1]; @@ -383,7 +383,7 @@ size_t StringSearch::BoyerMooreSearch( size_t j = pattern_length - 1; int c; while (last_char != (c = subject[index + j])) { - int shift = j - CharOccurrence(bad_char_occurence, c); + int shift = j - CharOccurrence(bad_char_occurrence, c); index += shift; if (index > subject_length - pattern_length) { return subject.length(); @@ -399,11 +399,11 @@ size_t StringSearch::BoyerMooreSearch( // we have matched more than our tables allow us to be smart about. // Fall back on BMH shift. index += pattern_length - 1 - - CharOccurrence(bad_char_occurence, + CharOccurrence(bad_char_occurrence, static_cast(last_char)); } else { int gs_shift = good_suffix_shift[j + 1]; - int bc_occ = CharOccurrence(bad_char_occurence, c); + int bc_occ = CharOccurrence(bad_char_occurrence, c); int shift = j - bc_occ; if (gs_shift > shift) { shift = gs_shift; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index d56128fec6c5ce..581e017ef85016 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -123,7 +123,7 @@ void TLSWrap::InitSSL() { SSL_set_bio(ssl_, enc_in_, enc_out_); - // NOTE: This could be overriden in SetVerifyMode + // NOTE: This could be overridden in SetVerifyMode SSL_set_verify(ssl_, SSL_VERIFY_NONE, crypto::VerifyCallback); #ifdef SSL_MODE_RELEASE_BUFFERS diff --git a/test/internet/test-dgram-broadcast-multi-process.js b/test/internet/test-dgram-broadcast-multi-process.js index da3bd8cceb74e3..8414e558bab6d1 100644 --- a/test/internet/test-dgram-broadcast-multi-process.js +++ b/test/internet/test-dgram-broadcast-multi-process.js @@ -227,7 +227,7 @@ if (process.argv[2] === 'child') { listenSocket.on('close', function() { //HACK: Wait to exit the process to ensure that the parent //process has had time to receive all messages via process.send() - //This may be indicitave of some other issue. + //This may be indicative of some other issue. setTimeout(function() { process.exit(); }, 1000); diff --git a/test/parallel/test-child-process-fork-dgram.js b/test/parallel/test-child-process-fork-dgram.js index 4447c54cae8f0c..37b40dccd3f369 100644 --- a/test/parallel/test-child-process-fork-dgram.js +++ b/test/parallel/test-child-process-fork-dgram.js @@ -63,7 +63,7 @@ if (process.argv[2] === 'child') { const timer = setInterval(function() { /* * Both the parent and the child got at least one message, - * test passed, clean up everyting. + * test passed, clean up everything. */ if (parentGotMessage && childGotMessage) { clearInterval(timer); diff --git a/test/parallel/test-cluster-message.js b/test/parallel/test-cluster-message.js index 5b537bbe73a755..0b699093821b82 100644 --- a/test/parallel/test-cluster-message.js +++ b/test/parallel/test-cluster-message.js @@ -102,7 +102,7 @@ if (cluster.isWorker) { if (data.code === 'received message') { check('worker', data.echo === 'message from master'); } else { - throw new Error('wrong TCP message recived: ' + data); + throw new Error('wrong TCP message received: ' + data); } }); diff --git a/test/parallel/test-cluster-setup-master-multiple.js b/test/parallel/test-cluster-setup-master-multiple.js index 25cff7cb33e0c1..c8fefddc39a23e 100644 --- a/test/parallel/test-cluster-setup-master-multiple.js +++ b/test/parallel/test-cluster-setup-master-multiple.js @@ -6,7 +6,7 @@ const cluster = require('cluster'); assert(cluster.isMaster); // The cluster.settings object is cloned even though the current implementation -// makes that unecessary. This is to make the test less fragile if the +// makes that unnecessary. This is to make the test less fragile if the // implementation ever changes such that cluster.settings is mutated instead of // replaced. function cheapClone(obj) { diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js index 6ee3aeac36dd89..7dbd5e41639a38 100644 --- a/test/parallel/test-crypto-binary-default.js +++ b/test/parallel/test-crypto-binary-default.js @@ -477,7 +477,7 @@ function testCipher2(key) { function testCipher3(key, iv) { - // Test encyrption and decryption with explicit key and iv + // Test encryption and decryption with explicit key and iv const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + @@ -496,7 +496,7 @@ function testCipher3(key, iv) { function testCipher4(key, iv) { - // Test encyrption and decryption with explicit key and iv + // Test encryption and decryption with explicit key and iv const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + diff --git a/test/parallel/test-crypto-cipheriv-decipheriv.js b/test/parallel/test-crypto-cipheriv-decipheriv.js index 6f22dbe71affb1..a03a25d511fe16 100644 --- a/test/parallel/test-crypto-cipheriv-decipheriv.js +++ b/test/parallel/test-crypto-cipheriv-decipheriv.js @@ -9,7 +9,7 @@ if (!common.hasCrypto) { const crypto = require('crypto'); function testCipher1(key, iv) { - // Test encyrption and decryption with explicit key and iv + // Test encryption and decryption with explicit key and iv const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + @@ -41,7 +41,7 @@ function testCipher1(key, iv) { function testCipher2(key, iv) { - // Test encyrption and decryption with explicit key and iv + // Test encryption and decryption with explicit key and iv const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + diff --git a/test/parallel/test-event-emitter-add-listeners.js b/test/parallel/test-event-emitter-add-listeners.js index 33125daabdb3b3..81af3fd50c8b50 100644 --- a/test/parallel/test-event-emitter-add-listeners.js +++ b/test/parallel/test-event-emitter-add-listeners.js @@ -5,8 +5,8 @@ const EventEmitter = require('events'); { const ee = new EventEmitter(); - const events_new_listener_emited = []; - const listeners_new_listener_emited = []; + const events_new_listener_emitted = []; + const listeners_new_listener_emitted = []; // Sanity check assert.strictEqual(ee.addListener, ee.on); @@ -16,8 +16,8 @@ const EventEmitter = require('events'); if (event === 'newListener') return; - events_new_listener_emited.push(event); - listeners_new_listener_emited.push(listener); + events_new_listener_emitted.push(event); + listeners_new_listener_emitted.push(listener); }); const hello = common.mustCall(function(a, b) { @@ -33,8 +33,8 @@ const EventEmitter = require('events'); ee.on('hello', hello); ee.once('foo', common.fail); - assert.deepStrictEqual(['hello', 'foo'], events_new_listener_emited); - assert.deepStrictEqual([hello, common.fail], listeners_new_listener_emited); + assert.deepStrictEqual(['hello', 'foo'], events_new_listener_emitted); + assert.deepStrictEqual([hello, common.fail], listeners_new_listener_emitted); ee.emit('hello', 'a', 'b'); } diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index b03bf572f6a5bd..d5934dd614ec04 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -32,11 +32,11 @@ createFileWithPerms(readWriteFile, 0o666); * * There's not really any point in resetting the process' user id to 0 after * changing it to 'nobody', since in the case that the test runs without - * superuser priviledge, it is not possible to change its process user id to + * superuser privilege, it is not possible to change its process user id to * superuser. * * It can prevent the test from removing files created before the change of user - * id, but that's fine. In this case, it is the responsability of the + * id, but that's fine. In this case, it is the responsibility of the * continuous integration platform to take care of that. */ let hasWriteAccessForReadonlyFile = false; diff --git a/test/parallel/test-process-no-deprecation.js b/test/parallel/test-process-no-deprecation.js index 60394ea0d38ddf..4d4dfa86fb67ad 100644 --- a/test/parallel/test-process-no-deprecation.js +++ b/test/parallel/test-process-no-deprecation.js @@ -1,7 +1,7 @@ 'use strict'; // Flags: --no-warnings -// The --no-warnings flag only supresses writing the warning to stderr, not the +// The --no-warnings flag only suppresses writing the warning to stderr, not the // emission of the corresponding event. This test file can be run without it. const common = require('../common'); diff --git a/test/parallel/test-stream-readable-needReadable.js b/test/parallel/test-stream-readable-needReadable.js index 48229edd202333..be397dc5dc5f74 100644 --- a/test/parallel/test-stream-readable-needReadable.js +++ b/test/parallel/test-stream-readable-needReadable.js @@ -74,7 +74,7 @@ const slowProducer = new Readable({ slowProducer.on('readable', common.mustCall(() => { if (slowProducer.read(8) === null) { - // The buffer doesn't have enough data, and the stream is not ened, + // The buffer doesn't have enough data, and the stream is not need, // we need to notify the reader when data arrives. assert.strictEqual(slowProducer._readableState.needReadable, true); } else { diff --git a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js index f42144360b6941..5d57bbaae0011e 100644 --- a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js +++ b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js @@ -25,7 +25,7 @@ const server = net.createServer(function onClient(client) { clients[1].end(); }); - // Use a delay that is higher than the lowest timer resolution accross all + // Use a delay that is higher than the lowest timer resolution across all // supported platforms, so that the two timers don't fire at the same time. clients[1].setTimeout(50); } diff --git a/test/parallel/test-tls-check-server-identity.js b/test/parallel/test-tls-check-server-identity.js index 5c89ef8bf4d425..9439735ce069b4 100644 --- a/test/parallel/test-tls-check-server-identity.js +++ b/test/parallel/test-tls-check-server-identity.js @@ -177,7 +177,7 @@ const tests = [ error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' + 'DNS:*b.a.com' }, - // Mutliple DNS names + // Multiple DNS names { host: 'a.b.a.com', cert: { subjectaltname: 'DNS:*b.a.com, DNS:a.b.a.com', From 24e6fcce8b61fe3b94dc5d86af0ce15e180a367a Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Tue, 28 Feb 2017 10:06:25 +0100 Subject: [PATCH 31/49] url: use `hasIntl` instead of `try-catch` Like the other internal modules, we should use `process.binding('config').hasIntl` instead of `try-catch` to make sure `icu` is bonded or not. PR-URL: https://github.com/nodejs/node/pull/11571 Reviewed-By: James M Snell Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Jackson Tian --- lib/url.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/url.js b/lib/url.js index 42853e346c474f..cc098593a5f238 100644 --- a/lib/url.js +++ b/lib/url.js @@ -1,15 +1,7 @@ 'use strict'; -function importPunycode() { - try { - return process.binding('icu'); - } catch (e) { - return require('punycode'); - } -} - -const { toASCII } = importPunycode(); - +const { toASCII } = process.binding('config').hasIntl ? + process.binding('icu') : require('punycode'); const { StorageObject, hexTable } = require('internal/querystring'); const internalUrl = require('internal/url'); exports.parse = urlParse; From f69685be65e43e8ba1fa1ea4b18677c83fefa118 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 1 Mar 2017 18:58:10 -0800 Subject: [PATCH 32/49] test: remove obsolete eslint-disable comment The align-function-arguments custom rule is obsolete and has been removed from the code base. Remove comment that used to disable it for one file. PR-URL: https://github.com/nodejs/node/pull/11643 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Teddy Katz --- test/parallel/test-http-parser-bad-ref.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/parallel/test-http-parser-bad-ref.js b/test/parallel/test-http-parser-bad-ref.js index 97b4685e18382b..c4ab1db8659ef7 100644 --- a/test/parallel/test-http-parser-bad-ref.js +++ b/test/parallel/test-http-parser-bad-ref.js @@ -75,12 +75,10 @@ demoBug('POST /1', '/22 HTTP/1.1\r\n' + 'Content-Length: 4\r\n\r\n' + 'pong'); -/* eslint-disable align-function-arguments */ demoBug('POST /1/22 HTTP/1.1\r\n' + 'Content-Type: tex', 't/plain\r\n' + 'Content-Length: 4\r\n\r\n' + 'pong'); -/* eslint-enable align-function-arguments */ process.on('exit', function() { assert.strictEqual(2, headersComplete); From 821d713a38a139c82f1406d27a8455e3d1ff209c Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 3 Mar 2017 11:02:20 +0100 Subject: [PATCH 33/49] src: remove outdated FIXME in node_crypto.cc Issue 4641 contains a FIXME regarding the InitCrypto function. After discussing this with bnoordhuis it seems to be an outdated comment. Refs: https://github.com/nodejs/node/issues/4641 PR-URL: https://github.com/nodejs/node/pull/11669 Reviewed-By: Gibson Fahnestock Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/node_crypto.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index dec89b151171bf..4c282956581e8f 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5998,7 +5998,6 @@ void SetFipsCrypto(const FunctionCallbackInfo& args) { #endif /* NODE_FIPS_MODE */ } -// FIXME(bnoordhuis) Handle global init correctly. void InitCrypto(Local target, Local unused, Local context, From 039a1a97d80ad629ed31f2520125d0a0867018a4 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 27 Feb 2017 17:54:16 -0800 Subject: [PATCH 34/49] dns: minor refactor of dns module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move to the more efficient module.exports = {} pattern. PR-URL: https://github.com/nodejs/node/pull/11597 Reviewed-By: Colin Ihrig Reviewed-By: Claudio Rodriguez Reviewed-By: Michaël Zasso --- lib/dns.js | 130 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 56 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index cfa04ed192050f..1f22c91c78c27a 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -99,7 +99,7 @@ function onlookupall(err, addresses) { // Easy DNS A/AAAA look up // lookup(hostname, [options,] callback) -exports.lookup = function lookup(hostname, options, callback) { +function lookup(hostname, options, callback) { var hints = 0; var family = -1; var all = false; @@ -119,9 +119,9 @@ exports.lookup = function lookup(hostname, options, callback) { all = options.all === true; if (hints !== 0 && - hints !== exports.ADDRCONFIG && - hints !== exports.V4MAPPED && - hints !== (exports.ADDRCONFIG | exports.V4MAPPED)) { + hints !== cares.AI_ADDRCONFIG && + hints !== cares.AI_V4MAPPED && + hints !== (cares.AI_ADDRCONFIG | cares.AI_V4MAPPED)) { throw new TypeError('Invalid argument: hints must use valid flags'); } } else { @@ -166,7 +166,7 @@ exports.lookup = function lookup(hostname, options, callback) { callback.immediately = true; return req; -}; +} function onlookupservice(err, host, service) { @@ -178,7 +178,7 @@ function onlookupservice(err, host, service) { // lookupService(address, port, callback) -exports.lookupService = function lookupService(host, port, callback) { +function lookupService(host, port, callback) { if (arguments.length !== 3) throw new Error('Invalid arguments'); @@ -205,7 +205,7 @@ exports.lookupService = function lookupService(host, port, callback) { callback.immediately = true; return req; -}; +} function onresolve(err, result, ttls) { @@ -251,26 +251,25 @@ function resolver(bindingName) { var resolveMap = Object.create(null); -exports.resolve4 = resolveMap.A = resolver('queryA'); -exports.resolve6 = resolveMap.AAAA = resolver('queryAaaa'); -exports.resolveCname = resolveMap.CNAME = resolver('queryCname'); -exports.resolveMx = resolveMap.MX = resolver('queryMx'); -exports.resolveNs = resolveMap.NS = resolver('queryNs'); -exports.resolveTxt = resolveMap.TXT = resolver('queryTxt'); -exports.resolveSrv = resolveMap.SRV = resolver('querySrv'); -exports.resolvePtr = resolveMap.PTR = resolver('queryPtr'); -exports.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr'); -exports.resolveSoa = resolveMap.SOA = resolver('querySoa'); -exports.reverse = resolver('getHostByAddr'); - - -exports.resolve = function resolve(hostname, type_, callback_) { +resolveMap.A = resolver('queryA'); +resolveMap.AAAA = resolver('queryAaaa'); +resolveMap.CNAME = resolver('queryCname'); +resolveMap.MX = resolver('queryMx'); +resolveMap.NS = resolver('queryNs'); +resolveMap.TXT = resolver('queryTxt'); +resolveMap.SRV = resolver('querySrv'); +resolveMap.PTR = resolver('queryPtr'); +resolveMap.NAPTR = resolver('queryNaptr'); +resolveMap.SOA = resolver('querySoa'); + + +function resolve(hostname, type_, callback_) { var resolver, callback; if (typeof type_ === 'string') { resolver = resolveMap[type_]; callback = callback_; } else if (typeof type_ === 'function') { - resolver = exports.resolve4; + resolver = resolveMap.A; callback = type_; } else { throw new Error('"type" argument must be a string'); @@ -281,15 +280,15 @@ exports.resolve = function resolve(hostname, type_, callback_) { } else { throw new Error(`Unknown type "${type_}"`); } -}; +} -exports.getServers = function getServers() { +function getServers() { return cares.getServers(); -}; +} -exports.setServers = function setServers(servers) { +function setServers(servers) { // cache the original servers because in the event of an error setting the // servers cares won't have any servers available for resolution const orig = cares.getServers(); @@ -326,34 +325,53 @@ exports.setServers = function setServers(servers) { var err = cares.strerror(errorNumber); throw new Error(`c-ares failed to set servers: "${err}" [${servers}]`); } -}; +} -// uv_getaddrinfo flags -exports.ADDRCONFIG = cares.AI_ADDRCONFIG; -exports.V4MAPPED = cares.AI_V4MAPPED; - -// ERROR CODES -exports.NODATA = 'ENODATA'; -exports.FORMERR = 'EFORMERR'; -exports.SERVFAIL = 'ESERVFAIL'; -exports.NOTFOUND = 'ENOTFOUND'; -exports.NOTIMP = 'ENOTIMP'; -exports.REFUSED = 'EREFUSED'; -exports.BADQUERY = 'EBADQUERY'; -exports.BADNAME = 'EBADNAME'; -exports.BADFAMILY = 'EBADFAMILY'; -exports.BADRESP = 'EBADRESP'; -exports.CONNREFUSED = 'ECONNREFUSED'; -exports.TIMEOUT = 'ETIMEOUT'; -exports.EOF = 'EOF'; -exports.FILE = 'EFILE'; -exports.NOMEM = 'ENOMEM'; -exports.DESTRUCTION = 'EDESTRUCTION'; -exports.BADSTR = 'EBADSTR'; -exports.BADFLAGS = 'EBADFLAGS'; -exports.NONAME = 'ENONAME'; -exports.BADHINTS = 'EBADHINTS'; -exports.NOTINITIALIZED = 'ENOTINITIALIZED'; -exports.LOADIPHLPAPI = 'ELOADIPHLPAPI'; -exports.ADDRGETNETWORKPARAMS = 'EADDRGETNETWORKPARAMS'; -exports.CANCELLED = 'ECANCELLED'; +module.exports = { + lookup, + lookupService, + getServers, + setServers, + resolve, + resolve4: resolveMap.A, + resolve6: resolveMap.AAAA, + resolveCname: resolveMap.CNAME, + resolveMx: resolveMap.MX, + resolveNs: resolveMap.NS, + resolveTxt: resolveMap.TXT, + resolveSrv: resolveMap.SRV, + resolvePtr: resolveMap.PTR, + resolveNaptr: resolveMap.NAPTR, + resolveSoa: resolveMap.SOA, + reverse: resolver('getHostByAddr'), + + // uv_getaddrinfo flags + ADDRCONFIG: cares.AI_ADDRCONFIG, + V4MAPPED: cares.AI_V4MAPPED, + + // ERROR CODES + NODATA: 'ENODATA', + FORMERR: 'EFORMERR', + SERVFAIL: 'ESERVFAIL', + NOTFOUND: 'ENOTFOUND', + NOTIMP: 'ENOTIMP', + REFUSED: 'EREFUSED', + BADQUERY: 'EBADQUERY', + BADNAME: 'EBADNAME', + BADFAMILY: 'EBADFAMILY', + BADRESP: 'EBADRESP', + CONNREFUSED: 'ECONNREFUSED', + TIMEOUT: 'ETIMEOUT', + EOF: 'EOF', + FILE: 'EFILE', + NOMEM: 'ENOMEM', + DESTRUCTION: 'EDESTRUCTION', + BADSTR: 'EBADSTR', + BADFLAGS: 'EBADFLAGS', + NONAME: 'ENONAME', + BADHINTS: 'EBADHINTS', + NOTINITIALIZED: 'ENOTINITIALIZED', + LOADIPHLPAPI: 'ELOADIPHLPAPI', + ADDRGETNETWORKPARAMS: 'EADDRGETNETWORKPARAMS', + CANCELLED: 'ECANCELLED' +}; From b4dcb26681a240bf0741d54ec324d4239accd0c4 Mon Sep 17 00:00:00 2001 From: maurice_hayward Date: Mon, 27 Feb 2017 16:37:05 -0500 Subject: [PATCH 35/49] test: changed test1 of test-vm-timeout.js test: changed test1 of test-vm-timeout.js so that entire error message would be matched in assert.throw. Before test 1 of test-vm-timeout.js would match any error, now it looks specifically for the error message "Script execution timed out." PR-URL: https://github.com/nodejs/node/pull/11590 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- test/parallel/test-vm-timeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-vm-timeout.js b/test/parallel/test-vm-timeout.js index 5260ca7dc28572..6ed73f8b4ffd78 100644 --- a/test/parallel/test-vm-timeout.js +++ b/test/parallel/test-vm-timeout.js @@ -6,7 +6,7 @@ const vm = require('vm'); // Test 1: Timeout of 100ms executing endless loop assert.throws(function() { vm.runInThisContext('while(true) {}', { timeout: 100 }); -}); +}, /^Error: Script execution timed out\.$/); // Test 2: Timeout must be >= 0ms assert.throws(function() { From 5df9110178d2ea1a36b706d7f2977de697b7115e Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Sun, 5 Mar 2017 16:40:23 +0100 Subject: [PATCH 36/49] test: check the origin of the blob URLs In the getter of the origin in URL, the URL that has blob protocol will be parsed in a function called "originFor". Add test cases into the url-tests-additional fixture to test that. Refs: https://github.com/w3c/web-platform-tests/pull/4941 PR-URL: https://github.com/nodejs/node/pull/11426 Reviewed-By: Joyee Cheung Reviewed-By: Anna Henningsen Reviewed-By: Timothy Gu Reviewed-By: James M Snell --- test/fixtures/url-tests.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/fixtures/url-tests.js b/test/fixtures/url-tests.js index 3e303910ca6e19..0e510eb366d0f2 100644 --- a/test/fixtures/url-tests.js +++ b/test/fixtures/url-tests.js @@ -5622,5 +5622,33 @@ module.exports = "input": "non-special://[:80/", "base": "about:blank", "failure": true + }, + { + "input": "blob:https://example.com:443/", + "base": "about:blank", + "href": "blob:https://example.com:443/", + "protocol": "blob:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "https://example.com:443/", + "search": "", + "hash": "" + }, + { + "input": "blob:d3958f5c-0777-0845-9dcf-2cb28783acaf", + "base": "about:blank", + "href": "blob:d3958f5c-0777-0845-9dcf-2cb28783acaf", + "protocol": "blob:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "d3958f5c-0777-0845-9dcf-2cb28783acaf", + "search": "", + "hash": "" } ] From d06dbf03cc135bf8bb521f844bcbcadfbba98916 Mon Sep 17 00:00:00 2001 From: Rahat Ahmed Date: Thu, 2 Mar 2017 09:22:12 -0600 Subject: [PATCH 37/49] doc: fix misleading ASCII comments PR-URL: https://github.com/nodejs/node/pull/11657 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Claudio Rodriguez --- doc/api/buffer.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 9aa7d0d9cbbbda..eda33fb7c27c19 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -38,11 +38,11 @@ const buf3 = Buffer.allocUnsafe(10); // Creates a Buffer containing [0x1, 0x2, 0x3]. const buf4 = Buffer.from([1, 2, 3]); -// Creates a Buffer containing ASCII bytes [0x74, 0x65, 0x73, 0x74]. -const buf5 = Buffer.from('test'); - // Creates a Buffer containing UTF-8 bytes [0x74, 0xc3, 0xa9, 0x73, 0x74]. -const buf6 = Buffer.from('tést', 'utf8'); +const buf5 = Buffer.from('tést'); + +// Creates a Buffer containing Latin-1 bytes [0x74, 0xe9, 0x73, 0x74]. +const buf6 = Buffer.from('tést', 'latin-1'); ``` ## `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()` @@ -331,7 +331,7 @@ Allocates a new `Buffer` using an `array` of octets. Example: ```js -// Creates a new Buffer containing the ASCII bytes of the string 'buffer' +// Creates a new Buffer containing the UTF-8 bytes of the string 'buffer' const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); ``` @@ -779,7 +779,7 @@ Allocates a new `Buffer` using an `array` of octets. Example: ```js -// Creates a new Buffer containing ASCII bytes of the string 'buffer' +// Creates a new Buffer containing UTF-8 bytes of the string 'buffer' const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); ``` From 986d3910662cd97e7c3f1587cfa709bf1da36f22 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 2 Mar 2017 10:35:24 -0800 Subject: [PATCH 38/49] doc: unlock module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update documentation for `module` to reflect stability index 2 (Stable) rather than 3 (Locked). PR-URL: https://github.com/nodejs/node/pull/11661 Ref: https://github.com/nodejs/node/issues/11200 Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson Reviewed-By: Michaël Zasso Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 43bddab4faa310..0aeab0ad14bbd2 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -1,6 +1,6 @@ # Modules -> Stability: 3 - Locked +> Stability: 2 - Stable From d5c436311ca4c9080f7a0c85b3ae1e00b3fd02fc Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 2 Mar 2017 10:37:20 -0800 Subject: [PATCH 39/49] doc: remove Locked from stability index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stability index 3 (Locked) is unused and is being eliminated. Remove it from the documentation about the stability index. Remove mention of the Locked from CONTRIBUTING.md. The remaining text about the stability index is slight and not seemingly valuable. Removing it too. PR-URL: https://github.com/nodejs/node/pull/11661 Ref: https://github.com/nodejs/node/issues/11200 Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson Reviewed-By: Michaël Zasso Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell --- CONTRIBUTING.md | 9 --------- doc/api/documentation.md | 6 ------ 2 files changed, 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bf3dbd0ad0e163..290cad8faaeb7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,15 +46,6 @@ $ git remote add upstream git://github.com/nodejs/node.git For developing new features and bug fixes, the `master` branch should be pulled and built upon. -#### Respect the stability index - -The rules for the master branch are less strict; consult the -[stability index](./doc/api/documentation.md#stability-index) for details. - -In a nutshell, modules are at varying levels of API stability. Bug fixes are -always welcome but API or behavioral changes to modules at stability level 3 -(Locked) are off-limits. - #### Dependencies Node.js has several bundled dependencies in the *deps/* and the *tools/* diff --git a/doc/api/documentation.md b/doc/api/documentation.md index 947010d951bdab..5f45c9b56ed387 100644 --- a/doc/api/documentation.md +++ b/doc/api/documentation.md @@ -56,12 +56,6 @@ The API has proven satisfactory. Compatibility with the npm ecosystem is a high priority, and will not be broken unless absolutely necessary. ``` -```txt -Stability: 3 - Locked -Only bug fixes, security fixes, and performance improvements will be accepted. -Please do not suggest API changes in this area; they will be refused. -``` - ## JSON Output > Stability: 1 - Experimental From 84028888dbf1be8f09c41e2e686a202527caccf9 Mon Sep 17 00:00:00 2001 From: Poker <306766053@qq.com> Date: Fri, 3 Mar 2017 19:36:22 +0800 Subject: [PATCH 40/49] doc: fix broken URL to event loop guide PR-URL: https://github.com/nodejs/node/pull/11670 Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- doc/api/timers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/timers.md b/doc/api/timers.md index 09c43bfeaa3532..df48905001e19b 100644 --- a/doc/api/timers.md +++ b/doc/api/timers.md @@ -163,7 +163,7 @@ added: v0.0.1 Cancels a `Timeout` object created by [`setTimeout()`][]. -[the Node.js Event Loop]: https://github.com/nodejs/node/blob/master/doc/topics/event-loop-timers-and-nexttick.md +[the Node.js Event Loop]: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick [`TypeError`]: errors.html#errors_class_typeerror [`clearImmediate()`]: timers.html#timers_clearimmediate_immediate [`clearInterval()`]: timers.html#timers_clearinterval_timeout From 7b84363636843b6267f755c7023999ec67f981e2 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Fri, 3 Mar 2017 13:43:16 +0100 Subject: [PATCH 41/49] util: fix inspecting symbol key in string PR-URL: https://github.com/nodejs/node/pull/11672 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- lib/util.js | 4 ++++ test/parallel/test-util-inspect.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/util.js b/lib/util.js index 64c4c94c29a81f..8c880c674b5ad3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -396,6 +396,10 @@ function formatValue(ctx, value, recurseTimes) { // for boxed Strings, we have to remove the 0-n indexed entries, // since they just noisy up the output and are redundant keys = keys.filter(function(key) { + if (typeof key === 'symbol') { + return true; + } + return !(key >= 0 && key < raw.length); }); } diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index cf07f4c8213cee..33e0253a9e9b7c 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -50,6 +50,9 @@ assert.strictEqual(util.inspect(Object.create({}, {visible: {value: 1, enumerable: true}, hidden: {value: 2}})), '{ visible: 1 }' ); +assert.strictEqual(util.inspect(Object.assign(new String('hello'), + { [Symbol('foo')]: 123 }), { showHidden: true }), + '{ [String: \'hello\'] [length]: 5, [Symbol(foo)]: 123 }'); { const regexp = /regexp/; From 3b27b8da9d61db7e45f8560704fb45e413aed1fb Mon Sep 17 00:00:00 2001 From: Laurent Fortin Date: Fri, 3 Mar 2017 12:44:28 -0500 Subject: [PATCH 42/49] doc: fixed readable.isPaused() version annotation readable.isPaused(): added a missing YAML placeholder so the 'Added to version' annotation is displayed in docs PR-URL: https://github.com/nodejs/node/pull/11677 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto --- doc/api/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index b1b14f4f93b992..7756ddbef234a1 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -737,7 +737,7 @@ end preferred over the use of the `'readable'` event. ##### readable.isPaused() - From ed6d7412a74bbbf612b138b41f2432a089f21b34 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Tue, 28 Feb 2017 10:46:29 -0800 Subject: [PATCH 43/49] deps: fix CLEAR_HASH macro to be usable as a single statement Apply unreleased (as of zlib v1.2.11) patch from upstream: - https://github.com/madler/zlib/commit/38e8ce32afbaa82f67d992b9f3056f281fe69259 Original commit message: Fix CLEAR_HASH macro to be usable as a single statement. As it is used in deflateParams(). PR-URL: https://github.com/nodejs/node/pull/11616 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- deps/zlib/deflate.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/deps/zlib/deflate.c b/deps/zlib/deflate.c index 1ec761448de926..909606df01fb70 100644 --- a/deps/zlib/deflate.c +++ b/deps/zlib/deflate.c @@ -190,8 +190,11 @@ local const config configuration_table[10] = { * prev[] will be initialized on the fly. */ #define CLEAR_HASH(s) \ - s->head[s->hash_size-1] = NIL; \ - zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); + do { \ + s->head[s->hash_size-1] = NIL; \ + zmemzero((Bytef *)s->head, \ + (unsigned)(s->hash_size-1)*sizeof(*s->head)); \ + } while (0) /* =========================================================================== * Slide the hash table when sliding the window down (could be avoided with 32 From fdb4a6c796b2220731c6365f7effa7c03d88fde6 Mon Sep 17 00:00:00 2001 From: "Sakthipriyan Vairamani (thefourtheye)" Date: Tue, 28 Feb 2017 00:15:58 +0530 Subject: [PATCH 44/49] test: skip the test with proper TAP message On Windows, the test simply returns which will be counted as passed. The test actually skips the rest of the test. So proper TAP message has to be included while skipping. This patch uses `common.skip` rather than `console.log` to print the skip messages. PR-URL: https://github.com/nodejs/node/pull/11584 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock Reviewed-By: Luigi Pinca --- test/parallel/test-setproctitle.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-setproctitle.js b/test/parallel/test-setproctitle.js index a971d604b37d14..072ddd447e5bf9 100644 --- a/test/parallel/test-setproctitle.js +++ b/test/parallel/test-setproctitle.js @@ -4,8 +4,7 @@ const common = require('../common'); // FIXME add sunos support if (common.isSunOS) { - console.log(`1..0 # Skipped: Unsupported platform [${process.platform}]`); - return; + return common.skip(`Unsupported platform [${process.platform}]`); } const assert = require('assert'); @@ -22,8 +21,9 @@ process.title = title; assert.strictEqual(process.title, title); // Test setting the title but do not try to run `ps` on Windows. -if (common.isWindows) - return; +if (common.isWindows) { + return common.skip('Windows does not have "ps" utility'); +} exec(`ps -p ${process.pid} -o args=`, function callback(error, stdout, stderr) { assert.ifError(error); From e5b530cb6223d15dca4a9e0256d8c24d32f79734 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Fri, 3 Mar 2017 15:22:08 +0900 Subject: [PATCH 45/49] build: fix llvm version detection in freebsd-10 In FreeBSD-10, the banner of clang version is "FreeBSD clang version". Fix regex to detect it. PR-URL: https://github.com/nodejs/node/pull/11668 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 866d095e2e74a9..4bae197df3a021 100755 --- a/configure +++ b/configure @@ -576,11 +576,11 @@ def get_version_helper(cc, regexp): def get_llvm_version(cc): return get_version_helper( - cc, r"(^clang version|based on LLVM) ([3-9]\.[0-9]+)") + cc, r"(^(?:FreeBSD )?clang version|based on LLVM) ([3-9]\.[0-9]+)") def get_xcode_version(cc): return get_version_helper( - cc, r"(^Apple LLVM version) ([5-9]\.[0-9]+)") + cc, r"(^Apple LLVM version) ([5-9]\.[0-9]+)") def get_gas_version(cc): try: From a7eba9c71c9737f80ca3a5ff510da87e5e63b121 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 25 Feb 2017 11:16:16 -0800 Subject: [PATCH 46/49] meta: move WORKING_GROUPS.md to CTC repo PR-URL: https://github.com/nodejs/node/pull/11555 Ref: https://github.com/nodejs/CTC/pull/73 Reviewed-By: Gibson Fahnestock Reviewed-By: Ben Noordhuis --- README.md | 5 + WORKING_GROUPS.md | 281 ---------------------------------------------- 2 files changed, 5 insertions(+), 281 deletions(-) delete mode 100644 WORKING_GROUPS.md diff --git a/README.md b/README.md index 87e73ffb441cc8..5db1b427ce499e 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,11 @@ Previous releases may also have been signed with one of the following GPG keys: * **Timothy J Fontaine** <tjfontaine@gmail.com> `7937DFD2AB06298B2293C3187D33FF9D0246406D` +### Working Groups + +Information on the current Node.js Working Groups can be found in the +[CTC repository](https://github.com/nodejs/CTC/blob/master/WORKING_GROUPS.md). + [npm]: https://www.npmjs.com [Website]: https://nodejs.org/en/ [Contributing to the project]: CONTRIBUTING.md diff --git a/WORKING_GROUPS.md b/WORKING_GROUPS.md deleted file mode 100644 index 6ba06c9cafa697..00000000000000 --- a/WORKING_GROUPS.md +++ /dev/null @@ -1,281 +0,0 @@ -# Node.js Core Working Groups - -Node.js Core Working Groups are autonomous projects created by the -[Core Technical Committee (CTC)](https://github.com/nodejs/node/blob/master/GOVERNANCE.md#core-technical-committee). - -Working Groups can be formed at any time but must be ratified by the CTC. -Once formed the work defined in the Working Group charter is the -responsibility of the WG rather than the CTC. - -It is important that Working Groups are not formed pre-maturely. Working -Groups are not formed to *begin* a set of tasks but instead are formed -once that work is already underway and the contributors -think it would benefit from being done as an autonomous project. - -If the work defined in a Working Group's charter is complete, the charter -should be revoked. - -A Working Group's charter can be revoked either by consensus of the Working -Group's members or by a CTC vote. Once revoked, any future work that arises -becomes the responsibility of the CTC. - -## Joining a WG - -To find out how to join a working group, consult the GOVERNANCE.md in -the working group's repository, or in the working group's repository. - -## Starting A Core Working Group - -The process to start a Core Working Group is identical to [creating a -Top Level Working Group](https://github.com/nodejs/TSC/blob/master/WORKING_GROUPS.md#starting-a-wg). - -## Current Working Groups - -* [Website](#website) -* [Streams](#streams) -* [Build](#build) -* [Diagnostics](#diagnostics) -* [i18n](#i18n) -* [Evangelism](#evangelism) -* [Docker](#docker) -* [Addon API](#addon-api) -* [Benchmarking](#benchmarking) -* [Post-mortem](#post-mortem) -* [Intl](#intl) -* [Documentation](#documentation) -* [Testing](#testing) - - -### [Website](https://github.com/nodejs/nodejs.org) - -The website Working Group's purpose is to build and maintain a public -website for the Node.js project. - -Responsibilities include: -* Developing and maintaining a build and automation system for nodejs.org. -* Ensuring the site is regularly updated with changes made to Node.js, like - releases and features. -* Fostering and enabling a community of translators. - -### [Streams](https://github.com/nodejs/readable-stream) - -The Streams Working Group is dedicated to the support and improvement of the -Streams API as used in Node.js and the npm ecosystem. We seek to create a -composable API that solves the problem of representing multiple occurrences -of an event over time in a humane, low-overhead fashion. Improvements to the -API will be driven by the needs of the ecosystem; interoperability and -backwards compatibility with other solutions and prior versions are paramount -in importance. - -Responsibilities include: -* Addressing stream issues on the Node.js issue tracker. -* Authoring and editing stream documentation within the Node.js project. -* Reviewing changes to stream subclasses within the Node.js project. -* Redirecting changes to streams from the Node.js project to this project. -* Assisting in the implementation of stream providers within Node.js. -* Recommending versions of `readable-stream` to be included in Node.js. -* Messaging about the future of streams to give the community advance notice of - changes. - -### [Build](https://github.com/nodejs/build) - -The Build Working Group's purpose is to create and maintain a distributed -automation infrastructure. - -Responsibilities include: -* Producing packages for all target platforms. -* Running tests. -* Running performance testing and comparisons. -* Creating and managing build-containers. - -### [Diagnostics](https://github.com/nodejs/diagnostics) - -The Diagnostics Working Group's purpose is to surface a set of comprehensive, -documented, and extensible diagnostic interfaces for use by Node.js tools and -JavaScript VMs. - -Responsibilities include: -* Collaborating with V8 to integrate `v8_inspector` into Node.js. -* Collaborating with V8 to integrate `trace_event` into Node.js. -* Collaborating with Core to refine `async_wrap` and `async_hooks`. -* Maintaining and improving OS trace system integration (e.g. ETW, LTTNG, dtrace). -* Documenting diagnostic capabilities and APIs in Node.js and its components. -* Exploring opportunities and gaps, discussing feature requests, and addressing - conflicts in Node.js diagnostics. -* Fostering an ecosystem of diagnostics tools for Node.js. - -### i18n - -The i18n Working Groups handle more than just translations. They -are endpoints for community members to collaborate with each -other in their language of choice. - -Each team is organized around a common spoken language. Each -language community might then produce multiple localizations for -various project resources. - -Responsibilities include: -* Translating any Node.js materials they believe are relevant to their - community. -* Reviewing processes for keeping translations up to date and of high quality. -* Managing and monitoring social media channels in their language. -* Promoting Node.js speakers for meetups and conferences in their language. - -Note that the i18n Working Groups are distinct from the [Intl](#Intl) Working Group. - -Each language community maintains its own membership. - -* [nodejs-ar - Arabic (اللغة العربية)](https://github.com/nodejs/nodejs-ar) -* [nodejs-bg - Bulgarian (български език)](https://github.com/nodejs/nodejs-bg) -* [nodejs-bn - Bengali (বাংলা)](https://github.com/nodejs/nodejs-bn) -* [nodejs-zh-CN - Chinese (中文)](https://github.com/nodejs/nodejs-zh-CN) -* [nodejs-cs - Czech (Český Jazyk)](https://github.com/nodejs/nodejs-cs) -* [nodejs-da - Danish (Dansk)](https://github.com/nodejs/nodejs-da) -* [nodejs-de - German (Deutsch)](https://github.com/nodejs/nodejs-de) -* [nodejs-el - Greek (Ελληνικά)](https://github.com/nodejs/nodejs-el) -* [nodejs-es - Spanish (Español)](https://github.com/nodejs/nodejs-es) -* [nodejs-fa - Persian (فارسی)](https://github.com/nodejs/nodejs-fa) -* [nodejs-fi - Finnish (Suomi)](https://github.com/nodejs/nodejs-fi) -* [nodejs-fr - French (Français)](https://github.com/nodejs/nodejs-fr) -* [nodejs-he - Hebrew (עברית)](https://github.com/nodejs/nodejs-he) -* [nodejs-hi - Hindi (फिजी बात)](https://github.com/nodejs/nodejs-hi) -* [nodejs-hu - Hungarian (Magyar)](https://github.com/nodejs/nodejs-hu) -* [nodejs-id - Indonesian (Bahasa Indonesia)](https://github.com/nodejs/nodejs-id) -* [nodejs-it - Italian (Italiano)](https://github.com/nodejs/nodejs-it) -* [nodejs-ja - Japanese (日本語)](https://github.com/nodejs/nodejs-ja) -* [nodejs-ka - Georgian (ქართული)](https://github.com/nodejs/nodejs-ka) -* [nodejs-ko - Korean (조선말)](https://github.com/nodejs/nodejs-ko) -* [nodejs-mk - Macedonian (Mакедонски)](https://github.com/nodejs/nodejs-mk) -* [nodejs-ms - Malay (بهاس ملايو)](https://github.com/nodejs/nodejs-ms) -* [nodejs-nl - Dutch (Nederlands)](https://github.com/nodejs/nodejs-nl) -* [nodejs-no - Norwegian (Norsk)](https://github.com/nodejs/nodejs-no) -* [nodejs-pl - Polish (Język Polski)](https://github.com/nodejs/nodejs-pl) -* [nodejs-pt - Portuguese (Português)](https://github.com/nodejs/nodejs-pt) -* [nodejs-ro - Romanian (Română)](https://github.com/nodejs/nodejs-ro) -* [nodejs-ru - Russian (Русский)](https://github.com/nodejs/nodejs-ru) -* [nodejs-sv - Swedish (Svenska)](https://github.com/nodejs/nodejs-sv) -* [nodejs-ta - Tamil (தமிழ்)](https://github.com/nodejs/nodejs-ta) -* [nodejs-tr - Turkish (Türkçe)](https://github.com/nodejs/nodejs-tr) -* [nodejs-zh-TW - Taiwanese (Hō-ló)](https://github.com/nodejs/nodejs-zh-TW) -* [nodejs-uk - Ukrainian (Українська)](https://github.com/nodejs/nodejs-uk) -* [nodejs-vi - Vietnamese (Tiếng Việtnam)](https://github.com/nodejs/nodejs-vi) - -### [Intl](https://github.com/nodejs/Intl) - -The Intl Working Group is dedicated to support and improvement of -Internationalization (i18n) and Localization (l10n) in Node. - -Responsibilities include: -* Ensuring functionality & compliance (standards: ECMA, Unicode…) -* Supporting Globalization and Internationalization issues that come up - in the tracker -* Communicating guidance and best practices -* Refining the existing `Intl` implementation - -The Intl Working Group is not responsible for translation of content. That is the -responsibility of the specific [i18n](#i18n) group for each language. - -### [Evangelism](https://github.com/nodejs/evangelism) - -The Evangelism Working Group promotes the accomplishments -of Node.js and lets the community know how they can get involved. - -Responsibilities include: -* Facilitating project messaging. -* Managing official project social media. -* Handling the promotion of speakers for meetups and conferences. -* Handling the promotion of community events. -* Publishing regular update summaries and other promotional - content. - -### [Docker](https://github.com/nodejs/docker-iojs) - -The Docker Working Group's purpose is to build, maintain, and improve official -Docker images for the Node.js project. - -Responsibilities include: -* Keeping the official Docker images updated in line with new Node.js releases. -* Decide and implement image improvements and/or fixes. -* Maintain and improve the images' documentation. - -### [Addon API](https://github.com/nodejs/nan) - -The Addon API Working Group is responsible for maintaining the NAN project and -corresponding _nan_ package in npm. The NAN project makes available an -abstraction layer for native add-on authors for Node.js, -assisting in the writing of code that is compatible with many actively used -versions of Node.js, V8 and libuv. - -Responsibilities include: -* Maintaining the [NAN](https://github.com/nodejs/nan) GitHub repository, - including code, issues and documentation. -* Maintaining the [addon-examples](https://github.com/nodejs/node-addon-examples) - GitHub repository, including code, issues and documentation. -* Maintaining the C++ Addon API within the Node.js project, in subordination to - the Node.js CTC. -* Maintaining the Addon documentation within the Node.js project, in - subordination to the Node.js CTC. -* Maintaining the _nan_ package in npm, releasing new versions as appropriate. -* Messaging about the future of the Node.js and NAN interface to give the - community advance notice of changes. - -The current members can be found in their -[README](https://github.com/nodejs/nan#collaborators). - -### [Benchmarking](https://github.com/nodejs/benchmarking) - -The purpose of the Benchmark Working Group is to gain consensus -on an agreed set of benchmarks that can be used to: - -* track and evangelize performance gains made between Node.js releases -* avoid performance regressions between releases - -Responsibilities include: -* Identifying 1 or more benchmarks that reflect customer usage. - Likely will need more than one to cover typical Node.js use cases - including low-latency and high concurrency -* Working to get community consensus on the list chosen -* Adding regular execution of chosen benchmarks to Node.js builds -* Tracking/publicizing performance between builds/releases - -### [Post-mortem](https://github.com/nodejs/post-mortem) - -The Post-mortem Diagnostics Working Group is dedicated to the support -and improvement of postmortem debugging for Node.js. It seeks to -elevate the role of postmortem debugging for Node, to assist in the -development of techniques and tools, and to make techniques and tools -known and available to Node.js users. - -Responsibilities include: -* Defining and adding interfaces/APIs in order to allow dumps - to be generated when needed. -* Defining and adding common structures to the dumps generated - in order to support tools that want to introspect those dumps. - -### [Documentation](https://github.com/nodejs/docs) - -The Documentation Working Group exists to support the improvement of Node.js -documentation, both in the core API documentation, and elsewhere, such as the -Node.js website. Its intent is to work closely with the Evangelism, Website, and -Intl Working Groups to make excellent documentation available and accessible -to all. - -Responsibilities include: -* Defining and maintaining documentation style and content standards. -* Producing documentation in a format acceptable for the Website Working Group - to consume. -* Ensuring that Node's documentation addresses a wide variety of audiences. -* Creating and operating a process for documentation review that produces - quality documentation and avoids impeding the progress of Core work. - -### [Testing](https://github.com/nodejs/testing) - -The Node.js Testing Working Group's purpose is to extend and improve testing of -the Node.js source code. - -Responsibilities include: -* Coordinating an overall strategy for improving testing. -* Documenting guidelines around tests. -* Working with the Build Working Group to improve continuous integration. -* Improving tooling for testing. - From b56e851c4813bdec86e47e84d7c18527a01d4ffd Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 4 Mar 2017 00:52:12 +0800 Subject: [PATCH 47/49] net: refactor overloaded argument handling * Make normalizeArgs return either [options, null] or [options, cb] (the second element won't be undefined anymore) and avoid OOB read * Use Socket.prototype.connect.call instead of .apply when the number of arguments is certain(returned by normalizeArgs). * Rename some args[i] for readability * Refactor Server.prototype.listen, separate backlogFromArgs and options.backlog, comment the overloading process, refactor control flow PR-URL: https://github.com/nodejs/node/pull/11667 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- lib/net.js | 170 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 101 insertions(+), 69 deletions(-) diff --git a/lib/net.js b/lib/net.js index f3f8bb1a984ea8..018b58b941f100 100644 --- a/lib/net.js +++ b/lib/net.js @@ -24,7 +24,6 @@ var cluster; const errnoException = util._errnoException; const exceptionWithHostPort = util._exceptionWithHostPort; const isLegalPort = internalNet.isLegalPort; -const assertPort = internalNet.assertPort; function noop() {} @@ -60,37 +59,50 @@ exports.createServer = function(options, connectionListener) { // connect(path, [cb]); // exports.connect = exports.createConnection = function() { - var args = new Array(arguments.length); + const args = new Array(arguments.length); for (var i = 0; i < arguments.length; i++) args[i] = arguments[i]; - args = normalizeArgs(args); - debug('createConnection', args); - var s = new Socket(args[0]); + // TODO(joyeecheung): use destructuring when V8 is fast enough + const normalized = normalizeArgs(args); + const options = normalized[0]; + const cb = normalized[1]; + debug('createConnection', normalized); + const socket = new Socket(options); - if (args[0].timeout) { - s.setTimeout(args[0].timeout); + if (options.timeout) { + socket.setTimeout(options.timeout); } - return Socket.prototype.connect.apply(s, args); + return Socket.prototype.connect.call(socket, options, cb); }; -// Returns an array [options, cb], where cb can be null. -// It is the same as the argument of Socket.prototype.connect(). -// This is used by Server.prototype.listen() and Socket.prototype.connect(). -function normalizeArgs(args) { - var options = {}; +// Returns an array [options, cb], where options is an object, +// cb is either a funciton or null. +// Used to normalize arguments of Socket.prototype.connect() and +// Server.prototype.listen(). Possible combinations of paramters: +// (options[...][, cb]) +// (path[...][, cb]) +// ([port][, host][...][, cb]) +// For Socket.prototype.connect(), the [...] part is ignored +// For Server.prototype.listen(), the [...] part is [, backlog] +// but will not be handled here (handled in listen()) +function normalizeArgs(args) { if (args.length === 0) { - return [options]; - } else if (args[0] !== null && typeof args[0] === 'object') { - // connect(options, [cb]) - options = args[0]; - } else if (isPipeName(args[0])) { - // connect(path, [cb]); - options.path = args[0]; + return [{}, null]; + } + + const arg0 = args[0]; + var options = {}; + if (typeof arg0 === 'object' && arg0 !== null) { + // (options[...][, cb]) + options = arg0; + } else if (isPipeName(arg0)) { + // (path[...][, cb]) + options.path = arg0; } else { - // connect(port, [host], [cb]) - options.port = args[0]; + // ([port][, host][...][, cb]) + options.port = arg0; if (args.length > 1 && typeof args[1] === 'string') { options.host = args[1]; } @@ -98,8 +110,9 @@ function normalizeArgs(args) { var cb = args[args.length - 1]; if (typeof cb !== 'function') - cb = null; - return [options, cb]; + return [options, null]; + else + return [options, cb]; } exports._normalizeArgs = normalizeArgs; @@ -892,13 +905,16 @@ Socket.prototype.connect = function(options, cb) { if (options === null || typeof options !== 'object') { // Old API: - // connect(port, [host], [cb]) - // connect(path, [cb]); - var args = new Array(arguments.length); + // connect(port[, host][, cb]) + // connect(path[, cb]); + const args = new Array(arguments.length); for (var i = 0; i < arguments.length; i++) args[i] = arguments[i]; - args = normalizeArgs(args); - return Socket.prototype.connect.apply(this, args); + const normalized = normalizeArgs(args); + const normalizedOptions = normalized[0]; + const normalizedCb = normalized[1]; + return Socket.prototype.connect.call(this, + normalizedOptions, normalizedCb); } if (this.destroyed) { @@ -923,7 +939,7 @@ Socket.prototype.connect = function(options, cb) { initSocketHandle(this); } - if (typeof cb === 'function') { + if (cb !== null) { this.once('connect', cb); } @@ -1333,57 +1349,73 @@ function listen(self, address, port, addressType, backlog, fd, exclusive) { Server.prototype.listen = function() { - var args = new Array(arguments.length); + const args = new Array(arguments.length); for (var i = 0; i < arguments.length; i++) args[i] = arguments[i]; - var [options, cb] = normalizeArgs(args); + // TODO(joyeecheung): use destructuring when V8 is fast enough + const normalized = normalizeArgs(args); + var options = normalized[0]; + const cb = normalized[1]; - if (typeof cb === 'function') { + var hasCallback = (cb !== null); + if (hasCallback) { this.once('listening', cb); } - - if (args.length === 0 || typeof args[0] === 'function') { - // Bind to a random port. - options.port = 0; - } - - // The third optional argument is the backlog size. - // When the ip is omitted it can be the second argument. - var backlog = toNumber(args.length > 1 && args[1]) || - toNumber(args.length > 2 && args[2]); + const backlogFromArgs = + // (handle, backlog) or (path, backlog) or (port, backlog) + toNumber(args.length > 1 && args[1]) || + toNumber(args.length > 2 && args[2]); // (port, host, backlog) options = options._handle || options.handle || options; - + // (handle[, backlog][, cb]) where handle is an object with a handle if (options instanceof TCP) { this._handle = options; - listen(this, null, -1, -1, backlog); - } else if (typeof options.fd === 'number' && options.fd >= 0) { - listen(this, null, null, null, backlog, options.fd); - } else { - backlog = options.backlog || backlog; - - if (typeof options.port === 'number' || typeof options.port === 'string' || - (typeof options.port === 'undefined' && 'port' in options)) { - // Undefined is interpreted as zero (random port) for consistency - // with net.connect(). - assertPort(options.port); - if (options.host) { - lookupAndListen(this, options.port | 0, options.host, backlog, - options.exclusive); - } else { - listen(this, null, options.port | 0, 4, backlog, undefined, - options.exclusive); - } - } else if (options.path && isPipeName(options.path)) { - // UNIX socket or Windows pipe. - const pipeName = this._pipeName = options.path; - listen(this, pipeName, -1, -1, backlog, undefined, options.exclusive); - } else { - throw new Error('Invalid listen argument: ' + options); + listen(this, null, -1, -1, backlogFromArgs); + return this; + } + // (handle[, backlog][, cb]) where handle is an object with a fd + if (typeof options.fd === 'number' && options.fd >= 0) { + listen(this, null, null, null, backlogFromArgs, options.fd); + return this; + } + + // ([port][, host][, backlog][, cb]) where port is omitted, + // that is, listen() or listen(cb), + // or (options[, cb]) where options.port is explicitly set as undefined, + // bind to an arbitrary unused port + if (args.length === 0 || typeof args[0] === 'function' || + (typeof options.port === 'undefined' && 'port' in options)) { + options.port = 0; + } + // ([port][, host][, backlog][, cb]) where port is specified + // or (options[, cb]) where options.port is specified + // or if options.port is normalized as 0 before + if (typeof options.port === 'number' || typeof options.port === 'string') { + if (!isLegalPort(options.port)) { + throw new RangeError('"port" argument must be >= 0 and < 65536'); + } + const backlog = options.backlog || backlogFromArgs; + // start TCP server listening on host:port + if (options.host) { + lookupAndListen(this, options.port | 0, options.host, backlog, + options.exclusive); + } else { // Undefined host, listens on unspecified address + listen(this, null, options.port | 0, 4, // addressType will be ignored + backlog, undefined, options.exclusive); } + return this; } - return this; + // (path[, backlog][, cb]) or (options[, cb]) + // where path or options.path is a UNIX domain socket or Windows pipe + if (options.path && isPipeName(options.path)) { + const pipeName = this._pipeName = options.path; + const backlog = options.backlog || backlogFromArgs; + listen(this, pipeName, -1, -1, backlog, undefined, options.exclusive); + return this; + } + + throw new Error('Invalid listen argument: ' + options); }; function lookupAndListen(self, port, address, backlog, exclusive) { From a7d37984eb6be2b96f5d05f631b7791bbdc3a4b2 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Wed, 8 Mar 2017 05:49:25 -0600 Subject: [PATCH 48/49] 2017-03-08, Version 7.7.2 (Current) Notable changes: * doc: add `Daijiro Wachi` to collaborators (Daijiro Wachi) https://github.com/nodejs/node/pull/11676 * tty: add ref() so process.stdin.ref() etc. work (Ben Schmidt) https://github.com/nodejs/node/pull/7360 * util: fix inspecting symbol key in string (Ali BARIN) https://github.com/nodejs/node/pull/11672 PR-URL: https://github.com/nodejs/node/pull/11745 --- CHANGELOG.md | 3 +- doc/changelogs/CHANGELOG_V7.md | 59 ++++++++++++++++++++++++++++++++++ src/node_version.h | 2 +- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20008f19ed34df..ce2c2a9f01df78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,8 @@ release. - 7.7.1
+ 7.7.2
+ 7.7.1
7.7.0
7.6.0
7.5.0
diff --git a/doc/changelogs/CHANGELOG_V7.md b/doc/changelogs/CHANGELOG_V7.md index 2b63c5a07c6abf..53c6b345ba4cfe 100644 --- a/doc/changelogs/CHANGELOG_V7.md +++ b/doc/changelogs/CHANGELOG_V7.md @@ -29,6 +29,65 @@ * [io.js](CHANGELOG_IOJS.md) * [Archive](CHANGELOG_ARCHIVE.md) + +## 2017-03-08, Version 7.7.2 (Current), @evanlucas + +### Notable changes + +* **doc**: add `Daijiro Wachi` to collaborators (Daijiro Wachi) [#11676](https://github.com/nodejs/node/pull/11676) +* **tty**: add ref() so process.stdin.ref() etc. work (Ben Schmidt) [#7360](https://github.com/nodejs/node/pull/7360) +* **util**: fix inspecting symbol key in string (Ali BARIN) [#11672](https://github.com/nodejs/node/pull/11672) + +### Commits + +* [[`f56ca30bf0`](https://github.com/nodejs/node/commit/f56ca30bf0)] - **benchmark,build,doc,lib,src,test**: correct typos (Benjamin Fleischer) [#11189](https://github.com/nodejs/node/pull/11189) +* [[`02dbae6b3f`](https://github.com/nodejs/node/commit/02dbae6b3f)] - **buffer**: refactor Buffer.prototype.inspect() (Rich Trott) [#11600](https://github.com/nodejs/node/pull/11600) +* [[`e5b530cb62`](https://github.com/nodejs/node/commit/e5b530cb62)] - **build**: fix llvm version detection in freebsd-10 (Shigeki Ohtsu) [#11668](https://github.com/nodejs/node/pull/11668) +* [[`ed6d7412a7`](https://github.com/nodejs/node/commit/ed6d7412a7)] - **deps**: fix CLEAR_HASH macro to be usable as a single statement (Sam Roberts) [#11616](https://github.com/nodejs/node/pull/11616) +* [[`039a1a97d8`](https://github.com/nodejs/node/commit/039a1a97d8)] - **dns**: minor refactor of dns module (James M Snell) [#11597](https://github.com/nodejs/node/pull/11597) +* [[`3b27b8da9d`](https://github.com/nodejs/node/commit/3b27b8da9d)] - **doc**: fixed readable.isPaused() version annotation (Laurent Fortin) [#11677](https://github.com/nodejs/node/pull/11677) +* [[`84028888db`](https://github.com/nodejs/node/commit/84028888db)] - **doc**: fix broken URL to event loop guide (Poker) [#11670](https://github.com/nodejs/node/pull/11670) +* [[`d5c436311c`](https://github.com/nodejs/node/commit/d5c436311c)] - **doc**: remove Locked from stability index (Rich Trott) [#11661](https://github.com/nodejs/node/pull/11661) +* [[`986d391066`](https://github.com/nodejs/node/commit/986d391066)] - **doc**: unlock module (Rich Trott) [#11661](https://github.com/nodejs/node/pull/11661) +* [[`d06dbf03cc`](https://github.com/nodejs/node/commit/d06dbf03cc)] - **doc**: fix misleading ASCII comments (Rahat Ahmed) [#11657](https://github.com/nodejs/node/pull/11657) +* [[`98d33282d9`](https://github.com/nodejs/node/commit/98d33282d9)] - **doc**: add `Daijiro Wachi` to collaborators (Daijiro Wachi) [#11676](https://github.com/nodejs/node/pull/11676) +* [[`3e79dffd2c`](https://github.com/nodejs/node/commit/3e79dffd2c)] - **doc**: fix WHATWG URL url.protocol example (Richard Lau) [#11647](https://github.com/nodejs/node/pull/11647) +* [[`e468cd3ee7`](https://github.com/nodejs/node/commit/e468cd3ee7)] - **doc**: argument types for console methods (Amelia Clarke) [#11554](https://github.com/nodejs/node/pull/11554) +* [[`83c7b245e2`](https://github.com/nodejs/node/commit/83c7b245e2)] - **doc**: fix typo in stream doc (Bradley Curran) [#11560](https://github.com/nodejs/node/pull/11560) +* [[`a0c117ba95`](https://github.com/nodejs/node/commit/a0c117ba95)] - **doc**: fixup errors.md (Vse Mozhet Byt) [#11566](https://github.com/nodejs/node/pull/11566) +* [[`b116830d64`](https://github.com/nodejs/node/commit/b116830d64)] - **doc**: add link to references in net.Socket (Joyee Cheung) [#11625](https://github.com/nodejs/node/pull/11625) +* [[`b968491dc2`](https://github.com/nodejs/node/commit/b968491dc2)] - **doc**: document WHATWG IDNA methods' error handling (Timothy Gu) [#11549](https://github.com/nodejs/node/pull/11549) +* [[`d329abf1c6`](https://github.com/nodejs/node/commit/d329abf1c6)] - **doc**: use common malformed instead of misformatted (James Sumners) [#11518](https://github.com/nodejs/node/pull/11518) +* [[`11aea2662f`](https://github.com/nodejs/node/commit/11aea2662f)] - **doc**: fix typo in STYLE_GUIDE.md (Nikolai Vavilov) [#11615](https://github.com/nodejs/node/pull/11615) +* [[`f972bd81c6`](https://github.com/nodejs/node/commit/f972bd81c6)] - **inspector**: libuv notification on incoming message (Eugene Ostroukhov) [#11617](https://github.com/nodejs/node/pull/11617) +* [[`a7eba9c71c`](https://github.com/nodejs/node/commit/a7eba9c71c)] - **meta**: move WORKING_GROUPS.md to CTC repo (James M Snell) [#11555](https://github.com/nodejs/node/pull/11555) +* [[`5963566367`](https://github.com/nodejs/node/commit/5963566367)] - **meta**: remove out of date ROADMAP.md file (James M Snell) [#11556](https://github.com/nodejs/node/pull/11556) +* [[`b56e851c48`](https://github.com/nodejs/node/commit/b56e851c48)] - **net**: refactor overloaded argument handling (Joyee Cheung) [#11667](https://github.com/nodejs/node/pull/11667) +* [[`13cb8a69e4`](https://github.com/nodejs/node/commit/13cb8a69e4)] - **net**: remove misleading comment (Ben Noordhuis) [#11573](https://github.com/nodejs/node/pull/11573) +* [[`e2133f3e57`](https://github.com/nodejs/node/commit/e2133f3e57)] - **os**: improve cpus() performance (Brian White) [#11564](https://github.com/nodejs/node/pull/11564) +* [[`821d713a38`](https://github.com/nodejs/node/commit/821d713a38)] - **src**: remove outdated FIXME in node_crypto.cc (Daniel Bevenius) [#11669](https://github.com/nodejs/node/pull/11669) +* [[`1b6ba9effb`](https://github.com/nodejs/node/commit/1b6ba9effb)] - **src**: do not ignore IDNA conversion error (Timothy Gu) [#11549](https://github.com/nodejs/node/pull/11549) +* [[`fdb4a6c796`](https://github.com/nodejs/node/commit/fdb4a6c796)] - **test**: skip the test with proper TAP message (Sakthipriyan Vairamani (thefourtheye)) [#11584](https://github.com/nodejs/node/pull/11584) +* [[`5df9110178`](https://github.com/nodejs/node/commit/5df9110178)] - **test**: check the origin of the blob URLs (Daijiro Wachi) [#11426](https://github.com/nodejs/node/pull/11426) +* [[`b4dcb26681`](https://github.com/nodejs/node/commit/b4dcb26681)] - **test**: changed test1 of test-vm-timeout.js (maurice_hayward) [#11590](https://github.com/nodejs/node/pull/11590) +* [[`f69685be65`](https://github.com/nodejs/node/commit/f69685be65)] - **test**: remove obsolete eslint-disable comment (Rich Trott) [#11643](https://github.com/nodejs/node/pull/11643) +* [[`a4d14363a9`](https://github.com/nodejs/node/commit/a4d14363a9)] - **test**: fix args in parallel/test-fs-null-bytes.js (Vse Mozhet Byt) [#11601](https://github.com/nodejs/node/pull/11601) +* [[`8377374754`](https://github.com/nodejs/node/commit/8377374754)] - **test**: fix tests when npn feature is disabled. (Shigeki Ohtsu) [#11655](https://github.com/nodejs/node/pull/11655) +* [[`1445e282c3`](https://github.com/nodejs/node/commit/1445e282c3)] - **test**: add test-buffer-prototype-inspect (Rich Trott) [#11600](https://github.com/nodejs/node/pull/11600) +* [[`00dd20c173`](https://github.com/nodejs/node/commit/00dd20c173)] - **test**: fix flaky test-https-agent-create-connection (Santiago Gimeno) [#11649](https://github.com/nodejs/node/pull/11649) +* [[`91a222de99`](https://github.com/nodejs/node/commit/91a222de99)] - **test**: enable max-len for test-repl (Rich Trott) [#11559](https://github.com/nodejs/node/pull/11559) +* [[`924b785d50`](https://github.com/nodejs/node/commit/924b785d50)] - **test**: fix test-internal-util-assertCrypto regex (Daniel Bevenius) [#11620](https://github.com/nodejs/node/pull/11620) +* [[`cdee945307`](https://github.com/nodejs/node/commit/cdee945307)] - **test**: improve https coverage to check create connection (chiaki-yokoo) [#11435](https://github.com/nodejs/node/pull/11435) +* [[`4f9253686d`](https://github.com/nodejs/node/commit/4f9253686d)] - **test**: apply strict mode in test-repl (Rich Trott) [#11575](https://github.com/nodejs/node/pull/11575) +* [[`2601c06486`](https://github.com/nodejs/node/commit/2601c06486)] - **test**: skip tests with common.skip (Sakthipriyan Vairamani (thefourtheye)) [#11585](https://github.com/nodejs/node/pull/11585) +* [[`6a5d96164a`](https://github.com/nodejs/node/commit/6a5d96164a)] - **test**: more comprehensive IDNA test cases (Timothy Gu) [#11549](https://github.com/nodejs/node/pull/11549) +* [[`163d2d1624`](https://github.com/nodejs/node/commit/163d2d1624)] - **timers**: unlock the timers API (Rich Trott) [#11580](https://github.com/nodejs/node/pull/11580) +* [[`d6ac192fa3`](https://github.com/nodejs/node/commit/d6ac192fa3)] - **tls**: fix macro to check NPN feature (Shigeki Ohtsu) [#11655](https://github.com/nodejs/node/pull/11655) +* [[`ac3deb1481`](https://github.com/nodejs/node/commit/ac3deb1481)] - **tools**: remove NODE_PATH from environment for tests (Rich Trott) [#11612](https://github.com/nodejs/node/pull/11612) +* [[`3c54f8199c`](https://github.com/nodejs/node/commit/3c54f8199c)] - **tty**: add ref() so process.stdin.ref() etc. work (Ben Schmidt) [#7360](https://github.com/nodejs/node/pull/7360) +* [[`24e6fcce8b`](https://github.com/nodejs/node/commit/24e6fcce8b)] - **url**: use `hasIntl` instead of `try-catch` (Daijiro Wachi) [#11571](https://github.com/nodejs/node/pull/11571) +* [[`7b84363636`](https://github.com/nodejs/node/commit/7b84363636)] - **util**: fix inspecting symbol key in string (Ali BARIN) [#11672](https://github.com/nodejs/node/pull/11672) + ## 2017-03-01, Version 7.7.1 (Current), @italoacasas diff --git a/src/node_version.h b/src/node_version.h index f54cf3d99c28ae..b81e7b400d22e2 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -5,7 +5,7 @@ #define NODE_MINOR_VERSION 7 #define NODE_PATCH_VERSION 2 -#define NODE_VERSION_IS_RELEASE 0 +#define NODE_VERSION_IS_RELEASE 1 #ifndef NODE_STRINGIFY #define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n) From c62798034ab2ad3b110122406ee37e5074d596f5 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Wed, 8 Mar 2017 15:56:09 -0600 Subject: [PATCH 49/49] Working on v7.7.3 PR-URL: https://github.com/nodejs/node/pull/11745 --- src/node_version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_version.h b/src/node_version.h index b81e7b400d22e2..c2cfd395d8931e 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -3,9 +3,9 @@ #define NODE_MAJOR_VERSION 7 #define NODE_MINOR_VERSION 7 -#define NODE_PATCH_VERSION 2 +#define NODE_PATCH_VERSION 3 -#define NODE_VERSION_IS_RELEASE 1 +#define NODE_VERSION_IS_RELEASE 0 #ifndef NODE_STRINGIFY #define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n)