Subj : Re: [SpiderMonkey] Serializing JSObject To : netscape.public.mozilla.jseng From : ggadwa@charter.net Date : Wed Jun 23 2004 05:42 pm Brendan Eich wrote: >> Question two: Why does JSTYPE's have JSTYPE_NUMBER, but in reality >> it's either a DOUBLE or an INT (easy enough to figure out.) Nothing >> else drills down like that. Just wondering. > > > This API corresponds to the typeof operator in the language, which > does not distinguish between double and int (that distinction is an > implementation detail, from the language user and spec points of view). > > Since you are dealing with an implementation of the language here, > namely SpiderMonkey, you might rather use JSVAL_IS_INT, > JSVAL_IS_DOUBLE, etc., than JS_TypeOfValue. Ah ... okey dokey. I use JS_TypeOfValue to filter out the things I don't want to serialize (i.e., functions, and currently, objects, though that will change.) I use the _IS_ to filter it down further. That makes sense to me. > >> I'll post up the code (in case it's useful to anybody, it would be >> quite easy to modify it to save objects and recurse through them.) >> Might be something useful for core. > > > Generally, serialization is domain-specific. If you did it a compact way, it would be. I'm basically generating strings that are ... to a point ... human readable. I never serialize into bytes (which would blow away different machines) - but serialize into strings. Length bytes are all text, etc. This should be crossable to all domains. It'd be an interesting way to pass off objects between load-balanced servers (not that anybody would do that!) For instance, if you had a object that had three properties, and int, a double, a boolean, and a string, it could look like: I myIntProperty 67 D myDoubleProperty 1.345+E00 B myBooleanProperty T S myStringProperty 10 My String! When I add objects, they will just be tabbed in after the start of the 'O' object definition. So be pretty portable. > > Did you look at the XDR stuff? Yeah, but everything seems to be more complex then it needs to be :) Surely, there's good reason, but what I think is useful is just two function calls that take a JSObject, return a string, and the opposite. Nothing else to be done. [>] Brian .