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 fe4675b as of 2017-10-21.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
chakrabot committed Oct 26, 2017
2 parents 559f7cf + fe4675b commit 0fa8358
Show file tree
Hide file tree
Showing 28 changed files with 482 additions and 140 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ who you are:
$ git config --global user.name "J. Random User"
$ git config --global user.email "[email protected]"
```
Please make sure this local email is also added to your
[GitHub email list](https://github.com/settings/emails) so that your commits
will be properly associated with your account and you will be promoted
to Contributor once your first commit is landed.

#### Step 1: Fork

Expand Down
14 changes: 10 additions & 4 deletions benchmark/misc/punycode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';

const common = require('../common.js');
const icu = process.binding('icu');
let icu;
try {
icu = process.binding('icu');
} catch (err) {}
const punycode = require('punycode');

const bench = common.createBenchmark(main, {
method: ['punycode', 'icu'],
method: ['punycode'].concat(icu !== undefined ? ['icu'] : []),
n: [1024],
val: [
'افغانستا.icom.museum',
Expand Down Expand Up @@ -69,8 +72,11 @@ function main(conf) {
runPunycode(n, val);
break;
case 'icu':
runICU(n, val);
break;
if (icu !== undefined) {
runICU(n, val);
break;
}
// fallthrough
default:
throw new Error('Unexpected method');
}
Expand Down
6 changes: 3 additions & 3 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@
'EnableFunctionLevelLinking': 'true',
'EnableIntrinsicFunctions': 'true',
'RuntimeTypeInfo': 'false',
'AdditionalOptions': [
'/MP', # compile across multiple CPUs
],
},
'VCLibrarianTool': {
'AdditionalOptions': [
Expand Down Expand Up @@ -257,6 +254,9 @@
# and their sheer number drowns out other, more legitimate warnings.
'DisableSpecificWarnings': ['4267'],
'WarnAsError': 'false',
'AdditionalOptions': [
'/MP', # compile across multiple CPUs
],
},
'VCLibrarianTool': {
},
Expand Down
2 changes: 1 addition & 1 deletion doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,6 @@ constructor.

[`after` callback]: #async_hooks_after_asyncid
[`before` callback]: #async_hooks_before_asyncid
[`destroy` callback]: #async_hooks_before_asyncid
[`destroy` callback]: #async_hooks_destroy_asyncid
[`init` callback]: #async_hooks_init_asyncid_type_triggerasyncid_resource
[Hook Callbacks]: #async_hooks_hook_callbacks
18 changes: 13 additions & 5 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -1437,9 +1437,12 @@ user programs.
added: v8.0.0
-->

* `err` {Error} An error.
* `callback` {Function} A callback function that takes an optional error argument
which is invoked when the writable is destroyed.
* `err` {Error} A possible error.
* `callback` {Function} A callback function that takes an optional error
argument.

The `_destroy()` method is called by [`writable.destroy()`][writable-destroy].
It can be overriden by child classes but it **must not** be called directly.

#### writable.\_final(callback)
<!-- YAML
Expand Down Expand Up @@ -1606,9 +1609,12 @@ user programs.
added: v8.0.0
-->

* `err` {Error} An error.
* `err` {Error} A possible error.
* `callback` {Function} A callback function that takes an optional error
argument which is invoked when the readable is destroyed.
argument.

The `_destroy()` method is called by [`readable.destroy()`][readable-destroy].
It can be overriden by child classes but it **must not** be called directly.

#### readable.push(chunk[, encoding])
<!-- YAML
Expand Down Expand Up @@ -2232,4 +2238,6 @@ contain multi-byte characters.
[stream-resume]: #stream_readable_resume
[stream-write]: #stream_writable_write_chunk_encoding_callback
[readable-_destroy]: #stream_readable_destroy_err_callback
[readable-destroy]: #stream_readable_destroy_error
[writable-_destroy]: #stream_writable_destroy_err_callback
[writable-destroy]: #stream_writable_destroy_error
5 changes: 2 additions & 3 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,8 @@ TLSSocket.prototype._init = function(socket, wrap) {
var ssl = this._handle;

// lib/net.js expect this value to be non-zero if write hasn't been flushed
// immediately
// TODO(indutny): revise this solution, it might be 1 before handshake and
// represent real writeQueueSize during regular writes.
// immediately. After the handshake is done this will represent the actual
// write queue size
ssl.writeQueueSize = 1;

this.server = options.server;
Expand Down
124 changes: 53 additions & 71 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'use strict';

var domain;
var spliceOne;

function EventEmitter() {
EventEmitter.init.call(this);
Expand Down Expand Up @@ -54,9 +55,6 @@ Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
return defaultMaxListeners;
},
set: function(arg) {
// force global console to be compiled.
// see https://github.com/nodejs/node/issues/4467
console;
// check whether the input is a positive number (whose value is zero or
// greater and not a NaN).
if (typeof arg !== 'number' || arg < 0 || arg !== arg) {
Expand All @@ -77,7 +75,8 @@ EventEmitter.init = function() {
}
}

if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
if (this._events === undefined ||
this._events === Object.getPrototypeOf(this)._events) {
this._events = Object.create(null);
this._eventsCount = 0;
}
Expand Down Expand Up @@ -163,24 +162,23 @@ function emitMany(handler, isFn, self, args) {
}
}

EventEmitter.prototype.emit = function emit(type) {
var er, handler, len, args, i, events, domain;
var needDomainExit = false;
var doError = (type === 'error');
EventEmitter.prototype.emit = function emit(type, ...args) {
let doError = (type === 'error');

events = this._events;
if (events)
doError = (doError && events.error == null);
const events = this._events;
if (events !== undefined)
doError = (doError && events.error === undefined);
else if (!doError)
return false;

domain = this.domain;
const domain = this.domain;

// If there is no 'error' event listener then throw.
if (doError) {
if (arguments.length > 1)
er = arguments[1];
if (domain) {
let er;
if (args.length > 0)
er = args[0];
if (domain !== null && domain !== undefined) {
if (!er) {
const errors = lazyErrors();
er = new errors.Error('ERR_UNHANDLED_ERROR');
Expand All @@ -203,37 +201,32 @@ EventEmitter.prototype.emit = function emit(type) {
return false;
}

handler = events[type];
const handler = events[type];

if (!handler)
if (handler === undefined)
return false;

if (domain && this !== process) {
let needDomainExit = false;
if (domain !== null && domain !== undefined && this !== process) {
domain.enter();
needDomainExit = true;
}

var isFn = typeof handler === 'function';
len = arguments.length;
switch (len) {
// fast cases
case 1:
const isFn = typeof handler === 'function';
switch (args.length) {
case 0:
emitNone(handler, isFn, this);
break;
case 1:
emitOne(handler, isFn, this, args[0]);
break;
case 2:
emitOne(handler, isFn, this, arguments[1]);
emitTwo(handler, isFn, this, args[0], args[1]);
break;
case 3:
emitTwo(handler, isFn, this, arguments[1], arguments[2]);
emitThree(handler, isFn, this, args[0], args[1], args[2]);
break;
case 4:
emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
break;
// slower
default:
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
emitMany(handler, isFn, this, args);
}

Expand All @@ -254,13 +247,13 @@ function _addListener(target, type, listener, prepend) {
}

events = target._events;
if (!events) {
if (events === undefined) {
events = target._events = Object.create(null);
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (events.newListener) {
if (events.newListener !== undefined) {
target.emit('newListener', type,
listener.listener ? listener.listener : listener);

Expand All @@ -271,7 +264,7 @@ function _addListener(target, type, listener, prepend) {
existing = events[type];
}

if (!existing) {
if (existing === undefined) {
// Optimize the case of one listener. Don't need the extra array object.
existing = events[type] = listener;
++target._eventsCount;
Expand Down Expand Up @@ -335,10 +328,7 @@ function onceWrapper() {
return this.listener.call(this.target, arguments[0], arguments[1],
arguments[2]);
default:
const args = new Array(arguments.length);
for (var i = 0; i < args.length; ++i)
args[i] = arguments[i];
this.listener.apply(this.target, args);
this.listener.apply(this.target, arguments);
}
}
}
Expand Down Expand Up @@ -383,11 +373,11 @@ EventEmitter.prototype.removeListener =
}

events = this._events;
if (!events)
if (events === undefined)
return this;

list = events[type];
if (!list)
if (list === undefined)
return this;

if (list === listener || list.listener === listener) {
Expand All @@ -414,13 +404,16 @@ EventEmitter.prototype.removeListener =

if (position === 0)
list.shift();
else
else {
if (spliceOne === undefined)
spliceOne = require('internal/util').spliceOne;
spliceOne(list, position);
}

if (list.length === 1)
events[type] = list[0];

if (events.removeListener)
if (events.removeListener !== undefined)
this.emit('removeListener', type, originalListener || listener);
}

Expand All @@ -432,15 +425,15 @@ EventEmitter.prototype.removeAllListeners =
var listeners, events, i;

events = this._events;
if (!events)
if (events === undefined)
return this;

// not listening for removeListener, no need to emit
if (!events.removeListener) {
if (events.removeListener === undefined) {
if (arguments.length === 0) {
this._events = Object.create(null);
this._eventsCount = 0;
} else if (events[type]) {
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else
Expand Down Expand Up @@ -468,7 +461,7 @@ EventEmitter.prototype.removeAllListeners =

if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (listeners) {
} else if (listeners !== undefined) {
// LIFO order
for (i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type, listeners[i]);
Expand All @@ -479,23 +472,19 @@ EventEmitter.prototype.removeAllListeners =
};

EventEmitter.prototype.listeners = function listeners(type) {
var evlistener;
var ret;
var events = this._events;
const events = this._events;

if (!events)
ret = [];
else {
evlistener = events[type];
if (!evlistener)
ret = [];
else if (typeof evlistener === 'function')
ret = [evlistener.listener || evlistener];
else
ret = unwrapListeners(evlistener);
}
if (events === undefined)
return [];

return ret;
const evlistener = events[type];
if (evlistener === undefined)
return [];

if (typeof evlistener === 'function')
return [evlistener.listener || evlistener];

return unwrapListeners(evlistener);
};

EventEmitter.listenerCount = function(emitter, type) {
Expand All @@ -510,12 +499,12 @@ EventEmitter.prototype.listenerCount = listenerCount;
function listenerCount(type) {
const events = this._events;

if (events) {
if (events !== undefined) {
const evlistener = events[type];

if (typeof evlistener === 'function') {
return 1;
} else if (evlistener) {
} else if (evlistener !== undefined) {
return evlistener.length;
}
}
Expand All @@ -527,13 +516,6 @@ EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
};

// About 1.5x faster than the two-arg version of Array#splice().
function spliceOne(list, index) {
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
list[i] = list[k];
list.pop();
}

function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
Expand Down
Loading

0 comments on commit 0fa8358

Please sign in to comment.