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

Commit

Permalink
meta: merge node/master into node-chakracore/master
Browse files Browse the repository at this point in the history
Merge 4117e22 as of 2017-12-29
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Taylor Woll <tawoll@ntdev.microsoft.com>
  • Loading branch information
chakrabot committed Jan 20, 2018
2 parents 159dcd5 + 4117e22 commit 967a8d2
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 54 deletions.
6 changes: 4 additions & 2 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ added: v0.9.12
The number of milliseconds of inactivity before a socket is presumed
to have timed out.

A value of 0 will disable the timeout behavior on incoming connections.
A value of `0` will disable the timeout behavior on incoming connections.

*Note*: The socket timeout logic is set up on connection, so changing this
value only affects new connections to the server, not any existing connections.
Expand All @@ -929,7 +929,9 @@ will be destroyed. If the server receives new data before the keep-alive
timeout has fired, it will reset the regular inactivity timeout, i.e.,
[`server.timeout`][].

A value of 0 will disable the keep-alive timeout behavior on incoming connections.
A value of `0` will disable the keep-alive timeout behavior on incoming connections.
A value of `0` makes the http server behave similarly to Node.js versions prior to 8.0.0,
which did not have a keep-alive timeout.

*Note*: The socket timeout logic is set up on connection, so changing this
value only affects new connections to the server, not any existing connections.
Expand Down
10 changes: 9 additions & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,15 @@ assert.ifError = function ifError(err) { if (err) throw err; };

// Expose a strict only variant of assert
function strict(value, message) {
if (!value) innerFail(value, true, message, '==', strict);
if (!value) {
innerFail({
actual: value,
expected: true,
message,
operator: '==',
stackStartFn: strict
});
}
}
assert.strict = Object.assign(strict, assert, {
equal: assert.strictEqual,
Expand Down
11 changes: 6 additions & 5 deletions lib/internal/http.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
'use strict';

const timers = require('timers');
const { setUnrefTimeout } = require('internal/timers');

var dateCache;
function utcDate() {
if (!dateCache) {
const d = new Date();
dateCache = d.toUTCString();
timers.enroll(utcDate, 1000 - d.getMilliseconds());
timers._unrefActive(utcDate);

setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
}
return dateCache;
}
utcDate._onTimeout = function() {

function resetCache() {
dateCache = undefined;
};
}

function ondrain() {
if (this._httpMessage) this._httpMessage.emit('drain');
Expand Down
13 changes: 6 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,12 @@ function error(...args) {
}

function _errnoException(err, syscall, original) {
if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err',
'negative number');
if (typeof err !== 'number') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', 'number', err);
}
if (err >= 0 || !Number.isSafeInteger(err)) {
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'err',
'a negative integer', err);
}
const name = errname(err);
var message = `${syscall} ${name}`;
Expand Down Expand Up @@ -1093,10 +1096,6 @@ function _exceptionWithHostPort(err,
return ex;
}

// process.versions needs a custom function as some values are lazy-evaluated.
process.versions[inspect.custom] =
() => exports.format(JSON.parse(JSON.stringify(process.versions)));

function callbackifyOnRejected(reason, cb) {
// `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
// Because `null` is a special error value in callbacks which means "no error
Expand Down
49 changes: 25 additions & 24 deletions test/parallel/test-accessor-properties.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
const common = require('../common');

// This tests that the accessor properties do not raise assertions
// when called with incompatible receivers.
Expand All @@ -12,9 +12,6 @@ const assert = require('assert');
const TTY = process.binding('tty_wrap').TTY;
const UDP = process.binding('udp_wrap').UDP;

// There are accessor properties in crypto too
const crypto = process.binding('crypto');

{
// Should throw instead of raise assertions
assert.throws(() => {
Expand All @@ -33,15 +30,6 @@ const crypto = process.binding('crypto');
UDP.prototype.fd;
}, TypeError);

assert.throws(() => {
crypto.SecureContext.prototype._external;
}, TypeError);

assert.throws(() => {
crypto.Connection.prototype._external;
}, TypeError);


// Should not throw for Object.getOwnPropertyDescriptor
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(TTY.prototype, 'bytesRead'),
Expand All @@ -63,15 +51,28 @@ const crypto = process.binding('crypto');
'object'
);

assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(
crypto.SecureContext.prototype, '_external'),
'object'
);

assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(
crypto.Connection.prototype, '_external'),
'object'
);
if (common.hasCrypto) { // eslint-disable-line crypto-check
// There are accessor properties in crypto too
const crypto = process.binding('crypto');

assert.throws(() => {
crypto.SecureContext.prototype._external;
}, TypeError);

assert.throws(() => {
crypto.Connection.prototype._external;
}, TypeError);

assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(
crypto.SecureContext.prototype, '_external'),
'object'
);

assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(
crypto.Connection.prototype, '_external'),
'object'
);
}
}
8 changes: 8 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,14 @@ common.expectsError(
assert.equal(Object.keys(assert).length, Object.keys(a).length);
/* eslint-enable no-restricted-properties */
assert(7);
common.expectsError(
() => assert(),
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: 'undefined == true'
}
);
}

