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 95bbb68 as of 2017-08-13.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
chakrabot authored and MSLaguana committed Aug 17, 2017
2 parents 5aa5042 + 95bbb68 commit 8b9f135
Show file tree
Hide file tree
Showing 26 changed files with 1,861 additions and 1,597 deletions.
47 changes: 47 additions & 0 deletions benchmark/http2/headers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

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

var bench = common.createBenchmark(main, {
n: [1e3],
nheaders: [100, 1000],
}, { flags: ['--expose-http2', '--no-warnings'] });

function main(conf) {
const n = +conf.n;
const nheaders = +conf.nheaders;
const http2 = require('http2');
const server = http2.createServer();

const headersObject = { ':path': '/' };
for (var i = 0; i < nheaders; i++) {
headersObject[`foo${i}`] = `some header value ${i}`;
}

server.on('stream', (stream) => {
stream.respond();
stream.end('Hi!');
});
server.listen(PORT, () => {
const client = http2.connect(`http://localhost:${PORT}/`);

function doRequest(remaining) {
const req = client.request(headersObject);
req.end();
req.on('data', () => {});
req.on('end', () => {
if (remaining > 0) {
doRequest(remaining - 1);
} else {
bench.end(n);
server.close();
client.destroy();
}
});
}

bench.start();
doRequest(n);
});
}
39 changes: 39 additions & 0 deletions benchmark/util/inspect-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

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

const bench = common.createBenchmark(main, {
n: [1e2],
len: [1e5],
type: [
'denseArray',
'sparseArray',
'mixedArray'
]
});

function main(conf) {
const { n, len, type } = conf;
var arr = Array(len);
var i;

switch (type) {
case 'denseArray':
arr = arr.fill(0);
break;
case 'sparseArray':
break;
case 'mixedArray':
for (i = 0; i < n; i += 2)
arr[i] = i;
break;
default:
throw new Error(`Unsupported type ${type}`);
}
bench.start();
for (i = 0; i < n; i++) {
util.inspect(arr);
}
bench.end(n);
}
3 changes: 3 additions & 0 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,9 @@ changes:
Returns a new `Buffer` that references the same memory as the original, but
offset and cropped by the `start` and `end` indices.

Specifying `end` greater than [`buf.length`] will return the same result as
that of `end` equal to [`buf.length`].

*Note*: Modifying the new `Buffer` slice will modify the memory in the
original `Buffer` because the allocated memory of the two objects overlap.

Expand Down
31 changes: 31 additions & 0 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,35 @@ callback invocation, even if it has been successfully cancelled.

## Version Management

### napi_get_node_version
<!-- YAML
added: REPLACEME
-->

```C
typedef struct {
uint32_t major;
uint32_t minor;
uint32_t patch;
const char* release;
} napi_node_version;

NAPI_EXTERN
napi_status napi_get_node_version(napi_env env,
const napi_node_version** version);
```
- `[in] env`: The environment that the API is invoked under.
- `[out] version`: A pointer to version information for Node itself.
Returns `napi_ok` if the API succeeded.
This function fills the `version` struct with the major, minor and patch version
of Node that is currently running, and the `release` field with the
value of [`process.release.name`][`process.release`].
The returned buffer is statically allocated and does not need to be freed.
### napi_get_version
<!-- YAML
added: v8.0.0
Expand Down Expand Up @@ -3368,3 +3397,5 @@ support it:
[`napi_throw_type_error`]: #n_api_napi_throw_type_error
[`napi_unwrap`]: #n_api_napi_unwrap
[`napi_wrap`]: #n_api_napi_wrap

