11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset=utf-8> 31cb0ef41Sopenharmony_ci<title>Blob constructor</title> 41cb0ef41Sopenharmony_ci<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob"> 51cb0ef41Sopenharmony_ci<link rel=help href="https://heycam.github.io/webidl/#es-union"> 61cb0ef41Sopenharmony_ci<link rel=help href="https://heycam.github.io/webidl/#es-dictionary"> 71cb0ef41Sopenharmony_ci<link rel=help href="https://heycam.github.io/webidl/#es-sequence"> 81cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 91cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 101cb0ef41Sopenharmony_ci<script src="../support/Blob.js"></script> 111cb0ef41Sopenharmony_ci<div id="log"></div> 121cb0ef41Sopenharmony_ci<script> 131cb0ef41Sopenharmony_citest(function() { 141cb0ef41Sopenharmony_ci assert_true("Blob" in window, "window should have a Blob property."); 151cb0ef41Sopenharmony_ci assert_equals(Blob.length, 0, "Blob.length should be 0."); 161cb0ef41Sopenharmony_ci assert_true(Blob instanceof Function, "Blob should be a function."); 171cb0ef41Sopenharmony_ci}, "Blob interface object"); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci// Step 1. 201cb0ef41Sopenharmony_citest(function() { 211cb0ef41Sopenharmony_ci var blob = new Blob(); 221cb0ef41Sopenharmony_ci assert_true(blob instanceof Blob); 231cb0ef41Sopenharmony_ci assert_equals(String(blob), '[object Blob]'); 241cb0ef41Sopenharmony_ci assert_equals(blob.size, 0); 251cb0ef41Sopenharmony_ci assert_equals(blob.type, ""); 261cb0ef41Sopenharmony_ci}, "Blob constructor with no arguments"); 271cb0ef41Sopenharmony_citest(function() { 281cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { var blob = Blob(); }); 291cb0ef41Sopenharmony_ci}, "Blob constructor with no arguments, without 'new'"); 301cb0ef41Sopenharmony_citest(function() { 311cb0ef41Sopenharmony_ci var blob = new Blob; 321cb0ef41Sopenharmony_ci assert_true(blob instanceof Blob); 331cb0ef41Sopenharmony_ci assert_equals(blob.size, 0); 341cb0ef41Sopenharmony_ci assert_equals(blob.type, ""); 351cb0ef41Sopenharmony_ci}, "Blob constructor without brackets"); 361cb0ef41Sopenharmony_citest(function() { 371cb0ef41Sopenharmony_ci var blob = new Blob(undefined); 381cb0ef41Sopenharmony_ci assert_true(blob instanceof Blob); 391cb0ef41Sopenharmony_ci assert_equals(String(blob), '[object Blob]'); 401cb0ef41Sopenharmony_ci assert_equals(blob.size, 0); 411cb0ef41Sopenharmony_ci assert_equals(blob.type, ""); 421cb0ef41Sopenharmony_ci}, "Blob constructor with undefined as first argument"); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci// blobParts argument (WebIDL). 451cb0ef41Sopenharmony_citest(function() { 461cb0ef41Sopenharmony_ci var args = [ 471cb0ef41Sopenharmony_ci null, 481cb0ef41Sopenharmony_ci true, 491cb0ef41Sopenharmony_ci false, 501cb0ef41Sopenharmony_ci 0, 511cb0ef41Sopenharmony_ci 1, 521cb0ef41Sopenharmony_ci 1.5, 531cb0ef41Sopenharmony_ci "FAIL", 541cb0ef41Sopenharmony_ci new Date(), 551cb0ef41Sopenharmony_ci new RegExp(), 561cb0ef41Sopenharmony_ci {}, 571cb0ef41Sopenharmony_ci { 0: "FAIL", length: 1 }, 581cb0ef41Sopenharmony_ci document.createElement("div"), 591cb0ef41Sopenharmony_ci window, 601cb0ef41Sopenharmony_ci ]; 611cb0ef41Sopenharmony_ci args.forEach(function(arg) { 621cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 631cb0ef41Sopenharmony_ci new Blob(arg); 641cb0ef41Sopenharmony_ci }, "Should throw for argument " + format_value(arg) + "."); 651cb0ef41Sopenharmony_ci }); 661cb0ef41Sopenharmony_ci}, "Passing non-objects, Dates and RegExps for blobParts should throw a TypeError."); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_citest_blob(function() { 691cb0ef41Sopenharmony_ci return new Blob({ 701cb0ef41Sopenharmony_ci [Symbol.iterator]: Array.prototype[Symbol.iterator], 711cb0ef41Sopenharmony_ci }); 721cb0ef41Sopenharmony_ci}, { 731cb0ef41Sopenharmony_ci expected: "", 741cb0ef41Sopenharmony_ci type: "", 751cb0ef41Sopenharmony_ci desc: "A plain object with @@iterator should be treated as a sequence for the blobParts argument." 761cb0ef41Sopenharmony_ci}); 771cb0ef41Sopenharmony_citest(t => { 781cb0ef41Sopenharmony_ci const blob = new Blob({ 791cb0ef41Sopenharmony_ci [Symbol.iterator]() { 801cb0ef41Sopenharmony_ci var i = 0; 811cb0ef41Sopenharmony_ci return {next: () => [ 821cb0ef41Sopenharmony_ci {done:false, value:'ab'}, 831cb0ef41Sopenharmony_ci {done:false, value:'cde'}, 841cb0ef41Sopenharmony_ci {done:true} 851cb0ef41Sopenharmony_ci ][i++] 861cb0ef41Sopenharmony_ci }; 871cb0ef41Sopenharmony_ci } 881cb0ef41Sopenharmony_ci }); 891cb0ef41Sopenharmony_ci assert_equals(blob.size, 5, 'Custom @@iterator should be treated as a sequence'); 901cb0ef41Sopenharmony_ci}, "A plain object with custom @@iterator should be treated as a sequence for the blobParts argument."); 911cb0ef41Sopenharmony_citest_blob(function() { 921cb0ef41Sopenharmony_ci return new Blob({ 931cb0ef41Sopenharmony_ci [Symbol.iterator]: Array.prototype[Symbol.iterator], 941cb0ef41Sopenharmony_ci 0: "PASS", 951cb0ef41Sopenharmony_ci length: 1 961cb0ef41Sopenharmony_ci }); 971cb0ef41Sopenharmony_ci}, { 981cb0ef41Sopenharmony_ci expected: "PASS", 991cb0ef41Sopenharmony_ci type: "", 1001cb0ef41Sopenharmony_ci desc: "A plain object with @@iterator and a length property should be treated as a sequence for the blobParts argument." 1011cb0ef41Sopenharmony_ci}); 1021cb0ef41Sopenharmony_citest_blob(function() { 1031cb0ef41Sopenharmony_ci return new Blob(new String("xyz")); 1041cb0ef41Sopenharmony_ci}, { 1051cb0ef41Sopenharmony_ci expected: "xyz", 1061cb0ef41Sopenharmony_ci type: "", 1071cb0ef41Sopenharmony_ci desc: "A String object should be treated as a sequence for the blobParts argument." 1081cb0ef41Sopenharmony_ci}); 1091cb0ef41Sopenharmony_citest_blob(function() { 1101cb0ef41Sopenharmony_ci return new Blob(new Uint8Array([1, 2, 3])); 1111cb0ef41Sopenharmony_ci}, { 1121cb0ef41Sopenharmony_ci expected: "123", 1131cb0ef41Sopenharmony_ci type: "", 1141cb0ef41Sopenharmony_ci desc: "A Uint8Array object should be treated as a sequence for the blobParts argument." 1151cb0ef41Sopenharmony_ci}); 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_civar test_error = { 1181cb0ef41Sopenharmony_ci name: "test", 1191cb0ef41Sopenharmony_ci message: "test error", 1201cb0ef41Sopenharmony_ci}; 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_citest(function() { 1231cb0ef41Sopenharmony_ci var obj = { 1241cb0ef41Sopenharmony_ci [Symbol.iterator]: Array.prototype[Symbol.iterator], 1251cb0ef41Sopenharmony_ci get length() { throw test_error; } 1261cb0ef41Sopenharmony_ci }; 1271cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 1281cb0ef41Sopenharmony_ci new Blob(obj); 1291cb0ef41Sopenharmony_ci }); 1301cb0ef41Sopenharmony_ci}, "The length getter should be invoked and any exceptions should be propagated."); 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_citest(function() { 1331cb0ef41Sopenharmony_ci var element = document.createElement("div"); 1341cb0ef41Sopenharmony_ci element.appendChild(document.createElement("div")); 1351cb0ef41Sopenharmony_ci element.appendChild(document.createElement("p")); 1361cb0ef41Sopenharmony_ci var list = element.children; 1371cb0ef41Sopenharmony_ci Object.defineProperty(list, "length", { 1381cb0ef41Sopenharmony_ci get: function() { throw test_error; } 1391cb0ef41Sopenharmony_ci }); 1401cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 1411cb0ef41Sopenharmony_ci new Blob(list); 1421cb0ef41Sopenharmony_ci }); 1431cb0ef41Sopenharmony_ci}, "A platform object that supports indexed properties should be treated as a sequence for the blobParts argument (overwritten 'length'.)"); 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_citest(function() { 1461cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 1471cb0ef41Sopenharmony_ci var obj = { 1481cb0ef41Sopenharmony_ci [Symbol.iterator]: Array.prototype[Symbol.iterator], 1491cb0ef41Sopenharmony_ci length: { 1501cb0ef41Sopenharmony_ci valueOf: null, 1511cb0ef41Sopenharmony_ci toString: function() { throw test_error; } 1521cb0ef41Sopenharmony_ci } 1531cb0ef41Sopenharmony_ci }; 1541cb0ef41Sopenharmony_ci new Blob(obj); 1551cb0ef41Sopenharmony_ci }); 1561cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 1571cb0ef41Sopenharmony_ci var obj = { 1581cb0ef41Sopenharmony_ci [Symbol.iterator]: Array.prototype[Symbol.iterator], 1591cb0ef41Sopenharmony_ci length: { valueOf: function() { throw test_error; } } 1601cb0ef41Sopenharmony_ci }; 1611cb0ef41Sopenharmony_ci new Blob(obj); 1621cb0ef41Sopenharmony_ci }); 1631cb0ef41Sopenharmony_ci}, "ToUint32 should be applied to the length and any exceptions should be propagated."); 1641cb0ef41Sopenharmony_ci 1651cb0ef41Sopenharmony_citest(function() { 1661cb0ef41Sopenharmony_ci var received = []; 1671cb0ef41Sopenharmony_ci var obj = { 1681cb0ef41Sopenharmony_ci get [Symbol.iterator]() { 1691cb0ef41Sopenharmony_ci received.push("Symbol.iterator"); 1701cb0ef41Sopenharmony_ci return Array.prototype[Symbol.iterator]; 1711cb0ef41Sopenharmony_ci }, 1721cb0ef41Sopenharmony_ci get length() { 1731cb0ef41Sopenharmony_ci received.push("length getter"); 1741cb0ef41Sopenharmony_ci return { 1751cb0ef41Sopenharmony_ci valueOf: function() { 1761cb0ef41Sopenharmony_ci received.push("length valueOf"); 1771cb0ef41Sopenharmony_ci return 3; 1781cb0ef41Sopenharmony_ci } 1791cb0ef41Sopenharmony_ci }; 1801cb0ef41Sopenharmony_ci }, 1811cb0ef41Sopenharmony_ci get 0() { 1821cb0ef41Sopenharmony_ci received.push("0 getter"); 1831cb0ef41Sopenharmony_ci return { 1841cb0ef41Sopenharmony_ci toString: function() { 1851cb0ef41Sopenharmony_ci received.push("0 toString"); 1861cb0ef41Sopenharmony_ci return "a"; 1871cb0ef41Sopenharmony_ci } 1881cb0ef41Sopenharmony_ci }; 1891cb0ef41Sopenharmony_ci }, 1901cb0ef41Sopenharmony_ci get 1() { 1911cb0ef41Sopenharmony_ci received.push("1 getter"); 1921cb0ef41Sopenharmony_ci throw test_error; 1931cb0ef41Sopenharmony_ci }, 1941cb0ef41Sopenharmony_ci get 2() { 1951cb0ef41Sopenharmony_ci received.push("2 getter"); 1961cb0ef41Sopenharmony_ci assert_unreached("Should not call the getter for 2 if the getter for 1 threw."); 1971cb0ef41Sopenharmony_ci } 1981cb0ef41Sopenharmony_ci }; 1991cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 2001cb0ef41Sopenharmony_ci new Blob(obj); 2011cb0ef41Sopenharmony_ci }); 2021cb0ef41Sopenharmony_ci assert_array_equals(received, [ 2031cb0ef41Sopenharmony_ci "Symbol.iterator", 2041cb0ef41Sopenharmony_ci "length getter", 2051cb0ef41Sopenharmony_ci "length valueOf", 2061cb0ef41Sopenharmony_ci "0 getter", 2071cb0ef41Sopenharmony_ci "0 toString", 2081cb0ef41Sopenharmony_ci "length getter", 2091cb0ef41Sopenharmony_ci "length valueOf", 2101cb0ef41Sopenharmony_ci "1 getter", 2111cb0ef41Sopenharmony_ci ]); 2121cb0ef41Sopenharmony_ci}, "Getters and value conversions should happen in order until an exception is thrown."); 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci// XXX should add tests edge cases of ToLength(length) 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_citest(function() { 2171cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 2181cb0ef41Sopenharmony_ci new Blob([{ toString: function() { throw test_error; } }]); 2191cb0ef41Sopenharmony_ci }, "Throwing toString"); 2201cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 2211cb0ef41Sopenharmony_ci new Blob([{ toString: undefined, valueOf: function() { throw test_error; } }]); 2221cb0ef41Sopenharmony_ci }, "Throwing valueOf"); 2231cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 2241cb0ef41Sopenharmony_ci new Blob([{ 2251cb0ef41Sopenharmony_ci toString: function() { throw test_error; }, 2261cb0ef41Sopenharmony_ci valueOf: function() { assert_unreached("Should not call valueOf if toString is present."); } 2271cb0ef41Sopenharmony_ci }]); 2281cb0ef41Sopenharmony_ci }, "Throwing toString and valueOf"); 2291cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 2301cb0ef41Sopenharmony_ci new Blob([{toString: null, valueOf: null}]); 2311cb0ef41Sopenharmony_ci }, "Null toString and valueOf"); 2321cb0ef41Sopenharmony_ci}, "ToString should be called on elements of the blobParts array and any exceptions should be propagated."); 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_citest_blob(function() { 2351cb0ef41Sopenharmony_ci var arr = [ 2361cb0ef41Sopenharmony_ci { toString: function() { arr.pop(); return "PASS"; } }, 2371cb0ef41Sopenharmony_ci { toString: function() { assert_unreached("Should have removed the second element of the array rather than called toString() on it."); } } 2381cb0ef41Sopenharmony_ci ]; 2391cb0ef41Sopenharmony_ci return new Blob(arr); 2401cb0ef41Sopenharmony_ci}, { 2411cb0ef41Sopenharmony_ci expected: "PASS", 2421cb0ef41Sopenharmony_ci type: "", 2431cb0ef41Sopenharmony_ci desc: "Changes to the blobParts array should be reflected in the returned Blob (pop)." 2441cb0ef41Sopenharmony_ci}); 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_citest_blob(function() { 2471cb0ef41Sopenharmony_ci var arr = [ 2481cb0ef41Sopenharmony_ci { 2491cb0ef41Sopenharmony_ci toString: function() { 2501cb0ef41Sopenharmony_ci if (arr.length === 3) { 2511cb0ef41Sopenharmony_ci return "A"; 2521cb0ef41Sopenharmony_ci } 2531cb0ef41Sopenharmony_ci arr.unshift({ 2541cb0ef41Sopenharmony_ci toString: function() { 2551cb0ef41Sopenharmony_ci assert_unreached("Should only access index 0 once."); 2561cb0ef41Sopenharmony_ci } 2571cb0ef41Sopenharmony_ci }); 2581cb0ef41Sopenharmony_ci return "P"; 2591cb0ef41Sopenharmony_ci } 2601cb0ef41Sopenharmony_ci }, 2611cb0ef41Sopenharmony_ci { 2621cb0ef41Sopenharmony_ci toString: function() { 2631cb0ef41Sopenharmony_ci return "SS"; 2641cb0ef41Sopenharmony_ci } 2651cb0ef41Sopenharmony_ci } 2661cb0ef41Sopenharmony_ci ]; 2671cb0ef41Sopenharmony_ci return new Blob(arr); 2681cb0ef41Sopenharmony_ci}, { 2691cb0ef41Sopenharmony_ci expected: "PASS", 2701cb0ef41Sopenharmony_ci type: "", 2711cb0ef41Sopenharmony_ci desc: "Changes to the blobParts array should be reflected in the returned Blob (unshift)." 2721cb0ef41Sopenharmony_ci}); 2731cb0ef41Sopenharmony_ci 2741cb0ef41Sopenharmony_citest_blob(function() { 2751cb0ef41Sopenharmony_ci // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17652 2761cb0ef41Sopenharmony_ci return new Blob([ 2771cb0ef41Sopenharmony_ci null, 2781cb0ef41Sopenharmony_ci undefined, 2791cb0ef41Sopenharmony_ci true, 2801cb0ef41Sopenharmony_ci false, 2811cb0ef41Sopenharmony_ci 0, 2821cb0ef41Sopenharmony_ci 1, 2831cb0ef41Sopenharmony_ci new String("stringobject"), 2841cb0ef41Sopenharmony_ci [], 2851cb0ef41Sopenharmony_ci ['x', 'y'], 2861cb0ef41Sopenharmony_ci {}, 2871cb0ef41Sopenharmony_ci { 0: "FAIL", length: 1 }, 2881cb0ef41Sopenharmony_ci { toString: function() { return "stringA"; } }, 2891cb0ef41Sopenharmony_ci { toString: undefined, valueOf: function() { return "stringB"; } }, 2901cb0ef41Sopenharmony_ci { valueOf: function() { assert_unreached("Should not call valueOf if toString is present on the prototype."); } } 2911cb0ef41Sopenharmony_ci ]); 2921cb0ef41Sopenharmony_ci}, { 2931cb0ef41Sopenharmony_ci expected: "nullundefinedtruefalse01stringobjectx,y[object Object][object Object]stringAstringB[object Object]", 2941cb0ef41Sopenharmony_ci type: "", 2951cb0ef41Sopenharmony_ci desc: "ToString should be called on elements of the blobParts array." 2961cb0ef41Sopenharmony_ci}); 2971cb0ef41Sopenharmony_ci 2981cb0ef41Sopenharmony_citest_blob(function() { 2991cb0ef41Sopenharmony_ci return new Blob([ 3001cb0ef41Sopenharmony_ci new ArrayBuffer(8) 3011cb0ef41Sopenharmony_ci ]); 3021cb0ef41Sopenharmony_ci}, { 3031cb0ef41Sopenharmony_ci expected: "\0\0\0\0\0\0\0\0", 3041cb0ef41Sopenharmony_ci type: "", 3051cb0ef41Sopenharmony_ci desc: "ArrayBuffer elements of the blobParts array should be supported." 3061cb0ef41Sopenharmony_ci}); 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_citest_blob(function() { 3091cb0ef41Sopenharmony_ci return new Blob([ 3101cb0ef41Sopenharmony_ci new Uint8Array([0x50, 0x41, 0x53, 0x53]), 3111cb0ef41Sopenharmony_ci new Int8Array([0x50, 0x41, 0x53, 0x53]), 3121cb0ef41Sopenharmony_ci new Uint16Array([0x4150, 0x5353]), 3131cb0ef41Sopenharmony_ci new Int16Array([0x4150, 0x5353]), 3141cb0ef41Sopenharmony_ci new Uint32Array([0x53534150]), 3151cb0ef41Sopenharmony_ci new Int32Array([0x53534150]), 3161cb0ef41Sopenharmony_ci new Float32Array([0xD341500000]) 3171cb0ef41Sopenharmony_ci ]); 3181cb0ef41Sopenharmony_ci}, { 3191cb0ef41Sopenharmony_ci expected: "PASSPASSPASSPASSPASSPASSPASS", 3201cb0ef41Sopenharmony_ci type: "", 3211cb0ef41Sopenharmony_ci desc: "Passing typed arrays as elements of the blobParts array should work." 3221cb0ef41Sopenharmony_ci}); 3231cb0ef41Sopenharmony_citest_blob(function() { 3241cb0ef41Sopenharmony_ci return new Blob([ 3251cb0ef41Sopenharmony_ci // 0x535 3415053534150 3261cb0ef41Sopenharmony_ci // 0x535 = 0b010100110101 -> Sign = +, Exponent = 1333 - 1023 = 310 3271cb0ef41Sopenharmony_ci // 0x13415053534150 * 2**(-52) 3281cb0ef41Sopenharmony_ci // ==> 0x13415053534150 * 2**258 = 2510297372767036725005267563121821874921913208671273727396467555337665343087229079989707079680 3291cb0ef41Sopenharmony_ci new Float64Array([2510297372767036725005267563121821874921913208671273727396467555337665343087229079989707079680]) 3301cb0ef41Sopenharmony_ci ]); 3311cb0ef41Sopenharmony_ci}, { 3321cb0ef41Sopenharmony_ci expected: "PASSPASS", 3331cb0ef41Sopenharmony_ci type: "", 3341cb0ef41Sopenharmony_ci desc: "Passing a Float64Array as element of the blobParts array should work." 3351cb0ef41Sopenharmony_ci}); 3361cb0ef41Sopenharmony_ci 3371cb0ef41Sopenharmony_citest_blob(function() { 3381cb0ef41Sopenharmony_ci var select = document.createElement("select"); 3391cb0ef41Sopenharmony_ci select.appendChild(document.createElement("option")); 3401cb0ef41Sopenharmony_ci return new Blob(select); 3411cb0ef41Sopenharmony_ci}, { 3421cb0ef41Sopenharmony_ci expected: "[object HTMLOptionElement]", 3431cb0ef41Sopenharmony_ci type: "", 3441cb0ef41Sopenharmony_ci desc: "Passing an platform object that supports indexed properties as the blobParts array should work (select)." 3451cb0ef41Sopenharmony_ci}); 3461cb0ef41Sopenharmony_ci 3471cb0ef41Sopenharmony_citest_blob(function() { 3481cb0ef41Sopenharmony_ci var elm = document.createElement("div"); 3491cb0ef41Sopenharmony_ci elm.setAttribute("foo", "bar"); 3501cb0ef41Sopenharmony_ci return new Blob(elm.attributes); 3511cb0ef41Sopenharmony_ci}, { 3521cb0ef41Sopenharmony_ci expected: "[object Attr]", 3531cb0ef41Sopenharmony_ci type: "", 3541cb0ef41Sopenharmony_ci desc: "Passing an platform object that supports indexed properties as the blobParts array should work (attributes)." 3551cb0ef41Sopenharmony_ci}); 3561cb0ef41Sopenharmony_ci 3571cb0ef41Sopenharmony_civar t_ports = async_test("Passing a FrozenArray as the blobParts array should work (FrozenArray<MessagePort>)."); 3581cb0ef41Sopenharmony_cit_ports.step(function() { 3591cb0ef41Sopenharmony_ci var channel = new MessageChannel(); 3601cb0ef41Sopenharmony_ci channel.port2.onmessage = this.step_func(function(e) { 3611cb0ef41Sopenharmony_ci var b_ports = new Blob(e.ports); 3621cb0ef41Sopenharmony_ci assert_equals(b_ports.size, "[object MessagePort]".length); 3631cb0ef41Sopenharmony_ci this.done(); 3641cb0ef41Sopenharmony_ci }); 3651cb0ef41Sopenharmony_ci var channel2 = new MessageChannel(); 3661cb0ef41Sopenharmony_ci channel.port1.postMessage('', [channel2.port1]); 3671cb0ef41Sopenharmony_ci}); 3681cb0ef41Sopenharmony_ci 3691cb0ef41Sopenharmony_citest_blob(function() { 3701cb0ef41Sopenharmony_ci var blob = new Blob(['foo']); 3711cb0ef41Sopenharmony_ci return new Blob([blob, blob]); 3721cb0ef41Sopenharmony_ci}, { 3731cb0ef41Sopenharmony_ci expected: "foofoo", 3741cb0ef41Sopenharmony_ci type: "", 3751cb0ef41Sopenharmony_ci desc: "Array with two blobs" 3761cb0ef41Sopenharmony_ci}); 3771cb0ef41Sopenharmony_ci 3781cb0ef41Sopenharmony_citest_blob_binary(function() { 3791cb0ef41Sopenharmony_ci var view = new Uint8Array([0, 255, 0]); 3801cb0ef41Sopenharmony_ci return new Blob([view.buffer, view.buffer]); 3811cb0ef41Sopenharmony_ci}, { 3821cb0ef41Sopenharmony_ci expected: [0, 255, 0, 0, 255, 0], 3831cb0ef41Sopenharmony_ci type: "", 3841cb0ef41Sopenharmony_ci desc: "Array with two buffers" 3851cb0ef41Sopenharmony_ci}); 3861cb0ef41Sopenharmony_ci 3871cb0ef41Sopenharmony_citest_blob_binary(function() { 3881cb0ef41Sopenharmony_ci var view = new Uint8Array([0, 255, 0, 4]); 3891cb0ef41Sopenharmony_ci var blob = new Blob([view, view]); 3901cb0ef41Sopenharmony_ci assert_equals(blob.size, 8); 3911cb0ef41Sopenharmony_ci var view1 = new Uint16Array(view.buffer, 2); 3921cb0ef41Sopenharmony_ci return new Blob([view1, view.buffer, view1]); 3931cb0ef41Sopenharmony_ci}, { 3941cb0ef41Sopenharmony_ci expected: [0, 4, 0, 255, 0, 4, 0, 4], 3951cb0ef41Sopenharmony_ci type: "", 3961cb0ef41Sopenharmony_ci desc: "Array with two bufferviews" 3971cb0ef41Sopenharmony_ci}); 3981cb0ef41Sopenharmony_ci 3991cb0ef41Sopenharmony_citest_blob(function() { 4001cb0ef41Sopenharmony_ci var view = new Uint8Array([0]); 4011cb0ef41Sopenharmony_ci var blob = new Blob(["fo"]); 4021cb0ef41Sopenharmony_ci return new Blob([view.buffer, blob, "foo"]); 4031cb0ef41Sopenharmony_ci}, { 4041cb0ef41Sopenharmony_ci expected: "\0fofoo", 4051cb0ef41Sopenharmony_ci type: "", 4061cb0ef41Sopenharmony_ci desc: "Array with mixed types" 4071cb0ef41Sopenharmony_ci}); 4081cb0ef41Sopenharmony_ci 4091cb0ef41Sopenharmony_citest(function() { 4101cb0ef41Sopenharmony_ci const accessed = []; 4111cb0ef41Sopenharmony_ci const stringified = []; 4121cb0ef41Sopenharmony_ci 4131cb0ef41Sopenharmony_ci new Blob([], { 4141cb0ef41Sopenharmony_ci get type() { accessed.push('type'); }, 4151cb0ef41Sopenharmony_ci get endings() { accessed.push('endings'); } 4161cb0ef41Sopenharmony_ci }); 4171cb0ef41Sopenharmony_ci new Blob([], { 4181cb0ef41Sopenharmony_ci type: { toString: () => { stringified.push('type'); return ''; } }, 4191cb0ef41Sopenharmony_ci endings: { toString: () => { stringified.push('endings'); return 'transparent'; } } 4201cb0ef41Sopenharmony_ci }); 4211cb0ef41Sopenharmony_ci assert_array_equals(accessed, ['endings', 'type']); 4221cb0ef41Sopenharmony_ci assert_array_equals(stringified, ['endings', 'type']); 4231cb0ef41Sopenharmony_ci}, "options properties should be accessed in lexicographic order."); 4241cb0ef41Sopenharmony_ci 4251cb0ef41Sopenharmony_citest(function() { 4261cb0ef41Sopenharmony_ci assert_throws_exactly(test_error, function() { 4271cb0ef41Sopenharmony_ci new Blob( 4281cb0ef41Sopenharmony_ci [{ toString: function() { throw test_error } }], 4291cb0ef41Sopenharmony_ci { 4301cb0ef41Sopenharmony_ci get type() { assert_unreached("type getter should not be called."); } 4311cb0ef41Sopenharmony_ci } 4321cb0ef41Sopenharmony_ci ); 4331cb0ef41Sopenharmony_ci }); 4341cb0ef41Sopenharmony_ci}, "Arguments should be evaluated from left to right."); 4351cb0ef41Sopenharmony_ci 4361cb0ef41Sopenharmony_ci[ 4371cb0ef41Sopenharmony_ci null, 4381cb0ef41Sopenharmony_ci undefined, 4391cb0ef41Sopenharmony_ci {}, 4401cb0ef41Sopenharmony_ci { unrecognized: true }, 4411cb0ef41Sopenharmony_ci /regex/, 4421cb0ef41Sopenharmony_ci function() {} 4431cb0ef41Sopenharmony_ci].forEach(function(arg, idx) { 4441cb0ef41Sopenharmony_ci test_blob(function() { 4451cb0ef41Sopenharmony_ci return new Blob([], arg); 4461cb0ef41Sopenharmony_ci }, { 4471cb0ef41Sopenharmony_ci expected: "", 4481cb0ef41Sopenharmony_ci type: "", 4491cb0ef41Sopenharmony_ci desc: "Passing " + format_value(arg) + " (index " + idx + ") for options should use the defaults." 4501cb0ef41Sopenharmony_ci }); 4511cb0ef41Sopenharmony_ci test_blob(function() { 4521cb0ef41Sopenharmony_ci return new Blob(["\na\r\nb\n\rc\r"], arg); 4531cb0ef41Sopenharmony_ci }, { 4541cb0ef41Sopenharmony_ci expected: "\na\r\nb\n\rc\r", 4551cb0ef41Sopenharmony_ci type: "", 4561cb0ef41Sopenharmony_ci desc: "Passing " + format_value(arg) + " (index " + idx + ") for options should use the defaults (with newlines)." 4571cb0ef41Sopenharmony_ci }); 4581cb0ef41Sopenharmony_ci}); 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci[ 4611cb0ef41Sopenharmony_ci 123, 4621cb0ef41Sopenharmony_ci 123.4, 4631cb0ef41Sopenharmony_ci true, 4641cb0ef41Sopenharmony_ci 'abc' 4651cb0ef41Sopenharmony_ci].forEach(arg => { 4661cb0ef41Sopenharmony_ci test(t => { 4671cb0ef41Sopenharmony_ci assert_throws_js(TypeError, () => new Blob([], arg), 4681cb0ef41Sopenharmony_ci 'Blob constructor should throw with invalid property bag'); 4691cb0ef41Sopenharmony_ci }, `Passing ${JSON.stringify(arg)} for options should throw`); 4701cb0ef41Sopenharmony_ci}); 4711cb0ef41Sopenharmony_ci 4721cb0ef41Sopenharmony_civar type_tests = [ 4731cb0ef41Sopenharmony_ci // blobParts, type, expected type 4741cb0ef41Sopenharmony_ci [[], '', ''], 4751cb0ef41Sopenharmony_ci [[], 'a', 'a'], 4761cb0ef41Sopenharmony_ci [[], 'A', 'a'], 4771cb0ef41Sopenharmony_ci [[], 'text/html', 'text/html'], 4781cb0ef41Sopenharmony_ci [[], 'TEXT/HTML', 'text/html'], 4791cb0ef41Sopenharmony_ci [[], 'text/plain;charset=utf-8', 'text/plain;charset=utf-8'], 4801cb0ef41Sopenharmony_ci [[], '\u00E5', ''], 4811cb0ef41Sopenharmony_ci [[], '\uD801\uDC7E', ''], // U+1047E 4821cb0ef41Sopenharmony_ci [[], ' image/gif ', ' image/gif '], 4831cb0ef41Sopenharmony_ci [[], '\timage/gif\t', ''], 4841cb0ef41Sopenharmony_ci [[], 'image/gif;\u007f', ''], 4851cb0ef41Sopenharmony_ci [[], '\u0130mage/gif', ''], // uppercase i with dot 4861cb0ef41Sopenharmony_ci [[], '\u0131mage/gif', ''], // lowercase dotless i 4871cb0ef41Sopenharmony_ci [[], 'image/gif\u0000', ''], 4881cb0ef41Sopenharmony_ci // check that type isn't changed based on sniffing 4891cb0ef41Sopenharmony_ci [[0x3C, 0x48, 0x54, 0x4D, 0x4C, 0x3E], 'unknown/unknown', 'unknown/unknown'], // "<HTML>" 4901cb0ef41Sopenharmony_ci [[0x00, 0xFF], 'text/plain', 'text/plain'], 4911cb0ef41Sopenharmony_ci [[0x47, 0x49, 0x46, 0x38, 0x39, 0x61], 'image/png', 'image/png'], // "GIF89a" 4921cb0ef41Sopenharmony_ci]; 4931cb0ef41Sopenharmony_ci 4941cb0ef41Sopenharmony_citype_tests.forEach(function(t) { 4951cb0ef41Sopenharmony_ci test(function() { 4961cb0ef41Sopenharmony_ci var arr = new Uint8Array([t[0]]).buffer; 4971cb0ef41Sopenharmony_ci var b = new Blob([arr], {type:t[1]}); 4981cb0ef41Sopenharmony_ci assert_equals(b.type, t[2]); 4991cb0ef41Sopenharmony_ci }, "Blob with type " + format_value(t[1])); 5001cb0ef41Sopenharmony_ci}); 5011cb0ef41Sopenharmony_ci</script> 502