From 4d3e1582d6b302b12fb2877a789a2686975ed91d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 15 Oct 2016 15:02:43 -0700 Subject: [PATCH 001/116] test,lib,benchmark: match function names In most cases, named functions match the variable or property to which they are being assigned. That also seems to be the practice in a series of PRs currently being evaluated that name currently-anonymous functions. This change applies that rule to instances in the code base that don't comply with that practice. This will be enforceable with a lint rule once we upgrade to ESLint 3.8.0. PR-URL: https://github.com/nodejs/node/pull/9113 Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann --- lib/_stream_wrap.js | 4 ++-- lib/_stream_writable.js | 2 +- lib/_tls_legacy.js | 6 +++--- lib/_tls_wrap.js | 6 +++--- lib/domain.js | 2 +- lib/fs.js | 2 +- lib/net.js | 2 +- test/parallel/test-child-process-spawn-typeerror.js | 2 +- test/parallel/test-http-client-readable.js | 4 ++-- test/parallel/test-repl-persistent-history.js | 2 +- test/pummel/test-tls-server-large-request.js | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/_stream_wrap.js b/lib/_stream_wrap.js index 7eb3008484b2aa..fbc32965980e96 100644 --- a/lib/_stream_wrap.js +++ b/lib/_stream_wrap.js @@ -159,7 +159,7 @@ function QueueItem(type, req) { this.next = this; } -StreamWrap.prototype._enqueue = function enqueue(type, req) { +StreamWrap.prototype._enqueue = function _enqueue(type, req) { const item = new QueueItem(type, req); if (this._list === null) { this._list = item; @@ -174,7 +174,7 @@ StreamWrap.prototype._enqueue = function enqueue(type, req) { return item; }; -StreamWrap.prototype._dequeue = function dequeue(item) { +StreamWrap.prototype._dequeue = function _dequeue(item) { assert(item instanceof QueueItem); var next = item.next; diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 75ce7a187970cf..3dee1d8e4cc618 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -118,7 +118,7 @@ function WritableState(options, stream) { this.corkedRequestsFree = new CorkedRequest(this); } -WritableState.prototype.getBuffer = function writableStateGetBuffer() { +WritableState.prototype.getBuffer = function getBuffer() { var current = this.bufferedRequest; var out = []; while (current) { diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js index bf79d7c8678331..e44a4d74615acd 100644 --- a/lib/_tls_legacy.js +++ b/lib/_tls_legacy.js @@ -142,7 +142,7 @@ CryptoStream.prototype.init = function init() { }; -CryptoStream.prototype._write = function write(data, encoding, cb) { +CryptoStream.prototype._write = function _write(data, encoding, cb) { assert(this._pending === null); // Black-hole data @@ -223,7 +223,7 @@ CryptoStream.prototype._write = function write(data, encoding, cb) { }; -CryptoStream.prototype._writePending = function writePending() { +CryptoStream.prototype._writePending = function _writePending() { const data = this._pending; const encoding = this._pendingEncoding; const cb = this._pendingCallback; @@ -235,7 +235,7 @@ CryptoStream.prototype._writePending = function writePending() { }; -CryptoStream.prototype._read = function read(size) { +CryptoStream.prototype._read = function _read(size) { // XXX: EOF?! if (!this.pair.ssl) return this.push(null); diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 056499b723f0d0..4bea3134d4f632 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -316,7 +316,7 @@ proxiedMethods.forEach(function(name) { }; }); -tls_wrap.TLSWrap.prototype.close = function closeProxy(cb) { +tls_wrap.TLSWrap.prototype.close = function close(cb) { let ssl; if (this.owner) { ssl = this.owner.ssl; @@ -369,10 +369,10 @@ TLSSocket.prototype._wrapHandle = function(wrap) { res._secureContext = context; res.reading = handle.reading; Object.defineProperty(handle, 'reading', { - get: function readingGetter() { + get: function get() { return res.reading; }, - set: function readingSetter(value) { + set: function set(value) { res.reading = value; } }); diff --git a/lib/domain.js b/lib/domain.js index d0f51d9c14296b..564ac11b732a77 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -58,7 +58,7 @@ Domain.prototype._disposed = undefined; // Called by process._fatalException in case an error was thrown. -Domain.prototype._errorHandler = function errorHandler(er) { +Domain.prototype._errorHandler = function _errorHandler(er) { var caught = false; var self = this; diff --git a/lib/fs.js b/lib/fs.js index 64978efb9d0b2c..37a03973e7975b 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -697,7 +697,7 @@ fs.truncate = function(path, len, callback) { fs.open(path, 'r+', function(er, fd) { if (er) return callback(er); var req = new FSReqWrap(); - req.oncomplete = function ftruncateCb(er) { + req.oncomplete = function oncomplete(er) { fs.close(fd, function(er2) { callback(er || er2); }); diff --git a/lib/net.js b/lib/net.js index e166fadaa8a075..92dd52ebf78e61 100644 --- a/lib/net.js +++ b/lib/net.js @@ -189,7 +189,7 @@ function Socket(options) { } util.inherits(Socket, stream.Duplex); -Socket.prototype._unrefTimer = function unrefTimer() { +Socket.prototype._unrefTimer = function _unrefTimer() { for (var s = this; s !== null; s = s._parent) timers._unrefActive(s); }; diff --git a/test/parallel/test-child-process-spawn-typeerror.js b/test/parallel/test-child-process-spawn-typeerror.js index 46216b63d569ef..0cc4801f820f4e 100644 --- a/test/parallel/test-child-process-spawn-typeerror.js +++ b/test/parallel/test-child-process-spawn-typeerror.js @@ -57,7 +57,7 @@ assert.throws(function() { // Argument types for combinatorics const a = []; const o = {}; -const c = function callback() {}; +const c = function c() {}; const s = 'string'; const u = undefined; const n = null; diff --git a/test/parallel/test-http-client-readable.js b/test/parallel/test-http-client-readable.js index 8328afb01c6478..de58e897a4e745 100644 --- a/test/parallel/test-http-client-readable.js +++ b/test/parallel/test-http-client-readable.js @@ -15,7 +15,7 @@ FakeAgent.prototype.createConnection = function createConnection() { var s = new Duplex(); var once = false; - s._read = function read() { + s._read = function _read() { if (once) return this.push(null); once = true; @@ -27,7 +27,7 @@ FakeAgent.prototype.createConnection = function createConnection() { }; // Blackhole - s._write = function write(data, enc, cb) { + s._write = function _write(data, enc, cb) { cb(); }; diff --git a/test/parallel/test-repl-persistent-history.js b/test/parallel/test-repl-persistent-history.js index 29ca0d56344bc9..732a327ceb6844 100644 --- a/test/parallel/test-repl-persistent-history.js +++ b/test/parallel/test-repl-persistent-history.js @@ -176,7 +176,7 @@ const tests = [ expected: [prompt, replFailedRead, prompt, replDisabled, prompt] }, { // Make sure this is always the last test, since we change os.homedir() - before: function mockHomedirFailure() { + before: function before() { // Mock os.homedir() failure os.homedir = function() { throw new Error('os.homedir() failure'); diff --git a/test/pummel/test-tls-server-large-request.js b/test/pummel/test-tls-server-large-request.js index cd201a0aa71b27..c2b1a0aba08914 100644 --- a/test/pummel/test-tls-server-large-request.js +++ b/test/pummel/test-tls-server-large-request.js @@ -27,7 +27,7 @@ function Mediator() { } util.inherits(Mediator, stream.Writable); -Mediator.prototype._write = function write(data, enc, cb) { +Mediator.prototype._write = function _write(data, enc, cb) { this.buf += data; setTimeout(cb, 0); From 2677b9b072a11c0b5b0d8698ee85e4f25fd58bb3 Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Tue, 10 Jan 2017 16:27:10 -0800 Subject: [PATCH 002/116] deps: V8: fix debug backtrace for symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cherry-pick of #7612 to v4.x (4369055) added in #9298 wasn't quite correct as it depends on a runtime function %SymbolDescriptiveString that doesn't exist on v4.x. We can use %SymbolDescription instead. Ref: https://github.com/nodejs/node/pull/7612 Ref: https://github.com/nodejs/node/pull/9298 PR-URL: https://github.com/nodejs/node/pull/10732 Reviewed-By: James M Snell Reviewed-By: Fedor Indutny Reviewed-By: Myles Borins Reviewed-By: Michaël Zasso Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig --- deps/v8/include/v8-version.h | 2 +- deps/v8/src/mirror-debugger.js | 2 +- deps/v8/test/mjsunit/debug-backtrace-text.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index da3946133d5082..f88cdeddb2a237 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -11,7 +11,7 @@ #define V8_MAJOR_VERSION 4 #define V8_MINOR_VERSION 5 #define V8_BUILD_NUMBER 103 -#define V8_PATCH_LEVEL 43 +#define V8_PATCH_LEVEL 44 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/deps/v8/src/mirror-debugger.js b/deps/v8/src/mirror-debugger.js index c6540e31d96f06..d2b97ec66f0800 100644 --- a/deps/v8/src/mirror-debugger.js +++ b/deps/v8/src/mirror-debugger.js @@ -1515,7 +1515,7 @@ PropertyMirror.prototype.name = function() { PropertyMirror.prototype.toText = function() { - if (IS_SYMBOL(this.name_)) return %SymbolDescriptiveString(this.name_); + if (IS_SYMBOL(this.name_)) return %SymbolDescription(this.name_); return this.name_; }; diff --git a/deps/v8/test/mjsunit/debug-backtrace-text.js b/deps/v8/test/mjsunit/debug-backtrace-text.js index cfc89e6c1d6762..8afc1f8d9b3a75 100644 --- a/deps/v8/test/mjsunit/debug-backtrace-text.js +++ b/deps/v8/test/mjsunit/debug-backtrace-text.js @@ -106,7 +106,7 @@ function listener(event, exec_state, event_data, data) { // 2: [anonymous] assertEquals("new Point(x=0, y=0)", exec_state.frame(0).invocationText()); - assertEquals("#[Symbol(Das Symbol)](x=0, y=0)", + assertEquals("#[Das Symbol](x=0, y=0)", exec_state.frame(1).invocationText()); assertEquals("[anonymous]()", exec_state.frame(2).invocationText()); listenerCalled = true; From 47d18d4936063c5931d7876d20574e073b854ab4 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Mon, 20 Jun 2016 07:29:54 -0700 Subject: [PATCH 003/116] deps: backport d800a65 from V8 upstream This backport does not include the original changes to SLOW_DCHECK as it does not exist in the V8 in node v4.x Original commit message: Filter out stale left-trimmed handles BUG=chromium:620553 LOG=N R=jochen@chromium.org Review-Url: https://codereview.chromium.org/2078403002 Cr-Commit-Position: refs/heads/master@{#37108} PR-URL: https://github.com/nodejs/node/pull/10668 Reviewed-By: James M Snell Reviewed-By: Fedor Indutny Reviewed-By: Ali Ijaz Sheikh --- deps/v8/src/heap/mark-compact.cc | 28 ++++++++++++++++++- .../v8/test/mjsunit/regress/regress-620553.js | 17 +++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 deps/v8/test/mjsunit/regress/regress-620553.js diff --git a/deps/v8/src/heap/mark-compact.cc b/deps/v8/src/heap/mark-compact.cc index dcc2fb943046d6..e39ff83e9f381e 100644 --- a/deps/v8/src/heap/mark-compact.cc +++ b/deps/v8/src/heap/mark-compact.cc @@ -1648,8 +1648,34 @@ class RootMarkingVisitor : public ObjectVisitor { void MarkObjectByPointer(Object** p) { if (!(*p)->IsHeapObject()) return; - // Replace flat cons strings in place. HeapObject* object = ShortCircuitConsString(p); + + // We cannot avoid stale handles to left-trimmed objects, but can only make + // sure all handles still needed are updated. Filter out any stale pointers + // and clear the slot to allow post processing of handles (needed because + // the sweeper might actually free the underlying page). + if (object->IsFiller()) { +#ifdef DEBUG + // We need to find a FixedArrayBase map after walking the fillers. + Heap* heap = collector_->heap(); + HeapObject* current = object; + while (current->IsFiller()) { + Address next = reinterpret_cast
(current); + if (current->map() == heap->one_pointer_filler_map()) { + next += kPointerSize; + } else if (current->map() == heap->two_pointer_filler_map()) { + next += 2 * kPointerSize; + } else { + next += current->Size(); + } + current = reinterpret_cast(next); + } + DCHECK(current->IsFixedArrayBase()); +#endif // DEBUG + *p = nullptr; + return; + } + MarkBit mark_bit = Marking::MarkBitFrom(object); if (Marking::IsBlackOrGrey(mark_bit)) return; diff --git a/deps/v8/test/mjsunit/regress/regress-620553.js b/deps/v8/test/mjsunit/regress/regress-620553.js new file mode 100644 index 00000000000000..461b9bb189e559 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-620553.js @@ -0,0 +1,17 @@ +// Copyright 2016 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-gc + +var o0 = []; +var o1 = []; +var cnt = 0; +o1.__defineGetter__(0, function() { + if (cnt++ > 2) return; + o0.shift(); + gc(); + o0.push(0); + o0.concat(o1); +}); +o1[0]; From 83144af828e71d3a6d260207afb98326ab0183fb Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Wed, 22 Jun 2016 05:21:16 -0700 Subject: [PATCH 004/116] deps: backport 7a88ff3 from V8 upstream This backport does not include the changes to `src/heap/scavenger.cc` as it does not exist in the V8 included in the v4.x stream. Original commit message: Filter out stale left-trimmed handles for scavenges The missing part from https://codereview.chromium.org/2078403002/ R=jochen@chromium.org BUG=chromium:621869 LOG=N Review-Url: https://codereview.chromium.org/2077353004 Cr-Commit-Position: refs/heads/master@{#37184} PR-URL: https://github.com/nodejs/node/pull/10668 Reviewed-By: James M Snell Reviewed-By: Fedor Indutny Reviewed-By: Ali Ijaz Sheikh --- deps/v8/src/heap/heap-inl.h | 25 +++++++++++++++++- deps/v8/src/heap/heap.h | 6 +++++ deps/v8/src/heap/mark-compact.cc | 26 +------------------ deps/v8/src/objects-inl.h | 2 +- deps/v8/src/objects.h | 2 +- .../v8/test/mjsunit/regress/regress-621869.js | 18 +++++++++++++ 6 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 deps/v8/test/mjsunit/regress/regress-621869.js diff --git a/deps/v8/src/heap/heap-inl.h b/deps/v8/src/heap/heap-inl.h index fdb1d7345b4d79..39110f6d58e17a 100644 --- a/deps/v8/src/heap/heap-inl.h +++ b/deps/v8/src/heap/heap-inl.h @@ -393,12 +393,35 @@ bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) { return false; } - void Heap::CopyBlock(Address dst, Address src, int byte_size) { CopyWords(reinterpret_cast(dst), reinterpret_cast(src), static_cast(byte_size / kPointerSize)); } +bool Heap::PurgeLeftTrimmedObject(Object** object) { + HeapObject* current = reinterpret_cast(*object); + const MapWord map_word = current->map_word(); + if (current->IsFiller() && !map_word.IsForwardingAddress()) { +#ifdef DEBUG + // We need to find a FixedArrayBase map after walking the fillers. + while (current->IsFiller()) { + Address next = reinterpret_cast
(current); + if (current->map() == one_pointer_filler_map()) { + next += kPointerSize; + } else if (current->map() == two_pointer_filler_map()) { + next += 2 * kPointerSize; + } else { + next += current->Size(); + } + current = reinterpret_cast(next); + } + DCHECK(current->IsFixedArrayBase()); +#endif // DEBUG + *object = nullptr; + return true; + } + return false; +} void Heap::MoveBlock(Address dst, Address src, int byte_size) { DCHECK(IsAligned(byte_size, kPointerSize)); diff --git a/deps/v8/src/heap/heap.h b/deps/v8/src/heap/heap.h index 0afac311c4816e..529050c8bf51ce 100644 --- a/deps/v8/src/heap/heap.h +++ b/deps/v8/src/heap/heap.h @@ -590,6 +590,12 @@ class Heap { // jslimit_/real_jslimit_ variable in the StackGuard. void SetStackLimits(); + // We cannot avoid stale handles to left-trimmed objects, but can only make + // sure all handles still needed are updated. Filter out a stale pointer + // and clear the slot to allow post processing of handles (needed because + // the sweeper might actually free the underlying page). + inline bool PurgeLeftTrimmedObject(Object** object); + // Notifies the heap that is ok to start marking or other activities that // should not happen during deserialization. void NotifyDeserializationComplete(); diff --git a/deps/v8/src/heap/mark-compact.cc b/deps/v8/src/heap/mark-compact.cc index e39ff83e9f381e..3a71578f713632 100644 --- a/deps/v8/src/heap/mark-compact.cc +++ b/deps/v8/src/heap/mark-compact.cc @@ -1650,31 +1650,7 @@ class RootMarkingVisitor : public ObjectVisitor { HeapObject* object = ShortCircuitConsString(p); - // We cannot avoid stale handles to left-trimmed objects, but can only make - // sure all handles still needed are updated. Filter out any stale pointers - // and clear the slot to allow post processing of handles (needed because - // the sweeper might actually free the underlying page). - if (object->IsFiller()) { -#ifdef DEBUG - // We need to find a FixedArrayBase map after walking the fillers. - Heap* heap = collector_->heap(); - HeapObject* current = object; - while (current->IsFiller()) { - Address next = reinterpret_cast
(current); - if (current->map() == heap->one_pointer_filler_map()) { - next += kPointerSize; - } else if (current->map() == heap->two_pointer_filler_map()) { - next += 2 * kPointerSize; - } else { - next += current->Size(); - } - current = reinterpret_cast(next); - } - DCHECK(current->IsFixedArrayBase()); -#endif // DEBUG - *p = nullptr; - return; - } + if (collector_->heap()->PurgeLeftTrimmedObject(p)) return; MarkBit mark_bit = Marking::MarkBitFrom(object); if (Marking::IsBlackOrGrey(mark_bit)) return; diff --git a/deps/v8/src/objects-inl.h b/deps/v8/src/objects-inl.h index 3caf52bff4b086..3e91c2bac97051 100644 --- a/deps/v8/src/objects-inl.h +++ b/deps/v8/src/objects-inl.h @@ -1351,7 +1351,7 @@ Map* MapWord::ToMap() { } -bool MapWord::IsForwardingAddress() { +bool MapWord::IsForwardingAddress() const { return HAS_SMI_TAG(reinterpret_cast(value_)); } diff --git a/deps/v8/src/objects.h b/deps/v8/src/objects.h index 1c5743eb838918..5481b1834de762 100644 --- a/deps/v8/src/objects.h +++ b/deps/v8/src/objects.h @@ -1382,7 +1382,7 @@ class MapWord BASE_EMBEDDED { // True if this map word is a forwarding address for a scavenge // collection. Only valid during a scavenge collection (specifically, // when all map words are heap object pointers, i.e. not during a full GC). - inline bool IsForwardingAddress(); + inline bool IsForwardingAddress() const; // Create a map word from a forwarding address. static inline MapWord FromForwardingAddress(HeapObject* object); diff --git a/deps/v8/test/mjsunit/regress/regress-621869.js b/deps/v8/test/mjsunit/regress/regress-621869.js new file mode 100644 index 00000000000000..ee1b58b0266032 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-621869.js @@ -0,0 +1,18 @@ +// Copyright 2016 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-gc + +var o0 = []; +var o1 = []; +var cnt = 0; +var only_scavenge = true; +o1.__defineGetter__(0, function() { + if (cnt++ > 2) return; + o0.shift(); + gc(only_scavenge); + o0.push((64)); + o0.concat(o1); +}); +o1[0]; \ No newline at end of file From e0db108d418816b8eed8eb36a85e4b6830ed4662 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Wed, 29 Jun 2016 01:16:07 -0700 Subject: [PATCH 005/116] deps: backport a715957 from V8 upstream This commit does not include the changes to `src/heap/scavenger.cc`. These changes would revert the changes that should have come in 086bd5aede, meaning that there is no issue with that change missing in the previous commit. Original commit message: Iterate handles with special left-trim visitor BUG=chromium:620553 LOG=N R=hpayer@chromium.org Review-Url: https://codereview.chromium.org/2102243002 Cr-Commit-Position: refs/heads/master@{#37366} PR-URL: https://github.com/nodejs/node/pull/10668 Reviewed-By: James M Snell Reviewed-By: Fedor Indutny Reviewed-By: Ali Ijaz Sheikh --- deps/v8/src/heap/heap-inl.h | 25 ------------------ deps/v8/src/heap/heap.cc | 45 ++++++++++++++++++++++++++++++++ deps/v8/src/heap/heap.h | 6 ----- deps/v8/src/heap/mark-compact.cc | 2 -- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/deps/v8/src/heap/heap-inl.h b/deps/v8/src/heap/heap-inl.h index 39110f6d58e17a..20540b9e88e992 100644 --- a/deps/v8/src/heap/heap-inl.h +++ b/deps/v8/src/heap/heap-inl.h @@ -398,31 +398,6 @@ void Heap::CopyBlock(Address dst, Address src, int byte_size) { static_cast(byte_size / kPointerSize)); } -bool Heap::PurgeLeftTrimmedObject(Object** object) { - HeapObject* current = reinterpret_cast(*object); - const MapWord map_word = current->map_word(); - if (current->IsFiller() && !map_word.IsForwardingAddress()) { -#ifdef DEBUG - // We need to find a FixedArrayBase map after walking the fillers. - while (current->IsFiller()) { - Address next = reinterpret_cast
(current); - if (current->map() == one_pointer_filler_map()) { - next += kPointerSize; - } else if (current->map() == two_pointer_filler_map()) { - next += 2 * kPointerSize; - } else { - next += current->Size(); - } - current = reinterpret_cast(next); - } - DCHECK(current->IsFixedArrayBase()); -#endif // DEBUG - *object = nullptr; - return true; - } - return false; -} - void Heap::MoveBlock(Address dst, Address src, int byte_size) { DCHECK(IsAligned(byte_size, kPointerSize)); diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc index 6bc200a0e59289..7730327b412d73 100644 --- a/deps/v8/src/heap/heap.cc +++ b/deps/v8/src/heap/heap.cc @@ -5316,6 +5316,49 @@ void Heap::IterateSmiRoots(ObjectVisitor* v) { v->Synchronize(VisitorSynchronization::kSmiRootList); } +// We cannot avoid stale handles to left-trimmed objects, but can only make +// sure all handles still needed are updated. Filter out a stale pointer +// and clear the slot to allow post processing of handles (needed because +// the sweeper might actually free the underlying page). +class FixStaleLeftTrimmedHandlesVisitor : public ObjectVisitor { + public: + explicit FixStaleLeftTrimmedHandlesVisitor(Heap* heap) : heap_(heap) { + USE(heap_); + } + + void VisitPointer(Object** p) override { FixHandle(p); } + + void VisitPointers(Object** start, Object** end) override { + for (Object** p = start; p < end; p++) FixHandle(p); + } + + private: + inline void FixHandle(Object** p) { + HeapObject* current = reinterpret_cast(*p); + if (!current->IsHeapObject()) return; + const MapWord map_word = current->map_word(); + if (!map_word.IsForwardingAddress() && current->IsFiller()) { +#ifdef DEBUG + // We need to find a FixedArrayBase map after walking the fillers. + while (current->IsFiller()) { + Address next = reinterpret_cast
(current); + if (current->map() == heap_->one_pointer_filler_map()) { + next += kPointerSize; + } else if (current->map() == heap_->two_pointer_filler_map()) { + next += 2 * kPointerSize; + } else { + next += current->Size(); + } + current = reinterpret_cast(next); + } + DCHECK(current->IsFixedArrayBase()); +#endif // DEBUG + *p = nullptr; + } + } + + Heap* heap_; +}; void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) { v->VisitPointers(&roots_[0], &roots_[kStrongRootListLength]); @@ -5339,6 +5382,8 @@ void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) { v->Synchronize(VisitorSynchronization::kCompilationCache); // Iterate over local handles in handle scopes. + FixStaleLeftTrimmedHandlesVisitor left_trim_visitor(this); + isolate_->handle_scope_implementer()->Iterate(&left_trim_visitor); isolate_->handle_scope_implementer()->Iterate(v); isolate_->IterateDeferredHandles(v); v->Synchronize(VisitorSynchronization::kHandleScope); diff --git a/deps/v8/src/heap/heap.h b/deps/v8/src/heap/heap.h index 529050c8bf51ce..0afac311c4816e 100644 --- a/deps/v8/src/heap/heap.h +++ b/deps/v8/src/heap/heap.h @@ -590,12 +590,6 @@ class Heap { // jslimit_/real_jslimit_ variable in the StackGuard. void SetStackLimits(); - // We cannot avoid stale handles to left-trimmed objects, but can only make - // sure all handles still needed are updated. Filter out a stale pointer - // and clear the slot to allow post processing of handles (needed because - // the sweeper might actually free the underlying page). - inline bool PurgeLeftTrimmedObject(Object** object); - // Notifies the heap that is ok to start marking or other activities that // should not happen during deserialization. void NotifyDeserializationComplete(); diff --git a/deps/v8/src/heap/mark-compact.cc b/deps/v8/src/heap/mark-compact.cc index 3a71578f713632..c827237598ee43 100644 --- a/deps/v8/src/heap/mark-compact.cc +++ b/deps/v8/src/heap/mark-compact.cc @@ -1650,8 +1650,6 @@ class RootMarkingVisitor : public ObjectVisitor { HeapObject* object = ShortCircuitConsString(p); - if (collector_->heap()->PurgeLeftTrimmedObject(p)) return; - MarkBit mark_bit = Marking::MarkBitFrom(object); if (Marking::IsBlackOrGrey(mark_bit)) return; From 20bee0ff09a2c81c2ec13e7d49fa4cec4568409a Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 12 Jan 2017 17:33:09 -0500 Subject: [PATCH 006/116] deps: update patch level in V8 PR-URL: https://github.com/nodejs/node/pull/10668 Reviewed-By: James M Snell Reviewed-By: Fedor Indutny Reviewed-By: Ali Ijaz Sheikh --- deps/v8/include/v8-version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index f88cdeddb2a237..89cf41c1f70d52 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -11,7 +11,7 @@ #define V8_MAJOR_VERSION 4 #define V8_MINOR_VERSION 5 #define V8_BUILD_NUMBER 103 -#define V8_PATCH_LEVEL 44 +#define V8_PATCH_LEVEL 45 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) From 504b01babf02904dba24f813e01fd1963f3d292d Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Tue, 29 Dec 2015 11:54:35 +0100 Subject: [PATCH 007/116] v8,src: expose statistics about heap spaces Provide means to inspect information about the separate heap spaces via a callable API. This is helpful to analyze memory issues. Fixes: https://github.com/nodejs/node/issues/2079 PR-URL: https://github.com/nodejs/node/pull/4463 Reviewed-By: Colin Ihrig Reviewed-By: Trevor Norris Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- doc/api/v8.md | 49 +++++++++++++++++++ lib/v8.js | 33 ++++++++++++- src/env-inl.h | 12 +++++ src/env.h | 4 ++ src/node_v8.cc | 87 +++++++++++++++++++++++++++++++++- test/parallel/test-v8-stats.js | 19 ++++++++ 6 files changed, 202 insertions(+), 2 deletions(-) diff --git a/doc/api/v8.md b/doc/api/v8.md index f74d76820cbf3f..8b8a78d12142b2 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -24,6 +24,55 @@ Returns an object with the following properties } ``` +## getHeapSpaceStatistics() + +Returns statistics about the V8 heap spaces, i.e. the segments which make up +the V8 heap. Order of heap spaces nor availability of a heap space can be +guaranteed as the statistics are provided via the V8 `GetHeapSpaceStatistics` +function. + +Example result: + +``` +[ + { + "space_name": "new_space", + "space_size": 2063872, + "space_used_size": 951112, + "space_available_size": 80824, + "physical_space_size": 2063872 + }, + { + "space_name": "old_space", + "space_size": 3090560, + "space_used_size": 2493792, + "space_available_size": 0, + "physical_space_size": 3090560 + }, + { + "space_name": "code_space", + "space_size": 1260160, + "space_used_size": 644256, + "space_available_size": 960, + "physical_space_size": 1260160 + }, + { + "space_name": "map_space", + "space_size": 1094160, + "space_used_size": 201608, + "space_available_size": 0, + "physical_space_size": 1094160 + }, + { + "space_name": "large_object_space", + "space_size": 0, + "space_used_size": 0, + "space_available_size": 1490980608, + "physical_space_size": 0 + } +] +``` + ## setFlagsFromString(string) -Returns an object describing the memory usage of the Node.js process -measured in bytes. +* Returns: {Object} + * `rss` {Integer} + * `heapTotal` {Integer} + * `heapUsed` {Integer} + * `external` {Integer} + +The `process.memoryUsage()` method returns an object describing the memory usage +of the Node.js process measured in bytes. + +For example, the code: ```js console.log(process.memoryUsage()); @@ -776,10 +784,14 @@ This will generate: ```js { rss: 4935680, heapTotal: 1826816, - heapUsed: 650472 } + heapUsed: 650472, + external: 49879 +} ``` `heapTotal` and `heapUsed` refer to V8's memory usage. +`external` refers to the memory usage of C++ objects bound to JavaScript +objects managed by V8. ## process.nextTick(callback[, arg][, ...]) diff --git a/src/env.h b/src/env.h index a015988c345e24..2be7aa1824d152 100644 --- a/src/env.h +++ b/src/env.h @@ -90,6 +90,7 @@ namespace node { V(exponent_string, "exponent") \ V(exports_string, "exports") \ V(ext_key_usage_string, "ext_key_usage") \ + V(external_string, "external") \ V(external_stream_string, "_externalStream") \ V(family_string, "family") \ V(fatal_exception_string, "_fatalException") \ diff --git a/src/node.cc b/src/node.cc index 2935729bbb9f41..de3e5757705a47 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2145,11 +2145,15 @@ void MemoryUsage(const FunctionCallbackInfo& args) { Number::New(env->isolate(), v8_heap_stats.total_heap_size()); Local heap_used = Number::New(env->isolate(), v8_heap_stats.used_heap_size()); + Local external_mem = + Number::New(env->isolate(), + env->isolate()->AdjustAmountOfExternalAllocatedMemory(0)); Local info = Object::New(env->isolate()); info->Set(env->rss_string(), Number::New(env->isolate(), rss)); info->Set(env->heap_total_string(), heap_total); info->Set(env->heap_used_string(), heap_used); + info->Set(env->external_string(), external_mem); args.GetReturnValue().Set(info); } diff --git a/test/parallel/test-memory-usage.js b/test/parallel/test-memory-usage.js index f704c8812801ba..c5905c537ac613 100644 --- a/test/parallel/test-memory-usage.js +++ b/test/parallel/test-memory-usage.js @@ -6,3 +6,4 @@ var r = process.memoryUsage(); assert.ok(r.rss > 0); assert.ok(r.heapTotal > 0); assert.ok(r.heapUsed > 0); +assert.ok(r.external > 0); From 6b6664780550d8edd1e4b62ebdf7a0e46f50dc96 Mon Sep 17 00:00:00 2001 From: Kyle Corsi Date: Thu, 1 Dec 2016 11:57:23 -0500 Subject: [PATCH 011/116] test: refactor test-net-keepalive.js - Replace require() vars with const. - Replace assert.equal() with assert.strictEqual(). - Add common.mustCall() to the setTimeout() callback. PR-URL: https://github.com/nodejs/node/pull/9995 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- test/parallel/test-net-keepalive.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-net-keepalive.js b/test/parallel/test-net-keepalive.js index d414393a9346cd..e466f0ff580d06 100644 --- a/test/parallel/test-net-keepalive.js +++ b/test/parallel/test-net-keepalive.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); var serverConnection; var clientConnection; var echoServer = net.createServer(function(connection) { serverConnection = connection; - setTimeout(function() { + setTimeout(common.mustCall(function() { // make sure both connections are still open - assert.equal(serverConnection.readyState, 'open'); - assert.equal(clientConnection.readyState, 'open'); + assert.strictEqual(serverConnection.readyState, 'open'); + assert.strictEqual(clientConnection.readyState, 'open'); serverConnection.end(); clientConnection.end(); echoServer.close(); - }, common.platformTimeout(100)); + }, 1), common.platformTimeout(100)); connection.setTimeout(0); assert.notEqual(connection.setKeepAlive, undefined); // send a keepalive packet after 50 ms From 821498eba96b4f5f7018dc0350473d56cdf2dc26 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Thu, 1 Dec 2016 11:32:45 -0600 Subject: [PATCH 012/116] test: check for error on invalid signal Asserts that an error should be thrown when an invalid signal is passed to process.kill(). PR-URL: https://github.com/nodejs/node/pull/10026 Reviewed-By: Ben Noordhuis Reviewed-By: Jeremiah Senkpiel Reviewed-By: Colin Ihrig --- test/parallel/test-process-kill-pid.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index 5c11be2903c4a7..ee0554c32083f6 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -24,6 +24,10 @@ assert.throws(function() { process.kill(+'not a number'); }, TypeError); assert.throws(function() { process.kill(1 / 0); }, TypeError); assert.throws(function() { process.kill(-1 / 0); }, TypeError); +// Test that kill throws an error for invalid signal + +assert.throws(function() { process.kill(1, 'test'); }, Error); + // Test kill argument processing in valid cases. // // Monkey patch _kill so that we don't actually send any signals, particularly From 25fea4561833b22f159d4fac121e6773e069c340 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 3 Dec 2016 07:56:01 +0100 Subject: [PATCH 013/116] tools: add macosx-firwall script to avoid popups Currently, there are a number of popups that get displayed when running the tests asking to accept incoming network connections. Rules can be added manually to the socket firewall on Mac OS X but getting this right might not be obvious and quite a lot of time can be wasted trying to get the rules right. This script hopes to simplify things a little so that it can be re-run when needed. The script should be runnable from both the projects root directory and from the tools directory, for example: $ sudo ./tools/macosx-firewall.sh Fixes: https://github.com/nodejs/node/issues/8911 PR-URL: https://github.com/nodejs/node/pull/10114 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig --- BUILDING.md | 9 ++++++++ tools/macosx-firewall.sh | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 tools/macosx-firewall.sh diff --git a/BUILDING.md b/BUILDING.md index c657e63514139a..55f6d8a8763472 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -24,6 +24,15 @@ On OS X, you will also need: this under the menu `Xcode -> Preferences -> Downloads` * This step will install `gcc` and the related toolchain containing `make` +* You may want to setup [firewall rules](tools/macosx-firewall.sh) to avoid +popups asking to accept incoming network connections when running tests: + +```console +$ sudo ./tools/macosx-firewall.sh +``` +Running this script will add rules for the executable `node` in the out +directory and the symbolic `node` link in the projects root directory. + On FreeBSD and OpenBSD, you may also need: * libexecinfo (FreeBSD and OpenBSD only) diff --git a/tools/macosx-firewall.sh b/tools/macosx-firewall.sh new file mode 100755 index 00000000000000..c1de916e3c87ea --- /dev/null +++ b/tools/macosx-firewall.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Script that adds rules to Mac OS X Socket Firewall to avoid +# popups asking to accept incoming network connections when +# running tests. +SFW="/usr/libexec/ApplicationFirewall/socketfilterfw" +TOOLSDIR="`dirname \"$0\"`" +TOOLSDIR="`( cd \"$TOOLSDIR\" && pwd) `" +ROOTDIR="`( cd \"$TOOLSDIR/..\" && pwd) `" +OUTDIR="$TOOLSDIR/../out" +# Using cd and pwd here so that the path used for socketfilterfw does not +# contain a '..', which seems to cause the rules to be incorrectly added +# and they are not removed when this script is re-run. Instead the new +# rules are simply appended. By using pwd we can get the full path +# without '..' and things work as expected. +OUTDIR="`( cd \"$OUTDIR\" && pwd) `" +NODE_RELEASE="$OUTDIR/Release/node" +NODE_DEBUG="$OUTDIR/Debug/node" +NODE_LINK="$ROOTDIR/node" +CCTEST_RELEASE="$OUTDIR/Release/cctest" +CCTEST_DEBUG="$OUTDIR/Debug/cctest" + +if [ -f $SFW ]; +then + # Duplicating these commands on purpose as the symbolic link node might be + # linked to either out/Debug/node or out/Release/node depending on the + # BUILDTYPE. + $SFW --remove "$NODE_DEBUG" + $SFW --remove "$NODE_DEBUG" + $SFW --remove "$NODE_RELEASE" + $SFW --remove "$NODE_RELEASE" + $SFW --remove "$NODE_LINK" + $SFW --remove "$CCTEST_DEBUG" + $SFW --remove "$CCTEST_RELEASE" + + $SFW --add "$NODE_DEBUG" + $SFW --add "$NODE_RELEASE" + $SFW --add "$NODE_LINK" + $SFW --add "$CCTEST_DEBUG" + $SFW --add "$CCTEST_RELEASE" + + $SFW --unblock "$NODE_DEBUG" + $SFW --unblock "$NODE_RELEASE" + $SFW --unblock "$NODE_LINK" + $SFW --unblock "$CCTEST_DEBUG" + $SFW --unblock "$CCTEST_RELEASE" +else + echo "SocketFirewall not found in location: $SFW" +fi From 3bd7ab1678c3c0337b2bc8eb38afc573f400b33b Mon Sep 17 00:00:00 2001 From: "Italo A. Casas" Date: Wed, 30 Nov 2016 20:48:58 -0500 Subject: [PATCH 014/116] test: stream readableListening internal state PR-URL: https://github.com/nodejs/node/pull/9864 Refs: https://github.com/nodejs/node/issues/8683 Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig --- .../test-stream-readableListening-state.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/parallel/test-stream-readableListening-state.js diff --git a/test/parallel/test-stream-readableListening-state.js b/test/parallel/test-stream-readableListening-state.js new file mode 100644 index 00000000000000..5e3071faf370e5 --- /dev/null +++ b/test/parallel/test-stream-readableListening-state.js @@ -0,0 +1,34 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const stream = require('stream'); + +const r = new stream.Readable({ + read: () => {} +}); + +// readableListening state should start in `false`. +assert.strictEqual(r._readableState.readableListening, false); + +r.on('readable', common.mustCall(() => { + // Inside the readable event this state should be true. + assert.strictEqual(r._readableState.readableListening, true); +})); + +r.push(Buffer.from('Testing readableListening state')); + +const r2 = new stream.Readable({ + read: () => {} +}); + +// readableListening state should start in `false`. +assert.strictEqual(r2._readableState.readableListening, false); + +r2.on('data', common.mustCall((chunk) => { + // readableListening should be false because we don't have + // a `readable` listener + assert.strictEqual(r2._readableState.readableListening, false); +})); + +r2.push(Buffer.from('Testing readableListening state')); From b302358da8822f7982525fec6415fc5f5a986637 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 8 Dec 2016 22:26:28 -0800 Subject: [PATCH 015/116] test: refactor test-handle-wrap-close-abort * use common.mustCall() to confirm number of uncaught exceptions * var -> const * specify duration of 1ms for setTimeout() and setInterval() PR-URL: https://github.com/nodejs/node/pull/10188 Reviewed-By: Santiago Gimeno Reviewed-By: Colin Ihrig Reviewed-By: Sakthipriyan Vairamani --- test/parallel/test-handle-wrap-close-abort.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-handle-wrap-close-abort.js b/test/parallel/test-handle-wrap-close-abort.js index 8572668f666864..5355e65df60821 100644 --- a/test/parallel/test-handle-wrap-close-abort.js +++ b/test/parallel/test-handle-wrap-close-abort.js @@ -1,16 +1,16 @@ 'use strict'; -require('../common'); +const common = require('../common'); -process.on('uncaughtException', function() { }); +process.on('uncaughtException', common.mustCall(function() {}, 2)); setTimeout(function() { process.nextTick(function() { - var c = setInterval(function() { + const c = setInterval(function() { clearInterval(c); throw new Error('setInterval'); - }); + }, 1); }); setTimeout(function() { throw new Error('setTimeout'); - }); + }, 1); }); From 151cca6c9d0f92fb4bd505176bfec7ffeef77f31 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Tue, 5 Apr 2016 09:17:48 -0400 Subject: [PATCH 016/116] process: add process.cpuUsage() - implementation, doc, tests Backport to v4.x Original commit message: Add process.cpuUsage() method that returns the user and system CPU time usage of the current process PR-URL: https://github.com/nodejs/node/pull/6157 Reviewed-By: Robert Lindstaedt Reviewed-By: James M Snell Reviewed-By: Trevor Norris Reviewed-By: Santiago Gimeno PR-URL: https://github.com/nodejs/node/pull/10796 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Ali Ijaz Sheikh Reviewed-By: Brian White Reviewed-By: Sakthipriyan Vairamani --- doc/api/process.md | 23 +++++++++ src/node.cc | 35 ++++++++++++++ src/node.js | 53 ++++++++++++++++++++ test/parallel/test-process-cpuUsage.js | 67 ++++++++++++++++++++++++++ test/pummel/test-process-cpuUsage.js | 30 ++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 test/parallel/test-process-cpuUsage.js create mode 100644 test/pummel/test-process-cpuUsage.js diff --git a/doc/api/process.md b/doc/api/process.md index 1cb946aa2579c7..efffa85b7b7f5b 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -421,6 +421,29 @@ added: v0.7.2 If `process.connected` is false, it is no longer possible to send messages. +## process.cpuUsage([previousValue]) + +Returns the user and system CPU time usage of the current process, in an object +with properties `user` and `system`, whose values are microsecond values +(millionth of a second). These values measure time spent in user and +system code respectively, and may end up being greater than actual elapsed time +if multiple CPU cores are performing work for this process. + +The result of a previous call to `process.cpuUsage()` can be passed as the +argument to the function, to get a diff reading. + +```js +const startUsage = process.cpuUsage(); +// { user: 38579, system: 6986 } + +// spin the CPU for 500 milliseconds +const now = Date.now(); +while (Date.now() - now < 500); + +console.log(process.cpuUsage(startUsage)); +// { user: 514883, system: 11226 } +``` + ## process.cwd() -NPN (Next Protocol Negotiation) and SNI (Server Name Indication) are TLS +ALPN (Application-Layer Protocol Negotiation Extension), NPN (Next +Protocol Negotiation) and SNI (Server Name Indication) are TLS handshake extensions allowing you: - * NPN - to use one TLS server for multiple protocols (HTTP, SPDY) + * ALPN/NPN - to use one TLS server for multiple protocols (HTTP, SPDY, HTTP/2) * SNI - to use one TLS server for multiple hostnames with different SSL certificates. @@ -305,7 +306,13 @@ server. If `socket.authorized` is false, then `socket.authorizationError` is set to describe how authorization failed. Implied but worth mentioning: depending on the settings of the TLS server, you unauthorized connections may be accepted. -`socket.npnProtocol` is a string containing selected NPN protocol. + +`socket.npnProtocol` is a string containing the selected NPN protocol +and `socket.alpnProtocol` is a string containing the selected ALPN +protocol, When both NPN and ALPN extensions are received, ALPN takes +precedence over NPN and the next protocol is selected by ALPN. When +ALPN has no selected protocol, this returns false. + `socket.servername` is a string containing servername requested with SNI. @@ -429,6 +436,8 @@ Construct a new TLSSocket object from existing TCP socket. - `NPNProtocols`: Optional, see [`tls.createServer()`][] + - `ALPNProtocols`: Optional, see [tls.createServer][] + - `SNICallback`: Optional, see [`tls.createServer()`][] - `session`: Optional, a `Buffer` instance, containing TLS session @@ -460,8 +469,9 @@ The listener will be called no matter if the server's certificate was authorized or not. It is up to the user to test `tlsSocket.authorized` to see if the server certificate was signed by one of the specified CAs. If `tlsSocket.authorized === false` then the error can be found in -`tlsSocket.authorizationError`. Also if NPN was used you can check -`tlsSocket.npnProtocol` for negotiated protocol. +`tlsSocket.authorizationError`. Also if ALPN or NPN was used - you can +check `tlsSocket.alpnProtocol` or `tlsSocket.npnProtocol` for the +negotiated protocol. ### tlsSocket.address() `const` as applicable - `assert.equal` --> `assert.strictEqual` - `assert(false, ..)` --> `common.fail()` - `common.mustCall` for functions that need to be called exactly once - modified an `assert(!signal, 'Worker exited by a signal');` call to `assert.strictEqual(signal, null);` call as that made more sense PR-URL: https://github.com/nodejs/node/pull/10049 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig --- .../test-cluster-send-handle-twice.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-cluster-send-handle-twice.js b/test/parallel/test-cluster-send-handle-twice.js index 172a5563f306f5..f4d1bd8e0cc137 100644 --- a/test/parallel/test-cluster-send-handle-twice.js +++ b/test/parallel/test-cluster-send-handle-twice.js @@ -1,36 +1,36 @@ 'use strict'; // Testing to send an handle twice to the parent process. -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); -var workers = { +const workers = { toStart: 1 }; if (cluster.isMaster) { - for (var i = 0; i < workers.toStart; ++i) { - var worker = cluster.fork(); - worker.on('exit', function(code, signal) { + for (let i = 0; i < workers.toStart; ++i) { + const worker = cluster.fork(); + worker.on('exit', common.mustCall(function(code, signal) { assert.strictEqual(code, 0, 'Worker exited with an error code'); - assert(!signal, 'Worker exited by a signal'); - }); + assert.strictEqual(signal, null, 'Worker exited by a signal'); + })); } } else { - var server = net.createServer(function(socket) { + const server = net.createServer(function(socket) { process.send('send-handle-1', socket); process.send('send-handle-2', socket); }); server.listen(common.PORT, function() { - var client = net.connect({ host: 'localhost', port: common.PORT }); - client.on('close', function() { cluster.worker.disconnect(); }); + const client = net.connect({ host: 'localhost', port: common.PORT }); + client.on('close', common.mustCall(() => { cluster.worker.disconnect(); })); setTimeout(function() { client.end(); }, 50); }).on('error', function(e) { console.error(e); - assert(false, 'server.listen failed'); + common.fail('server.listen failed'); cluster.worker.disconnect(); }); } From 9b13d98f10db697fee0000fc72a138d828e9d49b Mon Sep 17 00:00:00 2001 From: Brian Chirgwin Date: Thu, 1 Dec 2016 11:10:28 -0600 Subject: [PATCH 048/116] test: refactor test-tls-interleave var -> let / const added common.mustCall() to callback assert.equal() -> assert.strictEqual() PR-URL: https://github.com/nodejs/node/pull/10017 Reviewed-By: Colin Ihrig --- test/parallel/test-tls-interleave.js | 34 +++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-tls-interleave.js b/test/parallel/test-tls-interleave.js index d03ed249d53253..9cccee82506005 100644 --- a/test/parallel/test-tls-interleave.js +++ b/test/parallel/test-tls-interleave.js @@ -1,37 +1,38 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const assert = require('assert'); -var fs = require('fs'); +const tls = require('tls'); -var dir = common.fixturesDir; -var options = { key: fs.readFileSync(dir + '/test_key.pem'), - cert: fs.readFileSync(dir + '/test_cert.pem'), - ca: [ fs.readFileSync(dir + '/test_ca.pem') ] }; +const fs = require('fs'); -var writes = [ +const dir = common.fixturesDir; +const options = { key: fs.readFileSync(dir + '/test_key.pem'), + cert: fs.readFileSync(dir + '/test_cert.pem'), + ca: [ fs.readFileSync(dir + '/test_ca.pem') ] }; + +const writes = [ 'some server data', 'and a separate packet', 'and one more', ]; -var receivedWrites = 0; +let receivedWrites = 0; -var server = tls.createServer(options, function(c) { +const server = tls.createServer(options, function(c) { writes.forEach(function(str) { c.write(str); }); -}).listen(0, function() { +}).listen(0, common.mustCall(function() { const connectOpts = { rejectUnauthorized: false }; - var c = tls.connect(this.address().port, connectOpts, function() { + const c = tls.connect(this.address().port, connectOpts, function() { c.write('some client data'); c.on('readable', function() { - var data = c.read(); + let data = c.read(); if (data === null) return; @@ -47,8 +48,9 @@ var server = tls.createServer(options, function(c) { } }); }); -}); +})); + process.on('exit', function() { - assert.equal(receivedWrites, writes.length); + assert.strictEqual(receivedWrites, writes.length); }); From f69b01e300dc2386e155f9e9ad91eeb9f547fb13 Mon Sep 17 00:00:00 2001 From: Josh Mays Date: Thu, 1 Dec 2016 11:57:14 -0600 Subject: [PATCH 049/116] test: refactor test-pipe-file-to-http Changing var defs to const/let, changing assert.equal to assert.strictEqual. Wrapping functions called once with common.mustCall PR-URL: https://github.com/nodejs/node/pull/10054 Reviewed-By: Colin Ihrig --- test/parallel/test-pipe-file-to-http.js | 41 ++++++++++++------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/test/parallel/test-pipe-file-to-http.js b/test/parallel/test-pipe-file-to-http.js index 8d804f70b7b0e1..f72cfe7d793348 100644 --- a/test/parallel/test-pipe-file-to-http.js +++ b/test/parallel/test-pipe-file-to-http.js @@ -1,20 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var http = require('http'); -var path = require('path'); -var cp = require('child_process'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const http = require('http'); +const path = require('path'); +const cp = require('child_process'); common.refreshTmpDir(); -var filename = path.join(common.tmpDir || '/tmp', 'big'); -var clientReqComplete = false; -var count = 0; +const filename = path.join(common.tmpDir || '/tmp', 'big'); +let count = 0; -var server = http.createServer(function(req, res) { - var timeoutId; - assert.equal('POST', req.method); +const server = http.createServer(function(req, res) { + let timeoutId; + assert.strictEqual('POST', req.method); req.pause(); setTimeout(function() { @@ -36,27 +35,26 @@ var server = http.createServer(function(req, res) { server.listen(0); server.on('listening', function() { - var cmd = common.ddCommand(filename, 10240); + const cmd = common.ddCommand(filename, 10240); - cp.exec(cmd, function(err, stdout, stderr) { + cp.exec(cmd, function(err) { if (err) throw err; makeRequest(); }); }); function makeRequest() { - var req = http.request({ + const req = http.request({ port: server.address().port, path: '/', method: 'POST' }); - var s = fs.ReadStream(filename); + const s = fs.ReadStream(filename); s.pipe(req); - s.on('close', function(err) { - if (err) throw err; - clientReqComplete = true; - }); + s.on('close', common.mustCall((err) => { + assert.ifError(err); + })); req.on('response', function(res) { res.resume(); @@ -67,6 +65,5 @@ function makeRequest() { } process.on('exit', function() { - assert.equal(1024 * 10240, count); - assert.ok(clientReqComplete); + assert.strictEqual(1024 * 10240, count); }); From f80084cd46df461ce4d48ae629c8fdbaf30f9dd8 Mon Sep 17 00:00:00 2001 From: "Sakthipriyan Vairamani (thefourtheye)" Date: Wed, 21 Dec 2016 07:20:45 +0530 Subject: [PATCH 050/116] test: fix and improve debug-break-on-uncaught This test runs based on a expectation that the stderr will get the string 'Debugger listening on port'. But the actual message printed to stderr has changed to 'Debugger listening on host:port'. So the the actuals tests did not even start and eventually timeout. Apart from that, changed `var`s to `let`s or `const`s. Refs: https://github.com/nodejs/node/issues/10361 PR-URL: https://github.com/nodejs/node/pull/10370 Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: James M Snell Date: Thu, 1 Dec 2016 08:54:06 -0800 Subject: [PATCH 051/116] test: refactor test-child-process-ipc Change var to const or let. Change assert.equal() to assert.strictEqual(). PR-URL: https://github.com/nodejs/node/pull/9990 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Roman Reiss --- test/parallel/test-child-process-ipc.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-child-process-ipc.js b/test/parallel/test-child-process-ipc.js index 7d0447569ffe73..cbaa270f5e8440 100644 --- a/test/parallel/test-child-process-ipc.js +++ b/test/parallel/test-child-process-ipc.js @@ -1,17 +1,18 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); -var path = require('path'); +const spawn = require('child_process').spawn; -var sub = path.join(common.fixturesDir, 'echo.js'); +const path = require('path'); -var gotHelloWorld = false; -var gotEcho = false; +const sub = path.join(common.fixturesDir, 'echo.js'); -var child = spawn(process.argv[0], [sub]); +let gotHelloWorld = false; +let gotEcho = false; + +const child = spawn(process.argv[0], [sub]); child.stderr.on('data', function(data) { console.log('parent stderr: ' + data); @@ -23,7 +24,7 @@ child.stdout.on('data', function(data) { console.log('child said: ' + JSON.stringify(data)); if (!gotHelloWorld) { console.error('testing for hello world'); - assert.equal('hello world\r\n', data); + assert.strictEqual('hello world\r\n', data); gotHelloWorld = true; console.error('writing echo me'); child.stdin.write('echo me\r\n'); From 6d5110869e306143c4877e70319af2dade5d8e4a Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Fri, 23 Dec 2016 14:01:17 -0500 Subject: [PATCH 052/116] test: improve code in test-vm-symbols * use const instead of var * use assert.strictEqual instead of assert.equal PR-URL: https://github.com/nodejs/node/pull/10429 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- test/parallel/test-vm-symbols.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-vm-symbols.js b/test/parallel/test-vm-symbols.js index d3419af559a2f2..3a360e05108da6 100644 --- a/test/parallel/test-vm-symbols.js +++ b/test/parallel/test-vm-symbols.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var vm = require('vm'); +const vm = require('vm'); -var symbol = Symbol(); +const symbol = Symbol(); function Document() { this[symbol] = 'foo'; @@ -15,11 +15,11 @@ Document.prototype.getSymbolValue = function() { return this[symbol]; }; -var context = new Document(); +const context = new Document(); vm.createContext(context); -assert.equal(context.getSymbolValue(), 'foo', +assert.strictEqual(context.getSymbolValue(), 'foo', 'should return symbol-keyed value from the outside'); -assert.equal(vm.runInContext('this.getSymbolValue()', context), 'foo', +assert.strictEqual(vm.runInContext('this.getSymbolValue()', context), 'foo', 'should return symbol-keyed value from the inside'); From 81649fdd80d3c0a3abe7a9a4706762c81ff60192 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Tue, 20 Dec 2016 19:27:56 -0500 Subject: [PATCH 053/116] test: improve code in test-fs-readfile-error * use const instead of var * use common.mustCall to control the functions execution automatically * use assert.strictEqual instead of assert.equal * use assert.notStrictEqual instead of assert.notEqual * use arrow functions PR-URL: https://github.com/nodejs/node/pull/10367 Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-fs-readfile-error.js | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-fs-readfile-error.js b/test/parallel/test-fs-readfile-error.js index c2b3c015512497..df44c8491f347c 100644 --- a/test/parallel/test-fs-readfile-error.js +++ b/test/parallel/test-fs-readfile-error.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; -var path = require('path'); +const common = require('../common'); +const assert = require('assert'); +const exec = require('child_process').exec; +const path = require('path'); // `fs.readFile('/')` does not fail on FreeBSD, because you can open and read // the directory there. @@ -14,28 +14,28 @@ if (process.platform === 'freebsd') { var callbacks = 0; function test(env, cb) { - var filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js'); - var execPath = '"' + process.execPath + '" "' + filename + '"'; - var options = { env: Object.assign(process.env, env) }; - exec(execPath, options, function(err, stdout, stderr) { + const filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js'); + const execPath = '"' + process.execPath + '" "' + filename + '"'; + const options = { env: Object.assign(process.env, env) }; + exec(execPath, options, common.mustCall((err, stdout, stderr) => { assert(err); - assert.equal(stdout, ''); - assert.notEqual(stderr, ''); + assert.strictEqual(stdout, ''); + assert.notStrictEqual(stderr, ''); cb('' + stderr); - }); + })); } -test({ NODE_DEBUG: '' }, function(data) { +test({ NODE_DEBUG: '' }, common.mustCall((data) => { assert(/EISDIR/.test(data)); assert(!/test-fs-readfile-error/.test(data)); callbacks++; -}); +})); -test({ NODE_DEBUG: 'fs' }, function(data) { +test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => { assert(/EISDIR/.test(data)); assert(/test-fs-readfile-error/.test(data)); callbacks++; -}); +})); process.on('exit', function() { assert.equal(callbacks, 2); From 70595437488c6cc95d0d8b340b95f9490b486027 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Tue, 27 Dec 2016 12:12:07 -0500 Subject: [PATCH 054/116] test: improve the code in test-pipe.js * use const and let instead of var * use common.mustCall to control functions executions * use assert.strictEqual instead of assert.equal * use assert.ifError to handle errors * use arrow functions * remove console.log and process.stdout.write PR-URL: https://github.com/nodejs/node/pull/10452 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Brian White --- test/sequential/test-pipe.js | 94 +++++++++++++++--------------------- 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/test/sequential/test-pipe.js b/test/sequential/test-pipe.js index c311a64d717833..32caed16df4320 100644 --- a/test/sequential/test-pipe.js +++ b/test/sequential/test-pipe.js @@ -1,111 +1,97 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var webPort = common.PORT; -var tcpPort = webPort + 1; +const webPort = common.PORT; +const tcpPort = webPort + 1; +const bufferSize = 5 * 1024 * 1024; -var listenCount = 0; -var gotThanks = false; -var tcpLengthSeen = 0; -var bufferSize = 5 * 1024 * 1024; +let listenCount = 0; +let gotThanks = false; +let tcpLengthSeen = 0; /* * 5MB of random buffer. */ -var buffer = Buffer(bufferSize); -for (var i = 0; i < buffer.length; i++) { +const buffer = Buffer.allocUnsafe(bufferSize); +for (let i = 0; i < buffer.length; i++) { buffer[i] = parseInt(Math.random() * 10000) % 256; } -var web = http.Server(function(req, res) { +const web = http.Server(common.mustCall((req, res) => { web.close(); - console.log(req.headers); - - var socket = net.Stream(); + const socket = net.Stream(); socket.connect(tcpPort); - socket.on('connect', function() { - console.log('socket connected'); - }); + socket.on('connect', common.mustCall(() => {})); req.pipe(socket); - req.on('end', function() { + req.on('end', common.mustCall(() => { res.writeHead(200); res.write('thanks'); res.end(); - console.log('response with \'thanks\''); - }); + })); - req.connection.on('error', function(e) { - console.log('http server-side error: ' + e.message); - process.exit(1); + req.connection.on('error', (e) => { + assert.ifError(e); }); -}); +})); + web.listen(webPort, startClient); -var tcp = net.Server(function(s) { +const tcp = net.Server(common.mustCall((s) => { tcp.close(); - console.log('tcp server connection'); - - var i = 0; + let i = 0; - s.on('data', function(d) { - process.stdout.write('.'); + s.on('data', (d) => { tcpLengthSeen += d.length; - for (var j = 0; j < d.length; j++) { - assert.equal(buffer[i], d[j]); + for (let j = 0; j < d.length; j++) { + assert.strictEqual(buffer[i], d[j]); i++; } }); - s.on('end', function() { - console.log('tcp socket disconnect'); + s.on('end', common.mustCall(() => { s.end(); - }); + })); - s.on('error', function(e) { - console.log('tcp server-side error: ' + e.message); - process.exit(1); + s.on('error', (e) => { + assert.ifError(e); }); -}); -tcp.listen(tcpPort, startClient); +})); +tcp.listen(tcpPort, startClient); function startClient() { listenCount++; if (listenCount < 2) return; - console.log('Making request'); - - var req = http.request({ + const req = http.request({ port: common.PORT, method: 'GET', path: '/', headers: { 'content-length': buffer.length } - }, function(res) { - console.log('Got response'); + }, common.mustCall((res) => { res.setEncoding('utf8'); - res.on('data', function(string) { - assert.equal('thanks', string); + res.on('data', common.mustCall((string) => { + assert.strictEqual('thanks', string); gotThanks = true; - }); - }); + })); + })); req.write(buffer); req.end(); - console.error('ended request', req); } -process.on('exit', function() { +process.on('exit', () => { assert.ok(gotThanks); - assert.equal(bufferSize, tcpLengthSeen); + assert.strictEqual(bufferSize, tcpLengthSeen); }); From a394d00125549d8a2c2b9f7c57ecce9912d981e8 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 25 Dec 2016 19:57:12 +0200 Subject: [PATCH 055/116] doc: var -> const / let in the console.md PR-URL: https://github.com/nodejs/node/pull/10451 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/console.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/console.md b/doc/api/console.md index 4de1c096430d16..6d75198d019d67 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -88,7 +88,7 @@ const errorOutput = fs.createWriteStream('./stderr.log'); // custom simple logger const logger = new Console(output, errorOutput); // use it like console -var count = 5; +const count = 5; logger.log('count: %d', count); // in stdout.log: count 5 ``` @@ -217,7 +217,7 @@ values similar to printf(3) (the arguments are all passed to [`util.format()`][]). ```js -var count = 5; +const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); @@ -249,7 +249,7 @@ prints the result to stdout: ```js console.time('100-elements'); -for (var i = 0; i < 100; i++) { +for (let i = 0; i < 100; i++) { ; } console.timeEnd('100-elements'); From f59b6ddb2b3987ad07b10598d1086646c16694c7 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 25 Dec 2016 20:04:45 +0200 Subject: [PATCH 056/116] doc: more efficient example in the console.md Object.setPrototypeOf() -> Object.create() PR-URL: https://github.com/nodejs/node/pull/10451 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/console.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/doc/api/console.md b/doc/api/console.md index 6d75198d019d67..a7d56b4a37a95e 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -135,15 +135,20 @@ the default behavior of `console` in Node.js. // Creates a simple extension of console with a // new impl for assert without monkey-patching. -const myConsole = Object.setPrototypeOf({ - assert(assertion, message, ...args) { - try { - console.assert(assertion, message, ...args); - } catch (err) { - console.error(err.stack); - } - } -}, console); +const myConsole = Object.create(console, { + assert: { + value: function assert(assertion, message, ...args) { + try { + console.assert(assertion, message, ...args); + } catch (err) { + console.error(err.stack); + } + }, + configurable: true, + enumerable: true, + writable: true, + }, +}); module.exports = myConsole; ``` From 03d39909ffde538d6bb1df475130f578a9145b33 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Sat, 24 Dec 2016 16:07:52 -0500 Subject: [PATCH 057/116] test: refactor the code in test-fs-chmod * use const and let instead of var * use common.mustCall to control functions executions * use assert.strictEqual instead of assert.equal * use assert.ifError to handle errors * use arrow functions * remove unnecessary variables PR-URL: https://github.com/nodejs/node/pull/10440 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- test/parallel/test-fs-chmod.js | 117 ++++++++++++++------------------- 1 file changed, 51 insertions(+), 66 deletions(-) diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js index 954916cbdbb365..ecba2e27bb2c6e 100644 --- a/test/parallel/test-fs-chmod.js +++ b/test/parallel/test-fs-chmod.js @@ -1,12 +1,11 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var got_error = false; -var success_count = 0; -var mode_async; -var mode_sync; +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); + +let mode_async; +let mode_sync; // Need to hijack fs.open/close to make sure that things // get closed once they're opened. @@ -19,7 +18,7 @@ fs._closeSync = fs.closeSync; fs.close = close; fs.closeSync = closeSync; -var openCount = 0; +let openCount = 0; function open() { openCount++; @@ -54,57 +53,49 @@ if (common.isWindows) { const file1 = path.join(common.fixturesDir, 'a.js'); const file2 = path.join(common.fixturesDir, 'a1.js'); -fs.chmod(file1, mode_async.toString(8), function(err) { - if (err) { - got_error = true; +fs.chmod(file1, mode_async.toString(8), common.mustCall((err) => { + assert.ifError(err); + + console.log(fs.statSync(file1).mode); + + if (common.isWindows) { + assert.ok((fs.statSync(file1).mode & 0o777) & mode_async); } else { - console.log(fs.statSync(file1).mode); + assert.strictEqual(mode_async, fs.statSync(file1).mode & 0o777); + } + + fs.chmodSync(file1, mode_sync); + if (common.isWindows) { + assert.ok((fs.statSync(file1).mode & 0o777) & mode_sync); + } else { + assert.strictEqual(mode_sync, fs.statSync(file1).mode & 0o777); + } +})); + +fs.open(file2, 'a', common.mustCall((err, fd) => { + assert.ifError(err); + + fs.fchmod(fd, mode_async.toString(8), common.mustCall((err) => { + assert.ifError(err); + + console.log(fs.fstatSync(fd).mode); if (common.isWindows) { - assert.ok((fs.statSync(file1).mode & 0o777) & mode_async); + assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_async); } else { - assert.equal(mode_async, fs.statSync(file1).mode & 0o777); + assert.strictEqual(mode_async, fs.fstatSync(fd).mode & 0o777); } - fs.chmodSync(file1, mode_sync); + fs.fchmodSync(fd, mode_sync); if (common.isWindows) { - assert.ok((fs.statSync(file1).mode & 0o777) & mode_sync); + assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_sync); } else { - assert.equal(mode_sync, fs.statSync(file1).mode & 0o777); + assert.strictEqual(mode_sync, fs.fstatSync(fd).mode & 0o777); } - success_count++; - } -}); -fs.open(file2, 'a', function(err, fd) { - if (err) { - got_error = true; - console.error(err.stack); - return; - } - fs.fchmod(fd, mode_async.toString(8), function(err) { - if (err) { - got_error = true; - } else { - console.log(fs.fstatSync(fd).mode); - - if (common.isWindows) { - assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_async); - } else { - assert.equal(mode_async, fs.fstatSync(fd).mode & 0o777); - } - - fs.fchmodSync(fd, mode_sync); - if (common.isWindows) { - assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_sync); - } else { - assert.equal(mode_sync, fs.fstatSync(fd).mode & 0o777); - } - success_count++; - fs.close(fd); - } - }); -}); + fs.close(fd); + })); +})); // lchmod if (fs.lchmod) { @@ -113,26 +104,20 @@ if (fs.lchmod) { common.refreshTmpDir(); fs.symlinkSync(file2, link); - fs.lchmod(link, mode_async, function(err) { - if (err) { - got_error = true; - } else { - console.log(fs.lstatSync(link).mode); - assert.equal(mode_async, fs.lstatSync(link).mode & 0o777); + fs.lchmod(link, mode_async, common.mustCall((err) => { + assert.ifError(err); - fs.lchmodSync(link, mode_sync); - assert.equal(mode_sync, fs.lstatSync(link).mode & 0o777); - success_count++; - } - }); -} else { - success_count++; + console.log(fs.lstatSync(link).mode); + assert.strictEqual(mode_async, fs.lstatSync(link).mode & 0o777); + + fs.lchmodSync(link, mode_sync); + assert.strictEqual(mode_sync, fs.lstatSync(link).mode & 0o777); + + })); } process.on('exit', function() { - assert.equal(3, success_count); - assert.equal(0, openCount); - assert.equal(false, got_error); + assert.strictEqual(0, openCount); }); From b5b1ca6bdd271fdbec7eef7ad3a21c3a35142e60 Mon Sep 17 00:00:00 2001 From: William Kapke Date: Thu, 17 Nov 2016 06:27:07 +0000 Subject: [PATCH 058/116] doc: add Working Group dissolution text PR-URL: https://github.com/nodejs/node/pull/9656 Reviewed-By: Myles Borins Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Anna Henningsen --- WORKING_GROUPS.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/WORKING_GROUPS.md b/WORKING_GROUPS.md index a29309d7f71621..f013a574610d0f 100644 --- a/WORKING_GROUPS.md +++ b/WORKING_GROUPS.md @@ -12,9 +12,12 @@ 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 charter is completed the Working -Group should be dissolved and the responsibility for governance absorbed -back in to the CTC. +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. ## Current Working Groups From e1971291c5312cf2f7e1131d53044d3f49b8e791 Mon Sep 17 00:00:00 2001 From: Rob Adelmann Date: Sun, 18 Dec 2016 19:56:18 -0800 Subject: [PATCH 059/116] test: refactor test-stdin-from-file Remove console.log statement. Replace error check with assert.ifError(). PR-URL: https://github.com/nodejs/node/pull/10331 Reviewed-By: Colin Ihrig Reviewed-By: Italo A. Casas Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-stdin-from-file.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/parallel/test-stdin-from-file.js b/test/parallel/test-stdin-from-file.js index f3a78192e5e5aa..9a847118bd670d 100644 --- a/test/parallel/test-stdin-from-file.js +++ b/test/parallel/test-stdin-from-file.js @@ -33,8 +33,7 @@ fs.writeFileSync(tmpFile, string); childProcess.exec(cmd, common.mustCall(function(err, stdout, stderr) { fs.unlinkSync(tmpFile); - if (err) throw err; - console.log(stdout); + assert.ifError(err); assert.strictEqual(stdout, 'hello world\r\n' + string); assert.strictEqual('', stderr); })); From e83c121fb396f5e47d01a9acf2011d0830e7f1e3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 23 Dec 2016 12:54:32 -0800 Subject: [PATCH 060/116] test: fix flaky test-http-client-timeout-with-data test-http-client-timeout-with-data has failed here and there in CI on FreeBSD and OS X. The test has a socket timeout set to 50ms and a timer set for 100ms. However, they are not necessarily set in the same tick of the event loop and their ordering is therefore not guaranteed. Instead of using a timer, this change listens for an event on the listener to know when the socket timeout has occurred and then runs the code originally in the timer. Additional refactoring: Replaced `process.on('exit', ...)` checks with `common.mustCall()` and replaced usage of `assert.equal()` with `assert.strictEqual()`. PR-URL: https://github.com/nodejs/node/pull/10431 Reviewed-By: James M Snell --- .../test-http-client-timeout-with-data.js | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/test/parallel/test-http-client-timeout-with-data.js b/test/parallel/test-http-client-timeout-with-data.js index f5b2a60dc52a54..c82327beb295da 100644 --- a/test/parallel/test-http-client-timeout-with-data.js +++ b/test/parallel/test-http-client-timeout-with-data.js @@ -3,14 +3,8 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -var ntimeouts = 0; var nchunks = 0; -process.on('exit', function() { - assert.equal(ntimeouts, 1); - assert.equal(nchunks, 2); -}); - const options = { method: 'GET', port: undefined, @@ -21,7 +15,7 @@ const options = { const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Length': '2'}); res.write('*'); - setTimeout(function() { res.end('*'); }, common.platformTimeout(100)); + server.once('timeout', common.mustCall(function() { res.end('*'); })); }); server.listen(0, options.host, function() { @@ -30,19 +24,19 @@ server.listen(0, options.host, function() { req.end(); function onresponse(res) { - req.setTimeout(50, function() { - assert.equal(nchunks, 1); // should have received the first chunk by now - ntimeouts++; - }); + req.setTimeout(50, common.mustCall(function() { + assert.strictEqual(nchunks, 1); // should have received the first chunk + server.emit('timeout'); + })); - res.on('data', function(data) { - assert.equal('' + data, '*'); + res.on('data', common.mustCall(function(data) { + assert.strictEqual('' + data, '*'); nchunks++; - }); + }, 2)); - res.on('end', function() { - assert.equal(nchunks, 2); + res.on('end', common.mustCall(function() { + assert.strictEqual(nchunks, 2); server.close(); - }); + })); } }); From cbbe46adbef1fbe39f740734974f66412e46fec3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 30 Dec 2016 11:46:21 -0500 Subject: [PATCH 061/116] test: s/ASSERT/assert/ This commit addresses an inconsistency with eight tests. These tests use the assert module, but named the variable ASSERT. This goes against the project's typical coding style, and negatively impacts global find and replace updates. PR-URL: https://github.com/nodejs/node/pull/10544 Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Jackson Tian Reviewed-By: Prince John Wesley Reviewed-By: Luigi Pinca --- test/parallel/test-readdouble.js | 62 +++---- test/parallel/test-readfloat.js | 38 ++--- test/parallel/test-readint.js | 62 +++---- test/parallel/test-readuint.js | 40 ++--- test/parallel/test-writedouble.js | 270 +++++++++++++++--------------- test/parallel/test-writefloat.js | 142 ++++++++-------- test/parallel/test-writeint.js | 154 ++++++++--------- test/parallel/test-writeuint.js | 106 ++++++------ 8 files changed, 437 insertions(+), 437 deletions(-) diff --git a/test/parallel/test-readdouble.js b/test/parallel/test-readdouble.js index 6c55a65007aa88..a6fc91c351f089 100644 --- a/test/parallel/test-readdouble.js +++ b/test/parallel/test-readdouble.js @@ -3,7 +3,7 @@ * Tests to verify we're reading in doubles correctly */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); /* * Test (64 bit) double @@ -19,8 +19,8 @@ function test(clazz) { buffer[5] = 0x55; buffer[6] = 0xd5; buffer[7] = 0x3f; - ASSERT.equal(1.1945305291680097e+103, buffer.readDoubleBE(0)); - ASSERT.equal(0.3333333333333333, buffer.readDoubleLE(0)); + assert.equal(1.1945305291680097e+103, buffer.readDoubleBE(0)); + assert.equal(0.3333333333333333, buffer.readDoubleLE(0)); buffer[0] = 1; buffer[1] = 0; @@ -30,18 +30,18 @@ function test(clazz) { buffer[5] = 0; buffer[6] = 0xf0; buffer[7] = 0x3f; - ASSERT.equal(7.291122019655968e-304, buffer.readDoubleBE(0)); - ASSERT.equal(1.0000000000000002, buffer.readDoubleLE(0)); + assert.equal(7.291122019655968e-304, buffer.readDoubleBE(0)); + assert.equal(1.0000000000000002, buffer.readDoubleLE(0)); buffer[0] = 2; - ASSERT.equal(4.778309726801735e-299, buffer.readDoubleBE(0)); - ASSERT.equal(1.0000000000000004, buffer.readDoubleLE(0)); + assert.equal(4.778309726801735e-299, buffer.readDoubleBE(0)); + assert.equal(1.0000000000000004, buffer.readDoubleLE(0)); buffer[0] = 1; buffer[6] = 0; buffer[7] = 0; - ASSERT.equal(7.291122019556398e-304, buffer.readDoubleBE(0)); - ASSERT.equal(5e-324, buffer.readDoubleLE(0)); + assert.equal(7.291122019556398e-304, buffer.readDoubleBE(0)); + assert.equal(5e-324, buffer.readDoubleLE(0)); buffer[0] = 0xff; buffer[1] = 0xff; @@ -51,13 +51,13 @@ function test(clazz) { buffer[5] = 0xff; buffer[6] = 0x0f; buffer[7] = 0x00; - ASSERT.ok(isNaN(buffer.readDoubleBE(0))); - ASSERT.equal(2.225073858507201e-308, buffer.readDoubleLE(0)); + assert.ok(isNaN(buffer.readDoubleBE(0))); + assert.equal(2.225073858507201e-308, buffer.readDoubleLE(0)); buffer[6] = 0xef; buffer[7] = 0x7f; - ASSERT.ok(isNaN(buffer.readDoubleBE(0))); - ASSERT.equal(1.7976931348623157e+308, buffer.readDoubleLE(0)); + assert.ok(isNaN(buffer.readDoubleBE(0))); + assert.equal(1.7976931348623157e+308, buffer.readDoubleLE(0)); buffer[0] = 0; buffer[1] = 0; @@ -67,42 +67,42 @@ function test(clazz) { buffer[5] = 0; buffer[6] = 0xf0; buffer[7] = 0x3f; - ASSERT.equal(3.03865e-319, buffer.readDoubleBE(0)); - ASSERT.equal(1, buffer.readDoubleLE(0)); + assert.equal(3.03865e-319, buffer.readDoubleBE(0)); + assert.equal(1, buffer.readDoubleLE(0)); buffer[6] = 0; buffer[7] = 0x40; - ASSERT.equal(3.16e-322, buffer.readDoubleBE(0)); - ASSERT.equal(2, buffer.readDoubleLE(0)); + assert.equal(3.16e-322, buffer.readDoubleBE(0)); + assert.equal(2, buffer.readDoubleLE(0)); buffer[7] = 0xc0; - ASSERT.equal(9.5e-322, buffer.readDoubleBE(0)); - ASSERT.equal(-2, buffer.readDoubleLE(0)); + assert.equal(9.5e-322, buffer.readDoubleBE(0)); + assert.equal(-2, buffer.readDoubleLE(0)); buffer[6] = 0x10; buffer[7] = 0; - ASSERT.equal(2.0237e-320, buffer.readDoubleBE(0)); - ASSERT.equal(2.2250738585072014e-308, buffer.readDoubleLE(0)); + assert.equal(2.0237e-320, buffer.readDoubleBE(0)); + assert.equal(2.2250738585072014e-308, buffer.readDoubleLE(0)); buffer[6] = 0; - ASSERT.equal(0, buffer.readDoubleBE(0)); - ASSERT.equal(0, buffer.readDoubleLE(0)); - ASSERT.equal(false, 1 / buffer.readDoubleLE(0) < 0); + assert.equal(0, buffer.readDoubleBE(0)); + assert.equal(0, buffer.readDoubleLE(0)); + assert.equal(false, 1 / buffer.readDoubleLE(0) < 0); buffer[7] = 0x80; - ASSERT.equal(6.3e-322, buffer.readDoubleBE(0)); - ASSERT.equal(0, buffer.readDoubleLE(0)); - ASSERT.equal(true, 1 / buffer.readDoubleLE(0) < 0); + assert.equal(6.3e-322, buffer.readDoubleBE(0)); + assert.equal(0, buffer.readDoubleLE(0)); + assert.equal(true, 1 / buffer.readDoubleLE(0) < 0); buffer[6] = 0xf0; buffer[7] = 0x7f; - ASSERT.equal(3.0418e-319, buffer.readDoubleBE(0)); - ASSERT.equal(Infinity, buffer.readDoubleLE(0)); + assert.equal(3.0418e-319, buffer.readDoubleBE(0)); + assert.equal(Infinity, buffer.readDoubleLE(0)); buffer[6] = 0xf0; buffer[7] = 0xff; - ASSERT.equal(3.04814e-319, buffer.readDoubleBE(0)); - ASSERT.equal(-Infinity, buffer.readDoubleLE(0)); + assert.equal(3.04814e-319, buffer.readDoubleBE(0)); + assert.equal(-Infinity, buffer.readDoubleLE(0)); } diff --git a/test/parallel/test-readfloat.js b/test/parallel/test-readfloat.js index 468faf76029613..533b7caa8f1047 100644 --- a/test/parallel/test-readfloat.js +++ b/test/parallel/test-readfloat.js @@ -3,7 +3,7 @@ * Tests to verify we're reading in floats correctly */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); /* * Test (32 bit) float @@ -15,56 +15,56 @@ function test(clazz) { buffer[1] = 0; buffer[2] = 0x80; buffer[3] = 0x3f; - ASSERT.equal(4.600602988224807e-41, buffer.readFloatBE(0)); - ASSERT.equal(1, buffer.readFloatLE(0)); + assert.equal(4.600602988224807e-41, buffer.readFloatBE(0)); + assert.equal(1, buffer.readFloatLE(0)); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0xc0; - ASSERT.equal(2.6904930515036488e-43, buffer.readFloatBE(0)); - ASSERT.equal(-2, buffer.readFloatLE(0)); + assert.equal(2.6904930515036488e-43, buffer.readFloatBE(0)); + assert.equal(-2, buffer.readFloatLE(0)); buffer[0] = 0xff; buffer[1] = 0xff; buffer[2] = 0x7f; buffer[3] = 0x7f; - ASSERT.ok(isNaN(buffer.readFloatBE(0))); - ASSERT.equal(3.4028234663852886e+38, buffer.readFloatLE(0)); + assert.ok(isNaN(buffer.readFloatBE(0))); + assert.equal(3.4028234663852886e+38, buffer.readFloatLE(0)); buffer[0] = 0xab; buffer[1] = 0xaa; buffer[2] = 0xaa; buffer[3] = 0x3e; - ASSERT.equal(-1.2126478207002966e-12, buffer.readFloatBE(0)); - ASSERT.equal(0.3333333432674408, buffer.readFloatLE(0)); + assert.equal(-1.2126478207002966e-12, buffer.readFloatBE(0)); + assert.equal(0.3333333432674408, buffer.readFloatLE(0)); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0; - ASSERT.equal(0, buffer.readFloatBE(0)); - ASSERT.equal(0, buffer.readFloatLE(0)); - ASSERT.equal(false, 1 / buffer.readFloatLE(0) < 0); + assert.equal(0, buffer.readFloatBE(0)); + assert.equal(0, buffer.readFloatLE(0)); + assert.equal(false, 1 / buffer.readFloatLE(0) < 0); buffer[3] = 0x80; - ASSERT.equal(1.793662034335766e-43, buffer.readFloatBE(0)); - ASSERT.equal(0, buffer.readFloatLE(0)); - ASSERT.equal(true, 1 / buffer.readFloatLE(0) < 0); + assert.equal(1.793662034335766e-43, buffer.readFloatBE(0)); + assert.equal(0, buffer.readFloatLE(0)); + assert.equal(true, 1 / buffer.readFloatLE(0) < 0); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0x80; buffer[3] = 0x7f; - ASSERT.equal(4.609571298396486e-41, buffer.readFloatBE(0)); - ASSERT.equal(Infinity, buffer.readFloatLE(0)); + assert.equal(4.609571298396486e-41, buffer.readFloatBE(0)); + assert.equal(Infinity, buffer.readFloatLE(0)); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0x80; buffer[3] = 0xff; - ASSERT.equal(4.627507918739843e-41, buffer.readFloatBE(0)); - ASSERT.equal(-Infinity, buffer.readFloatLE(0)); + assert.equal(4.627507918739843e-41, buffer.readFloatBE(0)); + assert.equal(-Infinity, buffer.readFloatLE(0)); } diff --git a/test/parallel/test-readint.js b/test/parallel/test-readint.js index b3997f74f17721..c068ddcb6c554a 100644 --- a/test/parallel/test-readint.js +++ b/test/parallel/test-readint.js @@ -3,7 +3,7 @@ * Tests to verify we're reading in signed integers correctly */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); /* * Test 8 bit signed integers @@ -12,19 +12,19 @@ function test8(clazz) { var data = new clazz(4); data[0] = 0x23; - ASSERT.equal(0x23, data.readInt8(0)); + assert.equal(0x23, data.readInt8(0)); data[0] = 0xff; - ASSERT.equal(-1, data.readInt8(0)); + assert.equal(-1, data.readInt8(0)); data[0] = 0x87; data[1] = 0xab; data[2] = 0x7c; data[3] = 0xef; - ASSERT.equal(-121, data.readInt8(0)); - ASSERT.equal(-85, data.readInt8(1)); - ASSERT.equal(124, data.readInt8(2)); - ASSERT.equal(-17, data.readInt8(3)); + assert.equal(-121, data.readInt8(0)); + assert.equal(-85, data.readInt8(1)); + assert.equal(124, data.readInt8(2)); + assert.equal(-17, data.readInt8(3)); } @@ -33,13 +33,13 @@ function test16(clazz) { buffer[0] = 0x16; buffer[1] = 0x79; - ASSERT.equal(0x1679, buffer.readInt16BE(0)); - ASSERT.equal(0x7916, buffer.readInt16LE(0)); + assert.equal(0x1679, buffer.readInt16BE(0)); + assert.equal(0x7916, buffer.readInt16LE(0)); buffer[0] = 0xff; buffer[1] = 0x80; - ASSERT.equal(-128, buffer.readInt16BE(0)); - ASSERT.equal(-32513, buffer.readInt16LE(0)); + assert.equal(-128, buffer.readInt16BE(0)); + assert.equal(-32513, buffer.readInt16LE(0)); /* test offset with weenix */ buffer[0] = 0x77; @@ -48,16 +48,16 @@ function test16(clazz) { buffer[3] = 0x6e; buffer[4] = 0x69; buffer[5] = 0x78; - ASSERT.equal(0x7765, buffer.readInt16BE(0)); - ASSERT.equal(0x6565, buffer.readInt16BE(1)); - ASSERT.equal(0x656e, buffer.readInt16BE(2)); - ASSERT.equal(0x6e69, buffer.readInt16BE(3)); - ASSERT.equal(0x6978, buffer.readInt16BE(4)); - ASSERT.equal(0x6577, buffer.readInt16LE(0)); - ASSERT.equal(0x6565, buffer.readInt16LE(1)); - ASSERT.equal(0x6e65, buffer.readInt16LE(2)); - ASSERT.equal(0x696e, buffer.readInt16LE(3)); - ASSERT.equal(0x7869, buffer.readInt16LE(4)); + assert.equal(0x7765, buffer.readInt16BE(0)); + assert.equal(0x6565, buffer.readInt16BE(1)); + assert.equal(0x656e, buffer.readInt16BE(2)); + assert.equal(0x6e69, buffer.readInt16BE(3)); + assert.equal(0x6978, buffer.readInt16BE(4)); + assert.equal(0x6577, buffer.readInt16LE(0)); + assert.equal(0x6565, buffer.readInt16LE(1)); + assert.equal(0x6e65, buffer.readInt16LE(2)); + assert.equal(0x696e, buffer.readInt16LE(3)); + assert.equal(0x7869, buffer.readInt16LE(4)); } @@ -68,15 +68,15 @@ function test32(clazz) { buffer[1] = 0x53; buffer[2] = 0x16; buffer[3] = 0x79; - ASSERT.equal(0x43531679, buffer.readInt32BE(0)); - ASSERT.equal(0x79165343, buffer.readInt32LE(0)); + assert.equal(0x43531679, buffer.readInt32BE(0)); + assert.equal(0x79165343, buffer.readInt32LE(0)); buffer[0] = 0xff; buffer[1] = 0xfe; buffer[2] = 0xef; buffer[3] = 0xfa; - ASSERT.equal(-69638, buffer.readInt32BE(0)); - ASSERT.equal(-84934913, buffer.readInt32LE(0)); + assert.equal(-69638, buffer.readInt32BE(0)); + assert.equal(-84934913, buffer.readInt32LE(0)); buffer[0] = 0x42; buffer[1] = 0xc3; @@ -84,12 +84,12 @@ function test32(clazz) { buffer[3] = 0xa9; buffer[4] = 0x36; buffer[5] = 0x17; - ASSERT.equal(0x42c395a9, buffer.readInt32BE(0)); - ASSERT.equal(-1013601994, buffer.readInt32BE(1)); - ASSERT.equal(-1784072681, buffer.readInt32BE(2)); - ASSERT.equal(-1449802942, buffer.readInt32LE(0)); - ASSERT.equal(917083587, buffer.readInt32LE(1)); - ASSERT.equal(389458325, buffer.readInt32LE(2)); + assert.equal(0x42c395a9, buffer.readInt32BE(0)); + assert.equal(-1013601994, buffer.readInt32BE(1)); + assert.equal(-1784072681, buffer.readInt32BE(2)); + assert.equal(-1449802942, buffer.readInt32LE(0)); + assert.equal(917083587, buffer.readInt32LE(1)); + assert.equal(389458325, buffer.readInt32LE(2)); } diff --git a/test/parallel/test-readuint.js b/test/parallel/test-readuint.js index 154af1841a98cd..9fcaf45603fd83 100644 --- a/test/parallel/test-readuint.js +++ b/test/parallel/test-readuint.js @@ -4,7 +4,7 @@ */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); /* * We need to check the following things: @@ -20,13 +20,13 @@ function test8(clazz) { data[1] = 23; data[2] = 23; data[3] = 23; - ASSERT.equal(23, data.readUInt8(0)); - ASSERT.equal(23, data.readUInt8(1)); - ASSERT.equal(23, data.readUInt8(2)); - ASSERT.equal(23, data.readUInt8(3)); + assert.equal(23, data.readUInt8(0)); + assert.equal(23, data.readUInt8(1)); + assert.equal(23, data.readUInt8(2)); + assert.equal(23, data.readUInt8(3)); data[0] = 255; /* If it became a signed int, would be -1 */ - ASSERT.equal(255, data.readUInt8(0)); + assert.equal(255, data.readUInt8(0)); } @@ -45,17 +45,17 @@ function test16(clazz) { data[1] = 0x23; data[2] = 0x42; data[3] = 0x3f; - ASSERT.equal(0x23, data.readUInt16BE(0)); - ASSERT.equal(0x2342, data.readUInt16BE(1)); - ASSERT.equal(0x423f, data.readUInt16BE(2)); - ASSERT.equal(0x2300, data.readUInt16LE(0)); - ASSERT.equal(0x4223, data.readUInt16LE(1)); - ASSERT.equal(0x3f42, data.readUInt16LE(2)); + assert.equal(0x23, data.readUInt16BE(0)); + assert.equal(0x2342, data.readUInt16BE(1)); + assert.equal(0x423f, data.readUInt16BE(2)); + assert.equal(0x2300, data.readUInt16LE(0)); + assert.equal(0x4223, data.readUInt16LE(1)); + assert.equal(0x3f42, data.readUInt16LE(2)); data[0] = 0xfe; data[1] = 0xfe; - ASSERT.equal(0xfefe, data.readUInt16BE(0)); - ASSERT.equal(0xfefe, data.readUInt16LE(0)); + assert.equal(0xfefe, data.readUInt16BE(0)); + assert.equal(0xfefe, data.readUInt16LE(0)); } @@ -75,12 +75,12 @@ function test32(clazz) { data[3] = 0x56; data[4] = 0x23; data[5] = 0xff; - ASSERT.equal(0x32654256, data.readUInt32BE(0)); - ASSERT.equal(0x65425623, data.readUInt32BE(1)); - ASSERT.equal(0x425623ff, data.readUInt32BE(2)); - ASSERT.equal(0x56426532, data.readUInt32LE(0)); - ASSERT.equal(0x23564265, data.readUInt32LE(1)); - ASSERT.equal(0xff235642, data.readUInt32LE(2)); + assert.equal(0x32654256, data.readUInt32BE(0)); + assert.equal(0x65425623, data.readUInt32BE(1)); + assert.equal(0x425623ff, data.readUInt32BE(2)); + assert.equal(0x56426532, data.readUInt32LE(0)); + assert.equal(0x23564265, data.readUInt32LE(1)); + assert.equal(0xff235642, data.readUInt32LE(2)); } diff --git a/test/parallel/test-writedouble.js b/test/parallel/test-writedouble.js index 4e86182137de29..107bf521342ef3 100644 --- a/test/parallel/test-writedouble.js +++ b/test/parallel/test-writedouble.js @@ -3,173 +3,173 @@ * Tests to verify we're writing doubles correctly */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); function test(clazz) { var buffer = new clazz(16); buffer.writeDoubleBE(2.225073858507201e-308, 0); buffer.writeDoubleLE(2.225073858507201e-308, 8); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x0f, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0xff, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xff, buffer[7]); - ASSERT.equal(0xff, buffer[8]); - ASSERT.equal(0xff, buffer[9]); - ASSERT.equal(0xff, buffer[10]); - ASSERT.equal(0xff, buffer[11]); - ASSERT.equal(0xff, buffer[12]); - ASSERT.equal(0xff, buffer[13]); - ASSERT.equal(0x0f, buffer[14]); - ASSERT.equal(0x00, buffer[15]); + assert.equal(0x00, buffer[0]); + assert.equal(0x0f, buffer[1]); + assert.equal(0xff, buffer[2]); + assert.equal(0xff, buffer[3]); + assert.equal(0xff, buffer[4]); + assert.equal(0xff, buffer[5]); + assert.equal(0xff, buffer[6]); + assert.equal(0xff, buffer[7]); + assert.equal(0xff, buffer[8]); + assert.equal(0xff, buffer[9]); + assert.equal(0xff, buffer[10]); + assert.equal(0xff, buffer[11]); + assert.equal(0xff, buffer[12]); + assert.equal(0xff, buffer[13]); + assert.equal(0x0f, buffer[14]); + assert.equal(0x00, buffer[15]); buffer.writeDoubleBE(1.0000000000000004, 0); buffer.writeDoubleLE(1.0000000000000004, 8); - ASSERT.equal(0x3f, buffer[0]); - ASSERT.equal(0xf0, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x02, buffer[7]); - ASSERT.equal(0x02, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0xf0, buffer[14]); - ASSERT.equal(0x3f, buffer[15]); + assert.equal(0x3f, buffer[0]); + assert.equal(0xf0, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x02, buffer[7]); + assert.equal(0x02, buffer[8]); + assert.equal(0x00, buffer[9]); + assert.equal(0x00, buffer[10]); + assert.equal(0x00, buffer[11]); + assert.equal(0x00, buffer[12]); + assert.equal(0x00, buffer[13]); + assert.equal(0xf0, buffer[14]); + assert.equal(0x3f, buffer[15]); buffer.writeDoubleBE(-2, 0); buffer.writeDoubleLE(-2, 8); - ASSERT.equal(0xc0, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0x00, buffer[14]); - ASSERT.equal(0xc0, buffer[15]); + assert.equal(0xc0, buffer[0]); + assert.equal(0x00, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x00, buffer[7]); + assert.equal(0x00, buffer[8]); + assert.equal(0x00, buffer[9]); + assert.equal(0x00, buffer[10]); + assert.equal(0x00, buffer[11]); + assert.equal(0x00, buffer[12]); + assert.equal(0x00, buffer[13]); + assert.equal(0x00, buffer[14]); + assert.equal(0xc0, buffer[15]); buffer.writeDoubleBE(1.7976931348623157e+308, 0); buffer.writeDoubleLE(1.7976931348623157e+308, 8); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0xef, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0xff, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xff, buffer[7]); - ASSERT.equal(0xff, buffer[8]); - ASSERT.equal(0xff, buffer[9]); - ASSERT.equal(0xff, buffer[10]); - ASSERT.equal(0xff, buffer[11]); - ASSERT.equal(0xff, buffer[12]); - ASSERT.equal(0xff, buffer[13]); - ASSERT.equal(0xef, buffer[14]); - ASSERT.equal(0x7f, buffer[15]); + assert.equal(0x7f, buffer[0]); + assert.equal(0xef, buffer[1]); + assert.equal(0xff, buffer[2]); + assert.equal(0xff, buffer[3]); + assert.equal(0xff, buffer[4]); + assert.equal(0xff, buffer[5]); + assert.equal(0xff, buffer[6]); + assert.equal(0xff, buffer[7]); + assert.equal(0xff, buffer[8]); + assert.equal(0xff, buffer[9]); + assert.equal(0xff, buffer[10]); + assert.equal(0xff, buffer[11]); + assert.equal(0xff, buffer[12]); + assert.equal(0xff, buffer[13]); + assert.equal(0xef, buffer[14]); + assert.equal(0x7f, buffer[15]); buffer.writeDoubleBE(0 * -1, 0); buffer.writeDoubleLE(0 * -1, 8); - ASSERT.equal(0x80, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0x00, buffer[14]); - ASSERT.equal(0x80, buffer[15]); + assert.equal(0x80, buffer[0]); + assert.equal(0x00, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x00, buffer[7]); + assert.equal(0x00, buffer[8]); + assert.equal(0x00, buffer[9]); + assert.equal(0x00, buffer[10]); + assert.equal(0x00, buffer[11]); + assert.equal(0x00, buffer[12]); + assert.equal(0x00, buffer[13]); + assert.equal(0x00, buffer[14]); + assert.equal(0x80, buffer[15]); buffer.writeDoubleBE(Infinity, 0); buffer.writeDoubleLE(Infinity, 8); - ASSERT.equal(0x7F, buffer[0]); - ASSERT.equal(0xF0, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0xF0, buffer[14]); - ASSERT.equal(0x7F, buffer[15]); - ASSERT.equal(Infinity, buffer.readDoubleBE(0)); - ASSERT.equal(Infinity, buffer.readDoubleLE(8)); + assert.equal(0x7F, buffer[0]); + assert.equal(0xF0, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x00, buffer[7]); + assert.equal(0x00, buffer[8]); + assert.equal(0x00, buffer[9]); + assert.equal(0x00, buffer[10]); + assert.equal(0x00, buffer[11]); + assert.equal(0x00, buffer[12]); + assert.equal(0x00, buffer[13]); + assert.equal(0xF0, buffer[14]); + assert.equal(0x7F, buffer[15]); + assert.equal(Infinity, buffer.readDoubleBE(0)); + assert.equal(Infinity, buffer.readDoubleLE(8)); buffer.writeDoubleBE(-Infinity, 0); buffer.writeDoubleLE(-Infinity, 8); - ASSERT.equal(0xFF, buffer[0]); - ASSERT.equal(0xF0, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0xF0, buffer[14]); - ASSERT.equal(0xFF, buffer[15]); - ASSERT.equal(-Infinity, buffer.readDoubleBE(0)); - ASSERT.equal(-Infinity, buffer.readDoubleLE(8)); + assert.equal(0xFF, buffer[0]); + assert.equal(0xF0, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x00, buffer[7]); + assert.equal(0x00, buffer[8]); + assert.equal(0x00, buffer[9]); + assert.equal(0x00, buffer[10]); + assert.equal(0x00, buffer[11]); + assert.equal(0x00, buffer[12]); + assert.equal(0x00, buffer[13]); + assert.equal(0xF0, buffer[14]); + assert.equal(0xFF, buffer[15]); + assert.equal(-Infinity, buffer.readDoubleBE(0)); + assert.equal(-Infinity, buffer.readDoubleLE(8)); buffer.writeDoubleBE(NaN, 0); buffer.writeDoubleLE(NaN, 8); // Darwin ia32 does the other kind of NaN. // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]); + assert(0x7F === buffer[0] || 0xFF === buffer[0]); // mips processors use a slightly different NaN - ASSERT(0xF8 === buffer[1] || 0xF7 === buffer[1]); - ASSERT(0x00 === buffer[2] || 0xFF === buffer[2]); - ASSERT(0x00 === buffer[3] || 0xFF === buffer[3]); - ASSERT(0x00 === buffer[4] || 0xFF === buffer[4]); - ASSERT(0x00 === buffer[5] || 0xFF === buffer[5]); - ASSERT(0x00 === buffer[6] || 0xFF === buffer[6]); - ASSERT(0x00 === buffer[7] || 0xFF === buffer[7]); - ASSERT(0x00 === buffer[8] || 0xFF === buffer[8]); - ASSERT(0x00 === buffer[9] || 0xFF === buffer[9]); - ASSERT(0x00 === buffer[10] || 0xFF === buffer[10]); - ASSERT(0x00 === buffer[11] || 0xFF === buffer[11]); - ASSERT(0x00 === buffer[12] || 0xFF === buffer[12]); - ASSERT(0x00 === buffer[13] || 0xFF === buffer[13]); - ASSERT(0xF8 === buffer[14] || 0xF7 === buffer[14]); + assert(0xF8 === buffer[1] || 0xF7 === buffer[1]); + assert(0x00 === buffer[2] || 0xFF === buffer[2]); + assert(0x00 === buffer[3] || 0xFF === buffer[3]); + assert(0x00 === buffer[4] || 0xFF === buffer[4]); + assert(0x00 === buffer[5] || 0xFF === buffer[5]); + assert(0x00 === buffer[6] || 0xFF === buffer[6]); + assert(0x00 === buffer[7] || 0xFF === buffer[7]); + assert(0x00 === buffer[8] || 0xFF === buffer[8]); + assert(0x00 === buffer[9] || 0xFF === buffer[9]); + assert(0x00 === buffer[10] || 0xFF === buffer[10]); + assert(0x00 === buffer[11] || 0xFF === buffer[11]); + assert(0x00 === buffer[12] || 0xFF === buffer[12]); + assert(0x00 === buffer[13] || 0xFF === buffer[13]); + assert(0xF8 === buffer[14] || 0xF7 === buffer[14]); // Darwin ia32 does the other kind of NaN. // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[15] || 0xFF === buffer[15]); - ASSERT.ok(isNaN(buffer.readDoubleBE(0))); - ASSERT.ok(isNaN(buffer.readDoubleLE(8))); + assert(0x7F === buffer[15] || 0xFF === buffer[15]); + assert.ok(isNaN(buffer.readDoubleBE(0))); + assert.ok(isNaN(buffer.readDoubleLE(8))); } diff --git a/test/parallel/test-writefloat.js b/test/parallel/test-writefloat.js index 0cb748d603d0ff..2f76dd57c7b077 100644 --- a/test/parallel/test-writefloat.js +++ b/test/parallel/test-writefloat.js @@ -3,111 +3,111 @@ * Tests to verify we're writing floats correctly */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); function test(clazz) { var buffer = new clazz(8); buffer.writeFloatBE(1, 0); buffer.writeFloatLE(1, 4); - ASSERT.equal(0x3f, buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x80, buffer[6]); - ASSERT.equal(0x3f, buffer[7]); + assert.equal(0x3f, buffer[0]); + assert.equal(0x80, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x80, buffer[6]); + assert.equal(0x3f, buffer[7]); buffer.writeFloatBE(1 / 3, 0); buffer.writeFloatLE(1 / 3, 4); - ASSERT.equal(0x3e, buffer[0]); - ASSERT.equal(0xaa, buffer[1]); - ASSERT.equal(0xaa, buffer[2]); - ASSERT.equal(0xab, buffer[3]); - ASSERT.equal(0xab, buffer[4]); - ASSERT.equal(0xaa, buffer[5]); - ASSERT.equal(0xaa, buffer[6]); - ASSERT.equal(0x3e, buffer[7]); + assert.equal(0x3e, buffer[0]); + assert.equal(0xaa, buffer[1]); + assert.equal(0xaa, buffer[2]); + assert.equal(0xab, buffer[3]); + assert.equal(0xab, buffer[4]); + assert.equal(0xaa, buffer[5]); + assert.equal(0xaa, buffer[6]); + assert.equal(0x3e, buffer[7]); buffer.writeFloatBE(3.4028234663852886e+38, 0); buffer.writeFloatLE(3.4028234663852886e+38, 4); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0x7f, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0xff, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0x7f, buffer[6]); - ASSERT.equal(0x7f, buffer[7]); + assert.equal(0x7f, buffer[0]); + assert.equal(0x7f, buffer[1]); + assert.equal(0xff, buffer[2]); + assert.equal(0xff, buffer[3]); + assert.equal(0xff, buffer[4]); + assert.equal(0xff, buffer[5]); + assert.equal(0x7f, buffer[6]); + assert.equal(0x7f, buffer[7]); buffer.writeFloatLE(1.1754943508222875e-38, 0); buffer.writeFloatBE(1.1754943508222875e-38, 4); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x80, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x80, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); + assert.equal(0x00, buffer[0]); + assert.equal(0x00, buffer[1]); + assert.equal(0x80, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x80, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x00, buffer[7]); buffer.writeFloatBE(0 * -1, 0); buffer.writeFloatLE(0 * -1, 4); - ASSERT.equal(0x80, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x80, buffer[7]); + assert.equal(0x80, buffer[0]); + assert.equal(0x00, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x80, buffer[7]); buffer.writeFloatBE(Infinity, 0); buffer.writeFloatLE(Infinity, 4); - ASSERT.equal(0x7F, buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x80, buffer[6]); - ASSERT.equal(0x7F, buffer[7]); - ASSERT.equal(Infinity, buffer.readFloatBE(0)); - ASSERT.equal(Infinity, buffer.readFloatLE(4)); + assert.equal(0x7F, buffer[0]); + assert.equal(0x80, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x80, buffer[6]); + assert.equal(0x7F, buffer[7]); + assert.equal(Infinity, buffer.readFloatBE(0)); + assert.equal(Infinity, buffer.readFloatLE(4)); buffer.writeFloatBE(-Infinity, 0); buffer.writeFloatLE(-Infinity, 4); // Darwin ia32 does the other kind of NaN. // Compiler bug. No one really cares. - ASSERT(0xFF === buffer[0] || 0x7F === buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x80, buffer[6]); - ASSERT.equal(0xFF, buffer[7]); - ASSERT.equal(-Infinity, buffer.readFloatBE(0)); - ASSERT.equal(-Infinity, buffer.readFloatLE(4)); + assert(0xFF === buffer[0] || 0x7F === buffer[0]); + assert.equal(0x80, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x80, buffer[6]); + assert.equal(0xFF, buffer[7]); + assert.equal(-Infinity, buffer.readFloatBE(0)); + assert.equal(-Infinity, buffer.readFloatLE(4)); buffer.writeFloatBE(NaN, 0); buffer.writeFloatLE(NaN, 4); // Darwin ia32 does the other kind of NaN. // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]); + assert(0x7F === buffer[0] || 0xFF === buffer[0]); // mips processors use a slightly different NaN - ASSERT(0xC0 === buffer[1] || 0xBF === buffer[1]); - ASSERT(0x00 === buffer[2] || 0xFF === buffer[2]); - ASSERT(0x00 === buffer[3] || 0xFF === buffer[3]); - ASSERT(0x00 === buffer[4] || 0xFF === buffer[4]); - ASSERT(0x00 === buffer[5] || 0xFF === buffer[5]); - ASSERT(0xC0 === buffer[6] || 0xBF === buffer[6]); + assert(0xC0 === buffer[1] || 0xBF === buffer[1]); + assert(0x00 === buffer[2] || 0xFF === buffer[2]); + assert(0x00 === buffer[3] || 0xFF === buffer[3]); + assert(0x00 === buffer[4] || 0xFF === buffer[4]); + assert(0x00 === buffer[5] || 0xFF === buffer[5]); + assert(0xC0 === buffer[6] || 0xBF === buffer[6]); // Darwin ia32 does the other kind of NaN. // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[7] || 0xFF === buffer[7]); - ASSERT.ok(isNaN(buffer.readFloatBE(0))); - ASSERT.ok(isNaN(buffer.readFloatLE(4))); + assert(0x7F === buffer[7] || 0xFF === buffer[7]); + assert.ok(isNaN(buffer.readFloatBE(0))); + assert.ok(isNaN(buffer.readFloatLE(4))); } diff --git a/test/parallel/test-writeint.js b/test/parallel/test-writeint.js index d05a90d48b5ac6..43784fb390a1f9 100644 --- a/test/parallel/test-writeint.js +++ b/test/parallel/test-writeint.js @@ -3,7 +3,7 @@ * Tests to verify we're writing signed integers correctly */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); function test8(clazz) { var buffer = new clazz(2); @@ -11,14 +11,14 @@ function test8(clazz) { buffer.writeInt8(0x23, 0); buffer.writeInt8(-5, 1); - ASSERT.equal(0x23, buffer[0]); - ASSERT.equal(0xfb, buffer[1]); + assert.equal(0x23, buffer[0]); + assert.equal(0xfb, buffer[1]); /* Make sure we handle truncation correctly */ - ASSERT.throws(function() { + assert.throws(function() { buffer.writeInt8(0xabc, 0); }); - ASSERT.throws(function() { + assert.throws(function() { buffer.writeInt8(0xabc, 0); }); @@ -26,12 +26,12 @@ function test8(clazz) { buffer.writeInt8(0x7f, 0); buffer.writeInt8(-0x80, 1); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.throws(function() { + assert.equal(0x7f, buffer[0]); + assert.equal(0x80, buffer[1]); + assert.throws(function() { buffer.writeInt8(0x7f + 1, 0); }); - ASSERT.throws(function() { + assert.throws(function() { buffer.writeInt8(-0x80 - 1, 0); }); } @@ -42,49 +42,49 @@ function test16(clazz) { buffer.writeInt16BE(0x0023, 0); buffer.writeInt16LE(0x0023, 2); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x23, buffer[1]); - ASSERT.equal(0x23, buffer[2]); - ASSERT.equal(0x00, buffer[3]); + assert.equal(0x00, buffer[0]); + assert.equal(0x23, buffer[1]); + assert.equal(0x23, buffer[2]); + assert.equal(0x00, buffer[3]); buffer.writeInt16BE(-5, 0); buffer.writeInt16LE(-5, 2); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0xfb, buffer[1]); - ASSERT.equal(0xfb, buffer[2]); - ASSERT.equal(0xff, buffer[3]); + assert.equal(0xff, buffer[0]); + assert.equal(0xfb, buffer[1]); + assert.equal(0xfb, buffer[2]); + assert.equal(0xff, buffer[3]); buffer.writeInt16BE(-1679, 1); buffer.writeInt16LE(-1679, 3); - ASSERT.equal(0xf9, buffer[1]); - ASSERT.equal(0x71, buffer[2]); - ASSERT.equal(0x71, buffer[3]); - ASSERT.equal(0xf9, buffer[4]); + assert.equal(0xf9, buffer[1]); + assert.equal(0x71, buffer[2]); + assert.equal(0x71, buffer[3]); + assert.equal(0xf9, buffer[4]); /* Make sure we handle min/max correctly */ buffer.writeInt16BE(0x7fff, 0); buffer.writeInt16BE(-0x8000, 2); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0x80, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.throws(function() { + assert.equal(0x7f, buffer[0]); + assert.equal(0xff, buffer[1]); + assert.equal(0x80, buffer[2]); + assert.equal(0x00, buffer[3]); + assert.throws(function() { buffer.writeInt16BE(0x7fff + 1, 0); }); - ASSERT.throws(function() { + assert.throws(function() { buffer.writeInt16BE(-0x8000 - 1, 0); }); buffer.writeInt16LE(0x7fff, 0); buffer.writeInt16LE(-0x8000, 2); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0x7f, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x80, buffer[3]); - ASSERT.throws(function() { + assert.equal(0xff, buffer[0]); + assert.equal(0x7f, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x80, buffer[3]); + assert.throws(function() { buffer.writeInt16LE(0x7fff + 1, 0); }); - ASSERT.throws(function() { + assert.throws(function() { buffer.writeInt16LE(-0x8000 - 1, 0); }); } @@ -95,69 +95,69 @@ function test32(clazz) { buffer.writeInt32BE(0x23, 0); buffer.writeInt32LE(0x23, 4); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x23, buffer[3]); - ASSERT.equal(0x23, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); + assert.equal(0x00, buffer[0]); + assert.equal(0x00, buffer[1]); + assert.equal(0x00, buffer[2]); + assert.equal(0x23, buffer[3]); + assert.equal(0x23, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x00, buffer[7]); buffer.writeInt32BE(-5, 0); buffer.writeInt32LE(-5, 4); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xfb, buffer[3]); - ASSERT.equal(0xfb, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xff, buffer[7]); + assert.equal(0xff, buffer[0]); + assert.equal(0xff, buffer[1]); + assert.equal(0xff, buffer[2]); + assert.equal(0xfb, buffer[3]); + assert.equal(0xfb, buffer[4]); + assert.equal(0xff, buffer[5]); + assert.equal(0xff, buffer[6]); + assert.equal(0xff, buffer[7]); buffer.writeInt32BE(-805306713, 0); buffer.writeInt32LE(-805306713, 4); - ASSERT.equal(0xcf, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xfe, buffer[2]); - ASSERT.equal(0xa7, buffer[3]); - ASSERT.equal(0xa7, buffer[4]); - ASSERT.equal(0xfe, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xcf, buffer[7]); + assert.equal(0xcf, buffer[0]); + assert.equal(0xff, buffer[1]); + assert.equal(0xfe, buffer[2]); + assert.equal(0xa7, buffer[3]); + assert.equal(0xa7, buffer[4]); + assert.equal(0xfe, buffer[5]); + assert.equal(0xff, buffer[6]); + assert.equal(0xcf, buffer[7]); /* Make sure we handle min/max correctly */ buffer.writeInt32BE(0x7fffffff, 0); buffer.writeInt32BE(-0x80000000, 4); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0x80, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.throws(function() { + assert.equal(0x7f, buffer[0]); + assert.equal(0xff, buffer[1]); + assert.equal(0xff, buffer[2]); + assert.equal(0xff, buffer[3]); + assert.equal(0x80, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x00, buffer[7]); + assert.throws(function() { buffer.writeInt32BE(0x7fffffff + 1, 0); }); - ASSERT.throws(function() { + assert.throws(function() { buffer.writeInt32BE(-0x80000000 - 1, 0); }); buffer.writeInt32LE(0x7fffffff, 0); buffer.writeInt32LE(-0x80000000, 4); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0x7f, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x80, buffer[7]); - ASSERT.throws(function() { + assert.equal(0xff, buffer[0]); + assert.equal(0xff, buffer[1]); + assert.equal(0xff, buffer[2]); + assert.equal(0x7f, buffer[3]); + assert.equal(0x00, buffer[4]); + assert.equal(0x00, buffer[5]); + assert.equal(0x00, buffer[6]); + assert.equal(0x80, buffer[7]); + assert.throws(function() { buffer.writeInt32LE(0x7fffffff + 1, 0); }); - ASSERT.throws(function() { + assert.throws(function() { buffer.writeInt32LE(-0x80000000 - 1, 0); }); } diff --git a/test/parallel/test-writeuint.js b/test/parallel/test-writeuint.js index 843cc423072225..88446a3b499be4 100644 --- a/test/parallel/test-writeuint.js +++ b/test/parallel/test-writeuint.js @@ -3,7 +3,7 @@ * A battery of tests to help us read a series of uints */ require('../common'); -var ASSERT = require('assert'); +const assert = require('assert'); /* * We need to check the following things: @@ -19,25 +19,25 @@ function test8(clazz) { data.writeUInt8(23, 1); data.writeUInt8(23, 2); data.writeUInt8(23, 3); - ASSERT.equal(23, data[0]); - ASSERT.equal(23, data[1]); - ASSERT.equal(23, data[2]); - ASSERT.equal(23, data[3]); + assert.equal(23, data[0]); + assert.equal(23, data[1]); + assert.equal(23, data[2]); + assert.equal(23, data[3]); data.writeUInt8(23, 0); data.writeUInt8(23, 1); data.writeUInt8(23, 2); data.writeUInt8(23, 3); - ASSERT.equal(23, data[0]); - ASSERT.equal(23, data[1]); - ASSERT.equal(23, data[2]); - ASSERT.equal(23, data[3]); + assert.equal(23, data[0]); + assert.equal(23, data[1]); + assert.equal(23, data[2]); + assert.equal(23, data[3]); data.writeUInt8(255, 0); - ASSERT.equal(255, data[0]); + assert.equal(255, data[0]); data.writeUInt8(255, 0); - ASSERT.equal(255, data[0]); + assert.equal(255, data[0]); } @@ -46,37 +46,37 @@ function test16(clazz) { var data = new clazz(4); data.writeUInt16BE(value, 0); - ASSERT.equal(0x23, data[0]); - ASSERT.equal(0x43, data[1]); + assert.equal(0x23, data[0]); + assert.equal(0x43, data[1]); data.writeUInt16BE(value, 1); - ASSERT.equal(0x23, data[1]); - ASSERT.equal(0x43, data[2]); + assert.equal(0x23, data[1]); + assert.equal(0x43, data[2]); data.writeUInt16BE(value, 2); - ASSERT.equal(0x23, data[2]); - ASSERT.equal(0x43, data[3]); + assert.equal(0x23, data[2]); + assert.equal(0x43, data[3]); data.writeUInt16LE(value, 0); - ASSERT.equal(0x23, data[1]); - ASSERT.equal(0x43, data[0]); + assert.equal(0x23, data[1]); + assert.equal(0x43, data[0]); data.writeUInt16LE(value, 1); - ASSERT.equal(0x23, data[2]); - ASSERT.equal(0x43, data[1]); + assert.equal(0x23, data[2]); + assert.equal(0x43, data[1]); data.writeUInt16LE(value, 2); - ASSERT.equal(0x23, data[3]); - ASSERT.equal(0x43, data[2]); + assert.equal(0x23, data[3]); + assert.equal(0x43, data[2]); value = 0xff80; data.writeUInt16LE(value, 0); - ASSERT.equal(0xff, data[1]); - ASSERT.equal(0x80, data[0]); + assert.equal(0xff, data[1]); + assert.equal(0x80, data[0]); data.writeUInt16BE(value, 0); - ASSERT.equal(0xff, data[0]); - ASSERT.equal(0x80, data[1]); + assert.equal(0xff, data[0]); + assert.equal(0x80, data[1]); } @@ -85,40 +85,40 @@ function test32(clazz) { var value = 0xe7f90a6d; data.writeUInt32BE(value, 0); - ASSERT.equal(0xe7, data[0]); - ASSERT.equal(0xf9, data[1]); - ASSERT.equal(0x0a, data[2]); - ASSERT.equal(0x6d, data[3]); + assert.equal(0xe7, data[0]); + assert.equal(0xf9, data[1]); + assert.equal(0x0a, data[2]); + assert.equal(0x6d, data[3]); data.writeUInt32BE(value, 1); - ASSERT.equal(0xe7, data[1]); - ASSERT.equal(0xf9, data[2]); - ASSERT.equal(0x0a, data[3]); - ASSERT.equal(0x6d, data[4]); + assert.equal(0xe7, data[1]); + assert.equal(0xf9, data[2]); + assert.equal(0x0a, data[3]); + assert.equal(0x6d, data[4]); data.writeUInt32BE(value, 2); - ASSERT.equal(0xe7, data[2]); - ASSERT.equal(0xf9, data[3]); - ASSERT.equal(0x0a, data[4]); - ASSERT.equal(0x6d, data[5]); + assert.equal(0xe7, data[2]); + assert.equal(0xf9, data[3]); + assert.equal(0x0a, data[4]); + assert.equal(0x6d, data[5]); data.writeUInt32LE(value, 0); - ASSERT.equal(0xe7, data[3]); - ASSERT.equal(0xf9, data[2]); - ASSERT.equal(0x0a, data[1]); - ASSERT.equal(0x6d, data[0]); + assert.equal(0xe7, data[3]); + assert.equal(0xf9, data[2]); + assert.equal(0x0a, data[1]); + assert.equal(0x6d, data[0]); data.writeUInt32LE(value, 1); - ASSERT.equal(0xe7, data[4]); - ASSERT.equal(0xf9, data[3]); - ASSERT.equal(0x0a, data[2]); - ASSERT.equal(0x6d, data[1]); + assert.equal(0xe7, data[4]); + assert.equal(0xf9, data[3]); + assert.equal(0x0a, data[2]); + assert.equal(0x6d, data[1]); data.writeUInt32LE(value, 2); - ASSERT.equal(0xe7, data[5]); - ASSERT.equal(0xf9, data[4]); - ASSERT.equal(0x0a, data[3]); - ASSERT.equal(0x6d, data[2]); + assert.equal(0xe7, data[5]); + assert.equal(0xf9, data[4]); + assert.equal(0x0a, data[3]); + assert.equal(0x6d, data[2]); } @@ -129,10 +129,10 @@ function testUint(clazz) { // Test 0 to 5 bytes. for (var i = 0; i <= 5; i++) { const errmsg = `byteLength: ${i}`; - ASSERT.throws(function() { + assert.throws(function() { data.writeUIntBE(val, 0, i); }, /value is out of bounds/, errmsg); - ASSERT.throws(function() { + assert.throws(function() { data.writeUIntLE(val, 0, i); }, /value is out of bounds/, errmsg); val *= 0x100; From a8ff6b95afc9d184357af10529842eb7028985fc Mon Sep 17 00:00:00 2001 From: William Kapke Date: Thu, 17 Nov 2016 05:49:49 +0000 Subject: [PATCH 062/116] doc: redirect 'Start a Working Group' to TSC repo PR-URL: https://github.com/nodejs/node/pull/9655 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Gibson Fahnestock --- WORKING_GROUPS.md | 222 +++------------------------------------------- 1 file changed, 10 insertions(+), 212 deletions(-) diff --git a/WORKING_GROUPS.md b/WORKING_GROUPS.md index f013a574610d0f..7b5dfe65a42e89 100644 --- a/WORKING_GROUPS.md +++ b/WORKING_GROUPS.md @@ -19,6 +19,16 @@ 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) @@ -36,10 +46,6 @@ becomes the responsibility of the CTC. * [Documentation](#documentation) * [Testing](#testing) -#### Process: - -* [Starting a Working Group](#starting-a-wg) -* [Bootstrap Governance](#bootstrap-governance) ### [Website](https://github.com/nodejs/website) @@ -289,211 +295,3 @@ Responsibilities include: * Working with the Build Working Group to improve continuous integration. * Improving tooling for testing. -## Joining a WG - -To find out how to join a working group, consult the GOVERNANCE.md in -the working group's repository, or simply open an issue there. - -## Starting a WG - -A Working Group is established by first defining a charter that can be -ratified by the TC. A charter is a *statement of purpose*, a -*list of responsibilities* and a *list of initial membership*. - -A working group needs 3 initial members. These should be individuals -already undertaking the work described in the charter. - -The list of responsibilities should be specific. Once established, these -responsibilities are no longer governed by the TC and therefore should -not be broad or subjective. The only recourse the TC has over the working -group is to revoke the entire charter and take on the work previously -done by the working group themselves. - -If the responsibilities described in the charter are currently -undertaken by another WG then the charter will additionally have to be -ratified by that WG. - -You can submit the WG charter for ratification by sending -a Pull Request to this document, which adds it to the -list of current Working Groups. Once ratified the list of -members should be maintained in the Working Group's -README. - -## Bootstrap Governance - -Once the TC ratifies a charter the WG inherits the following -documentation for governance, contribution, conduct and an MIT -LICENSE. The WG is free to change these documents through their own -governance process, hence the term "bootstrap." - -### *[insert WG name]* Working Group - -The Node.js *[insert WG name]* is jointly governed by a Working Group (WG) -that is responsible for high-level guidance of the project. - -The WG has final authority over this project including: - -* Technical direction -* Project governance and process (including this policy) -* Contribution policy -* GitHub repository hosting -* Conduct guidelines -* Maintaining the list of additional Collaborators - -For the current list of WG members, see the project -[README.md](./README.md#current-project-team-members). - -### Collaborators - -The *[insert WG name]* GitHub repository is -maintained by the WG and additional Collaborators who are added by the -WG on an ongoing basis. - -Individuals making significant and valuable contributions are made -Collaborators and given commit-access to the project. These -individuals are identified by the WG and their addition as -Collaborators is discussed during the weekly WG meeting. - -_Note:_ If you make a significant contribution and are not considered -for commit-access log an issue or contact a WG member directly and it -will be brought up in the next WG meeting. - -Modifications of the contents of the *[insert WG repo]* repository are made on -a collaborative basis. Anybody with a GitHub account may propose a -modification via pull request and it will be considered by the project -Collaborators. All pull requests must be reviewed and accepted by a -Collaborator with sufficient expertise who is able to take full -responsibility for the change. In the case of pull requests proposed -by an existing Collaborator, an additional Collaborator is required -for sign-off. Consensus should be sought if additional Collaborators -participate and there is disagreement around a particular -modification. See _Consensus Seeking Process_ below for further detail -on the consensus model used for governance. - -Collaborators may opt to elevate significant or controversial -modifications, or modifications that have not found consensus to the -WG for discussion by assigning the ***WG-agenda*** tag to a pull -request or issue. The WG should serve as the final arbiter where -required. - -For the current list of Collaborators, see the project -[README.md](./README.md#current-project-team-members). - -### WG Membership - -WG seats are not time-limited. There is no fixed size of the WG. -However, the expected target is between 6 and 12, to ensure adequate -coverage of important areas of expertise, balanced with the ability to -make decisions efficiently. - -There is no specific set of requirements or qualifications for WG -membership beyond these rules. - -The WG may add additional members to the WG by unanimous consensus. - -A WG member may be removed from the WG by voluntary resignation, or by -unanimous consensus of all other WG members. - -Changes to WG membership should be posted in the agenda, and may be -suggested as any other agenda item (see "WG Meetings" below). - -If an addition or removal is proposed during a meeting, and the full -WG is not in attendance to participate, then the addition or removal -is added to the agenda for the subsequent meeting. This is to ensure -that all members are given the opportunity to participate in all -membership decisions. If a WG member is unable to attend a meeting -where a planned membership decision is being made, then their consent -is assumed. - -No more than 1/3 of the WG members may be affiliated with the same -employer. If removal or resignation of a WG member, or a change of -employment by a WG member, creates a situation where more than 1/3 of -the WG membership shares an employer, then the situation must be -immediately remedied by the resignation or removal of one or more WG -members affiliated with the over-represented employer(s). - -### WG Meetings - -The WG meets weekly on a Google Hangout On Air. A designated moderator -approved by the WG runs the meeting. Each meeting should be -published to YouTube. - -Items are added to the WG agenda that are considered contentious or -are modifications of governance, contribution policy, WG membership, -or release process. - -The intention of the agenda is not to approve or review all patches; -that should happen continuously on GitHub and be handled by the larger -group of Collaborators. - -Any community member or contributor can ask that something be added to -the next meeting's agenda by logging a GitHub Issue. Any Collaborator, -WG member or the moderator can add the item to the agenda by adding -the ***WG-agenda*** tag to the issue. - -Prior to each WG meeting the moderator will share the Agenda with -members of the WG. WG members can add any items they like to the -agenda at the beginning of each meeting. The moderator and the WG -cannot veto or remove items. - -The WG may invite persons or representatives from certain projects to -participate in a non-voting capacity. - -The moderator is responsible for summarizing the discussion of each -agenda item and sends it as a pull request after the meeting. - -### Consensus Seeking Process - -The WG follows a -[Consensus Seeking](http://en.wikipedia.org/wiki/Consensus-seeking_decision-making) -decision-making model. - -When an agenda item has appeared to reach a consensus the moderator -will ask "Does anyone object?" as a final call for dissent from the -consensus. - -If an agenda item cannot reach a consensus a WG member can call for -either a closing vote or a vote to table the issue to the next -meeting. The call for a vote must be seconded by a majority of the WG -or else the discussion will continue. Simple majority wins. - -Note that changes to WG membership require unanimous consensus. See -"WG Membership" above. - - -## Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -* (a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -* (b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -* (c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -* (d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. - -### Moderation Policy - -The [Node.js Moderation Policy] applies to this WG. - -### Code of Conduct - -The [Node.js Code of Conduct][] applies to this WG. - -[Node.js Code of Conduct]: https://github.com/nodejs/node/blob/master/CODE_OF_CONDUCT.md -[Node.js Moderation Policy]: https://github.com/nodejs/TSC/blob/master/Moderation-Policy.md From d32d64b73596cced32332edf9f4d2c414dc15c9d Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Tue, 30 Aug 2016 13:16:27 +0200 Subject: [PATCH 063/116] crypto: Use reference count to manage cert_store Setting reference count at the time of setting cert_store instead of trying to manage it by modifying internal states in destructor. PR-URL: https://github.com/nodejs/node/pull/9409 Reviewed-By: Fedor Indutny Reviewed-By: Shigeki Ohtsu --- src/node_crypto.cc | 2 ++ src/node_crypto.h | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 42932544aa02c8..1b6bd5e0abc8c9 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -785,6 +785,8 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo& args) { } sc->ca_store_ = root_cert_store; + // Increment reference count so global store is not deleted along with CTX. + CRYPTO_add(&root_cert_store->references, 1, CRYPTO_LOCK_X509_STORE); SSL_CTX_set_cert_store(sc->ctx_, sc->ca_store_); } diff --git a/src/node_crypto.h b/src/node_crypto.h index 1dc07e44cb6839..1f9271d0e6e13d 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -140,13 +140,6 @@ class SecureContext : public BaseObject { void FreeCTXMem() { if (ctx_) { env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize); - if (ctx_->cert_store == root_cert_store) { - // SSL_CTX_free() will attempt to free the cert_store as well. - // Since we want our root_cert_store to stay around forever - // we just clear the field. Hopefully OpenSSL will not modify this - // struct in future versions. - ctx_->cert_store = nullptr; - } SSL_CTX_free(ctx_); if (cert_ != nullptr) X509_free(cert_); From 5c8881decefb03ce649e13f9e021df8aac88da61 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Fri, 2 Dec 2016 17:36:02 -0500 Subject: [PATCH 064/116] debugger: call `this.resume()` after `this.run()` When the debugger has started we need to call `this.resume` otherwise, the prompt won't appear. Fixes: https://github.com/nodejs/node/issues/9854 PR-URL: https://github.com/nodejs/node/pull/10099 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: Rich Trott --- lib/_debugger.js | 2 +- test/parallel/test-debug-prompt.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-debug-prompt.js diff --git a/lib/_debugger.js b/lib/_debugger.js index 2ccbc5e6607379..32820803071c1c 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -835,7 +835,7 @@ function Interface(stdin, stdout, args) { // Run script automatically this.pause(); - setImmediate(() => { this.run(); }); + setImmediate(() => { this.run(() => this.resume()); }); } diff --git a/test/parallel/test-debug-prompt.js b/test/parallel/test-debug-prompt.js new file mode 100644 index 00000000000000..fdc3b4c27f4d45 --- /dev/null +++ b/test/parallel/test-debug-prompt.js @@ -0,0 +1,13 @@ +'use strict'; + +const assert = require('assert'); +const common = require('../common'); +const spawn = require('child_process').spawn; + +const proc = spawn(process.execPath, ['debug', 'foo']); +proc.stdout.setEncoding('utf8'); + +proc.stdout.once('data', common.mustCall((data) => { + assert.strictEqual(data, 'debug> '); + proc.kill(); +})); From 8f4c29bd0c4d6b92534ca38fbb27ee58b1273efb Mon Sep 17 00:00:00 2001 From: Gregory Date: Thu, 1 Dec 2016 01:52:23 -0500 Subject: [PATCH 065/116] test: stream readableState readingMore state PR-URL: https://github.com/nodejs/node/pull/9868 Refs: https://github.com/nodejs/node/issues/8685 Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig Reviewed-By: Italo A. Casas --- ...est-stream-readable-reading-readingMore.js | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/parallel/test-stream-readable-reading-readingMore.js diff --git a/test/parallel/test-stream-readable-reading-readingMore.js b/test/parallel/test-stream-readable-reading-readingMore.js new file mode 100644 index 00000000000000..bee3a1c82a8678 --- /dev/null +++ b/test/parallel/test-stream-readable-reading-readingMore.js @@ -0,0 +1,65 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const Readable = require('stream').Readable; + +const readable = new Readable({ + read(size) {} +}); + +const state = readable._readableState; + +// Starting off with false initially. +assert.strictEqual(state.reading, false); +assert.strictEqual(state.readingMore, false); + +readable.on('data', common.mustCall((data) => { + // while in a flowing state, should try to read more. + if (state.flowing) + assert.strictEqual(state.readingMore, true); + + // reading as long as we've not ended + assert.strictEqual(state.reading, !state.ended); +}, 2)); + +function onStreamEnd() { + // End of stream; state.reading is false + // And so should be readingMore. + assert.strictEqual(state.readingMore, false); + assert.strictEqual(state.reading, false); +} + +readable.on('readable', common.mustCall(() => { + // 'readable' always gets called before 'end' + // since 'end' hasn't been emitted, more data could be incoming + assert.strictEqual(state.readingMore, true); + + // if the stream has ended, we shouldn't be reading + assert.strictEqual(state.ended, !state.reading); + + if (readable.read() === null) // reached end of stream + process.nextTick(common.mustCall(onStreamEnd, 1)); +}, 2)); + +readable.on('end', common.mustCall(onStreamEnd)); + +readable.push('pushed'); + +// stop emitting 'data' events +readable.pause(); + +// read() should only be called while operating in paused mode +readable.read(6); + +// reading +assert.strictEqual(state.reading, true); +assert.strictEqual(state.readingMore, true); + +// resume emitting 'data' events +readable.resume(); + +// add chunk to front +readable.unshift('unshifted'); + +// end +readable.push(null); From 2f7270ad6224f49be30bad4ba35b155db72b1b7e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 6 Dec 2016 18:23:13 +0100 Subject: [PATCH 066/116] test: fail for missing output files Instead of ignoring missing `.out` files for message/pseudo-tty tests, raise an error to indicate that something is not quite right. Ref: https://github.com/nodejs/node/pull/10037 PR-URL: https://github.com/nodejs/node/pull/10150 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Sakthipriyan Vairamani --- test/message/testcfg.py | 3 +-- test/pseudo-tty/testcfg.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/message/testcfg.py b/test/message/testcfg.py index 60e64e29f709a4..f346104b92f372 100644 --- a/test/message/testcfg.py +++ b/test/message/testcfg.py @@ -127,8 +127,7 @@ def ListTests(self, current_path, path, arch, mode): file_path = file_prefix + ".js" output_path = file_prefix + ".out" if not exists(output_path): - print "Could not find %s" % output_path - continue + raise Exception("Could not find %s" % output_path) result.append(MessageTestCase(test, file_path, output_path, arch, mode, self.context, self)) return result diff --git a/test/pseudo-tty/testcfg.py b/test/pseudo-tty/testcfg.py index 96b30253498857..40396db247e279 100644 --- a/test/pseudo-tty/testcfg.py +++ b/test/pseudo-tty/testcfg.py @@ -142,8 +142,7 @@ def ListTests(self, current_path, path, arch, mode): file_path = file_prefix + ".js" output_path = file_prefix + ".out" if not exists(output_path): - print "Could not find %s" % output_path - continue + raise Exception("Could not find %s" % output_path) result.append(TTYTestCase(test, file_path, output_path, arch, mode, self.context, self)) return result From 24100083b475a0a33f533557d7cd20f3ddc3fff3 Mon Sep 17 00:00:00 2001 From: Siddhartha Sahai Date: Sat, 10 Dec 2016 02:05:10 +0530 Subject: [PATCH 067/116] test: refactor test-domain.js apply setTimeout duration, add const, remove unused var PR-URL: https://github.com/nodejs/node/pull/10207 Reviewed-By: Rich Trott Reviewed-By: Santiago Gimeno --- test/parallel/test-domain.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-domain.js b/test/parallel/test-domain.js index 69521108f6e47b..73ab3b96168930 100644 --- a/test/parallel/test-domain.js +++ b/test/parallel/test-domain.js @@ -2,10 +2,10 @@ // Simple tests of most basic domain functionality. require('../common'); -var assert = require('assert'); -var domain = require('domain'); -var events = require('events'); -var fs = require('fs'); +const assert = require('assert'); +const domain = require('domain'); +const events = require('events'); +const fs = require('fs'); var caught = 0; var expectCaught = 0; @@ -137,8 +137,8 @@ d.run(function() { // pretty common error. console.log(stat.isDirectory()); }); - }); - }); + }, 1); + }, 1); }); }); expectCaught++; @@ -148,7 +148,7 @@ expectCaught++; d.run(function() { setTimeout(function() { throw new Error('implicit timer'); - }); + }, 1); }); expectCaught++; @@ -162,7 +162,7 @@ expectCaught++; // get rid of the `if (er) return cb(er)` malarky, by intercepting // the cb functions to the domain, and using the intercepted function // as a callback instead. -function fn(er) { +function fn() { throw new Error('This function should never be called!'); } From ffbd63088791e444ae2ec9a84c80796b9f75fe30 Mon Sep 17 00:00:00 2001 From: Andy Chen Date: Fri, 9 Dec 2016 00:03:13 -0800 Subject: [PATCH 068/116] test: update test-domain-uncaught-exception.js file: test/parallel/test-domain-uncaught-exception.js 1. There are three setTimeout() in the file and they do not specify a duration (the second argument), so I change them to setImmediate() instead. 2. There are four callbacks that take an argument called `err` but that argument is never used, so I removed them. PR-URL: https://github.com/nodejs/node/pull/10193 Reviewed-By: Sam Roberts Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Michael Dawson --- test/parallel/test-domain-uncaught-exception.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-domain-uncaught-exception.js b/test/parallel/test-domain-uncaught-exception.js index 35632dbf537202..58df4ac59a7818 100644 --- a/test/parallel/test-domain-uncaught-exception.js +++ b/test/parallel/test-domain-uncaught-exception.js @@ -25,7 +25,7 @@ function test1() { d.run(function() { setTimeout(function onTimeout() { throw new Error('boom!'); - }); + }, 1); }); } @@ -59,7 +59,7 @@ function test3() { const d3 = domain.create(); const d4 = domain.create(); - d3.on('error', function onErrorInD3Domain(err) { + d3.on('error', function onErrorInD3Domain() { process.send('errorHandledByDomain'); }); @@ -88,7 +88,7 @@ function test4() { const d5 = domain.create(); const d6 = domain.create(); - d5.on('error', function onErrorInD2Domain(err) { + d5.on('error', function onErrorInD2Domain() { process.send('errorHandledByDomain'); }); @@ -96,7 +96,7 @@ function test4() { d6.run(function() { setTimeout(function onTimeout() { throw new Error('boom!'); - }); + }, 1); }); }); } @@ -115,7 +115,7 @@ function test5() { const d7 = domain.create(); const d8 = domain.create(); - d8.on('error', function onErrorInD3Domain(err) { + d8.on('error', function onErrorInD3Domain() { process.send('errorHandledByDomain'); }); @@ -139,7 +139,7 @@ function test6() { const d9 = domain.create(); const d10 = domain.create(); - d10.on('error', function onErrorInD2Domain(err) { + d10.on('error', function onErrorInD2Domain() { process.send('errorHandledByDomain'); }); @@ -147,7 +147,7 @@ function test6() { d10.run(function() { setTimeout(function onTimeout() { throw new Error('boom!'); - }); + }, 1); }); }); } From b6c88d699fd94eeceee312eee16cb654f4c42237 Mon Sep 17 00:00:00 2001 From: weyj4 Date: Thu, 15 Dec 2016 13:26:15 -0500 Subject: [PATCH 069/116] test: clean up domain-no-error-handler test Added duration to setTimeout and removed extraneous callback args, as per Rich Trott's instructions PR-URL: https://github.com/nodejs/node/pull/10291 Reviewed-By: Italo A. Casas Reviewed-By: Rich Trott Reviewed-By: Santiago Gimeno --- .../test-domain-no-error-handler-abort-on-uncaught.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js b/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js index 9fedba4ee6c541..239b04c79eff8f 100644 --- a/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js +++ b/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js @@ -58,7 +58,7 @@ const tests = [ d.run(function() { setTimeout(function() { throw new Error('boom!'); - }); + }, 1); }); }, @@ -87,7 +87,7 @@ const tests = [ d.run(function() { var fs = require('fs'); - fs.exists('/non/existing/file', function onExists(exists) { + fs.exists('/non/existing/file', function onExists() { throw new Error('boom!'); }); }); @@ -104,7 +104,7 @@ const tests = [ d2.run(function() { setTimeout(function() { throw new Error('boom!'); - }); + }, 1); }); }); }, @@ -151,7 +151,7 @@ const tests = [ d.run(function() { d2.run(function() { var fs = require('fs'); - fs.exists('/non/existing/file', function onExists(exists) { + fs.exists('/non/existing/file', function onExists() { throw new Error('boom!'); }); }); From 906092b7d8d18d62f4696db3c16069f0b0ca72b3 Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Thu, 1 Dec 2016 15:22:25 -0800 Subject: [PATCH 070/116] src: fix string format mistake for 32 bit node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=] BIO_printf(bio, "0x%lx", exponent_word); PR-URL: https://github.com/nodejs/node/pull/10082 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis --- src/node_crypto.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 1b6bd5e0abc8c9..0d3053625f38ba 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1457,9 +1457,14 @@ static Local X509ToObject(Environment* env, X509* cert) { String::kNormalString, mem->length)); (void) BIO_reset(bio); - BN_ULONG exponent_word = BN_get_word(rsa->e); - BIO_printf(bio, "0x%lx", exponent_word); - + uint64_t exponent_word = static_cast(BN_get_word(rsa->e)); + uint32_t lo = static_cast(exponent_word); + uint32_t hi = static_cast(exponent_word >> 32); + if (hi == 0) { + BIO_printf(bio, "0x%x", lo); + } else { + BIO_printf(bio, "0x%x%08x", hi, lo); + } BIO_get_mem_ptr(bio, &mem); info->Set(env->exponent_string(), String::NewFromUtf8(env->isolate(), mem->data, From f26213ac8180157ca78b486f545eac043f68ce21 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 13 Dec 2016 22:43:56 +0800 Subject: [PATCH 071/116] stream, test: test _readableState.emittedReadable Part of #8683, increase coverage of the internal state machine of streams. PR-URL: https://github.com/nodejs/node/pull/10249 See: https://github.com/nodejs/node/issues/8683 See: https://github.com/nodejs/node/issues/10230 Reviewed-By: Matteo Collina --- .../test-stream-readable-emittedReadable.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/parallel/test-stream-readable-emittedReadable.js diff --git a/test/parallel/test-stream-readable-emittedReadable.js b/test/parallel/test-stream-readable-emittedReadable.js new file mode 100644 index 00000000000000..65b6b5b15a5895 --- /dev/null +++ b/test/parallel/test-stream-readable-emittedReadable.js @@ -0,0 +1,70 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const Readable = require('stream').Readable; + +const readable = new Readable({ + read: () => {} +}); + +// Initialized to false. +assert.strictEqual(readable._readableState.emittedReadable, false); + +readable.on('readable', common.mustCall(() => { + // emittedReadable should be true when the readable event is emitted + assert.strictEqual(readable._readableState.emittedReadable, true); + readable.read(); + // emittedReadable is reset to false during read() + assert.strictEqual(readable._readableState.emittedReadable, false); +}, 4)); + +// When the first readable listener is just attached, +// emittedReadable should be false +assert.strictEqual(readable._readableState.emittedReadable, false); + +// Each one of these should trigger a readable event. +process.nextTick(common.mustCall(() => { + readable.push('foo'); +})); +process.nextTick(common.mustCall(() => { + readable.push('bar'); +})); +process.nextTick(common.mustCall(() => { + readable.push('quo'); +})); +process.nextTick(common.mustCall(() => { + readable.push(null); +})); + +const noRead = new Readable({ + read: () => {} +}); + +noRead.on('readable', common.mustCall(() => { + // emittedReadable should be true when the readable event is emitted + assert.strictEqual(noRead._readableState.emittedReadable, true); + noRead.read(0); + // emittedReadable is not reset during read(0) + assert.strictEqual(noRead._readableState.emittedReadable, true); +})); + +noRead.push('foo'); +noRead.push(null); + +const flowing = new Readable({ + read: () => {} +}); + +flowing.on('data', common.mustCall(() => { + // When in flowing mode, emittedReadable is always false. + assert.strictEqual(flowing._readableState.emittedReadable, false); + flowing.read(); + assert.strictEqual(flowing._readableState.emittedReadable, false); +}, 3)); + +flowing.push('foooo'); +flowing.push('bar'); +flowing.push('quo'); +process.nextTick(common.mustCall(() => { + flowing.push(null); +})); From 083ff5c7a7b38f22cff4b3ab4c5d277cd93425a6 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 13 Dec 2016 03:37:07 +0800 Subject: [PATCH 072/116] test: stream readable needReadable state PR-URL: https://github.com/nodejs/node/pull/10241 Ref: https://github.com/nodejs/node/issues/8683 Reviewed-By: Matteo Collina Reviewed-By: Italo A. Casas --- .../test-stream-readable-needReadable.js | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 test/parallel/test-stream-readable-needReadable.js diff --git a/test/parallel/test-stream-readable-needReadable.js b/test/parallel/test-stream-readable-needReadable.js new file mode 100644 index 00000000000000..48229edd202333 --- /dev/null +++ b/test/parallel/test-stream-readable-needReadable.js @@ -0,0 +1,96 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const Readable = require('stream').Readable; + +const readable = new Readable({ + read: () => {} +}); + +// Initialized to false. +assert.strictEqual(readable._readableState.needReadable, false); + +readable.on('readable', common.mustCall(() => { + // When the readable event fires, needReadable is reset. + assert.strictEqual(readable._readableState.needReadable, false); + readable.read(); +})); + +// If a readable listener is attached, then a readable event is needed. +assert.strictEqual(readable._readableState.needReadable, true); + +readable.push('foo'); +readable.push(null); + +readable.on('end', common.mustCall(() => { + // No need to emit readable anymore when the stream ends. + assert.strictEqual(readable._readableState.needReadable, false); +})); + +const asyncReadable = new Readable({ + read: () => {} +}); + +asyncReadable.on('readable', common.mustCall(() => { + if (asyncReadable.read() !== null) { + // After each read(), the buffer is empty. + // If the stream doesn't end now, + // then we need to notify the reader on future changes. + assert.strictEqual(asyncReadable._readableState.needReadable, true); + } +}, 3)); + +process.nextTick(common.mustCall(() => { + asyncReadable.push('foooo'); +})); +process.nextTick(common.mustCall(() => { + asyncReadable.push('bar'); +})); +process.nextTick(common.mustCall(() => { + asyncReadable.push(null); +})); + +const flowing = new Readable({ + read: () => {} +}); + +// Notice this must be above the on('data') call. +flowing.push('foooo'); +flowing.push('bar'); +flowing.push('quo'); +process.nextTick(common.mustCall(() => { + flowing.push(null); +})); + +// When the buffer already has enough data, and the stream is +// in flowing mode, there is no need for the readable event. +flowing.on('data', common.mustCall(function(data) { + assert.strictEqual(flowing._readableState.needReadable, false); +}, 3)); + +const slowProducer = new Readable({ + read: () => {} +}); + +slowProducer.on('readable', common.mustCall(() => { + if (slowProducer.read(8) === null) { + // The buffer doesn't have enough data, and the stream is not ened, + // we need to notify the reader when data arrives. + assert.strictEqual(slowProducer._readableState.needReadable, true); + } else { + assert.strictEqual(slowProducer._readableState.needReadable, false); + } +}, 4)); + +process.nextTick(common.mustCall(() => { + slowProducer.push('foo'); +})); +process.nextTick(common.mustCall(() => { + slowProducer.push('foo'); +})); +process.nextTick(common.mustCall(() => { + slowProducer.push('foo'); +})); +process.nextTick(common.mustCall(() => { + slowProducer.push(null); +})); From cf1587aabed50623881d3803e7561e7e4df06175 Mon Sep 17 00:00:00 2001 From: "Italo A. Casas" Date: Thu, 15 Dec 2016 20:17:38 -0500 Subject: [PATCH 073/116] test: stream readable resumeScheduled state PR-URL: https://github.com/nodejs/node/pull/10299 Ref: https://github.com/nodejs/node/issues/8683 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig --- .../test-stream-readable-resumeScheduled.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/parallel/test-stream-readable-resumeScheduled.js diff --git a/test/parallel/test-stream-readable-resumeScheduled.js b/test/parallel/test-stream-readable-resumeScheduled.js new file mode 100644 index 00000000000000..59042da3dbcb86 --- /dev/null +++ b/test/parallel/test-stream-readable-resumeScheduled.js @@ -0,0 +1,67 @@ +'use strict'; +const common = require('../common'); + +// Testing Readable Stream resumeScheduled state + +const assert = require('assert'); +const stream = require('stream'); +const Readable = stream.Readable; +const Writable = stream.Writable; + +{ + // pipe() test case + const r = new Readable({ read() {} }); + const w = new Writable(); + + // resumeScheduled should start = `false`. + assert.strictEqual(r._readableState.resumeScheduled, false); + + // calling pipe() should change the state value = true. + r.pipe(w); + assert.strictEqual(r._readableState.resumeScheduled, true); + + process.nextTick(common.mustCall(() => { + assert.strictEqual(r._readableState.resumeScheduled, false); + })); +} + +{ + // 'data' listener test case + const r = new Readable({ read() {} }); + + // resumeScheduled should start = `false`. + assert.strictEqual(r._readableState.resumeScheduled, false); + + r.push(Buffer.from([1, 2, 3])); + + // adding 'data' listener should change the state value + r.on('data', common.mustCall(() => { + assert.strictEqual(r._readableState.resumeScheduled, false); + })); + assert.strictEqual(r._readableState.resumeScheduled, true); + + process.nextTick(common.mustCall(() => { + assert.strictEqual(r._readableState.resumeScheduled, false); + })); +} + +{ + // resume() test case + const r = new Readable({ read() {} }); + + // resumeScheduled should start = `false`. + assert.strictEqual(r._readableState.resumeScheduled, false); + + // Calling resume() should change the state value. + r.resume(); + assert.strictEqual(r._readableState.resumeScheduled, true); + + r.on('resume', common.mustCall(() => { + // The state value should be `false` again + assert.strictEqual(r._readableState.resumeScheduled, false); + })); + + process.nextTick(common.mustCall(() => { + assert.strictEqual(r._readableState.resumeScheduled, false); + })); +} From 6dfddc802aa031ad861b063f2beaf307ed8467ae Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 10 Dec 2016 03:11:19 +0800 Subject: [PATCH 074/116] doc: clarify the review and landing process Adds/mentions: - Link to glossary - Commit squashing and CI run - 48/72 hour wait and PR review feature - Extra notes section - "Landed in " comment PR-URL: https://github.com/nodejs/node/pull/10202 Ref: https://github.com/nodejs/node/pull/10151 Reviewed-By: Anna Henningsen Reviewed-By: Evan Lucas Reviewed-By: Gibson Fahnestock --- CONTRIBUTING.md | 83 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64b4531b63ae6d..dcb7c3148e2b7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -240,18 +240,85 @@ If in doubt, you can always ask for guidance in the Pull Request or on [IRC in the #node-dev channel](https://webchat.freenode.net?channels=node-dev&uio=d4). Feel free to post a comment in the Pull Request to ping reviewers if you are -awaiting an answer on something. +awaiting an answer on something. If you encounter words or acronyms that +seem unfamiliar, check out this +[glossary](https://sites.google.com/a/chromium.org/dev/glossary). +Note that multiple commits often get squashed when they are landed (see the +notes about [commit squashing](#commit-squashing)). ### Step 8: Landing -Once your Pull Request has been reviewed and approved by at least one Node.js -Collaborators (often by saying LGTM, or Looks Good To Me), and as long as -there is consensus (no objections from a Collaborator), a -Collaborator can merge the Pull Request . GitHub often shows the Pull Request as - `Closed` at this point, but don't worry. If you look at the branch you raised - your Pull Request against (probably `master`), you should see a commit with - your name on it. Congratulations and thanks for your contribution! +In order to get landed, a Pull Request needs to be reviewed and +[approved](#getting-approvals-for-your-pull-request) by +at least one Node.js Collaborator and pass a +[CI (Continuous Integration) test run](#ci-testing). +After that, as long as there are no objections +from a Collaborator, the Pull Request can be merged. If you find your +Pull Request waiting longer than you expect, see the +[notes about the waiting time](#waiting-until-the-pull-request-gets-landed). + +When a collaborator lands your Pull Request, they will post +a comment to the Pull Request page mentioning the commit(s) it +landed as. GitHub often shows the Pull Request as `Closed` at this +point, but don't worry. If you look at the branch you raised your +Pull Request against (probably `master`), you should see a commit with +your name on it. Congratulations and thanks for your contribution! + +## Additional Notes + +### Commit Squashing + +When the commits in your Pull Request get landed, they will be squashed +into one commit per logical change, with metadata added to the commit +message (including links to the Pull Request, links to relevant issues, +and the names of the reviewers). The commit history of your Pull Request, +however, will stay intact on the Pull Request page. + +For the size of "one logical change", +[0b5191f](https://github.com/nodejs/node/commit/0b5191f15d0f311c804d542b67e2e922d98834f8) +can be a good example. It touches the implementation, the documentation, +and the tests, but is still one logical change. In general, the tests should +always pass when each individual commit lands on the master branch. + +### Getting Approvals for Your Pull Request + +A Pull Request is approved either by saying LGTM, which stands for +"Looks Good To Me", or by using GitHub's Approve button. +GitHub's Pull Request review feature can be used during the process. +For more information, check out +[the video tutorial](https://www.youtube.com/watch?v=HW0RPaJqm4g) +or [the official documentation](https://help.github.com/articles/reviewing-changes-in-pull-requests/). + +After you push new changes to your branch, you need to get +approval for these new changes again, even if GitHub shows "Approved" +because the reviewers have hit the buttons before. + +### CI Testing + +Every Pull Request needs to be tested +to make sure that it works on the platforms that Node.js +supports. This is done by running the code through the CI system. + +Only a Collaborator can request a CI run. Usually one of them will do it +for you as approvals for the Pull Request come in. +If not, you can ask a Collaborator to request a CI run. + +### Waiting Until the Pull Request Gets Landed + +A Pull Request needs to stay open for at least 48 hours (72 hours on a +weekend) from when it is submitted, even after it gets approved and +passes the CI. This is to make sure that everyone has a chance to +weigh in. If the changes are trivial, collaborators may decide it +doesn't need to wait. A Pull Request may well take longer to be +merged in. All these precautions are important because Node.js is +widely used, so don't be discouraged! + +### Check Out the Collaborator's Guide + +If you want to know more about the code review and the landing process, +you can take a look at the +[collaborator's guide](https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md). ## Developer's Certificate of Origin 1.1 From 2fb30f861f4a37465f20a2ad7b85f75179d71bdb Mon Sep 17 00:00:00 2001 From: Vicente Jimenez Aguilar Date: Sun, 18 Dec 2016 17:21:29 +0100 Subject: [PATCH 075/116] doc: require() tries first core not native modules Change a single word in documentation with a more precise one. Native is a module compiled in machine "native" code. A module normally written in a compiled language, not in JavaScript. Core modules form Node's built-in "core" functionalities. You don't need to install them. They are included in every Node installation and documented in https://nodejs.org/api/ . PR-URL: https://github.com/nodejs/node/pull/10324 Reviewed-By: Colin Ihrig Reviewed-By: Italo A. Casas Reviewed-By: Gibson Fahnestock Reviewed-By: Sam Roberts Reviewed-By: James M Snell --- doc/api/modules.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index f5dba78dac84b1..338e7e1c6ce2e5 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -368,11 +368,11 @@ example, then `require('./some-library')` would attempt to load: -If the module identifier passed to `require()` is not a native module, -and does not begin with `'/'`, `'../'`, or `'./'`, then Node.js starts at the -parent directory of the current module, and adds `/node_modules`, and -attempts to load the module from that location. Node will not append -`node_modules` to a path already ending in `node_modules`. +If the module identifier passed to `require()` is not a +[core](#modules_core_modules) module, and does not begin with `'/'`, `'../'`, or +`'./'`, then Node.js starts at the parent directory of the current module, and +adds `/node_modules`, and attempts to load the module from that location. Node +will not append `node_modules` to a path already ending in `node_modules`. If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached. From 312745afa4e9b0c8d46fe9358539f6e8f665eb6c Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Wed, 21 Dec 2016 16:47:19 -0500 Subject: [PATCH 076/116] test: improve test-cluster-worker-constructor.js * use let and const instead of var * use assert.strictEqual instead assert.equal PR-URL: https://github.com/nodejs/node/pull/10396 Reviewed-By: Colin Ihrig Reviewed-By: Italo A. Casas Reviewed-By: Santiago Gimeno Reviewed-By: James M Snell --- test/parallel/test-cluster-worker-constructor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-cluster-worker-constructor.js b/test/parallel/test-cluster-worker-constructor.js index f3ae7db73168a9..770d45c6a9edb7 100644 --- a/test/parallel/test-cluster-worker-constructor.js +++ b/test/parallel/test-cluster-worker-constructor.js @@ -3,9 +3,9 @@ // validates correct behavior of the cluster.Worker constructor require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var worker; +const assert = require('assert'); +const cluster = require('cluster'); +let worker; worker = new cluster.Worker(); assert.strictEqual(worker.suicide, undefined); From b3bc996b91dca139a67a5c61b583d7951c1e7a0c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 21 Dec 2016 17:53:11 -0800 Subject: [PATCH 077/116] test: fix flaky test-https-timeout Remove `setTimeout()` in test and instead rely on `common.mustCall()` on a `timeout` event handler. The test was flaky on CI. The flakiness was replicable by running the test under load. This version, in contrast, is robust under load. Took the opportunity to do some `var` -> `const` while refactoring. PR-URL: https://github.com/nodejs/node/pull/10404 Reviewed-By: Santiago Gimeno Reviewed-By: Colin Ihrig Reviewed-By: Italo A. Casas Reviewed-By: James M Snell --- test/parallel/test-https-timeout.js | 34 ++++++++++------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-https-timeout.js b/test/parallel/test-https-timeout.js index 865c15165e2460..ad8decc03cf474 100644 --- a/test/parallel/test-https-timeout.js +++ b/test/parallel/test-https-timeout.js @@ -1,24 +1,24 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; // a server that never replies -var server = https.createServer(options, function() { +const server = https.createServer(options, function() { console.log('Got request. Doing nothing.'); -}).listen(0, function() { - var req = https.request({ +}).listen(0, common.mustCall(function() { + const req = https.request({ host: 'localhost', port: this.address().port, path: '/', @@ -28,26 +28,14 @@ var server = https.createServer(options, function() { req.setTimeout(10); req.end(); - req.on('response', function(res) { + req.on('response', function() { console.log('got response'); }); - req.on('socket', function() { - console.log('got a socket'); - - req.socket.on('connect', function() { - console.log('socket connected'); - }); - - setTimeout(function() { - throw new Error('Did not get timeout event'); - }, 200); - }); - - req.on('timeout', function() { + req.on('timeout', common.mustCall(function() { console.log('timeout occurred outside'); req.destroy(); server.close(); process.exit(0); - }); -}); + })); +})); From 2a26a31a59d1cbd40878b84ccf14179f4bd2b7b3 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Fri, 23 Dec 2016 13:44:10 -0500 Subject: [PATCH 078/116] test: improve code in test-vm-preserves-property * use const instead of var * use assert.strictEqual instead assert.equal PR-URL https://github.com/nodejs/node/pull/10428 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- test/parallel/test-vm-preserves-property.js | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-vm-preserves-property.js b/test/parallel/test-vm-preserves-property.js index 9786ee54a7cffd..0ddc7b260a1393 100644 --- a/test/parallel/test-vm-preserves-property.js +++ b/test/parallel/test-vm-preserves-property.js @@ -1,25 +1,25 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var vm = require('vm'); +const vm = require('vm'); -var x = {}; +const x = {}; Object.defineProperty(x, 'prop', { configurable: false, enumerable: false, writable: false, value: 'val' }); -var o = vm.createContext(x); +const o = vm.createContext(x); -var code = 'Object.getOwnPropertyDescriptor(this, "prop")'; -var res = vm.runInContext(code, o, 'test'); +const code = 'Object.getOwnPropertyDescriptor(this, "prop")'; +const res = vm.runInContext(code, o, 'test'); assert(res); -assert.equal(typeof res, 'object'); -assert.equal(res.value, 'val'); -assert.equal(res.configurable, false, 'should not be configurable'); -assert.equal(res.enumerable, false, 'should not be enumerable'); -assert.equal(res.writable, false, 'should not be writable'); +assert.strictEqual(typeof res, 'object'); +assert.strictEqual(res.value, 'val'); +assert.strictEqual(res.configurable, false, 'should not be configurable'); +assert.strictEqual(res.enumerable, false, 'should not be enumerable'); +assert.strictEqual(res.writable, false, 'should not be writable'); From 0ea78d4dc0b0180e38f881cbd9766a0274d78e06 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 24 Dec 2016 10:32:47 -0800 Subject: [PATCH 079/116] doc: use "Node.js" in V8 guide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/10438 Reviewed-By: Michaël Zasso Reviewed-By: Gibson Fahnestock Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- doc/guides/maintaining-V8.md | 121 +++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 35 deletions(-) diff --git a/doc/guides/maintaining-V8.md b/doc/guides/maintaining-V8.md index 82312cf6bcf4d1..19ee61fe20c5d7 100644 --- a/doc/guides/maintaining-V8.md +++ b/doc/guides/maintaining-V8.md @@ -1,10 +1,17 @@ -# Maintaining V8 in Node +# Maintaining V8 in Node.js # Background -V8 follows the Chromium release schedule. The support horizon for Chromium is very different from the support horizon that Node.js needs to provide to its users. As a result Node.js needs to support a version of V8 for quite a bit longer than what upstream needs to support. Since V8 doesn't have an LTS supported branch, there is no official process around how the V8 branches in Node are maintained. +V8 follows the Chromium release schedule. The support horizon for Chromium is +very different from the support horizon that Node.js needs to provide to its +users. As a result Node.js needs to support a version of V8 for quite a bit +longer than what upstream needs to support. Since V8 doesn't have an LTS +supported branch, there is no official process around how the V8 branches in +Node.js are maintained. -This document attempts to document the current processes and proposes a workflow for maintaining the V8 branches in Node.js LTS and Current releases and how the Node and V8 teams at Google can help. +This document attempts to document the current processes and proposes a workflow +for maintaining the V8 branches in Node.js LTS and Current releases and how the +Node.js and V8 teams at Google can help. # V8 Release Schedule @@ -16,7 +23,8 @@ For example, at the time of this writing: * **Beta**: V8 5.5 is currently in beta. It will be promoted to stable next; approximately 6 weeks after V8 5.4 shipped as stable. * **Master**: V8 tip-of-tree corresponds to V8 5.6. This branch gets regularly released as part of the Chromium **canary** builds. This branch will be promoted to beta next when V8 5.5 ships as stable. -All older branches are considered **abandoned**, and are not maintained by the V8 team. +All older branches are considered **abandoned**, and are not maintained by the +V8 team. ## V8 merge process overview @@ -29,9 +37,11 @@ The process for backporting bug fixes to active branches is officially documente * Merge requests to an abandoned branch will be rejected. * Only bug fixes are accepted for backporting. -# Node Support Requirements +# Node.js Support Requirements -At any given time Node needs to be maintaining a few different V8 branches for the various Current, LTS, and nightly releases. At present this list includes the following branches1: +At any given time Node.js needs to be maintaining a few different V8 branches +for the various Current, LTS, and nightly releases. At present this list +includes the following branches1: @@ -49,7 +59,7 @@ At any given time Node needs to be maintaining a few different V8 branches for t - @@ -63,7 +73,7 @@ At any given time Node needs to be maintaining a few different V8 branches for t - @@ -77,7 +87,7 @@ At any given time Node needs to be maintaining a few different V8 branches for t - @@ -107,17 +117,22 @@ At any given time Node needs to be maintaining a few different V8 branches for t
Node v4.x + Node.js v4.x 2015-10-01
Node v6.x + Node.js v6.x 2016-04-01
Node v7.x + Node.js v7.x 2016-10-01
-The versions of V8 used in Node v4.x and v6.x have already been abandoned by upstream V8. However, Node.js needs to continue supporting these branches for many months (Current branches) or several years (LTS branches). +The versions of V8 used in Node.js v4.x and v6.x have already been abandoned by +upstream V8. However, Node.js needs to continue supporting these branches for +many months (Current branches) or several years (LTS branches). # Maintenance Process -Once a bug in Node.js has been identified to be caused by V8, the first step is to identify the versions of Node and V8 affected. The bug may be present in multiple different locations, each of which follows a slightly different process. +Once a bug in Node.js has been identified to be caused by V8, the first step is +to identify the versions of Node.js and V8 affected. The bug may be present in +multiple different locations, each of which follows a slightly different +process. * Unfixed bugs. The bug exists in the V8 master branch. * Fixed, but needs backport. The bug may need porting to one or more branches. * Backporting to active branches. * Backporting to abandoned branches. -* Backports identified by the V8 team. Bugs identified by upstream V8 that we haven't encountered in Node yet. +* Backports identified by the V8 team. Bugs identified by upstream V8 that we haven't encountered in Node.js yet. ## Unfixed Upstream Bugs @@ -127,7 +142,7 @@ If the bug can be reproduced on the [`vee-eight-lkgr` branch](https://github.com * Make sure to include a link to the corresponding Node.js issue (if one exists). * If the fix is simple enough, you may fix it yourself; [contributions](https://github.com/v8/v8/wiki/Contributing) are welcome. * V8's build waterfall tests your change. -* Once the bug is fixed it may still need backporting, if it exists in other V8 branches that are still active or are branches that Node cares about. Follow the process for backporting below. +* Once the bug is fixed it may still need backporting, if it exists in other V8 branches that are still active or are branches that Node.js cares about. Follow the process for backporting below. ## Backporting to Active Branches @@ -142,23 +157,28 @@ If the bug exists in any of the active V8 branches, we may need to get the fix b * Attach *merge-request-x.x* labels to the bug for any active branches that still contain the bug. (e.g. merge-request-5.3, merge-request-5.4) * Add ofrobots-at-google.com to the cc list. * Once the merge has been approved, it should be merged using the [merge script documented in the V8 wiki](https://github.com/v8/v8/wiki/Merging%20&%20Patching). Merging requires commit access to the V8 repository. If you don't have commit access you can indicate someone on the V8 team can do the merge for you. -* It is possible that the merge request may not get approved, for example if it is considered to be a feature or otherwise too risky for V8 stable. In such cases we float the patch on the Node side. See the process on 'Backporting to Abandoned branches'. +* It is possible that the merge request may not get approved, for example if it is considered to be a feature or otherwise too risky for V8 stable. In such cases we float the patch on the Node.js side. See the process on 'Backporting to Abandoned branches'. * Once the fix has been merged upstream, it can be picked up during an update of the V8 branch, (see below). ## Backporting to Abandoned Branches -Abandoned V8 branches are supported in the Node.js V8 repository. The fix needs to be cherry-picked in the Node.js repository and V8-CI must test the change. +Abandoned V8 branches are supported in the Node.js V8 repository. The fix needs +to be cherry-picked in the Node.js repository and V8-CI must test the change. * For each abandoned V8 branch corresponding to an LTS branch that is affected by the bug: * Open a cherry-pick PR on nodejs/node targeting the appropriate *vY.x-staging* branch (e.g. *v6.x-staging* to fix an issue in V8-5.1). * Increase the patch level version in v8-version.h. This will not cause any problems with versioning because V8 will not publish other patches for this branch, so Node.js can effectively bump the patch version. * In some cases the patch may require extra effort to merge in case V8 has changed substantially. For important issues we may be able to lean on the V8 team to get help with reimplementing the patch. - * Run Node's [V8-CI](https://ci.nodejs.org/job/node-test-commit-v8-linux/) in addition to the [Node CI](https://ci.nodejs.org/job/node-test-pull-request/). + * Run the Node.js [V8-CI](https://ci.nodejs.org/job/node-test-commit-v8-linux/) in addition to the [Node.js CI](https://ci.nodejs.org/job/node-test-pull-request/). -An example for workflow how to cherry-pick consider the following bug: https://crbug.com/v8/5199. From the bug we can see that it was merged by V8 into 5.2 and 5.3, and not into V8 5.1 (since it was already abandoned). Since Node.js `v6.x` uses V8 5.1, the fix needed to cherry-picked. To cherry-pick, here's an example workflow: +An example for workflow how to cherry-pick consider the following bug: +https://crbug.com/v8/5199. From the bug we can see that it was merged by V8 into +5.2 and 5.3, and not into V8 5.1 (since it was already abandoned). Since Node.js +`v6.x` uses V8 5.1, the fix needed to cherry-picked. To cherry-pick, here's an +example workflow: * Download and apply the commit linked-to in the issue (in this case a51f429). `curl -L https://github.com/v8/v8/commit/a51f429.patch | git apply --directory=deps/v8`. If the branches have diverged significantly, this may not apply cleanly. It may help to try to cherry-pick the merge to the oldest branch that was done upstream in V8. In this example, this would be the patch from the merge to 5.2. The hope is that this would be closer to the V8 5.1, and has a better chance of applying cleanly. If you're stuck, feel free to ping @ofrobots for help. -* Modify the commit message to match the format we use for V8 backports. You may want to add extra description if necessary to indicate the impact of the fix on Node. In this case the original issue was descriptive enough. Example: +* Modify the commit message to match the format we use for V8 backports. You may want to add extra description if necessary to indicate the impact of the fix on Node.js. In this case the original issue was descriptive enough. Example: ``` deps: cherry-pick a51f429 from V8 upstream @@ -182,24 +202,38 @@ PR-URL: ## Backports Identified by the V8 team -For bugs found through the browser or other channels, the V8 team marks bugs that might be applicable to the abandoned branches in use by Node.js. This is done through manual tagging by the V8 team and through an automated process that tags any fix that gets backported to the stable branch (as it is likely candidate for backporting further). +For bugs found through the browser or other channels, the V8 team marks bugs +that might be applicable to the abandoned branches in use by Node.js. This is +done through manual tagging by the V8 team and through an automated process that +tags any fix that gets backported to the stable branch (as it is likely +candidate for backporting further). Such fixes are tagged with the following labels in the V8 issue tracker: -* `NodeJS-Backport-Review` ([V8](https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Review), [Chromium](https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Review)): to be reviewed if this is applicable to abandoned branches in use by Node.js. This list if regularly reviewed by the node team at Google to determine applicability to Node.js. +* `NodeJS-Backport-Review` ([V8](https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Review), [Chromium](https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Review)): to be reviewed if this is applicable to abandoned branches in use by Node.js. This list if regularly reviewed by the Node.js team at Google to determine applicability to Node.js. * `NodeJS-Backport-Approved` ([V8](https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Approved), [Chromium](https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Approved)): marks bugs that are deemed relevant to Node.js and should be backported. * `NodeJS-Backport-Done` ([V8](https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Done), [Chromium](https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Done)): Backport for Node.js has been performed already. * `NodeJS-Backport-Rejected` ([V8](https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Rejected), [Chromium](https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Rejected)): Backport for Node.js is not desired. -The backlog of issues with such is regularly reviewed by the node-team at Google to shepherd through the backport process. External contributors are welcome to collaborate on the backport process as well. Note that some of the bugs may be security issues and will not be visible to external collaborators. +The backlog of issues with such is regularly reviewed by the node-team at Google +to shepherd through the backport process. External contributors are welcome to +collaborate on the backport process as well. Note that some of the bugs may be +security issues and will not be visible to external collaborators. # Updating V8 -Node keeps a vendored copy of V8 inside of deps/ directory. In addition Node may need to float patches that do not exist upstream. This means that some care may need to be taken to update the vendored copy of V8. +Node.js keeps a vendored copy of V8 inside of deps/ directory. In addition +Node.js may need to float patches that do not exist upstream. This means that +some care may need to be taken to update the vendored copy of V8. ## Minor updates (patch level) -Because there may be floating patches on the version of V8 in Node.js, it is safest to apply the patch level updates as a patch. For example, imagine that upstream V8 is at 5.0.71.47 and Node.js is at 5.0.71.32. It would be best to compute the diff between these tags on the V8 repository, and then apply that patch on the copy of V8 in Node.js. This should preserve the patches/backports that Node.js may be floating (or else cause a merge conflict). +Because there may be floating patches on the version of V8 in Node.js, it is +safest to apply the patch level updates as a patch. For example, imagine that +upstream V8 is at 5.0.71.47 and Node.js is at 5.0.71.32. It would be best to +compute the diff between these tags on the V8 repository, and then apply that +patch on the copy of V8 in Node.js. This should preserve the patches/backports +that Node.js may be floating (or else cause a merge conflict). The rough outline of the process is: @@ -216,14 +250,17 @@ curl -L https://github.com/v8/v8/compare/${V8_OLD_VERSION}...${V8_NEW_VERSION}.p # You may want to amend the commit message to describe the nature of the update ``` -V8 also keeps tags of the form *5.4-lkgr* which point to the *Last Known Good Revision* from the 5.4 branch that can be useful in the update process above. +V8 also keeps tags of the form *5.4-lkgr* which point to the *Last Known Good +Revision* from the 5.4 branch that can be useful in the update process above. ## Major Updates -We upgrade the version of V8 in Node.js master whenever a V8 release goes stable upstream, that is, whenever a new release of Chrome comes out. +We upgrade the version of V8 in Node.js master whenever a V8 release goes stable +upstream, that is, whenever a new release of Chrome comes out. -Upgrading major versions would be much harder to do with the patch mechanism above. A better strategy is to +Upgrading major versions would be much harder to do with the patch mechanism +above. A better strategy is to 1. Audit the current master branch and look at the patches that have been floated since the last major V8 update. 1. Replace the copy of V8 in Node.js with a fresh checkout of the latest stable V8 branch. Special care must be taken to recursively update the DEPS that V8 has a compile time dependency on (at the moment of this writing, these are only trace_event and gtest_prod.h) @@ -235,7 +272,7 @@ To audit for floating patches: git log --oneline deps/v8 ``` -To replace the copy of V8 in Node, use the '[update-v8](https://gist.github.com/targos/8da405e96e98fdff01a395bed365b816)' script2. For example, if you want to replace the copy of V8 in Node.js with the branch-head for V8 5.1 branch: +To replace the copy of V8 in Node.js, use the '[update-v8](https://gist.github.com/targos/8da405e96e98fdff01a395bed365b816)' script2. For example, if you want to replace the copy of V8 in Node.js with the branch-head for V8 5.1 branch: ```shell cd $NODE_DIR @@ -243,13 +280,17 @@ rm -rf deps/v8 path/to/update-v8 branch-heads/5.1 ``` -You may want to look at the commits created by the above scripts, and squash them once you have reviewed them. +You may want to look at the commits created by the above scripts, and squash +them once you have reviewed them. This should be followed up with manual refloating of all relevant patches. # Proposal: Using a fork repo to track upstream V8 -The fact that Node.js keeps a vendored, potentially edited copy of V8 in deps/ makes the above processes a bit complicated. An alternative proposal would be to create a fork of V8 at nodejs/v8 that would be used to maintain the V8 branches. This has several benefits: +The fact that Node.js keeps a vendored, potentially edited copy of V8 in deps/ +makes the above processes a bit complicated. An alternative proposal would be to +create a fork of V8 at nodejs/v8 that would be used to maintain the V8 branches. +This has several benefits: * The process to update the version of V8 in Node.js could be automated to track the tips of various V8 branches in nodejs/v8. * It would simplify cherry-picking and porting of fixes between branches as the version bumps in v8-version.h would happen as part of this update instead of on every change. @@ -259,17 +300,27 @@ The fact that Node.js keeps a vendored, potentially edited copy of V8 in deps/ m This would require some tooling to: -* A script that would update the V8 in a specific Node branch with V8 from upstream (dependent on branch abandoned vs. active). +* A script that would update the V8 in a specific Node.js branch with V8 from upstream (dependent on branch abandoned vs. active). * We need a script to bump V8 version numbers when a new version of V8 is promoted from nodejs/v8 to nodejs/node. * Enabled the V8-CI build in Jenkins to build from the nodejs/v8 fork. # Proposal: Dealing with the need to float patches to a stable/beta -Sometimes upstream V8 may not want to merge a fix to their stable branches, but we might. An example of this would be a fix for a performance regression that only affects Node.js and not the browser. At the moment we don't have a mechanism to deal with this situation. If we float a patch and bump the V8 version, we might run into a problem if upstream releases a fix with the same version number. - -One idea we have been kicking around is that we could move to a 5-place version number in V8, e.g.: 5.4.500.30.${embedder}. The ${embedder} represents the number of patches an embedder is floating on top of an official V8 version. This would also help with auditing the floating patches in the Node commit history. - -We are trying this out in https://github.com/nodejs/node/pull/9754. If this ends up working, we will investigate making this change upstream. +Sometimes upstream V8 may not want to merge a fix to their stable branches, but +we might. An example of this would be a fix for a performance regression that +only affects Node.js and not the browser. At the moment we don't have a +mechanism to deal with this situation. If we float a patch and bump the V8 +version, we might run into a problem if upstream releases a fix with the same +version number. + +One idea we have been kicking around is that we could move to a 5-place version +number in V8, e.g.: 5.4.500.30.${embedder}. The ${embedder} represents the +number of patches an embedder is floating on top of an official V8 version. This +would also help with auditing the floating patches in the Node.js commit +history. + +We are trying this out in https://github.com/nodejs/node/pull/9754. If this ends +up working, we will investigate making this change upstream. ## Notes From 78d85c689a4f495a5e1462986d573fa8fae730f5 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 22 Dec 2016 10:31:36 -0800 Subject: [PATCH 080/116] src: describe what NODE_MODULE_VERSION is for Current comment described what to do with it when the ABI changes, but implied that Node.js would load modules with newer ABI numbers, which it will not. PR-URL: https://github.com/nodejs/node/pull/10414 Reviewed-By: Anna Henningsen Reviewed-By: Gibson Fahnestock Reviewed-By: Italo A. Casas Reviewed-By: James M Snell Reviewed-By: Santiago Gimeno Reviewed-By: Sakthipriyan Vairamani --- src/node_version.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/node_version.h b/src/node_version.h index 539efd18467f2c..e2700754b2b639 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -47,6 +47,9 @@ (minor) == NODE_MINOR_VERSION && (patch) <= NODE_PATCH_VERSION)) /** + * Node.js will refuse to load modules that weren't compiled against its own + * module ABI number, exposed as the process.versions.modules property. + * * When this version number is changed, node.js will refuse * to load older modules. This should be done whenever * an API is broken in the C++ side, including in v8 or From 418d5ce3f5b53a1f70bc18fbbd0e3dffc699bed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 26 Dec 2016 14:29:25 +0100 Subject: [PATCH 081/116] build: add (not) cross-compiled configure flags Adds --cross-compiling and --no-cross-compiling flags Fixes: https://github.com/nodejs/node/issues/10271 PR-URL: https://github.com/nodejs/node/pull/10287 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- configure | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/configure b/configure index d33760dcf37e16..be38ff770eb315 100755 --- a/configure +++ b/configure @@ -79,6 +79,17 @@ parser.add_option('--dest-cpu', choices=valid_arch, help='CPU architecture to build for ({0})'.format(', '.join(valid_arch))) +parser.add_option('--cross-compiling', + action='store_true', + dest='cross_compiling', + default=None, + help='force build to be considered as cross compiled') +parser.add_option('--no-cross-compiling', + action='store_false', + dest='cross_compiling', + default=None, + help='force build to be considered as NOT cross compiled') + parser.add_option('--dest-os', action='store', dest='dest_os', @@ -725,7 +736,9 @@ def configure_node(o): o['variables']['target_arch'] = target_arch o['variables']['node_byteorder'] = sys.byteorder - cross_compiling = target_arch != host_arch + cross_compiling = (options.cross_compiling + if options.cross_compiling is not None + else target_arch != host_arch) want_snapshots = not options.without_snapshot o['variables']['want_separate_host_toolset'] = int( cross_compiling and want_snapshots) From ff5c11130b4c36dfa04b91ab60de5631f40c8b49 Mon Sep 17 00:00:00 2001 From: jBarz Date: Mon, 12 Dec 2016 23:56:24 -0500 Subject: [PATCH 082/116] os: fix os.release() for aix and add test PR-URL: https://github.com/nodejs/node/pull/10245 Reviewed-By: Michael Dawson Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/node_os.cc | 7 +++++++ test/parallel/test-os.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/node_os.cc b/src/node_os.cc index 8b8c7b62c8518c..fb62c768a4e31f 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -83,7 +83,14 @@ static void GetOSRelease(const FunctionCallbackInfo& args) { if (uname(&info) < 0) { return env->ThrowErrnoException(errno, "uname"); } +# ifdef _AIX + char release[256]; + snprintf(release, sizeof(release), + "%s.%s", info.version, info.release); + rval = release; +# else rval = info.release; +# endif #else // Windows char release[256]; OSVERSIONINFOW info; diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index 15fd189f9be20e..7d653ff04e8c90 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -62,6 +62,9 @@ assert.ok(type.length > 0); var release = os.release(); console.log('release = ', release); assert.ok(release.length > 0); +//TODO: Check format on more than just AIX +if (common.isAix) + assert.ok(/^\d+\.\d+$/.test(release)); var platform = os.platform(); console.log('platform = ', platform); From 4b55e9c299256bf7134217e5827a70d052919a94 Mon Sep 17 00:00:00 2001 From: Sarah Meyer Date: Thu, 1 Dec 2016 12:03:48 -0600 Subject: [PATCH 083/116] test: add test for SIGWINCH handling by stdio.js PR-URL: https://github.com/nodejs/node/pull/10063 Reviewed-By: James M Snell --- .../test-stderr-stdout-handle-sigwinch.js | 29 +++++++++++++++++++ .../test-stderr-stdout-handle-sigwinch.out | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 test/pseudo-tty/test-stderr-stdout-handle-sigwinch.js create mode 100644 test/pseudo-tty/test-stderr-stdout-handle-sigwinch.out diff --git a/test/pseudo-tty/test-stderr-stdout-handle-sigwinch.js b/test/pseudo-tty/test-stderr-stdout-handle-sigwinch.js new file mode 100644 index 00000000000000..f1a95559b9dc92 --- /dev/null +++ b/test/pseudo-tty/test-stderr-stdout-handle-sigwinch.js @@ -0,0 +1,29 @@ +'use strict'; +const common = require('../common'); + +const originalRefreshSizeStderr = process.stderr._refreshSize; +const originalRefreshSizeStdout = process.stdout._refreshSize; + +const wrap = (fn, ioStream, string) => { + return () => { + // The console.log() call prints a string that is in the .out file. In other + // words, the console.log() is part of the test, not extraneous debugging. + console.log(string); + try { + fn.call(ioStream); + } catch (e) { + // EINVAL happens on SmartOS if emulation is incomplete + if (!common.isSunOS || e.code !== 'EINVAL') + throw e; + } + }; +}; + +process.stderr._refreshSize = wrap(originalRefreshSizeStderr, + process.stderr, + 'calling stderr._refreshSize'); +process.stdout._refreshSize = wrap(originalRefreshSizeStdout, + process.stdout, + 'calling stdout._refreshSize'); + +process.emit('SIGWINCH'); diff --git a/test/pseudo-tty/test-stderr-stdout-handle-sigwinch.out b/test/pseudo-tty/test-stderr-stdout-handle-sigwinch.out new file mode 100644 index 00000000000000..dffbe030404487 --- /dev/null +++ b/test/pseudo-tty/test-stderr-stdout-handle-sigwinch.out @@ -0,0 +1,2 @@ +calling stdout._refreshSize +calling stderr._refreshSize From 45028513f8dcfcba0721953b854edc9d160d517d Mon Sep 17 00:00:00 2001 From: Chris Story Date: Thu, 1 Dec 2016 11:47:26 -0600 Subject: [PATCH 084/116] test: refactor test-stream2-unpipe-drain - Change var to const - Remove dependency crypto PR-URL: https://github.com/nodejs/node/pull/10033 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-stream2-unpipe-drain.js | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-stream2-unpipe-drain.js b/test/parallel/test-stream2-unpipe-drain.js index 39c3b19069b444..b546e269c8c272 100644 --- a/test/parallel/test-stream2-unpipe-drain.js +++ b/test/parallel/test-stream2-unpipe-drain.js @@ -1,15 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var stream = require('stream'); +require('../common'); +const assert = require('assert'); -if (!common.hasCrypto) { - common.skip('missing crypto'); - return; -} -var crypto = require('crypto'); - -var util = require('util'); +const stream = require('stream'); +const util = require('util'); function TestWriter() { stream.Writable.call(this); @@ -21,7 +15,7 @@ TestWriter.prototype._write = function(buffer, encoding, callback) { // super slow write stream (callback never called) }; -var dest = new TestWriter(); +const dest = new TestWriter(); function TestReader(id) { stream.Readable.call(this); @@ -31,11 +25,11 @@ util.inherits(TestReader, stream.Readable); TestReader.prototype._read = function(size) { this.reads += 1; - this.push(crypto.randomBytes(size)); + this.push(Buffer.alloc(size)); }; -var src1 = new TestReader(); -var src2 = new TestReader(); +const src1 = new TestReader(); +const src2 = new TestReader(); src1.pipe(dest); @@ -55,6 +49,6 @@ src1.once('readable', function() { process.on('exit', function() { - assert.equal(src1.reads, 2); - assert.equal(src2.reads, 2); + assert.strictEqual(src1.reads, 2); + assert.strictEqual(src2.reads, 2); }); From 41a67c92aef453371ffbf5cac4cc359b5e750dbd Mon Sep 17 00:00:00 2001 From: Stewart X Addison Date: Tue, 13 Dec 2016 19:49:00 +0000 Subject: [PATCH 085/116] build: add /opt/freeware/... to AIX library path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To ease the use of the AIX binaries, add /opt/freeware/lib/pthread{/ppc64} into the search path encoded into the library, so that any version the user has installed from the common download locations will work out of the box without having to explicitly set LIBPATH in their environment. PR-URL: https://github.com/nodejs/node/pull/10128 Reviewed-By: Michael Dawson Reviewed-By: Johan Bergström Reviewed-By: Gibson Fahnestock Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- node.gyp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/node.gyp b/node.gyp index e6e170d1d74487..1c10630f88bdb9 100644 --- a/node.gyp +++ b/node.gyp @@ -830,6 +830,16 @@ }, { 'type': 'executable', }], + ['target_arch=="ppc64"', { + 'ldflags': [ + '-Wl,-blibpath:/usr/lib:/lib:/opt/freeware/lib/pthread/ppc64' + ], + }], + ['target_arch=="ppc"', { + 'ldflags': [ + '-Wl,-blibpath:/usr/lib:/lib:/opt/freeware/lib/pthread' + ], + }] ], 'dependencies': ['<(node_core_target_name)', 'node_exp'], From 2eba1d5969baf2d6de52f42a6eb37a19a44b6ad8 Mon Sep 17 00:00:00 2001 From: Fabrice Tatieze Date: Tue, 27 Dec 2016 18:18:58 -0800 Subject: [PATCH 086/116] test: use strictEqual in test-http-server PR-URL: https://github.com/nodejs/node/pull/10478 Reviewed-By: James M Snell Reviewed-By: Italo A. Casas Reviewed-By: Colin Ihrig --- test/parallel/test-http-server.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-http-server.js b/test/parallel/test-http-server.js index 49283d621cecda..1870bcc7170726 100644 --- a/test/parallel/test-http-server.js +++ b/test/parallel/test-http-server.js @@ -16,23 +16,23 @@ var server = http.createServer(function(req, res) { req.id = request_number++; if (req.id === 0) { - assert.equal('GET', req.method); - assert.equal('/hello', url.parse(req.url).pathname); - assert.equal('world', qs.parse(url.parse(req.url).query).hello); - assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo); + assert.strictEqual('GET', req.method); + assert.strictEqual('/hello', url.parse(req.url).pathname); + assert.strictEqual('world', qs.parse(url.parse(req.url).query).hello); + assert.strictEqual('b==ar', qs.parse(url.parse(req.url).query).foo); } if (req.id === 1) { - assert.equal('POST', req.method); - assert.equal('/quit', url.parse(req.url).pathname); + assert.strictEqual('POST', req.method); + assert.strictEqual('/quit', url.parse(req.url).pathname); } if (req.id === 2) { - assert.equal('foo', req.headers['x-x']); + assert.strictEqual('foo', req.headers['x-x']); } if (req.id === 3) { - assert.equal('bar', req.headers['x-x']); + assert.strictEqual('bar', req.headers['x-x']); this.close(); } @@ -75,7 +75,7 @@ server.on('listening', function() { // you set server.httpAllowHalfOpen=true, which we've done // above. c.end(); - assert.equal(c.readyState, 'readOnly'); + assert.strictEqual(c.readyState, 'readOnly'); requests_sent += 2; } @@ -86,19 +86,19 @@ server.on('listening', function() { }); c.on('close', function() { - assert.equal(c.readyState, 'closed'); + assert.strictEqual(c.readyState, 'closed'); }); }); process.on('exit', function() { - assert.equal(4, request_number); - assert.equal(4, requests_sent); + assert.strictEqual(4, request_number); + assert.strictEqual(4, requests_sent); var hello = new RegExp('/hello'); - assert.equal(true, hello.exec(server_response) != null); + assert.notStrictEqual(null, hello.exec(server_response)); var quit = new RegExp('/quit'); - assert.equal(true, quit.exec(server_response) != null); + assert.notStrictEqual(null, quit.exec(server_response)); - assert.equal(true, client_got_eof); + assert.strictEqual(true, client_got_eof); }); From c51c3b038f8caf78be81c4475b0342cf0c126395 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 29 Dec 2016 16:16:37 -0800 Subject: [PATCH 087/116] doc: require two-factor authentication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Collaborators have elevated privileges. The CTC now requires Collaborator accounts to have two-factor authentication. This changes wording in the onboarding documentation to make it clear that two-factor authentication is required and not merely recommended. PR-URL: https://github.com/nodejs/node/pull/10529 Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas Reviewed-By: Ali Ijaz Sheikh Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell Reviewed-By: Michaël Zasso Reviewed-By: Gibson Fahnestock Reviewed-By: Luigi Pinca Reviewed-By: Matteo Collina --- doc/onboarding.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/onboarding.md b/doc/onboarding.md index f458cee46e6708..80be93ace89cb2 100644 --- a/doc/onboarding.md +++ b/doc/onboarding.md @@ -5,14 +5,19 @@ onboarding session. ## One week before the onboarding session -* Ask the new Collaborator if they are using two-factor authentication on their - GitHub account. If they are not, suggest that they enable it as their account - will have elevated privileges in many of the Node.js repositories. +* Confirm that the new Collaborator is using two-factor authentication on their + GitHub account. Unless two-factor authentication is enabled, do not give an + account elevated privileges such as the ability to land code in the main + repository or to start continuous integration (CI) jobs. ## Fifteen minutes before the onboarding session -* Prior to the onboarding session, add the new Collaborators to -[the Collaborators team](https://github.com/orgs/nodejs/teams/collaborators). +* Prior to the onboarding session, add the new Collaborator to + [the Collaborators team](https://github.com/orgs/nodejs/teams/collaborators). + Note that this is the step that gives the account elevated privileges, so + do not perform this step (or any subsequent steps) unless two-factor + authentication is enabled on the new Collaborator's GitHub account. + ## **thank you** for doing this From cd0ad3f2137e2db12a5c31e5fa684b2aa3ae5fc7 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Tue, 27 Dec 2016 21:43:44 -0500 Subject: [PATCH 088/116] test: improve test-fs-empty-readStream.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * use const instead of var * use common.mustCall to control functions execution * use assert.strictEqual instead of assert.equal * use arrow functions PR-URL: https://github.com/nodejs/node/pull/10479 Reviewed-By: James M Snell Reviewed-By: Michaël Zasso Reviewed-By: Colin Ihrig Reviewed-By: Italo A. Casas Reviewed-By: Luigi Pinca Reviewed-By: Brian White --- test/parallel/test-fs-empty-readStream.js | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-fs-empty-readStream.js b/test/parallel/test-fs-empty-readStream.js index c5a016f9ea2c36..858d07e4f0b982 100644 --- a/test/parallel/test-fs-empty-readStream.js +++ b/test/parallel/test-fs-empty-readStream.js @@ -1,30 +1,30 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); -var emptyFile = path.join(common.fixturesDir, 'empty.txt'); +const emptyFile = path.join(common.fixturesDir, 'empty.txt'); -fs.open(emptyFile, 'r', function(error, fd) { +fs.open(emptyFile, 'r', common.mustCall((error, fd) => { assert.ifError(error); - var read = fs.createReadStream(emptyFile, { 'fd': fd }); + const read = fs.createReadStream(emptyFile, { 'fd': fd }); - read.once('data', function() { + read.once('data', () => { throw new Error('data event should not emit'); }); read.once('end', common.mustCall(function endEvent1() {})); -}); +})); -fs.open(emptyFile, 'r', function(error, fd) { +fs.open(emptyFile, 'r', common.mustCall((error, fd) => { assert.ifError(error); - var read = fs.createReadStream(emptyFile, { 'fd': fd }); + const read = fs.createReadStream(emptyFile, { 'fd': fd }); read.pause(); - read.once('data', function() { + read.once('data', () => { throw new Error('data event should not emit'); }); @@ -32,7 +32,7 @@ fs.open(emptyFile, 'r', function(error, fd) { throw new Error('end event should not emit'); }); - setTimeout(function() { - assert.equal(read.isPaused(), true); - }, common.platformTimeout(50)); -}); + setTimeout(common.mustCall(() => { + assert.strictEqual(read.isPaused(), true); + }), common.platformTimeout(50)); +})); From 678c5632b56342321d03d025b9563611c433e593 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 26 Dec 2016 22:45:16 +0000 Subject: [PATCH 089/116] doc: warn about unvalidated input in child_process child_process.exec*() and child_process.spawn*() (if options.shell is true) allow trivial arbitrary command execution if code passes unsanitised user input to it. Add warnings in the docs to make that clear. PR-URL: https://github.com/nodejs/node/pull/10466 Reviewed-By: Gibson Fahnestock Reviewed-By: Sam Roberts Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- doc/api/child_process.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/api/child_process.md b/doc/api/child_process.md index afbb8a39df5153..d093900e397c73 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -141,6 +141,10 @@ added: v0.1.90 Spawns a shell then executes the `command` within that shell, buffering any generated output. +**Note: Never pass unsanitised user input to this function. Any input +containing shell metacharacters may be used to trigger arbitrary command +execution.** + ```js const exec = require('child_process').exec; exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => { @@ -314,6 +318,10 @@ The `child_process.spawn()` method spawns a new process using the given `command`, with command line arguments in `args`. If omitted, `args` defaults to an empty array. +**Note: If the `shell` option is enabled, do not pass unsanitised user input to +this function. Any input containing shell metacharacters may be used to +trigger arbitrary command execution.** + A third argument may be used to specify additional options, with these defaults: ```js @@ -620,6 +628,10 @@ If the process times out, or has a non-zero exit code, this method ***will*** throw. The [`Error`][] object will contain the entire result from [`child_process.spawnSync()`][] +**Note: Never pass unsanitised user input to this function. Any input +containing shell metacharacters may be used to trigger arbitrary command +execution.** + ### child_process.spawnSync(command[, args][, options]) + +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. + +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. + +[emit_warning]: process.html#process_process_emitwarning_warning_name_ctor [Buffer]: buffer.html#buffer_buffer [debugger]: debugger.html [REPL]: repl.html diff --git a/src/node.cc b/src/node.cc index 05930e8bac215f..3b0837b1c1eafe 100644 --- a/src/node.cc +++ b/src/node.cc @@ -4400,6 +4400,8 @@ int Start(int argc, char** argv) { Init(&argc, const_cast(argv), &exec_argc, &exec_argv); #if HAVE_OPENSSL + if (const char* extra = secure_getenv("NODE_EXTRA_CA_CERTS")) + crypto::UseExtraCaCerts(extra); // V8 on Windows doesn't have a good source of entropy. Seed it from // OpenSSL's pool. V8::SetEntropySource(crypto::EntropySource); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 0d3053625f38ba..e74e838cd650b8 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -120,6 +120,8 @@ const char* const root_certs[] = { #include "node_root_certs.h" // NOLINT(build/include_order) }; +std::string extra_root_certs_file; // NOLINT(runtime/string) + X509_STORE* root_cert_store; // Just to generate static methods @@ -753,6 +755,38 @@ void SecureContext::AddCRL(const FunctionCallbackInfo& args) { } +void UseExtraCaCerts(const std::string& file) { + extra_root_certs_file = file; +} + + +static unsigned long AddCertsFromFile( // NOLINT(runtime/int) + X509_STORE* store, + const char* file) { + ERR_clear_error(); + MarkPopErrorOnReturn mark_pop_error_on_return; + + BIO* bio = BIO_new_file(file, "r"); + if (!bio) { + return ERR_get_error(); + } + + while (X509* x509 = + PEM_read_bio_X509(bio, nullptr, CryptoPemCallback, nullptr)) { + X509_STORE_add_cert(store, x509); + X509_free(x509); + } + BIO_free_all(bio); + + unsigned long err = ERR_peek_error(); // NOLINT(runtime/int) + // Ignore error if its EOF/no start line found. + if (ERR_GET_LIB(err) == ERR_LIB_PEM && + ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { + return 0; + } + + return err; +} void SecureContext::AddRootCerts(const FunctionCallbackInfo& args) { SecureContext* sc; @@ -782,6 +816,18 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo& args) { BIO_free_all(bp); X509_free(x509); } + + if (!extra_root_certs_file.empty()) { + unsigned long err = AddCertsFromFile( // NOLINT(runtime/int) + root_cert_store, + extra_root_certs_file.c_str()); + if (err) { + ProcessEmitWarning(sc->env(), + "Ignoring extra certs from `%s`, load failed: %s\n", + extra_root_certs_file.c_str(), + ERR_error_string(err, nullptr)); + } + } } sc->ca_store_ = root_cert_store; diff --git a/src/node_crypto.h b/src/node_crypto.h index 1f9271d0e6e13d..9a4d936f305ee1 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -63,6 +63,8 @@ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx); extern X509_STORE* root_cert_store; +extern void UseExtraCaCerts(const std::string& file); + // Forward declaration class Connection; diff --git a/test/parallel/test-tls-env-bad-extra-ca.js b/test/parallel/test-tls-env-bad-extra-ca.js new file mode 100644 index 00000000000000..1862366e013af0 --- /dev/null +++ b/test/parallel/test-tls-env-bad-extra-ca.js @@ -0,0 +1,43 @@ +// Setting NODE_EXTRA_CA_CERTS to non-existent file emits a warning + +'use strict'; +const common = require('../common'); + +if (!common.hasCrypto) { + common.skip('missing crypto'); + return; +} + +const assert = require('assert'); +const tls = require('tls'); +const fork = require('child_process').fork; + +if (process.env.CHILD) { + // This will try to load the extra CA certs, and emit a warning when it fails. + return tls.createServer({}); +} + +const env = { + CHILD: 'yes', + NODE_EXTRA_CA_CERTS: common.fixturesDir + '/no-such-file-exists', +}; + +var opts = { + env: env, + silent: true, +}; +var stderr = ''; + +fork(__filename, opts) + .on('exit', common.mustCall(function(status) { + assert.equal(status, 0, 'client did not succeed in connecting'); + })) + .on('close', common.mustCall(function() { + assert(stderr.match(new RegExp( + 'Warning: Ignoring extra certs from.*no-such-file-exists' + + '.* load failed:.*No such file or directory' + )), stderr); + })) + .stderr.setEncoding('utf8').on('data', function(str) { + stderr += str; + }); diff --git a/test/parallel/test-tls-env-extra-ca.js b/test/parallel/test-tls-env-extra-ca.js new file mode 100644 index 00000000000000..12e3272bd401a2 --- /dev/null +++ b/test/parallel/test-tls-env-extra-ca.js @@ -0,0 +1,45 @@ +// Certs in NODE_EXTRA_CA_CERTS are used for TLS peer validation + +'use strict'; +const common = require('../common'); + +if (!common.hasCrypto) { + common.skip('missing crypto'); + return; +} + +const assert = require('assert'); +const tls = require('tls'); +const fork = require('child_process').fork; +const fs = require('fs'); + +if (process.env.CHILD) { + const copts = { + port: process.env.PORT, + checkServerIdentity: function() {}, + }; + const client = tls.connect(copts, function() { + client.end('hi'); + }); + return; +} + +const options = { + key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), + cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), +}; + +const server = tls.createServer(options, function(s) { + s.end('bye'); + server.close(); +}).listen(0, common.mustCall(function() { + const env = { + CHILD: 'yes', + PORT: this.address().port, + NODE_EXTRA_CA_CERTS: common.fixturesDir + '/keys/ca1-cert.pem', + }; + + fork(__filename, {env: env}).on('exit', common.mustCall(function(status) { + assert.equal(status, 0, 'client did not succeed in connecting'); + })); +})); From 0b2d0eb854876c218840b28dae6fc045e9864393 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Tue, 24 Jan 2017 13:15:28 -0800 Subject: [PATCH 116/116] fixup! crypto: allow adding extra certs to well-known CAs --- doc/api/cli.md | 4 ++-- src/node_crypto.cc | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index fbe44500ef0f97..b64cf55e849b3d 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -232,8 +232,8 @@ added: XXX 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 +certificates in PEM format. A message will be printed to stderr (once) +if the file is missing or misformatted, but any errors are otherwise ignored. Note that neither the well known nor extra certificates are used when the `ca` diff --git a/src/node_crypto.cc b/src/node_crypto.cc index e74e838cd650b8..e58b0bc25bb65b 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -822,10 +822,10 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo& args) { root_cert_store, extra_root_certs_file.c_str()); if (err) { - ProcessEmitWarning(sc->env(), - "Ignoring extra certs from `%s`, load failed: %s\n", - extra_root_certs_file.c_str(), - ERR_error_string(err, nullptr)); + fprintf(stderr, + "Warning: Ignoring extra certs from `%s`, load failed: %s\n", + extra_root_certs_file.c_str(), + ERR_error_string(err, nullptr)); } } }