Re: Exposing structured clone as an API?

2015-04-27 Thread Elliott Sprehn
On Apr 24, 2015 3:16 PM, "Joshua Bell" wrote: > > It seems like the OP's intent is just to deep-copy an object. Something like the OP's tweet... or this, which we use in some tests: > > function structuredClone(o) { > return new Promise(function(resolve) { > var mc = new MessageChannel

Re: Exposing structured clone as an API?

2015-04-27 Thread Jonas Sicking
On Thu, Apr 23, 2015 at 6:31 PM, Kyle Huey wrote: > On Thu, Apr 23, 2015 at 6:06 PM, Boris Zbarsky wrote: >> On 4/23/15 6:34 PM, Elliott Sprehn wrote: >>> >>> Have you benchmarked this? I think you're better off just writing your >>> own clone library. >> >> >> That requires having a list of all

Re: Exposing structured clone as an API?

2015-04-27 Thread Anne van Kesteren
On Sat, Apr 25, 2015 at 12:41 AM, Brendan Eich wrote: > Step where you need to, to avoid falling over :-P. Fair. I filed https://www.w3.org/Bugs/Public/show_bug.cgi?id=28566 on adding a structured clone API. > The problems with generalized/extensible clone are clear but we have > structured

Re: Exposing structured clone as an API?

2015-04-24 Thread Brendan Eich
Step where you need to, to avoid falling over :-P. The problems with generalized/extensible clone are clear but we have structured clone already. It is based on a hardcoded type-case statement. It could be improved a bit without trying to solve all possible problems, IMHO. /be Anne van Kest

Re: Exposing structured clone as an API?

2015-04-24 Thread Anne van Kesteren
On Fri, Apr 24, 2015 at 3:13 PM, Joshua Bell wrote: > If we're not dragging in the notion of extensibility, is there complication? I would be fine with adding an API without extensibility. I was just afraid we might step on TC39's toes, but maybe since they're not helping out with structured clon

Re: Exposing structured clone as an API?

2015-04-24 Thread Joshua Bell
It seems like the OP's intent is just to deep-copy an object. Something like the OP's tweet... or this, which we use in some tests: function structuredClone(o) { return new Promise(function(resolve) { var mc = new MessageChannel(); mc.port2.onmessage = function(e) { resolve(e.d

Re: Exposing structured clone as an API?

2015-04-24 Thread Anne van Kesteren
On Fri, Apr 24, 2015 at 2:08 AM, Robin Berjon wrote: > Does this have to be any more complicated than adding a toClone() convention > matching the ones we already have? Yes, much more complicated. This does not work at all. You need something to serialize the object so you can transport it to ano

Re: Exposing structured clone as an API?

2015-04-24 Thread Robin Berjon
On 24/04/2015 02:18 , Anne van Kesteren wrote: On Thu, Apr 23, 2015 at 3:02 PM, Ted Mielczarek wrote: Has anyone ever proposed exposing the structured clone algorithm directly as an API? There has been some talk about moving structured cloning into ECMAScript proper and exposing the primitive

Re: Exposing structured clone as an API?

2015-04-23 Thread Boris Zbarsky
On 4/23/15 9:31 PM, Kyle Huey wrote: Today it's not demanding, it's not even possible. e.g. how do you duplicate a FileList object? Ah, there we go. I figured there was something that would fail the "ways of cloning them all" test in the platform today... ;) We should make it possible to m

Re: Exposing structured clone as an API?

2015-04-23 Thread Kyle Huey
On Thu, Apr 23, 2015 at 6:06 PM, Boris Zbarsky wrote: > On 4/23/15 6:34 PM, Elliott Sprehn wrote: >> >> Have you benchmarked this? I think you're better off just writing your >> own clone library. > > > That requires having a list of all objects browsers consider clonable and > having ways of clon

Re: Exposing structured clone as an API?

2015-04-23 Thread Boris Zbarsky
On 4/23/15 6:34 PM, Elliott Sprehn wrote: Have you benchmarked this? I think you're better off just writing your own clone library. That requires having a list of all objects browsers consider clonable and having ways of cloning them all, right? Maintaining such a library is likely to be a s

Re: Exposing structured clone as an API?

2015-04-23 Thread Anne van Kesteren
On Thu, Apr 23, 2015 at 3:02 PM, Ted Mielczarek wrote: > Has anyone ever proposed exposing the structured clone algorithm directly as > an API? There has been some talk about moving structured cloning into ECMAScript proper and exposing the primitives. But TC39 does not seem particularly receptiv

Re: Exposing structured clone as an API?

2015-04-23 Thread Martin Thomson
On 23 April 2015 at 15:34, Elliott Sprehn wrote: > Have you benchmarked this? I think you're better off just writing your own > clone library. Not really the point of my mail. Of course you would be better writing a real clone. It could probably even be synchronous, though it removes this (or

Re: Exposing structured clone as an API?

2015-04-23 Thread Maciej Stachowiak
> On Apr 23, 2015, at 3:27 PM, Martin Thomson wrote: > > On 23 April 2015 at 15:02, Ted Mielczarek wrote: >> Has anyone ever proposed exposing the structured clone algorithm directly as >> an API? > > If you didn't just do so, I will :) > >> 1. https://twitter.com/TedMielczarek/status/591315

Re: Exposing structured clone as an API?

2015-04-23 Thread Elliott Sprehn
The way many browsers implement this isn't going to be particularly fast. It serializes the objects to a byte sequence so it can be transferred to another thread or process and then inflates the objects on the other side. Have you benchmarked this? I think you're better off just writing your own c

Re: Exposing structured clone as an API?

2015-04-23 Thread Martin Thomson
On 23 April 2015 at 15:02, Ted Mielczarek wrote: > Has anyone ever proposed exposing the structured clone algorithm directly as > an API? If you didn't just do so, I will :) > 1. https://twitter.com/TedMielczarek/status/591315580277391360 Looking at your jsfiddle, here's a way to turn that int

Exposing structured clone as an API?

2015-04-23 Thread Ted Mielczarek
Has anyone ever proposed exposing the structured clone algorithm directly as an API? Katelyn Gadd was musing about fast deep copy in JS on Twitter, and I proposed a hack to use postMessage to do so[1], which works but it's a little roundabout. Since structured clone is a primitive that the web plat