title: Extract a list of Transferable from a javascript object?
body: <p>The <a href="https://developer.mozilla.org/en/docs/Web/API/Worker/postMessage" rel="nofollow"><strong>postMessage()</strong></a> method of the Worker interface allows to pass a <code>transferList</code> which is an array of objects whose references should be passed (rather than the objects being copied).</p>
  
  <pre><code>myWorker.postMessage(aMessage, transferList);
  </code></pre>
  
  <p>Is there a safe way to recursively extract all objects that can have their references passed (according to the API, only <a href="https://developer.mozilla.org/en-US/docs/Web/API/MessagePort" rel="nofollow">MessagePort</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" rel="nofollow">ArrayBuffer</a>), so we don't have to worry about passing all of them manually?</p>
  
  <pre><code>myWorker.postMessage(aMessage, extractTransferList(aMessage));
  </code></pre>
  
  <p>Is it recommended to implement this behavior?</p>
  
  <p><strong>Example</strong>:</p>
  
  <p>When we consider the following code:</p>
  
  <pre><code>var objData =
  {
      str: "string",
      i8: new Int8Array(200),
      obj : {
         num : 8,
         ab: new ArrayBuffer(100)
      }  
  };
  objWorker.postMessage(objData, [objData.i8.buffer, objData.obj.ab]);
  </code></pre>
  
  <p>We need to specify in the second parameter all fields of our objects that should have their references passed. My question is about building a function that does the job for us, to make sure that we don't forget some transferable objects here (that could impact performances without us knowing it).</p>
  
  <pre><code>objWorker.postMessage(objData, extractTransferList(objData));
  </code></pre>