[`process.release`]: process.html#process_process_release
4 changes: 2 additions & 2 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ function setupChannel(target, channel) {
if (typeof callback === 'function') {
process.nextTick(callback, ex);
} else {
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
process.nextTick(() => this.emit('error', ex));
}
return false;
};
Expand Down Expand Up @@ -713,7 +713,7 @@ function setupChannel(target, channel) {
if (typeof callback === 'function') {
process.nextTick(callback, ex);
} else {
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
process.nextTick(() => this.emit('error', ex));
}
}
}
Expand Down
20 changes: 13 additions & 7 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ const kType = Symbol('type');
const kDefaultSocketTimeout = 2 * 60 * 1000;
const kRenegTest = /TLS session renegotiation disabled for this socket/;

const paddingBuffer = new Uint32Array(binding.paddingArrayBuffer);
const {
paddingBuffer,
PADDING_BUF_FRAME_LENGTH,
PADDING_BUF_MAX_PAYLOAD_LENGTH,
PADDING_BUF_RETURN_VALUE
} = binding;

const {
NGHTTP2_CANCEL,
Expand Down Expand Up @@ -393,12 +398,13 @@ function onSelectPadding(fn) {
'bug in Node.js');
return function getPadding() {
debug('fetching padding for frame');
const frameLen = paddingBuffer[0];
const maxFramePayloadLen = paddingBuffer[1];
paddingBuffer[2] = Math.min(maxFramePayloadLen,
Math.max(frameLen,
fn(frameLen,
maxFramePayloadLen) | 0));
const frameLen = paddingBuffer[PADDING_BUF_FRAME_LENGTH];
const maxFramePayloadLen = paddingBuffer[PADDING_BUF_MAX_PAYLOAD_LENGTH];
paddingBuffer[PADDING_BUF_RETURN_VALUE] =
Math.min(maxFramePayloadLen,
Math.max(frameLen,
fn(frameLen,
maxFramePayloadLen) | 0));
};
}

