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