Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
chore(assign): replace assign with native Object.assign (#259)
Browse files Browse the repository at this point in the history
Fixes NODE-1227
  • Loading branch information
daprahamian authored Dec 18, 2017
1 parent 243e942 commit ec2b7a6
Show file tree
Hide file tree
Showing 26 changed files with 268 additions and 325 deletions.
3 changes: 1 addition & 2 deletions lib/connection/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var inherits = require('util').inherits,
f = require('util').format,
Query = require('./commands').Query,
CommandResult = require('./command_result'),
assign = require('../utils').assign,
MESSAGE_HEADER_SIZE = require('../wireprotocol/shared').MESSAGE_HEADER_SIZE,
opcodes = require('../wireprotocol/shared').opcodes,
compress = require('../wireprotocol/compression').compress,
Expand Down Expand Up @@ -80,7 +79,7 @@ var Pool = function(topology, options) {
this.topology = topology;

// Add the options
this.options = assign(
this.options = Object.assign(
{
// Host and port settings
host: 'localhost',
Expand Down
5 changes: 2 additions & 3 deletions lib/topologies/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var inherits = require('util').inherits,
ThreeTwoWireProtocolSupport = require('../wireprotocol/3_2_support'),
BasicCursor = require('../cursor'),
sdam = require('./shared'),
assign = require('../utils').assign,
createClientInfo = require('./shared').createClientInfo,
createCompressionInfo = require('./shared').createCompressionInfo,
resolveClusterTime = require('./shared').resolveClusterTime,
Expand Down Expand Up @@ -534,7 +533,7 @@ Server.prototype.connect = function(options) {
}

// Create a pool
self.s.pool = new Pool(this, assign(self.s.options, options, { bson: this.s.bson }));
self.s.pool = new Pool(this, Object.assign(self.s.options, options, { bson: this.s.bson }));

// Set up listeners
self.s.pool.on('close', eventHandler(self, 'close'));
Expand Down Expand Up @@ -657,7 +656,7 @@ Server.prototype.command = function(ns, cmd, options, callback) {
if (result) return callback(result);

// Clone the options
options = assign({}, options, { wireProtocolCommand: false });
options = Object.assign({}, options, { wireProtocolCommand: false });

// Debug log
if (self.s.logger.isDebug())
Expand Down
32 changes: 0 additions & 32 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@

const crypto = require('crypto');

/**
* Copy the values of all enumerable own properties from one or more
* source objects to a target object. It will return the target object.
*/
const assign = Object.assign
? Object.assign
: function assign(target) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}

var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}

var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}

return to;
};

const uuidV4 = () => {
const result = crypto.randomBytes(16);
result[6] = (result[6] & 0x0f) | 0x40;
Expand All @@ -41,6 +10,5 @@ const uuidV4 = () => {
};

module.exports = {
assign: assign,
uuidV4: uuidV4
};
11 changes: 5 additions & 6 deletions test/tests/functional/mongos_mocks/mixed_seed_list_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var expect = require('chai').expect,
assign = require('../../../../lib/utils').assign,
co = require('co'),
mock = require('../../../mock');

Expand All @@ -25,12 +24,12 @@ describe('Mongos Mixed Seed List (mocks)', function() {
var mongos2 = null;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Default message fields
var defaultRSFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultRSFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
setName: 'rs',
setVersion: 1,
electionId: new ObjectId(),
Expand All @@ -39,7 +38,7 @@ describe('Mongos Mixed Seed List (mocks)', function() {
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields), assign({}, defaultRSFields)];
var serverIsMaster = [Object.assign({}, defaultFields), Object.assign({}, defaultRSFields)];

// Boot the mock
co(function*() {
Expand Down Expand Up @@ -116,7 +115,7 @@ describe('Mongos Mixed Seed List (mocks)', function() {
var mongos2 = null;

// Default message fields
var defaultRSFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultRSFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
setName: 'rs',
setVersion: 1,
electionId: new ObjectId(),
Expand All @@ -125,7 +124,7 @@ describe('Mongos Mixed Seed List (mocks)', function() {
});

// Primary server states
var serverIsMaster = [assign({}, defaultRSFields), assign({}, defaultRSFields)];
var serverIsMaster = [Object.assign({}, defaultRSFields), Object.assign({}, defaultRSFields)];

// Boot the mock
co(function*() {
Expand Down
9 changes: 4 additions & 5 deletions test/tests/functional/mongos_mocks/multiple_proxies_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var expect = require('chai').expect,
assign = require('../../../../lib/utils').assign,
co = require('co'),
mock = require('../../../mock');

Expand All @@ -23,12 +22,12 @@ describe('Mongos Multiple Proxies (mocks)', function() {
var mongos2 = null;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Boot the mock
co(function*() {
mongos1 = yield mock.createServer(11000, 'localhost');
Expand Down Expand Up @@ -107,12 +106,12 @@ describe('Mongos Multiple Proxies (mocks)', function() {
var Mongos = this.configuration.mongo.Mongos;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Boot the mock
co(function*() {
const mongos1 = yield mock.createServer(11002, 'localhost');
Expand Down
13 changes: 6 additions & 7 deletions test/tests/functional/mongos_mocks/proxy_failover_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var expect = require('chai').expect,
assign = require('../../../../lib/utils').assign,
co = require('co'),
mock = require('../../../mock');

Expand All @@ -19,12 +18,12 @@ describe('Mongos Proxy Failover (mocks)', function() {
var Mongos = this.configuration.mongo.Mongos;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Boot the mock
co(function*() {
const mongos1 = yield mock.createServer(52007, 'localhost');
Expand Down Expand Up @@ -98,12 +97,12 @@ describe('Mongos Proxy Failover (mocks)', function() {
var currentStep = 0;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Boot the mock
co(function*() {
const mongos1 = yield mock.createServer(52009, 'localhost');
Expand Down Expand Up @@ -198,12 +197,12 @@ describe('Mongos Proxy Failover (mocks)', function() {
var currentStep = 0;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Boot the mock
co(function*() {
const mongos1 = yield mock.createServer(52011, 'localhost');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var expect = require('chai').expect,
assign = require('../../../../lib/utils').assign,
co = require('co'),
mock = require('../../../mock');

Expand All @@ -21,12 +20,12 @@ describe('Mongos Proxy Read Preference (mocks)', function() {
ReadPreference = this.configuration.mongo.ReadPreference;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Received command on server
var command = null;
// Boot the mock
Expand Down Expand Up @@ -102,12 +101,12 @@ describe('Mongos Proxy Read Preference (mocks)', function() {
ReadPreference = this.configuration.mongo.ReadPreference;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Received command on server
var command = null;
// Boot the mock
Expand Down Expand Up @@ -182,12 +181,12 @@ describe('Mongos Proxy Read Preference (mocks)', function() {
ReadPreference = this.configuration.mongo.ReadPreference;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];
// Received command on server
var command = null;
// Boot the mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var expect = require('chai').expect,
f = require('util').format,
co = require('co'),
assign = require('../../../../lib/utils').assign,
mock = require('../../../mock');

describe('Mongos Single Proxy Connection (mocks)', function() {
Expand All @@ -25,12 +24,12 @@ describe('Mongos Single Proxy Connection (mocks)', function() {
var stopRespondingPrimary = false;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];

// Boot the mock
co(function*() {
Expand Down Expand Up @@ -109,12 +108,12 @@ describe('Mongos Single Proxy Connection (mocks)', function() {
ObjectId = this.configuration.mongo.BSON.ObjectId;

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
msg: 'isdbgrid'
});

// Primary server states
var serverIsMaster = [assign({}, defaultFields)];
var serverIsMaster = [Object.assign({}, defaultFields)];

// Boot the mock
co(function*() {
Expand Down
Loading

0 comments on commit ec2b7a6

Please sign in to comment.