Expand Down
20 changes: 11 additions & 9 deletions lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,14 @@ const kNoPayloadMethods = new Set([
// the native side with values that are filled in on demand, the js code then
// reads those values out. The set of IDX constants that follow identify the
// relevant data positions within these buffers.
const settingsBuffer = new Uint32Array(binding.settingsArrayBuffer);
const optionsBuffer = new Uint32Array(binding.optionsArrayBuffer);
const { settingsBuffer, optionsBuffer } = binding;

// Note that Float64Array is used here because there is no Int64Array available
// and these deal with numbers that can be beyond the range of Uint32 and Int32.
// The values set on the native side will always be integers. This is not a
// unique example of this, this pattern can be found in use in other parts of
// Node.js core as a performance optimization.
const sessionState = new Float64Array(binding.sessionStateArrayBuffer);
const streamState = new Float64Array(binding.streamStateArrayBuffer);
const { sessionState, streamState } = binding;

const IDX_SETTINGS_HEADER_TABLE_SIZE = 0;
const IDX_SETTINGS_ENABLE_PUSH = 1;
Expand Down Expand Up @@ -375,7 +373,8 @@ function assertValidPseudoHeaderTrailer(key) {

function mapToHeaders(map,
assertValuePseudoHeader = assertValidPseudoHeader) {
const ret = [];
let ret = '';
let count = 0;
const keys = Object.keys(map);
const singles = new Set();
for (var i = 0; i < keys.length; i++) {
Expand All @@ -402,7 +401,8 @@ function mapToHeaders(map,
const err = assertValuePseudoHeader(key);
if (err !== undefined)
return err;
ret.unshift([key, String(value)]);
ret = `${key}\0${String(value)}\0${ret}`;
count++;
} else {
if (kSingleValueHeaders.has(key)) {
if (singles.has(key))
Expand All @@ -415,16 +415,18 @@ function mapToHeaders(map,
if (isArray) {
for (var k = 0; k < value.length; k++) {
val = String(value[k]);
ret.push([key, val]);
ret += `${key}\0${val}\0`;
}
count += value.length;
} else {
val = String(value);
ret.push([key, val]);
ret += `${key}\0${val}\0`;
count++;
}
}
}

return ret;
return [ret, count];
}

class NghttpError extends Error {
Expand Down
35 changes: 19 additions & 16 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ function complete(line, callback) {
completeOn = match[1];
var subdir = match[2] || '';
filter = match[1];
var dir, files, f, name, base, ext, abs, subfiles, s;
var dir, files, f, name, base, ext, abs, subfiles, s, isDirectory;
group = [];
let paths = [];

Expand Down Expand Up @@ -851,23 +851,26 @@ function complete(line, callback) {
// Exclude versioned names that 'npm' installs.
continue;
}
if (exts.indexOf(ext) !== -1) {
if (!subdir || base !== 'index') {
group.push(subdir + base);
}
} else {
abs = path.resolve(dir, name);
abs = path.resolve(dir, name);
try {
isDirectory = fs.statSync(abs).isDirectory();
} catch (e) {
continue;
}
if (isDirectory) {
group.push(subdir + name + '/');
try {
if (fs.statSync(abs).isDirectory()) {
group.push(subdir + name + '/');
subfiles = fs.readdirSync(abs);
for (s = 0; s < subfiles.length; s++) {
if (indexRe.test(subfiles[s])) {
group.push(subdir + name);
}
}
subfiles = fs.readdirSync(abs);
} catch (e) {
continue;
}
for (s = 0; s < subfiles.length; s++) {
if (indexRe.test(subfiles[s])) {
group.push(subdir + name);
}
} catch (e) {}
}
} else if (exts.includes(ext) && (!subdir || base !== 'index')) {
group.push(subdir + base);
}
}
}
Expand Down
44 changes: 26 additions & 18 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const inspectDefaultOptions = Object.seal({

const numbersOnlyRE = /^\d+$/;

const objectHasOwnProperty = Object.prototype.hasOwnProperty;
const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
const regExpToString = RegExp.prototype.toString;
const dateToISOString = Date.prototype.toISOString;
Expand Down Expand Up @@ -683,22 +682,36 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
var output = [];
let visibleLength = 0;
let index = 0;
while (index < value.length && visibleLength < ctx.maxArrayLength) {
let emptyItems = 0;
while (index < value.length && !hasOwnProperty(value, String(index))) {
emptyItems++;
index++;
}
if (emptyItems > 0) {
for (const elem of keys) {
if (visibleLength === ctx.maxArrayLength)
break;
// Symbols might have been added to the keys
if (typeof elem !== 'string')
continue;
const i = +elem;
if (index !== i) {
// Skip zero and negative numbers as well as non numbers
if (i > 0 === false)
continue;
const emptyItems = i - index;
const ending = emptyItems > 1 ? 's' : '';
const message = `<${emptyItems} empty item${ending}>`;
output.push(ctx.stylize(message, 'undefined'));
} else {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
String(index), true));
index++;
index = i;
if (++visibleLength === ctx.maxArrayLength)
break;
}
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
elem, true));
visibleLength++;
index++;
}
if (index < value.length && visibleLength !== ctx.maxArrayLength) {
const len = value.length - index;
const ending = len > 1 ? 's' : '';
const message = `<${len} empty item${ending}>`;
output.push(ctx.stylize(message, 'undefined'));
index = value.length;
}
var remaining = value.length - index;
if (remaining > 0) {
Expand Down Expand Up @@ -814,7 +827,7 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
str = ctx.stylize('[Setter]', 'special');
}
}
if (!hasOwnProperty(visibleKeys, key)) {
if (visibleKeys[key] === undefined) {
if (typeof key === 'symbol') {
name = `[${ctx.stylize(key.toString(), 'symbol')}]`;
} else {
Expand Down Expand Up @@ -993,11 +1006,6 @@ function _extend(target, source) {
return target;
}

function hasOwnProperty(obj, prop) {
return objectHasOwnProperty.call(obj, prop);
}


// Deprecated old stuff.

function print(...args) {
Expand Down
Loading

0 comments on commit 8b9f135

Please sign in to comment.