2024-08-27 02:20:32 +00:00
|
|
|
// Flags: --expose-internals --no-warnings
|
2017-12-13 22:35:32 +00:00
|
|
|
'use strict';
|
|
|
|
|
2024-08-27 02:20:32 +00:00
|
|
|
const { hasCrypto } = require('../common');
|
2017-12-13 22:35:32 +00:00
|
|
|
|
|
|
|
// This tests that the accessor properties do not raise assertions
|
|
|
|
// when called with incompatible receivers.
|
|
|
|
|
|
|
|
const assert = require('assert');
|
2024-08-27 02:20:32 +00:00
|
|
|
const { test } = require('node:test');
|
2017-12-13 22:35:32 +00:00
|
|
|
|
|
|
|
// Objects that call StreamBase::AddMethods, when setting up
|
|
|
|
// their prototype
|
2018-08-23 14:20:12 +00:00
|
|
|
const { internalBinding } = require('internal/test/binding');
|
2024-08-27 02:20:32 +00:00
|
|
|
const { TTY } = internalBinding('tty_wrap');
|
|
|
|
const { UDP } = internalBinding('udp_wrap');
|
2017-12-13 22:35:32 +00:00
|
|
|
|
2024-08-27 02:20:32 +00:00
|
|
|
test('Should throw instead of raise assertions', () => {
|
2017-12-13 22:35:32 +00:00
|
|
|
assert.throws(() => {
|
2020-11-24 13:11:20 +00:00
|
|
|
UDP.prototype.fd; // eslint-disable-line no-unused-expressions
|
2017-12-13 22:35:32 +00:00
|
|
|
}, TypeError);
|
|
|
|
|
2018-09-23 17:24:33 +00:00
|
|
|
const StreamWrapProto = Object.getPrototypeOf(TTY.prototype);
|
2019-06-05 05:29:12 +00:00
|
|
|
const properties = ['bytesRead', 'fd', '_externalStream'];
|
2018-09-23 17:24:33 +00:00
|
|
|
|
2019-06-05 05:29:12 +00:00
|
|
|
properties.forEach((property) => {
|
2019-10-13 04:15:31 +00:00
|
|
|
// Should throw instead of raise assertions
|
|
|
|
assert.throws(() => {
|
2020-11-24 13:11:20 +00:00
|
|
|
TTY.prototype[property]; // eslint-disable-line no-unused-expressions
|
2019-10-13 04:15:31 +00:00
|
|
|
}, TypeError, `Missing expected TypeError for TTY.prototype.${property}`);
|
|
|
|
|
2019-06-05 05:29:12 +00:00
|
|
|
// Should not throw for Object.getOwnPropertyDescriptor
|
|
|
|
assert.strictEqual(
|
|
|
|
typeof Object.getOwnPropertyDescriptor(StreamWrapProto, property),
|
|
|
|
'object',
|
|
|
|
'typeof property descriptor ' + property + ' is not \'object\''
|
|
|
|
);
|
|
|
|
});
|
2024-08-27 02:20:32 +00:00
|
|
|
});
|
2018-07-08 20:12:58 +00:00
|
|
|
|
2024-08-27 02:20:32 +00:00
|
|
|
test('There are accessor properties in crypto too', { skip: !hasCrypto }, () => {
|
|
|
|
// There are accessor properties in crypto too
|
|
|
|
const crypto = internalBinding('crypto'); // eslint-disable-line node-core/crypto-check
|
2018-07-08 20:12:58 +00:00
|
|
|
|
2024-08-27 02:20:32 +00:00
|
|
|
assert.throws(() => {
|
|
|
|
// eslint-disable-next-line no-unused-expressions
|
|
|
|
crypto.SecureContext.prototype._external;
|
|
|
|
}, TypeError);
|
2018-07-08 20:12:58 +00:00
|
|
|
|
2024-08-27 02:20:32 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof Object.getOwnPropertyDescriptor(
|
|
|
|
crypto.SecureContext.prototype, '_external'),
|
|
|
|
'object'
|
|
|
|
);
|
|
|
|
});
|