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 bren...@secure.meer.net 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

Re: Exposing structured clone as an API?

2015-04-27 Thread Elliott Sprehn
On Apr 24, 2015 3:16 PM, Joshua Bell jsb...@google.com 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

Re: Exposing structured clone as an API?

2015-04-27 Thread Jonas Sicking
On Thu, Apr 23, 2015 at 6:31 PM, Kyle Huey m...@kylehuey.com wrote: On Thu, Apr 23, 2015 at 6:06 PM, Boris Zbarsky bzbar...@mit.edu 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

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 t...@mozilla.com 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

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

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 jsb...@google.com 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

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) {

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 ro...@w3.org 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

Re: Exposing structured clone as an API?

2015-04-23 Thread Martin Thomson
On 23 April 2015 at 15:02, Ted Mielczarek t...@mozilla.com 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

Re: Exposing structured clone as an API?

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

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

Re: Exposing structured clone as an API?

2015-04-23 Thread Martin Thomson
On 23 April 2015 at 15:34, Elliott Sprehn espr...@chromium.org 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

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

Re: Exposing structured clone as an API?

2015-04-23 Thread Kyle Huey
On Thu, Apr 23, 2015 at 6:06 PM, Boris Zbarsky bzbar...@mit.edu 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

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

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

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 t...@mozilla.com 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