Subj : Re: [SpiderMonkey] JS_SealObject To : Brian Barnes From : Brendan Eich Date : Sun Jul 20 2003 10:08 am Brian Barnes wrote: > On Saturday, July 19, 2003, at 10:48 PM, Brendan Eich wrote: > >> 2. Use JS_SealObject after you've populated an object, to prevent >> *any* properties from being added to it. > > ARGH! I was pulling my hair out wondering how I could miss this, and > I was about ready to put my head in the oven when I realized that it's > brand new. Yeah! I get to remove a bunch of wacky code! > > Two questions, since there doesn't seem to be a listing in the docs: > > JS_SealObject(JSContext *cx, JSObject *obj, JSBool deep); > > 1. What does deep do? I assume it means to it recursively. Yes, and it will walk right up the __proto__ and __parent__ slots, so beware. If you use it on an object sub-graph that's connected to your global object (all new objects get the __parent__ of their constructor function object), you will seal the entire object graph reachable from that global object! Use deep only for a newly-created standard object graph, in a "root" or bootstrapping context where you intend all later global objects to share the standard objects via a "superglobal" (__proto__-linked from each real global). Or use it carefully in conjunction with JS_SetParent(cx, obj, null) and JS_SetPrototype(cx, obj, null), and restore the proto and parent after sealing the sub-graph. > 2. I don't think so but have to ask -- Do I need to unseal sealed > objects to have a proper shutdown for JS? No. /be .