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

Commit

Permalink
Merge nodejs/master
Browse files Browse the repository at this point in the history
Merge 5100cc6 as of 2017-07-04.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
kfarnung committed Jul 7, 2017
2 parents 98b06ae + 5100cc6 commit 0b3e40c
Show file tree
Hide file tree
Showing 406 changed files with 1,327 additions and 2,049 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ rules:
no-delete-var: 2
no-undef: 2
no-unused-vars: [2, {args: none}]
no-use-before-define: [2, {classes: true,
functions: false,
variables: false}]

# Node.js and CommonJS
# http://eslint.org/docs/rules/#nodejs-and-commonjs
Expand Down
4 changes: 1 addition & 3 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ console.log('count:', count);
// Prints: count: 5, to stdout
```

If formatting elements (e.g. `%d`) are not found in the first string then
[`util.inspect()`][] is called on each argument and the resulting string
values are concatenated. See [`util.format()`][] for more information.
See [`util.format()`][] for more information.

### console.time(label)
<!-- YAML
Expand Down
4 changes: 2 additions & 2 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -1643,8 +1643,8 @@ added: v1.1.0
- `key` {string} A PEM encoded private key.
- `passphrase` {string} An optional passphrase for the private key.
- `padding` {crypto.constants} An optional padding value defined in
`crypto.constants`, which may be: `crypto.constants.RSA_NO_PADDING`,
`RSA_PKCS1_PADDING`, or `crypto.constants.RSA_PKCS1_OAEP_PADDING`.
`crypto.constants`, which may be: `crypto.constants.RSA_NO_PADDING` or
`RSA_PKCS1_PADDING`.
- `buffer` {Buffer | TypedArray | DataView}

Decrypts `buffer` with `publicKey`.
Expand Down
11 changes: 6 additions & 5 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,17 @@ util.format('%s:%s', 'foo');
// Returns: 'foo:%s'
```

If there are more arguments passed to the `util.format()` method than the
number of placeholders, the extra arguments are coerced into strings (for
objects and symbols, `util.inspect()` is used) then concatenated to the
returned string, each delimited by a space.
If there are more arguments passed to the `util.format()` method than the number
of placeholders, the extra arguments are coerced into strings then concatenated
to the returned string, each delimited by a space. Excessive arguments whose
`typeof` is `'object'` or `'symbol'` (except `null`) will be transformed by
`util.inspect()`.

```js
util.format('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'
```

If the first argument is not a format string then `util.format()` returns
If the first argument is not a string then `util.format()` returns
a string that is the concatenation of all arguments separated by spaces.
Each argument is converted to a string using `util.inspect()`.

Expand Down
37 changes: 19 additions & 18 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/*legacy*/,
} else if (sockLen < this.maxSockets) {
debug('call onSocket', sockLen, freeLen);
// If we are under maxSockets create a new one.
this.createSocket(req, options, function(err, newSocket) {
if (err) {
nextTick(newSocket._handle.getAsyncId(), function() {
req.emit('error', err);
});
return;
}
req.onSocket(newSocket);
});
this.createSocket(req, options, handleSocketCreation(req, true));
} else {
debug('wait for socket');
// We are over limit so we'll add it to the queue.
Expand Down Expand Up @@ -222,6 +214,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
const newSocket = self.createConnection(options, oncreate);
if (newSocket)
oncreate(null, newSocket);

function oncreate(err, s) {
if (called)
return;
Expand Down Expand Up @@ -294,15 +287,7 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
debug('removeSocket, have a request, make a socket');
var req = this.requests[name][0];
// If we have pending requests and a socket gets closed make a new one
this.createSocket(req, options, function(err, newSocket) {
if (err) {
nextTick(newSocket._handle.getAsyncId(), function() {
req.emit('error', err);
});
return;
}
newSocket.emit('free');
});
this.createSocket(req, options, handleSocketCreation(req, false));
}
};

Expand Down Expand Up @@ -332,6 +317,22 @@ Agent.prototype.destroy = function destroy() {
}
};

function handleSocketCreation(request, informRequest) {
return function handleSocketCreation_Inner(err, socket) {
if (err) {
const asyncId = (socket && socket._handle && socket._handle.getAsyncId) ?
socket._handle.getAsyncId() :
null;
nextTick(asyncId, () => request.emit('error', err));
return;
}
if (informRequest)
request.onSocket(socket);
else
socket.emit('free');
};
}

