Skip to content

Commit 09a922b

Browse files
authored
fix(storage-mixin): do not monkey-patch prototypes in SpliceDiskIpcBackend (#3434)
It can not have been intentional that this overwrote the prototype methods, rather than the methods of the specific instances, since the previous code meant that using `SpliceDiskIpcBackend` would have affected completely independent storage-mixing backends (even including other instances of `SpliceDiskIpcBackend` itself). This code has been broken like this since its inception. I did verify that saving credentials works as it did before.
1 parent f5247ea commit 09a922b

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

packages/storage-mixin/lib/backends/splice-disk-ipc.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,17 @@ function SpliceDiskIpcBackend(options) {
3737

3838
// patch the serialize methods in both backends
3939
var condition = options.secureCondition;
40-
DiskBackend.prototype.serialize = function(model) {
40+
this.diskBackend = new DiskBackend(options);
41+
this.diskBackend.serialize = function(model) {
4142
debug('Serializing for disk backend with condition', condition);
42-
var res = _.omitBy(model.serialize(), condition);
43-
return res;
43+
return _.omitBy(model.serialize(), condition);
4444
};
45-
this.diskBackend = new DiskBackend(options);
4645

47-
SecureIpcBackend.prototype.serialize = function(model) {
46+
this.secureBackend = new SecureIpcBackend(options);
47+
this.secureBackend.serialize = function(model) {
4848
debug('Serializing for secure backend with condition', condition);
49-
var res = _.pickBy(model.serialize(), condition);
50-
return res;
49+
return _.pickBy(model.serialize(), condition);
5150
};
52-
this.secureBackend = new SecureIpcBackend(options);
5351
}
5452

5553
inherits(SpliceDiskIpcBackend, BaseBackend);

packages/storage-mixin/lib/backends/splice-disk.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@ function SpliceDiskBackend(options) {
2727

2828
// patch the serialize methods in both backends
2929
var condition = options.secureCondition;
30-
DiskBackend.prototype.serialize = function(model) {
30+
this.diskBackend = new DiskBackend(options);
31+
this.diskBackend.serialize = function(model) {
3132
debug('Serializing for disk backend with condition', condition);
32-
var res = _.omitBy(model.serialize(), condition);
33-
return res;
33+
return _.omitBy(model.serialize(), condition);
3434
};
35-
this.diskBackend = new DiskBackend(options);
3635

37-
SecureBackend.prototype.serialize = function(model) {
36+
this.secureBackend = new SecureBackend(options);
37+
this.secureBackend.serialize = function(model) {
3838
debug('Serializing for secure backend with condition', condition);
39-
var res = _.pickBy(model.serialize(), condition);
40-
return res;
39+
return _.pickBy(model.serialize(), condition);
4140
};
42-
this.secureBackend = new SecureBackend(options);
4341
}
4442

4543
inherits(SpliceDiskBackend, BaseBackend);

0 commit comments

Comments
 (0)