11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { Readable, Writable, Duplex, Transform } = require('stream'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst readable = new Readable({ read() {} }); 71cb0ef41Sopenharmony_ciconst writable = new Writable({ write() {} }); 81cb0ef41Sopenharmony_ciconst duplex = new Duplex({ read() {}, write() {} }); 91cb0ef41Sopenharmony_ciconst transform = new Transform({ transform() {} }); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciassert.ok(readable instanceof Readable); 121cb0ef41Sopenharmony_ciassert.ok(!(writable instanceof Readable)); 131cb0ef41Sopenharmony_ciassert.ok(duplex instanceof Readable); 141cb0ef41Sopenharmony_ciassert.ok(transform instanceof Readable); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciassert.ok(!(readable instanceof Writable)); 171cb0ef41Sopenharmony_ciassert.ok(writable instanceof Writable); 181cb0ef41Sopenharmony_ciassert.ok(duplex instanceof Writable); 191cb0ef41Sopenharmony_ciassert.ok(transform instanceof Writable); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciassert.ok(!(readable instanceof Duplex)); 221cb0ef41Sopenharmony_ciassert.ok(!(writable instanceof Duplex)); 231cb0ef41Sopenharmony_ciassert.ok(duplex instanceof Duplex); 241cb0ef41Sopenharmony_ciassert.ok(transform instanceof Duplex); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciassert.ok(!(readable instanceof Transform)); 271cb0ef41Sopenharmony_ciassert.ok(!(writable instanceof Transform)); 281cb0ef41Sopenharmony_ciassert.ok(!(duplex instanceof Transform)); 291cb0ef41Sopenharmony_ciassert.ok(transform instanceof Transform); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciassert.ok(!(null instanceof Writable)); 321cb0ef41Sopenharmony_ciassert.ok(!(undefined instanceof Writable)); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci// Simple inheritance check for `Writable` works fine in a subclass constructor. 351cb0ef41Sopenharmony_cifunction CustomWritable() { 361cb0ef41Sopenharmony_ci assert.ok( 371cb0ef41Sopenharmony_ci this instanceof CustomWritable, 381cb0ef41Sopenharmony_ci `${this} does not inherit from CustomWritable` 391cb0ef41Sopenharmony_ci ); 401cb0ef41Sopenharmony_ci assert.ok( 411cb0ef41Sopenharmony_ci this instanceof Writable, 421cb0ef41Sopenharmony_ci `${this} does not inherit from Writable` 431cb0ef41Sopenharmony_ci ); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ciObject.setPrototypeOf(CustomWritable, Writable); 471cb0ef41Sopenharmony_ciObject.setPrototypeOf(CustomWritable.prototype, Writable.prototype); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_cinew CustomWritable(); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciassert.throws( 521cb0ef41Sopenharmony_ci CustomWritable, 531cb0ef41Sopenharmony_ci { 541cb0ef41Sopenharmony_ci code: 'ERR_ASSERTION', 551cb0ef41Sopenharmony_ci constructor: assert.AssertionError, 561cb0ef41Sopenharmony_ci message: 'undefined does not inherit from CustomWritable' 571cb0ef41Sopenharmony_ci } 581cb0ef41Sopenharmony_ci); 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ciclass OtherCustomWritable extends Writable {} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ciassert(!(new OtherCustomWritable() instanceof CustomWritable)); 631cb0ef41Sopenharmony_ciassert(!(new CustomWritable() instanceof OtherCustomWritable)); 64