module.exports = {
Agent,
globalAgent: new Agent()
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function writeHead(statusCode, reason, obj) {
statusCode |= 0;
if (statusCode < 100 || statusCode > 999) {
throw new errors.RangeError('ERR_HTTP_INVALID_STATUS_CODE',
originalStatusCode);
originalStatusCode);
}


Expand Down
212 changes: 106 additions & 106 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,112 @@ class URLContext {
}
}

class URLSearchParams {
// URL Standard says the default value is '', but as undefined and '' have
// the same result, undefined is used to prevent unnecessary parsing.
// Default parameter is necessary to keep URLSearchParams.length === 0 in
// accordance with Web IDL spec.
constructor(init = undefined) {
if (init === null || init === undefined) {
this[searchParams] = [];
} else if ((typeof init === 'object' && init !== null) ||
typeof init === 'function') {
const method = init[Symbol.iterator];
if (method === this[Symbol.iterator]) {
// While the spec does not have this branch, we can use it as a
// shortcut to avoid having to go through the costly generic iterator.
const childParams = init[searchParams];
this[searchParams] = childParams.slice();
} else if (method !== null && method !== undefined) {
if (typeof method !== 'function') {
throw new errors.TypeError('ERR_ARG_NOT_ITERABLE', 'Query pairs');
}

// sequence<sequence<USVString>>
// Note: per spec we have to first exhaust the lists then process them
const pairs = [];
for (const pair of init) {
if ((typeof pair !== 'object' && typeof pair !== 'function') ||
pair === null ||
typeof pair[Symbol.iterator] !== 'function') {
throw new errors.TypeError('ERR_INVALID_TUPLE', 'Each query pair',
'[name, value]');
}
const convertedPair = [];
for (const element of pair)
convertedPair.push(toUSVString(element));
pairs.push(convertedPair);
}

this[searchParams] = [];
for (const pair of pairs) {
if (pair.length !== 2) {
throw new errors.TypeError('ERR_INVALID_TUPLE', 'Each query pair',
'[name, value]');
}
this[searchParams].push(pair[0], pair[1]);
}
} else {
// record<USVString, USVString>
// Need to use reflection APIs for full spec compliance.
this[searchParams] = [];
const keys = Reflect.ownKeys(init);
for (var i = 0; i < keys.length; i++) {
const key = keys[i];
const desc = Reflect.getOwnPropertyDescriptor(init, key);
if (desc !== undefined && desc.enumerable) {
const typedKey = toUSVString(key);
const typedValue = toUSVString(init[key]);
this[searchParams].push(typedKey, typedValue);
}
}
}
} else {
// USVString
init = toUSVString(init);
if (init[0] === '?') init = init.slice(1);
initSearchParams(this, init);
}

// "associated url object"
this[context] = null;
}

[util.inspect.custom](recurseTimes, ctx) {
if (!this || !this[searchParams] || this[searchParams][searchParams]) {
throw new errors.TypeError('ERR_INVALID_THIS', 'URLSearchParams');
}

if (typeof recurseTimes === 'number' && recurseTimes < 0)
return ctx.stylize('[Object]', 'special');

var separator = ', ';
var innerOpts = Object.assign({}, ctx);
if (recurseTimes !== null) {
innerOpts.depth = recurseTimes - 1;
}
var innerInspect = (v) => util.inspect(v, innerOpts);

var list = this[searchParams];
var output = [];
for (var i = 0; i < list.length; i += 2)
output.push(`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`);

var colorRe = /\u001b\[\d\d?m/g;
var length = output.reduce(
(prev, cur) => prev + cur.replace(colorRe, '').length + separator.length,
-separator.length
);
if (length > ctx.breakLength) {
return `${this.constructor.name} {\n ${output.join(',\n ')} }`;
} else if (output.length) {
return `${this.constructor.name} { ${output.join(separator)} }`;
} else {
return `${this.constructor.name} {}`;
}
}
}

function onParseComplete(flags, protocol, username, password,
host, port, path, query, fragment) {
var ctx = this[context];
Expand Down Expand Up @@ -806,112 +912,6 @@ function defineIDLClass(proto, classStr, obj) {
}
}

class URLSearchParams {
// URL Standard says the default value is '', but as undefined and '' have
// the same result, undefined is used to prevent unnecessary parsing.
// Default parameter is necessary to keep URLSearchParams.length === 0 in
// accordance with Web IDL spec.
constructor(init = undefined) {
if (init === null || init === undefined) {
this[searchParams] = [];
} else if ((typeof init === 'object' && init !== null) ||
typeof init === 'function') {
const method = init[Symbol.iterator];
if (method === this[Symbol.iterator]) {
// While the spec does not have this branch, we can use it as a
// shortcut to avoid having to go through the costly generic iterator.
const childParams = init[searchParams];
this[searchParams] = childParams.slice();
} else if (method !== null && method !== undefined) {
if (typeof method !== 'function') {
throw new errors.TypeError('ERR_ARG_NOT_ITERABLE', 'Query pairs');
}

// sequence<sequence<USVString>>
// Note: per spec we have to first exhaust the lists then process them
const pairs = [];
for (const pair of init) {
if ((typeof pair !== 'object' && typeof pair !== 'function') ||
pair === null ||
typeof pair[Symbol.iterator] !== 'function') {
throw new errors.TypeError('ERR_INVALID_TUPLE', 'Each query pair',
'[name, value]');
}
const convertedPair = [];
for (const element of pair)
convertedPair.push(toUSVString(element));
pairs.push(convertedPair);
}

this[searchParams] = [];
for (const pair of pairs) {
if (pair.length !== 2) {
throw new errors.TypeError('ERR_INVALID_TUPLE', 'Each query pair',
'[name, value]');
}
this[searchParams].push(pair[0], pair[1]);
}
} else {
// record<USVString, USVString>
// Need to use reflection APIs for full spec compliance.
this[searchParams] = [];
const keys = Reflect.ownKeys(init);
for (var i = 0; i < keys.length; i++) {
const key = keys[i];
const desc = Reflect.getOwnPropertyDescriptor(init, key);
if (desc !== undefined && desc.enumerable) {
const typedKey = toUSVString(key);
const typedValue = toUSVString(init[key]);
this[searchParams].push(typedKey, typedValue);
}
}
}
} else {
// USVString
init = toUSVString(init);
if (init[0] === '?') init = init.slice(1);
initSearchParams(this, init);
}

// "associated url object"
this[context] = null;
}

[util.inspect.custom](recurseTimes, ctx) {
if (!this || !this[searchParams] || this[searchParams][searchParams]) {
throw new errors.TypeError('ERR_INVALID_THIS', 'URLSearchParams');
}

if (typeof recurseTimes === 'number' && recurseTimes < 0)
return ctx.stylize('[Object]', 'special');

var separator = ', ';
var innerOpts = Object.assign({}, ctx);
if (recurseTimes !== null) {
innerOpts.depth = recurseTimes - 1;
}
var innerInspect = (v) => util.inspect(v, innerOpts);

var list = this[searchParams];
var output = [];
for (var i = 0; i < list.length; i += 2)
output.push(`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`);

var colorRe = /\u001b\[\d\d?m/g;
var length = output.reduce(
(prev, cur) => prev + cur.replace(colorRe, '').length + separator.length,
-separator.length
);
if (length > ctx.breakLength) {
return `${this.constructor.name} {\n ${output.join(',\n ')} }`;
} else if (output.length) {
return `${this.constructor.name} { ${output.join(separator)} }`;
} else {
return `${this.constructor.name} {}`;
}
}
}

// for merge sort
function merge(out, start, mid, end, lBuffer, rBuffer) {
const sizeLeft = mid - start;
Expand Down
3 changes: 2 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ function complete(line, callback) {
var completeOn, i, group, c;

// REPL commands (e.g. ".break").
var filter;
var match = null;
match = line.match(/^\s*\.(\w*)$/);
if (match) {
Expand All @@ -759,7 +760,7 @@ function complete(line, callback) {

completeOn = match[1];
var subdir = match[2] || '';
var filter = match[1];
filter = match[1];
var dir, files, f, name, base, ext, abs, subfiles, s;
group = [];
var paths = module.paths.concat(require('module').globalPaths);
Expand Down
8 changes: 3 additions & 5 deletions test/abort/test-abort-backtrace.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';
const common = require('../common');
if (common.isWindows)
common.skip('Backtraces unimplemented on Windows.');

const assert = require('assert');
const cp = require('child_process');

if (common.isWindows) {
common.skip('Backtraces unimplemented on Windows.');
return;
}

if (process.argv[2] === 'child') {
process.abort();
} else {
Expand Down
Loading

0 comments on commit 0b3e40c

Please sign in to comment.