JSON.stringify replacer array semantics

Oliver Hunt oliver at apple.com
Fri Jun 5 14:21:41 PDT 2009


On Jun 5, 2009, at 11:24 AM, Allen Wirfs-Brock wrote:

> The effect of a side-effect of the stringify algorithm mutating the  
> replacer array is as well defined as any other side-effect sensitive  
> aspect of the algorithm, if the entire stringify algorithm is  
> strictly implemented as specified. A strict interpretation of the  
> current specification requires that the List in JO step 5.a gets  
> recreate on each use of JO. So side-effects that modify the replacer  
> array would result in different List contents.  I think it probably  
> is a good idea to move step 5.a into the top level stringify  
> algorithm so that the List is only generated once before any  
> possible side-effect producing operations.

json2.js appears to perform JO.5.a at the top level of the stringify  
so this makes sense.  Firefox also does the copy to an internal list  
on the entry to stringify, but performs toString conversion on each  
item in replacement for each object it calls.

--Oliver



More information about the es-discuss mailing list