StructuredClone-serializable-objects.html 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script src="../include.js"></script>
  2. <script>
  3. asyncTest(async done => {
  4. let blob = structuredClone(new Blob(["Hello, Blob!"], {type: "text/plain"}));
  5. println(`instanceOf Blob: ${blob instanceof Blob}`);
  6. println(`Blob.type: ${blob.type}`);
  7. let text = await blob.text();
  8. println(`Blob.text(): ${text}`);
  9. let file = structuredClone(new File(["Hello, File!"], "hello.txt", {type: "text/plain"}));
  10. println(`instanceOf File: ${file instanceof File}`);
  11. println(`File.name: ${file.name}`);
  12. println(`File.type: ${file.type}`);
  13. text = await file.text();
  14. println(`File.text(): ${text}`);
  15. println(`File.size: ${file.size}`);
  16. let domMatrixReadOnly = structuredClone(new DOMMatrixReadOnly([1.7976931348623157e+308, 2.2250738585072014e-308, 2.2204460492503131e-016, 40, 50, 60]));
  17. println(`instanceOf DOMMatrixReadOnly: ${domMatrixReadOnly instanceof DOMMatrixReadOnly}`);
  18. println(`DOMMatrixReadOnly: ${JSON.stringify(domMatrixReadOnly)}`);
  19. domMatrixReadOnly = structuredClone(new DOMMatrixReadOnly([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]));
  20. println(`DOMMatrixReadOnly: ${JSON.stringify(domMatrixReadOnly)}`);
  21. let domMatrix = structuredClone(new DOMMatrix([10, 20, 30, 40, 50, 60]));
  22. println(`instanceOf DOMMatrix: ${domMatrix instanceof DOMMatrix}`);
  23. println(`DOMMatrix: ${JSON.stringify(domMatrix)}`);
  24. domMatrix = structuredClone(new DOMMatrix([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]));
  25. println(`DOMMatrix: ${JSON.stringify(domMatrix)}`);
  26. let domPointReadOnly = structuredClone(new DOMPointReadOnly(10, 20, 30, 40));
  27. println(`instanceOf DOMPointReadOnly: ${domPointReadOnly instanceof DOMPointReadOnly}`);
  28. println(`DOMPointReadOnly: ${JSON.stringify(domPointReadOnly)}`);
  29. let domPoint = structuredClone(new DOMPoint(10, 20, 30, 40));
  30. println(`instanceOf DOMPoint: ${domPoint instanceof DOMPoint}`);
  31. println(`DOMPoint: ${JSON.stringify(domPoint)}`);
  32. let domRectReadOnly = structuredClone(new DOMRectReadOnly(10, 20, 30, 40));
  33. println(`instanceOf DOMRectReadOnly: ${domRectReadOnly instanceof DOMRectReadOnly}`);
  34. println(`DOMRectReadOnly: ${JSON.stringify(domRectReadOnly)}`);
  35. let domRect = structuredClone(new DOMRect(10, 20, 30, 40));
  36. println(`instanceOf DOMRect: ${domRect instanceof DOMRect}`);
  37. println(`DOMRect: ${JSON.stringify(domRect)}`);
  38. let domQuad = structuredClone(new DOMQuad(new DOMPoint(10, 20, 30, 40), new DOMPoint(50, 60, 70, 80), new DOMPoint(90, 100, 110, 120), new DOMPoint(130, 140, 150, 160)));
  39. println(`instanceOf DOMQuad: ${domQuad instanceof DOMQuad}`);
  40. println(`DOMQuad: ${JSON.stringify(domQuad)}`);
  41. let cryptoKey = await window.crypto.subtle.importKey(
  42. "raw",
  43. new TextEncoder().encode("password"),
  44. { name: "PBKDF2" },
  45. false,
  46. ["deriveBits", "deriveKey"]
  47. );
  48. let clonedCryptoKey = structuredClone(cryptoKey);
  49. println(`instanceOf CryptoKey: ${clonedCryptoKey instanceof CryptoKey}`);
  50. println(`CryptoKey.type: ${JSON.stringify(clonedCryptoKey.type)}`);
  51. println(`CryptoKey.extractable: ${JSON.stringify(clonedCryptoKey.extractable)}`);
  52. println(`CryptoKey.algorithm: ${JSON.stringify(clonedCryptoKey.algorithm)}`);
  53. println(`CryptoKey.usages: ${JSON.stringify(clonedCryptoKey.usages)}`);
  54. let domException = structuredClone(new DOMException("Index out of bounds", "IndexSizeError"));
  55. println(`instanceOf DOMException: ${domException instanceof DOMException}`);
  56. println(`DOMException: ${domException.message} - ${domException.name}`);
  57. done();
  58. });
  59. </script>