Closed Bug 781070 Opened 12 years ago Closed 11 years ago

make NullPtr public

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla22

People

(Reporter: Benjamin, Assigned: jonco)

References

Details

(Whiteboard: [js:t])

Attachments

(1 file, 1 obsolete file)

The other rooting stuff works outside of JS by virture of being templates. NullPtr is concrete, though, so it needs JS_PUBLIC_API.
Attached patch make it public (obsolete) — Splinter Review
Assignee: general → bpeterson
Attachment #649919 - Flags: review?(luke)
Will this make normal use inside the JS engine slower (requiring reading the GOT to find &NullPtr::constNullValue)?

If so, one alternative is to have the NullPtr provide the NULL-holding memory location as a member variable, although this has hazards like:

  HandleObject h = NullPtr();
  // NullPtr() has been destroyed, h still points at address
Luke and I talked about this and came to the conclusion that browser code can use Rooted* (cx, NULL) for now.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
Attachment #649919 - Flags: review?(luke)
This makes me :-(

I don't think it would be acceptable to finalize a handle API without a convenient way for consumers to pass null. Given that, I think we might as well solve this problem now.
Status: RESOLVED → REOPENED
Resolution: WONTFIX → ---
The handle API is not at all finalized. Where do you need this Bobby? Right now the only place where you might need to call a function that takes a handle is if you're calling a callback.
(In reply to Bill McCloskey (:billm) from comment #5)
> The handle API is not at all finalized. Where do you need this Bobby? Right
> now the only place where you might need to call a function that takes a
> handle is if you're calling a callback.

http://mxr.mozilla.org/mozilla-central/source/dom/base/nsJSEnvironment.cpp#1330
(In reply to Bobby Holley (:bholley) from comment #6)
> http://mxr.mozilla.org/mozilla-central/source/dom/base/nsJSEnvironment.
> cpp#1330

Oh yeah. Those handles should not have been added. We decided to leave them in rather than convert them back to raw pointers. Maybe that was a mistake, though.
Polyfilling std::nullptr_t per bug 806546 would also solve this problem, and probably better than by exposing NullPtr.  That said, I'm not totally sure it's possible to have both nullptr and std::nullptr_t at once, without compiler support, but I could easily be wrong.
(In reply to Bill McCloskey (:billm) from comment #7)
> Oh yeah. Those handles should not have been added. We decided to leave them
> in rather than convert them back to raw pointers. Maybe that was a mistake,
> though.

Ah I see. I probably had an inflated view of how much the handles have leaked out into the DOM because I see them everywhere in XPConnect (with all the JSClass hooks and such). If I'm not supposed to be using them I'm happy to forget about this bug for the time being (so long as there is eventually a solution).
When it does become relevant, we could add a JS_PUBLIC_API JS::NullHandle which would be separate from and thus avoid penalizing the engine-internal js::NullHandle.
(In reply to Luke Wagner [:luke] from comment #10)
> When it does become relevant, we could add a JS_PUBLIC_API JS::NullHandle
> which would be separate from and thus avoid penalizing the engine-internal
> js::NullHandle.

sgtm.
Whiteboard: [js:t]
Assignee: benjamin → general
Assignee: general → jcoppeard
Attachment #649919 - Attachment is obsolete: true
Attachment #726677 - Flags: review?(terrence)
Comment on attachment 726677 [details] [diff] [review]
Introduce separate public JS::NullPtr

Review of attachment 726677 [details] [diff] [review]:
-----------------------------------------------------------------

Nicely done!

::: js/public/RootingAPI.h
@@ +118,5 @@
>  template <typename T>
>  class MutableHandleBase {};
>  
> +/*
> + * Pass a NULL handle, internal version.

Lets expand on this a bit to give more context. Something like:

"js::NullPtr acts like a NULL pointer in contexts that require a Handle. This is the SpiderMonkey internal variant. js::NullPtr should be used in preference to JS::NullPtr to avoid the GOT access required for JS_PUBLIC_API symbols."

@@ +149,5 @@
>  CheckStackRoots(JSContext *cx);
>  #endif
>  
>  /*
> + * Pass a NULL handle, public version.

The same comment as above, but we can stop after the first sentence.
Attachment #726677 - Flags: review?(terrence) → review+
https://hg.mozilla.org/mozilla-central/rev/74b7f2c42ca4
Status: REOPENED → RESOLVED
Closed: 12 years ago11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla22
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: