Skip to content

Commit a5c2e52

Browse files
authored
Refactor: restore use of spread operator (#106)
Because the Chromium bug has been fixed. Ref: https://bugs.chromium.org/p/chromium/issues/detail?id=1204540 Category: fix
1 parent a05a8ea commit a5c2e52

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

abstract-chained-batch.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ class AbstractChainedBatch {
8080
if (keyError != null) throw keyError
8181
if (valueError != null) throw valueError
8282

83-
// Avoid spread operator because of https://bugs.chromium.org/p/chromium/issues/detail?id=1204540
84-
const op = Object.assign({}, options, {
83+
const op = {
84+
...options,
8585
type: 'put',
8686
key,
8787
value,
8888
keyEncoding: db.keyEncoding(options.keyEncoding),
8989
valueEncoding: db.valueEncoding(options.valueEncoding)
90-
})
90+
}
9191

9292
if (this.#prewriteRun !== null) {
9393
try {
@@ -135,7 +135,7 @@ class AbstractChainedBatch {
135135
// If the sublevel is not a descendant then we shouldn't emit events
136136
if (this.#publicOperations !== null && !siblings) {
137137
// Clone op before we mutate it for the private API
138-
const publicOperation = Object.assign({}, op)
138+
const publicOperation = { ...op }
139139
publicOperation.encodedKey = encodedKey
140140
publicOperation.encodedValue = encodedValue
141141

@@ -149,7 +149,7 @@ class AbstractChainedBatch {
149149

150150
this.#publicOperations.push(publicOperation)
151151
} else if (this.#legacyOperations !== null && !siblings) {
152-
const legacyOperation = Object.assign({}, original)
152+
const legacyOperation = { ...original }
153153

154154
legacyOperation.type = 'put'
155155
legacyOperation.key = key
@@ -189,12 +189,12 @@ class AbstractChainedBatch {
189189

190190
if (keyError != null) throw keyError
191191

192-
// Avoid spread operator because of https://bugs.chromium.org/p/chromium/issues/detail?id=1204540
193-
const op = Object.assign({}, options, {
192+
const op = {
193+
...options,
194194
type: 'del',
195195
key,
196196
keyEncoding: db.keyEncoding(options.keyEncoding)
197-
})
197+
}
198198

199199
if (this.#prewriteRun !== null) {
200200
try {
@@ -221,7 +221,7 @@ class AbstractChainedBatch {
221221

222222
if (this.#publicOperations !== null) {
223223
// Clone op before we mutate it for the private API
224-
const publicOperation = Object.assign({}, op)
224+
const publicOperation = { ...op }
225225
publicOperation.encodedKey = encodedKey
226226

227227
if (delegated) {
@@ -232,7 +232,7 @@ class AbstractChainedBatch {
232232

233233
this.#publicOperations.push(publicOperation)
234234
} else if (this.#legacyOperations !== null) {
235-
const legacyOperation = Object.assign({}, original)
235+
const legacyOperation = { ...original }
236236

237237
legacyOperation.type = 'del'
238238
legacyOperation.key = key

abstract-level.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class AbstractLevel extends EventEmitter {
5858
permanence: manifest.permanence !== false,
5959

6060
encodings: manifest.encodings || {},
61-
events: Object.assign({}, manifest.events, {
61+
events: {
62+
...manifest.events,
6263
opening: true,
6364
open: true,
6465
closing: true,
@@ -68,7 +69,7 @@ class AbstractLevel extends EventEmitter {
6869
del: true,
6970
batch: true,
7071
clear: true
71-
})
72+
}
7273
})
7374

7475
// Monitor event listeners
@@ -332,8 +333,7 @@ class AbstractLevel extends EventEmitter {
332333

333334
// Forward encoding options to the underlying store
334335
if (options.keyEncoding !== keyFormat || options.valueEncoding !== valueFormat) {
335-
// Avoid spread operator because of https://bugs.chromium.org/p/chromium/issues/detail?id=1204540
336-
options = Object.assign({}, options, { keyEncoding: keyFormat, valueEncoding: valueFormat })
336+
options = { ...options, keyEncoding: keyFormat, valueEncoding: valueFormat }
337337
}
338338

339339
const encodedKey = keyEncoding.encode(key)
@@ -390,7 +390,7 @@ class AbstractLevel extends EventEmitter {
390390

391391
// Forward encoding options
392392
if (options.keyEncoding !== keyFormat || options.valueEncoding !== valueFormat) {
393-
options = Object.assign({}, options, { keyEncoding: keyFormat, valueEncoding: valueFormat })
393+
options = { ...options, keyEncoding: keyFormat, valueEncoding: valueFormat }
394394
}
395395

396396
const mappedKeys = new Array(keys.length)
@@ -454,11 +454,10 @@ class AbstractLevel extends EventEmitter {
454454

455455
// Forward encoding options to the underlying store
456456
if (options === this.#defaultOptions.key) {
457-
// Avoid Object.assign() for default options
457+
// Avoid cloning for default options
458458
options = this.#defaultOptions.keyFormat
459459
} else if (options.keyEncoding !== keyFormat) {
460-
// Avoid spread operator because of https://bugs.chromium.org/p/chromium/issues/detail?id=1204540
461-
options = Object.assign({}, options, { keyEncoding: keyFormat })
460+
options = { ...options, keyEncoding: keyFormat }
462461
}
463462

464463
const encodedKey = keyEncoding.encode(key)
@@ -504,11 +503,10 @@ class AbstractLevel extends EventEmitter {
504503

505504
// Forward encoding options to the underlying store
506505
if (options === this.#defaultOptions.key) {
507-
// Avoid Object.assign() for default options
506+
// Avoid cloning for default options
508507
options = this.#defaultOptions.keyFormat
509508
} else if (options.keyEncoding !== keyFormat) {
510-
// Avoid spread operator because of https://bugs.chromium.org/p/chromium/issues/detail?id=1204540
511-
options = Object.assign({}, options, { keyEncoding: keyFormat })
509+
options = { ...options, keyEncoding: keyFormat }
512510
}
513511

514512
const mappedKeys = new Array(keys.length)
@@ -565,12 +563,12 @@ class AbstractLevel extends EventEmitter {
565563
const enableWriteEvent = this.#eventMonitor.write
566564
const original = options
567565

568-
// Avoid Object.assign() for default options
566+
// Avoid cloning for default options
569567
// TODO: also apply this tweak to get() and getMany()
570568
if (options === this.#defaultOptions.entry) {
571569
options = this.#defaultOptions.entryFormat
572570
} else if (options.keyEncoding !== keyFormat || options.valueEncoding !== valueFormat) {
573-
options = Object.assign({}, options, { keyEncoding: keyFormat, valueEncoding: valueFormat })
571+
options = { ...options, keyEncoding: keyFormat, valueEncoding: valueFormat }
574572
}
575573

576574
const encodedKey = keyEncoding.encode(key)
@@ -580,15 +578,16 @@ class AbstractLevel extends EventEmitter {
580578
await this._put(prefixedKey, encodedValue, options)
581579

582580
if (enableWriteEvent) {
583-
const op = Object.assign({}, original, {
581+
const op = {
582+
...original,
584583
type: 'put',
585584
key,
586585
value,
587586
keyEncoding,
588587
valueEncoding,
589588
encodedKey,
590589
encodedValue
591-
})
590+
}
592591

593592
this.emit('write', [op])
594593
} else {
@@ -622,11 +621,11 @@ class AbstractLevel extends EventEmitter {
622621
const enableWriteEvent = this.#eventMonitor.write
623622
const original = options
624623

625-
// Avoid Object.assign() for default options
624+
// Avoid cloning for default options
626625
if (options === this.#defaultOptions.key) {
627626
options = this.#defaultOptions.keyFormat
628627
} else if (options.keyEncoding !== keyFormat) {
629-
options = Object.assign({}, options, { keyEncoding: keyFormat })
628+
options = { ...options, keyEncoding: keyFormat }
630629
}
631630

632631
const encodedKey = keyEncoding.encode(key)
@@ -635,12 +634,13 @@ class AbstractLevel extends EventEmitter {
635634
await this._del(prefixedKey, options)
636635

637636
if (enableWriteEvent) {
638-
const op = Object.assign({}, original, {
637+
const op = {
638+
...original,
639639
type: 'del',
640640
key,
641641
keyEncoding,
642642
encodedKey
643-
})
643+
}
644644

645645
this.emit('write', [op])
646646
} else {
@@ -694,7 +694,7 @@ class AbstractLevel extends EventEmitter {
694694
// Clone the op so that we can freely mutate it. We can't use a class because the
695695
// op can have userland properties that we'd have to copy, negating the performance
696696
// benefits of a class. So use a plain object.
697-
const op = Object.assign({}, options, operations[i])
697+
const op = { ...options, ...operations[i] }
698698

699699
// Hook functions can modify op but not its type or sublevel, so cache those
700700
const isPut = op.type === 'put'
@@ -753,7 +753,7 @@ class AbstractLevel extends EventEmitter {
753753
if (enableWriteEvent && !siblings) {
754754
// Clone op before we mutate it for the private API
755755
// TODO (future semver-major): consider sending this shape to private API too
756-
publicOperation = Object.assign({}, op)
756+
publicOperation = { ...op }
757757
publicOperation.encodedKey = encodedKey
758758

759759
if (delegated) {

lib/prewrite-batch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class PrewriteBatch {
5858
// If the sublevel is not a descendant then we shouldn't emit events
5959
if (this.#publicOperations !== null && !siblings) {
6060
// Clone op before we mutate it for the private API
61-
publicOperation = Object.assign({}, op)
61+
publicOperation = { ...op }
6262
publicOperation.encodedKey = encodedKey
6363

6464
if (delegated) {

test/iterator-range-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports.range = function (test, testCommon) {
3838
// Test the documented promise that in reverse mode,
3939
// "the returned entries are the same, but in reverse".
4040
if (!opts.reverse && !('limit' in opts)) {
41-
const reverseOpts = Object.assign({}, opts, { reverse: true })
41+
const reverseOpts = { ...opts, reverse: true }
4242

4343
rangeTest(
4444
name + ' (flipped)',

0 commit comments

Comments
 (0)