Re: [whatwg] asynchronous JSON.parse

Le 08/03/2013 15:29, David Rajchenbach-Teller a écrit :
> On 3/8/13 1:59 PM, David Bruant wrote:
>>> Consider, for instance, a browser implemented as a web application,
>>> FirefoxOS-style. The data that needs to be collected to save its current
>>> state is held in the DOM. For performance and consistency, it is not
>>> practical to keep the DOM synchronized at all times with a worker
>>> thread. Consequently, data needs to be collected on the main thread and
>>> then sent to a worker thread.
>> I feel the data can be collected on the main thread in a Transferable
>> (probably awkward, yet doable). This way, when the data needs to be
>> transfered, the transfer is fast and heavy processing can happen in the
>> worker.
> Intuitively, this sounds like:
> 1. collect data to a JSON;
I don't understand this sentence. Do you mean "collect data in an object"?
Just to be sure we use the same vocabulary:
When I say "object", I mean something described by ES5 - 8.6 [1], so 
basically a bag of properties (usually data properties) with an internal 
[[Prototype]], etc.
When I say "JSON", it's a shortcut for "JSON string" following the 
grammar defined at ES5 - 5.1.5 [2].
Given the vocabulary I use, one can collect data in an object (by adding 
own properties, most likely), then serialize it as a JSON string with a 
call to JSON.stringify, but one cannot collect data in/to a JSON.

> 2. serialize JSON (hopefully asynchronously) to a Transferable (or
> several Transferables).
Why not collect the data in a Transferable like an ArrayBuffer directly? 
It skips the additional serialization part. Writing a byte stream 
directly is a bit hardcore I admit, but an object full of setters can 
give the impression to create an object while actually filling an 
ArrayBuffer as a backend. I feel that could work efficiently.

What are the data you want to collect? Is it all at once or are you 
building the object little by little? For a backup and for FirefoxOS 
specifically, could a FileHandle [3] work? It's an async API to write in 
a file.

David

[1] http://es5.github.com/#x8.6
[2] http://es5.github.com/#x5.1.5
[3] https://developer.mozilla.org/en-US/docs/WebAPI/FileHandle_API

Received on Friday, 8 March 2013 16:35:37 UTC