forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-accessor-properties.js
72 lines (56 loc) · 1.74 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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(() => {
TTY.prototype.bytesRead;
}, TypeError);
assert.throws(() => {
TTY.prototype.fd;
}, TypeError);
assert.throws(() => {
TTY.prototype._externalStream;
}, TypeError);
assert.throws(() => {
UDP.prototype.fd;
}, TypeError);
const StreamWrapProto = Object.getPrototypeOf(TTY.prototype);
// Should not throw for Object.getOwnPropertyDescriptor
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(StreamWrapProto, 'bytesRead'),
'object'
);
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(StreamWrapProto, 'fd'),
'object'
);
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(StreamWrapProto, '_externalStream'),
'object'
);
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(StreamWrapProto, 'fd'),
'object'
);
if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
// There are accessor properties in crypto too
const crypto = process.binding('crypto');
assert.throws(() => {
crypto.SecureContext.prototype._external;
}, TypeError);
assert.strictEqual(
typeof Object.getOwnPropertyDescriptor(
crypto.SecureContext.prototype, '_external'),
'object'
);
}
}