forked from nodejs/node
/
test-accessor-properties.js
55 lines (44 loc) · 1.7 KB
/
test-accessor-properties.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Flags: --expose-internals
'use strict';
const common = require('../common');
// This tests that the accessor properties do not raise assertions
// when called with incompatible receivers.
const assert = require('assert');
// Objects that call StreamBase::AddMethods, when setting up
// their prototype
const { internalBinding } = require('internal/test/binding');
const TTY = internalBinding('tty_wrap').TTY;
const UDP = internalBinding('udp_wrap').UDP;
{
// Should throw instead of raise assertions
assert.throws(() => {
UDP.prototype.fd; // eslint-disable-line no-unused-expressions
}, TypeError);
const StreamWrapProto = Object.getPrototypeOf(TTY.prototype);
const properties = ['bytesRead', 'fd', '_externalStream'];
properties.forEach((property) => {
// Should throw instead of raise assertions
assert.throws(() => {
TTY.prototype[property]; // eslint-disable-line no-unused-expressions
}, TypeError, `Missing expected TypeError for TTY.prototype.${property}`);
// Should not throw for Object.getOwnPropertyDescriptor
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(StreamWrapProto, property),
'object',
'typeof property descriptor ' + property + ' is not \'object\''
);
});
if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
// There are accessor properties in crypto too
const crypto = internalBinding('crypto');
assert.throws(() => {
// eslint-disable-next-line no-unused-expressions
crypto.SecureContext.prototype._external;
}, TypeError);
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(
crypto.SecureContext.prototype, '_external'),
'object'
);
}
}