Subj : Re: object serialization To : Jens Thiele From : Brendan Eich Date : Thu Apr 08 2004 11:38 am Jens Thiele wrote: > currently i use (in my code): > ECMA_BEGIN_FUNC(hashObject) > { > ECMA_CHECK_NUM_ARGS(1); > if (!JSVAL_IS_OBJECT(argv[0])) ECMA_ERROR("object required as > argument"); > JSObject *o=JSVAL_TO_OBJECT(argv[0]); > if (!o) return JS_FALSE; > *rval=INT_TO_JSVAL(o); > return JS_TRUE; > } My patch should work better. Your patch will cast o to an integer type, shift it left, and | 1 with it to tag it as an int jsval, which might at the limit create an id that aliases two objects. Very unlikely, but not fully general. The patch I posted is general, because object pointers are guaranteed to be aligned on 0 mod 8 boundaries, so |'ing 1 loses no data; nothing is shifted. > are object pointers guaranteed to remain constant during the lifetime of > a object? See http://lxr.mozilla.org/mozilla/source/js/src/jsapi.h#916: /be .