11cb0ef41Sopenharmony_ci// META: global=window,worker 21cb0ef41Sopenharmony_ci// META: script=resources/readable-stream-from-array.js 31cb0ef41Sopenharmony_ci// META: script=resources/readable-stream-to-array.js 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci'use strict'; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst error1 = new Error('error1'); 81cb0ef41Sopenharmony_cierror1.name = 'error1'; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cipromise_test(t => { 111cb0ef41Sopenharmony_ci const ts = new TextEncoderStream(); 121cb0ef41Sopenharmony_ci const writer = ts.writable.getWriter(); 131cb0ef41Sopenharmony_ci const reader = ts.readable.getReader(); 141cb0ef41Sopenharmony_ci const writePromise = writer.write({ 151cb0ef41Sopenharmony_ci toString() { throw error1; } 161cb0ef41Sopenharmony_ci }); 171cb0ef41Sopenharmony_ci const readPromise = reader.read(); 181cb0ef41Sopenharmony_ci return Promise.all([ 191cb0ef41Sopenharmony_ci promise_rejects_exactly(t, error1, readPromise, 'read should reject with error1'), 201cb0ef41Sopenharmony_ci promise_rejects_exactly(t, error1, writePromise, 'write should reject with error1'), 211cb0ef41Sopenharmony_ci promise_rejects_exactly(t, error1, reader.closed, 'readable should be errored with error1'), 221cb0ef41Sopenharmony_ci promise_rejects_exactly(t, error1, writer.closed, 'writable should be errored with error1'), 231cb0ef41Sopenharmony_ci ]); 241cb0ef41Sopenharmony_ci}, 'a chunk that cannot be converted to a string should error the streams'); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciconst oddInputs = [ 271cb0ef41Sopenharmony_ci { 281cb0ef41Sopenharmony_ci name: 'undefined', 291cb0ef41Sopenharmony_ci value: undefined, 301cb0ef41Sopenharmony_ci expected: 'undefined' 311cb0ef41Sopenharmony_ci }, 321cb0ef41Sopenharmony_ci { 331cb0ef41Sopenharmony_ci name: 'null', 341cb0ef41Sopenharmony_ci value: null, 351cb0ef41Sopenharmony_ci expected: 'null' 361cb0ef41Sopenharmony_ci }, 371cb0ef41Sopenharmony_ci { 381cb0ef41Sopenharmony_ci name: 'numeric', 391cb0ef41Sopenharmony_ci value: 3.14, 401cb0ef41Sopenharmony_ci expected: '3.14' 411cb0ef41Sopenharmony_ci }, 421cb0ef41Sopenharmony_ci { 431cb0ef41Sopenharmony_ci name: 'object', 441cb0ef41Sopenharmony_ci value: {}, 451cb0ef41Sopenharmony_ci expected: '[object Object]' 461cb0ef41Sopenharmony_ci }, 471cb0ef41Sopenharmony_ci { 481cb0ef41Sopenharmony_ci name: 'array', 491cb0ef41Sopenharmony_ci value: ['hi'], 501cb0ef41Sopenharmony_ci expected: 'hi' 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci]; 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_cifor (const input of oddInputs) { 551cb0ef41Sopenharmony_ci promise_test(async () => { 561cb0ef41Sopenharmony_ci const outputReadable = readableStreamFromArray([input.value]) 571cb0ef41Sopenharmony_ci .pipeThrough(new TextEncoderStream()) 581cb0ef41Sopenharmony_ci .pipeThrough(new TextDecoderStream()); 591cb0ef41Sopenharmony_ci const output = await readableStreamToArray(outputReadable); 601cb0ef41Sopenharmony_ci assert_equals(output.length, 1, 'output should contain one chunk'); 611cb0ef41Sopenharmony_ci assert_equals(output[0], input.expected, 'output should be correct'); 621cb0ef41Sopenharmony_ci }, `input of type ${input.name} should be converted correctly to string`); 631cb0ef41Sopenharmony_ci} 64