common.expectsError(
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-child-process-fork-net2.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ if (process.argv[2] === 'child') {
process.on('message', function(m, socket) {
if (!socket) return;

console.error('[%d] got socket', id, m);
console.error(`[${id}] got socket ${m}`);

// will call .end('end') or .write('write');
socket[m](m);

socket.resume();

socket.on('data', function() {
console.error('[%d] socket.data', id, m);
console.error(`[${id}] socket.data ${m}`);
});

socket.on('end', function() {
console.error('[%d] socket.end', id, m);
console.error(`[${id}] socket.end ${m}`);
});

// store the unfinished socket
Expand All @@ -54,27 +54,27 @@ if (process.argv[2] === 'child') {
}

socket.on('close', function(had_error) {
console.error('[%d] socket.close', id, had_error, m);
console.error(`[${id}] socket.close ${had_error} ${m}`);
});

socket.on('finish', function() {
console.error('[%d] socket finished', id, m);
console.error(`[${id}] socket finished ${m}`);
});
});

process.on('message', function(m) {
if (m !== 'close') return;
console.error('[%d] got close message', id);
console.error(`[${id}] got close message`);
needEnd.forEach(function(endMe, i) {
console.error('[%d] ending %d/%d', id, i, needEnd.length);
console.error(`[${id}] ending ${i}/${needEnd.length}`);
endMe.end('end');
});
});

process.on('disconnect', function() {
console.error('[%d] process disconnect, ending', id);
console.error(`[${id}] process disconnect, ending`);
needEnd.forEach(function(endMe, i) {
console.error('[%d] ending %d/%d', id, i, needEnd.length);
console.error(`[${id}] ending ${i}/${needEnd.length}`);
endMe.end('end');
});
});
Expand Down Expand Up @@ -107,7 +107,7 @@ if (process.argv[2] === 'child') {
connected += 1;

socket.once('close', function() {
console.log('[m] socket closed, total %d', ++closed);
console.log(`[m] socket closed, total ${++closed}`);
});

if (connected === count) {
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-http2-util-headers-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// to pass to the internal binding layer.

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { mapToHeaders } = require('internal/http2/util');

Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http2-util-update-options-buffer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Flags: --expose-internals
'use strict';

require('../common');
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

// Test coverage for the updateOptionsBuffer method used internally
// by the http2 implementation.
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ editor.completer('var log = console.l', common.mustCall((error, data) => {

['Let', 'Const', 'Klass'].forEach((type) => {
const query = `lexical${type[0]}`;
const expected = hasInspector ? [[`lexical${type}`], query] : [];
const expected = hasInspector ? [[`lexical${type}`], query] :
[[], `lexical${type[0]}`];
testRepl.complete(query, common.mustCall((error, data) => {
assert.deepStrictEqual(data, expected);
}));
Expand Down
17 changes: 15 additions & 2 deletions test/parallel/test-uv-errno.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ keys.forEach((key) => {
});
});

[0, 1, 'test', {}, [], Infinity, -Infinity, NaN].forEach((key) => {
['test', {}, []].forEach((key) => {
common.expectsError(
() => util._errnoException(key),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "err" argument must be of type negative number'
message: 'The "err" argument must be of type number. ' +
`Received type ${typeof key}`
});
});

[0, 1, Infinity, -Infinity, NaN].forEach((key) => {
common.expectsError(
() => util._errnoException(key),
{
code: 'ERR_OUT_OF_RANGE',
type: RangeError,
message: 'The value of "err" is out of range. ' +
'It must be a negative integer. ' +
`Received ${key}`
});
});
7 changes: 6 additions & 1 deletion tools/eslint-rules/crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ const utils = require('./rules-utils.js');
const msg = 'Please add a hasCrypto check to allow this test to be skipped ' +
'when Node is built "--without-ssl".';

const cryptoModules = ['crypto', 'http2'];
const requireModules = cryptoModules.concat(['tls', 'https']);
const bindingModules = cryptoModules.concat(['tls_wrap']);

module.exports = function(context) {
const missingCheckNodes = [];
const requireNodes = [];
var hasSkipCall = false;

function testCryptoUsage(node) {
if (utils.isRequired(node, ['crypto', 'tls', 'https', 'http2'])) {
if (utils.isRequired(node, requireModules) ||
utils.isBinding(node, bindingModules)) {
requireNodes.push(node);
}
}
Expand Down
12 changes: 12 additions & 0 deletions tools/eslint-rules/rules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ module.exports.isRequired = function(node, modules) {
modules.includes(node.arguments[0].value);
};

/**
* Returns true if any of the passed in modules are used in
* binding calls.
*/
module.exports.isBinding = function(node, modules) {
if (node.callee.object) {
return node.callee.object.name === 'process' &&
node.callee.property.name === 'binding' &&
modules.includes(node.arguments[0].value);
}
};

/**
* Returns true is the node accesses any property in the properties
* array on the 'common' object.
Expand Down

0 comments on commit 967a8d2

Please sign in to comment.