<p dir="auto"><strong>Environment:</strong></p>
<ul dir="auto">
<li>Zorin OS 16 (Ubuntu GNU/Linux variant) 64-bit</li>
<li>Deno 1.18.2</li>
<li>VSCode 1.63.2</li>
</ul>
<p dir="auto"><strong>Steps to reproduce:</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const blob_original = new Blob()
console.log('blob_original instanceof Blob', blob_original instanceof Blob)
const blob_copy = structuredClone(blob_original)
// Expcted 'blob_copy instanceof Blob true'
console.log('blob_copy instanceof Blob', blob_copy instanceof Blob)

const file_original = new File([new Uint8Array([1, 2, 3])], 'name.fake')
console.log('file_original instanceof File', file_original instanceof File)
const file_copy = structuredClone(file_original)
// Expcted 'file_copy instanceof File true'
console.log('file_copy instanceof File', file_copy instanceof File)"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">blob_original</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Blob</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'blob_original instanceof Blob'</span><span class="pl-kos">,</span> <span class="pl-s1">blob_original</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Blob</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-s1">blob_copy</span> <span class="pl-c1">=</span> <span class="pl-en">structuredClone</span><span class="pl-kos">(</span><span class="pl-s1">blob_original</span><span class="pl-kos">)</span>
<span class="pl-c">// Expcted 'blob_copy instanceof Blob true'</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'blob_copy instanceof Blob'</span><span class="pl-kos">,</span> <span class="pl-s1">blob_copy</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Blob</span><span class="pl-kos">)</span>

<span class="pl-k">const</span> <span class="pl-s1">file_original</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">File</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-k">new</span> <span class="pl-smi">Uint8Array</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s">'name.fake'</span><span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'file_original instanceof File'</span><span class="pl-kos">,</span> <span class="pl-s1">file_original</span> <span class="pl-k">instanceof</span> <span class="pl-smi">File</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-s1">file_copy</span> <span class="pl-c1">=</span> <span class="pl-en">structuredClone</span><span class="pl-kos">(</span><span class="pl-s1">file_original</span><span class="pl-kos">)</span>
<span class="pl-c">// Expcted 'file_copy instanceof File true'</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'file_copy instanceof File'</span><span class="pl-kos">,</span> <span class="pl-s1">file_copy</span> <span class="pl-k">instanceof</span> <span class="pl-smi">File</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">Appears to be problem with internals, as the <code class="notranslate">structuredClone</code> implementation is not catching before it hits the internals. Problem is also reproducible with a naive clone using the internals:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function clone (obj: any): any {
  // @ts-ignore: using Deno internals
  return Deno.core.deserialize(Deno.core.serialize(obj))
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">clone</span> <span class="pl-kos">(</span><span class="pl-s1">obj</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span> <span class="pl-kos">{</span>
  <span class="pl-c">// <span class="pl-k">@ts</span>-ignore: using Deno internals</span>
  <span class="pl-k">return</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-c1">core</span><span class="pl-kos">.</span><span class="pl-en">deserialize</span><span class="pl-kos">(</span><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-c1">core</span><span class="pl-kos">.</span><span class="pl-en">serialize</span><span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Deno's implementation of structured serialize currently supports serializing the JS built-in <code class="notranslate">SharedArrayBuffer</code>, and transferring the JS built-in <code class="notranslate">ArrayBuffer</code> as well as the <code class="notranslate">MessagePort</code> web API. With <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="977529457" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/11823" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/11823/hovercard" href="https://github.com/denoland/deno/issues/11823">#11823</a> it will also support serializing the wasm built-in <code class="notranslate">WebAssembly.Module</code>.</p>
<p dir="auto">But Deno also implements some web APIs that per the spec should be serializable or transferable but aren't in Deno's implementation. In particular, <code class="notranslate">DOMException</code>, <code class="notranslate">File</code>, <code class="notranslate">Blob</code> and <code class="notranslate">CryptoKey</code> should be serializable; and <code class="notranslate">ReadableStream</code>, <code class="notranslate">WritableStream</code> and <code class="notranslate">TransformStream</code> should be transferable.</p>
<p dir="auto">Implementing this would probably need adding some <code class="notranslate">Deno.core</code> API to define serialization and transfer steps, possibly in connection to the existing <code class="notranslate">Deno.core.createHostObject()</code>. This would also allow refactoring the implementation of <code class="notranslate">MessagePort</code>.</p>