-
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 more robust
- Loading branch information
1 parent
0a84e95
commit ddb12ac
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); | ||
} |