Closed
Bug 578821
Opened 14 years ago
Closed 14 years ago
Rooting of jetpack handles is too simplistic
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
Tracking | Status | |
---|---|---|
blocking2.0 | --- | beta4+ |
People
(Reporter: benjamin, Assigned: benjamin)
Details
Attachments
(1 file, 1 obsolete file)
The original design of jetpack handles was simple, but won't meet their needs. It rooted both sides of the handle, and some code was responsible for cleaning up the handle when it was no longer needed. This won't work, because there are a fair number of cases where a handle needs to live as long as the client holds it, e.g. the handle for an XMLHttpRequest object needs to live until the client throws it away. Otherwise, we'd have to eagerly send over every possible bit of data that the client might want from the XMLHttpRequest, which is a fair bit of data that most clients won't need. So I'm proposing the following change to the handle API: // Make a handle live only until it is no longer reachable from the calling code. handle.unroot(); // Register a callback which is notified when a handle bmecomes invalid, either // through an explicit invalidate() call or being unrooted and then unreachable. // This method is only called on the *other* side of a conversation. handle.onInvalidate(fn); When a handle is created, it is rooted. Handles can always reach their parent.
Assignee | ||
Comment 1•14 years ago
|
||
Assignee: nobody → benjamin
Status: NEW → ASSIGNED
Attachment #460628 -
Flags: review?(warner-bugzilla)
Attachment #460628 -
Flags: review?(bent.mozilla)
Assignee | ||
Updated•14 years ago
|
blocking2.0: --- → beta4+
Comment on attachment 460628 [details] [diff] [review] Add an .isRooted property, true by default, and .onInvalidate callback function, rev. 1 >+ , mRooted(true) Hm, this isn't really true... Why not make it false to begin with? >+ JS_AddNamedObjectRoot(mCx, &mObj, "Jetpack Handle"); That can fail, theoretically. Do you care? >+ NS_ASSERTION(mRooted, "Initialized incorrectly"); >+ JS_AddNamedObjectRoot(mCx, &mObj, "Jetpack Handle"); If you make mRooted default to false then you could just call Root() here. >+ if (JS_HasProperty(mCx, obj.object(), "onInvalidate", DOM uses all lowercase (e.g. "onload") for event handlers... Do you want to follow that convention here? >+ JS_CallFunctionName(mCx, obj.object(), "onInvalidate", 0, NULL, >+ r.addr()); The handler could throw an exception and screw you up later so I think you either want to report any pending exceptions or clear them here. >+ SetIsRooted(JSContext* cx, JSObject* obj, jsval, jsval* vp) { > ... >+ else >+ self->Unroot(); It's possible to have a null self here isn't it? This could crash. >+JetpackChild::GC(JSContext* cx, uintN argc, jsval *vp) Do you want this in non-test builds too? Maybe #ifdef the impl? >+JetpackChild::GCZeal(JSContext* cx, uintN argc, jsval *vp) Hm, JS_SetGCZeal isn't always available... You need some ifdefs in the impl somewhere.
Assignee | ||
Comment 3•14 years ago
|
||
Made the changes, including removing the weird const/mutable stuff from Handle.h. cjones for the ipc/ipdl changes, bent for the code, and bwarner for the API. I left onInvalidated interCaps because that's the common style in jetpack-land.
Attachment #460628 -
Attachment is obsolete: true
Attachment #461532 -
Flags: review?(warner-bugzilla)
Attachment #461532 -
Flags: review?(jones.chris.g)
Attachment #461532 -
Flags: review?(bent.mozilla)
Attachment #460628 -
Flags: review?(warner-bugzilla)
Attachment #460628 -
Flags: review?(bent.mozilla)
Updated•14 years ago
|
Attachment #461532 -
Flags: review?(jones.chris.g) → review+
Comment on attachment 461532 [details] [diff] [review] Add an .isRooted property, true by default, and .onInvalidate callback function, rev. 2 Looks good!
Attachment #461532 -
Flags: review?(bent.mozilla) → review+
Comment 5•14 years ago
|
||
Comment on attachment 461532 [details] [diff] [review] Add an .isRooted property, true by default, and .onInvalidate callback function, rev. 2 Atul is writing the jetpack-SDK -side code for this, so I think he's in a better position to review it than me.
Attachment #461532 -
Flags: review?(warner-bugzilla) → review?(avarma)
Comment 6•14 years ago
|
||
Comment on attachment 461532 [details] [diff] [review] Add an .isRooted property, true by default, and .onInvalidate callback function, rev. 2 This is perfect, just the kind of functionality we need for implementing our APIs. Thanks also for the gc()/gczeal() globals, they'll be useful for our own unit tests too.
Attachment #461532 -
Flags: review?(avarma) → review+
Assignee | ||
Comment 7•14 years ago
|
||
http://hg.mozilla.org/mozilla-central/rev/383c1d348414
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Comment 8•14 years ago
|
||
I've documented these changes here: https://developer.mozilla.org/en/Jetpack_Processes
You need to log in
before you can comment on or make changes to this bug.
Description
•