-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: make StreamBase prototype accessors robust
This PR makes the prototype accessors added by StreamBase::AddMethods nonenumerable and checks the signatures in the accessors so they throw instead of raising assertions when called with incompatible receivers. They could be enumerated when inspecting the prototype with util.inspect or the inspector protocol. PR-URL: #16860 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
1 parent
942a9ed
commit 5df3dc1
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
test/parallel/test-stream-base-prototype-accessors-enumerability.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
// This tests that the prototype accessors added by StreamBase::AddMethods | ||
// are not enumerable. They could be enumerated when inspecting the prototype | ||
// with util.inspect or the inspector protocol. | ||
|
||
const assert = require('assert'); | ||
|
||
// Or anything that calls StreamBase::AddMethods when setting up its prototype | ||
const TTY = process.binding('tty_wrap').TTY; | ||
|
||
{ | ||
assert.strictEqual(TTY.prototype.propertyIsEnumerable('bytesRead'), false); | ||
assert.strictEqual(TTY.prototype.propertyIsEnumerable('fd'), false); | ||
assert.strictEqual( | ||
TTY.prototype.propertyIsEnumerable('_externalStream'), false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
// This tests that the prototype accessors added by StreamBase::AddMethods | ||
// do not raise assersions when called with incompatible receivers. | ||
|
||
const assert = require('assert'); | ||
|
||
// Or anything that calls StreamBase::AddMethods when setting up its prototype | ||
const TTY = process.binding('tty_wrap').TTY; | ||
|
||
// Should throw instead of raise assertions | ||
{ | ||
const msg = /TypeError: Method \w+ called on incompatible receiver/; | ||
assert.throws(() => { | ||
TTY.prototype.bytesRead; | ||
}, msg); | ||
|
||
assert.throws(() => { | ||
TTY.prototype.fd; | ||
}, msg); | ||
|
||
assert.throws(() => { | ||
TTY.prototype._externalStream; | ||
}, msg); | ||
} |