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