[whatwg] Structured clone algorithm a little too friendly?

timeless timeless at gmail.com
Wed Mar 10 00:41:38 PST 2010

On Tue, Mar 2, 2010 at 12:50 AM, ben turner <bent at mozilla.com> wrote:
> Hi folks,
> I'm implementing the structured clone algorithm and this part bothers
> me a little bit:
>  - If input is a host object (e.g. a DOM node)
>      Return the null value.
> Seems like this has the potential to confuse web programmers somewhat.
> If I were to write code like this:
>  worker.postMessage(window);
> I would expect something meaningful to happen as long as no exception
> was generated. According to the spec, though, we would send null to
> the worker and not generate any exception. Is that really desirable?
> I like the idea of making the structured clone as friendly as possible
> but maybe we should add some teeth to this case just like we do for
> recursive objects?

You could convert objects into {toString:function(){return null},
valueOf:function(){return "[Window native object]"}} or something.

The general reason, I believe for this behavior is if you have:

a=[x,y,z,q,r,s]; worker.postMessage(a) and r turns out to be window,
you don't want to trigger an exception just because one value in a
list is a native object.

Serializing Window and similar items seems like a recipe for failure.

More information about the whatwg mailing list