11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// This tests that the accessor properties do not raise assertions
71cb0ef41Sopenharmony_ci// when called with incompatible receivers.
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci// Objects that call StreamBase::AddMethods, when setting up
121cb0ef41Sopenharmony_ci// their prototype
131cb0ef41Sopenharmony_ciconst { internalBinding } = require('internal/test/binding');
141cb0ef41Sopenharmony_ciconst TTY = internalBinding('tty_wrap').TTY;
151cb0ef41Sopenharmony_ciconst UDP = internalBinding('udp_wrap').UDP;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci{
181cb0ef41Sopenharmony_ci  // Should throw instead of raise assertions
191cb0ef41Sopenharmony_ci  assert.throws(() => {
201cb0ef41Sopenharmony_ci    UDP.prototype.fd; // eslint-disable-line no-unused-expressions
211cb0ef41Sopenharmony_ci  }, TypeError);
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  const StreamWrapProto = Object.getPrototypeOf(TTY.prototype);
241cb0ef41Sopenharmony_ci  const properties = ['bytesRead', 'fd', '_externalStream'];
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  properties.forEach((property) => {
271cb0ef41Sopenharmony_ci    // Should throw instead of raise assertions
281cb0ef41Sopenharmony_ci    assert.throws(() => {
291cb0ef41Sopenharmony_ci      TTY.prototype[property]; // eslint-disable-line no-unused-expressions
301cb0ef41Sopenharmony_ci    }, TypeError, `Missing expected TypeError for TTY.prototype.${property}`);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci    // Should not throw for Object.getOwnPropertyDescriptor
331cb0ef41Sopenharmony_ci    assert.strictEqual(
341cb0ef41Sopenharmony_ci      typeof Object.getOwnPropertyDescriptor(StreamWrapProto, property),
351cb0ef41Sopenharmony_ci      'object',
361cb0ef41Sopenharmony_ci      'typeof property descriptor ' + property + ' is not \'object\''
371cb0ef41Sopenharmony_ci    );
381cb0ef41Sopenharmony_ci  });
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
411cb0ef41Sopenharmony_ci    // There are accessor properties in crypto too
421cb0ef41Sopenharmony_ci    const crypto = internalBinding('crypto');
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci    assert.throws(() => {
451cb0ef41Sopenharmony_ci      // eslint-disable-next-line no-unused-expressions
461cb0ef41Sopenharmony_ci      crypto.SecureContext.prototype._external;
471cb0ef41Sopenharmony_ci    }, TypeError);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci    assert.strictEqual(
501cb0ef41Sopenharmony_ci      typeof Object.getOwnPropertyDescriptor(
511cb0ef41Sopenharmony_ci        crypto.SecureContext.prototype, '_external'),
521cb0ef41Sopenharmony_ci      'object'
531cb0ef41Sopenharmony_ci    );
541cb0ef41Sopenharmony_ci  }
551cb0ef41Sopenharmony_ci}
56