Skip to content

Commit 686b632

Browse files
felthyDan Pupius
authored and
Dan Pupius
committed
Use Object.defineProperty() when overriding properties from a frozen prototype.
1 parent 9049daa commit 686b632

File tree

6 files changed

+19
-18
lines changed

6 files changed

+19
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
npm-debug.log
3+
/.idea

lib/cat.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ function State(emitter, streams) {
6363
// We `bind()` the event listener callback methods, so that they
6464
// get an appropriate `this` when they're called during event
6565
// emission.
66-
this.onEnd = this.onEnd.bind(this);
67-
this.onData = this.onData.bind(this);
68-
this.onError = this.onError.bind(this);
66+
Object.defineProperty(this, 'onEnd', { value: this.onEnd.bind(this), enumerable: true });
67+
Object.defineProperty(this, 'onData', { value: this.onData.bind(this), enumerable: true });
68+
Object.defineProperty(this, 'onError', { value: this.onError.bind(this), enumerable: true });
6969

7070
if (!Array.isArray(streams)) {
7171
throw new Error("Invalid streams array.");

lib/dropper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function State(emitter, source, options) {
7676
// We `bind()` the event listener callback methods, so that they
7777
// get an appropriate `this` when they're called during event
7878
// emission.
79-
this.onCloseOrEnd = this.onCloseOrEnd.bind(this);
80-
this.onData = this.onData.bind(this);
81-
this.onError = this.onError.bind(this);
79+
Object.defineProperty(this, 'onCloseOrEnd', { value: this.onCloseOrEnd.bind(this), enumerable: true });
80+
Object.defineProperty(this, 'onData', { value: this.onData.bind(this), enumerable: true });
81+
Object.defineProperty(this, 'onError', { value: this.onError.bind(this), enumerable: true });
8282

8383
source.on(consts.CLOSE, this.onCloseOrEnd);
8484
source.on(consts.DATA, this.onData);

lib/sink.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ function State(emitter, source) {
7878
// We `bind()` the event listener callback methods, so that they
7979
// get an appropriate `this` when they're called during event
8080
// emission.
81-
this.onClose = this.onClose.bind(this);
82-
this.onData = this.onData.bind(this);
83-
this.onEnd = this.onEnd.bind(this);
84-
this.onError = this.onError.bind(this);
81+
Object.defineProperty(this, 'onClose', { value: this.onClose.bind(this), enumerable: true });
82+
Object.defineProperty(this, 'onData', { value: this.onData.bind(this), enumerable: true });
83+
Object.defineProperty(this, 'onEnd', { value: this.onEnd.bind(this), enumerable: true });
84+
Object.defineProperty(this, 'onError', { value: this.onError.bind(this), enumerable: true });
8585

8686
source.on(consts.CLOSE, this.onClose);
8787
source.on(consts.DATA, this.onData);

lib/slicer.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ function State(source) {
190190
// We `bind()` the event listener callback methods, so that they
191191
// get an appropriate `this` when they're called during event
192192
// emission.
193-
this.onClose = this.onClose.bind(this);
194-
this.onData = this.onData.bind(this);
195-
this.onEnd = this.onEnd.bind(this);
196-
this.onError = this.onError.bind(this);
193+
Object.defineProperty(this, 'onClose', { value: this.onClose.bind(this), enumerable: true });
194+
Object.defineProperty(this, 'onData', { value: this.onData.bind(this), enumerable: true });
195+
Object.defineProperty(this, 'onEnd', { value: this.onEnd.bind(this), enumerable: true });
196+
Object.defineProperty(this, 'onError', { value: this.onError.bind(this), enumerable: true });
197197

198198
source.on(consts.CLOSE, this.onClose);
199199
source.on(consts.DATA, this.onData);

lib/valve.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ function State(emitter, source) {
7070
// We `bind()` the event listener callback methods, so that they
7171
// get an appropriate `this` when they're called during event
7272
// emission.
73-
this.onClose = this.onClose.bind(this);
74-
this.onData = this.onData.bind(this);
75-
this.onEnd = this.onEnd.bind(this);
76-
this.onError = this.onError.bind(this);
73+
Object.defineProperty(this, 'onClose', { value: this.onClose.bind(this), enumerable: true });
74+
Object.defineProperty(this, 'onData', { value: this.onData.bind(this), enumerable: true });
75+
Object.defineProperty(this, 'onEnd', { value: this.onEnd.bind(this), enumerable: true });
76+
Object.defineProperty(this, 'onError', { value: this.onError.bind(this), enumerable: true });
7777

7878
source.on(consts.CLOSE, this.onClose);
7979
source.on(consts.DATA, this.onData);

0 commit comments

Comments
 (0)