aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-12-18 02:28:09 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-12-20 13:14:46 +0100
commit4b7a530f2b1a789b3feb64e3698d61b4ccc6bab5 (patch)
tree1cd8dd1d0ff4c113081502ddca54d5f9c7be8cb4
parent6f8ccef74ec514292ebf8ee65602d8c109b0aa2b (diff)
downloadandroid-node-v8-4b7a530f2b1a789b3feb64e3698d61b4ccc6bab5.tar.gz
android-node-v8-4b7a530f2b1a789b3feb64e3698d61b4ccc6bab5.tar.bz2
android-node-v8-4b7a530f2b1a789b3feb64e3698d61b4ccc6bab5.zip
lib: switch to object spread where possible
Use the object spread notation instead of using Object.assign. It is not only easier to read it is also faster as of V8 6.8. PR-URL: https://github.com/nodejs/node/pull/25104 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
-rw-r--r--lib/.eslintrc.yaml1
-rw-r--r--lib/_tls_wrap.js2
-rw-r--r--lib/child_process.js4
-rw-r--r--lib/internal/child_process.js2
-rw-r--r--lib/internal/console/constructor.js9
-rw-r--r--lib/internal/http2/compat.js2
-rw-r--r--lib/internal/http2/core.js20
-rw-r--r--lib/repl.js5
-rw-r--r--lib/tls.js10
-rw-r--r--lib/vm.js8
10 files changed, 32 insertions, 31 deletions
diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml
index 65c7c88ba0..a7a1c15e90 100644
--- a/lib/.eslintrc.yaml
+++ b/lib/.eslintrc.yaml
@@ -1,4 +1,5 @@
rules:
+ prefer-object-spread: error
no-restricted-syntax:
# Config copied from .eslintrc.js
- error
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index 1d6ccbb8a9..7a685042f3 100644
--- a/lib/_tls_wrap.js
+++ b/lib/_tls_wrap.js
@@ -291,7 +291,7 @@ function initRead(tls, wrapped) {
*/
function TLSSocket(socket, opts) {
- const tlsOptions = Object.assign({}, opts);
+ const tlsOptions = { ...opts };
if (tlsOptions.ALPNProtocols)
tls.convertALPNProtocols(tlsOptions.ALPNProtocols, tlsOptions);
diff --git a/lib/child_process.js b/lib/child_process.js
index 222df8aed7..2691de7019 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -136,7 +136,7 @@ function normalizeExecArgs(command, options, callback) {
}
// Make a shallow copy so we don't clobber the user's options object.
- options = Object.assign({}, options);
+ options = { ...options };
options.shell = typeof options.shell === 'string' ? options.shell : true;
return {
@@ -470,7 +470,7 @@ function normalizeSpawnArguments(file, args, options) {
}
// Make a shallow copy so we don't clobber the user's options object.
- options = Object.assign({}, options);
+ options = { ...options };
if (options.shell) {
const command = [file].concat(args).join(' ');
diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js
index 195cc156fc..498dbf6a1c 100644
--- a/lib/internal/child_process.js
+++ b/lib/internal/child_process.js
@@ -636,7 +636,7 @@ function setupChannel(target, channel) {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
- options = Object.assign({ swallowErrors: false }, options);
+ options = { swallowErrors: false, ...options };
if (this.connected) {
return this._send(message, handle, options, callback);
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js
index 7e1bcf802f..e10eef74c2 100644
--- a/lib/internal/console/constructor.js
+++ b/lib/internal/console/constructor.js
@@ -294,10 +294,11 @@ Console.prototype.warn = function warn(...args) {
Console.prototype.error = Console.prototype.warn;
Console.prototype.dir = function dir(object, options) {
- options = Object.assign({
- customInspect: false
- }, this[kGetInspectOptions](this._stdout), options);
- this[kWriteToConsole](kUseStdout, util.inspect(object, options));
+ this[kWriteToConsole](kUseStdout, util.inspect(object, {
+ customInspect: false,
+ ...this[kGetInspectOptions](this._stdout),
+ ...options
+ }));
};
Console.prototype.time = function time(label = 'default') {
diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js
index 927504621d..23c4e2e0f0 100644
--- a/lib/internal/http2/compat.js
+++ b/lib/internal/http2/compat.js
@@ -512,7 +512,7 @@ class Http2ServerResponse extends Stream {
}
getHeaders() {
- return Object.assign({}, this[kHeaders]);
+ return { ...this[kHeaders] };
}
hasHeader(name) {
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index 082bd552c2..f33ec48ff2 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -790,7 +790,7 @@ function pingCallback(cb) {
// 6. enablePush must be a boolean
// All settings are optional and may be left undefined
function validateSettings(settings) {
- settings = Object.assign({}, settings);
+ settings = { ...settings };
assertWithinRange('headerTableSize',
settings.headerTableSize,
0, kMaxInt);
@@ -1443,7 +1443,7 @@ class ClientHttp2Session extends Http2Session {
assertIsObject(options, 'options');
headers = Object.assign(Object.create(null), headers);
- options = Object.assign({}, options);
+ options = { ...options };
if (headers[HTTP2_HEADER_METHOD] === undefined)
headers[HTTP2_HEADER_METHOD] = HTTP2_METHOD_GET;
@@ -1848,7 +1848,7 @@ class Http2Stream extends Duplex {
throw new ERR_HTTP2_INVALID_STREAM();
assertIsObject(options, 'options');
- options = Object.assign({}, options);
+ options = { ...options };
validatePriorityOptions(options);
const priorityFn = submitPriority.bind(this, options);
@@ -2257,7 +2257,7 @@ class ServerHttp2Stream extends Http2Stream {
throw new ERR_INVALID_CALLBACK();
assertIsObject(options, 'options');
- options = Object.assign({}, options);
+ options = { ...options };
options.endStream = !!options.endStream;
assertIsObject(headers, 'headers');
@@ -2322,7 +2322,7 @@ class ServerHttp2Stream extends Http2Stream {
const state = this[kState];
assertIsObject(options, 'options');
- options = Object.assign({}, options);
+ options = { ...options };
const session = this[kSession];
debug(`Http2Stream ${this[kID]} [Http2Session ` +
@@ -2378,7 +2378,7 @@ class ServerHttp2Stream extends Http2Stream {
const session = this[kSession];
assertIsObject(options, 'options');
- options = Object.assign({}, options);
+ options = { ...options };
if (options.offset !== undefined && typeof options.offset !== 'number')
throw new ERR_INVALID_OPT_VALUE('offset', options.offset);
@@ -2441,7 +2441,7 @@ class ServerHttp2Stream extends Http2Stream {
throw new ERR_HTTP2_HEADERS_SENT();
assertIsObject(options, 'options');
- options = Object.assign({}, options);
+ options = { ...options };
if (options.offset !== undefined && typeof options.offset !== 'number')
throw new ERR_INVALID_OPT_VALUE('offset', options.offset);
@@ -2667,10 +2667,10 @@ function connectionListener(socket) {
function initializeOptions(options) {
assertIsObject(options, 'options');
- options = Object.assign({}, options);
+ options = { ...options };
options.allowHalfOpen = true;
assertIsObject(options.settings, 'options.settings');
- options.settings = Object.assign({}, options.settings);
+ options.settings = { ...options.settings };
// Used only with allowHTTP1
options.Http1IncomingMessage = options.Http1IncomingMessage ||
@@ -2775,7 +2775,7 @@ function connect(authority, options, listener) {
}
assertIsObject(options, 'options');
- options = Object.assign({}, options);
+ options = { ...options };
if (typeof authority === 'string')
authority = new URL(authority);
diff --git a/lib/repl.js b/lib/repl.js
index 2d618d3d38..5d4c6890fb 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -129,8 +129,7 @@ function hasOwnProperty(obj, prop) {
// and it can be overridden by custom print functions, such as `probe` or
// `eyes.js`.
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
-writer.options =
- Object.assign({}, util.inspect.defaultOptions, { showProxy: true });
+writer.options = { ...util.inspect.defaultOptions, showProxy: true };
exports._builtinLibs = builtinLibs;
@@ -509,7 +508,7 @@ function REPLServer(prompt,
if (self.useColors && self.writer === writer) {
// Turn on ANSI coloring.
self.writer = (obj) => util.inspect(obj, self.writer.options);
- self.writer.options = Object.assign({}, writer.options, { colors: true });
+ self.writer.options = { ...writer.options, colors: true };
}
function filterInternalStackFrames(structuredStack) {
diff --git a/lib/tls.js b/lib/tls.js
index 898e204c53..645c3e9269 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -270,9 +270,13 @@ class SecurePair extends EventEmitter {
this.credentials = secureContext;
this.encrypted = socket1;
- this.cleartext = new exports.TLSSocket(socket2, Object.assign({
- secureContext, isServer, requestCert, rejectUnauthorized
- }, options));
+ this.cleartext = new exports.TLSSocket(socket2, {
+ secureContext,
+ isServer,
+ requestCert,
+ rejectUnauthorized,
+ ...options
+ });
this.cleartext.once('secure', () => this.emit('secure'));
}
diff --git a/lib/vm.js b/lib/vm.js
index e50b08d336..12c4efa1a2 100644
--- a/lib/vm.js
+++ b/lib/vm.js
@@ -290,9 +290,7 @@ function runInContext(code, contextifiedSandbox, options) {
[kParsingContext]: contextifiedSandbox
};
} else {
- options = Object.assign({}, options, {
- [kParsingContext]: contextifiedSandbox
- });
+ options = { ...options, [kParsingContext]: contextifiedSandbox };
}
return createScript(code, options)
.runInContext(contextifiedSandbox, options);
@@ -303,9 +301,7 @@ function runInNewContext(code, sandbox, options) {
options = { filename: options };
}
sandbox = createContext(sandbox, getContextOptions(options));
- options = Object.assign({}, options, {
- [kParsingContext]: sandbox
- });
+ options = { ...options, [kParsingContext]: sandbox };
return createScript(code, options).runInNewContext(sandbox, options);
}