Closed Bug 860572 Opened 11 years ago Closed 11 years ago

Add specializations of Handle and MutableHandle for JSPropertyDescriptor

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla23

People

(Reporter: bzbarsky, Assigned: terrence)

References

Details

Attachments

(2 files, 3 obsolete files)

The idea is that:

1) Callees should be able to tell when their desc is rooted.
2) They should be able to easily get a MutableHandle<Value> for the .value of a
   MutableHandle<JSPropertyDescriptor>.  And perhaps similar for the .obj.  What
   to do with the getter and setter.... <sigh>.  I have no idea for those.
Attached patch v0 (obsolete) — Splinter Review
This should be all that's needed.

https://tbpl.mozilla.org/?tree=Try&rev=b42ebc59fbcc
Assignee: general → terrence
Status: NEW → ASSIGNED
I guess we'll need a followup to actually use this, right?
(In reply to Boris Zbarsky (:bz) from comment #2)
> I guess we'll need a followup to actually use this, right?

Yes, and some fixes to this patch as well. It seems there is a good reason I don't normally code when tired.
Build succeeded locally, so off to try again:
https://tbpl.mozilla.org/?tree=Try&rev=83688476493f
Attachment #736108 - Attachment is obsolete: true
Attached patch v2 (obsolete) — Splinter Review
And fix a namespace error. I hope this is the last try run we'll need:
https://tbpl.mozilla.org/?tree=Try&rev=63905e8538cb
Attachment #736554 - Attachment is obsolete: true
Attachment #737032 - Flags: review?(jcoppeard)
Comment on attachment 737032 [details] [diff] [review]
v2

Actually, lets add the helper methods to Handle and MutableHandle too.
Attachment #737032 - Flags: review?(jcoppeard)
Attached patch 1 of 2: v3Splinter Review
Implements HandleBase and MutableHandleBase as well.
Attachment #737032 - Attachment is obsolete: true
Attachment #737058 - Flags: review?(jcoppeard)
Rooted adds helper methods to JSPropertyDescriptor to make using it less error-prone. This is an example of such usage.
Attachment #737060 - Flags: review?(bobbyholley+bmo)
Attachment #737060 - Flags: review?(bobbyholley+bmo) → review+
Comment on attachment 737058 [details] [diff] [review]
1 of 2: v3

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

::: js/src/gc/RootMarking.cpp
@@ +67,5 @@
>        case THING_ROOT_VALUE:       MarkValueRoot(trc, (Value *)addr, "exact-value"); break;
>        case THING_ROOT_ID:          MarkIdRoot(trc, (jsid *)addr, "exact-id"); break;
>        case THING_ROOT_PROPERTY_ID: MarkIdRoot(trc, &((js::PropertyId *)addr)->asId(), "exact-propertyid"); break;
>        case THING_ROOT_BINDINGS:    ((Bindings *)addr)->trace(trc); break;
> +      case THING_ROOT_BINDINGS:    ((JSPropertyDescriptor *)addr)->trace(trc); break;

I think you mean THING_ROOT_PROPERTY_DESCRIPTOR here.

::: js/src/gc/Verifier.cpp
@@ +37,3 @@
>          return address == static_cast<void*>(w);
>  
>      Bindings *bp = static_cast<Bindings*>(address);

This assumes address is always a Binding which is now not the case any more.

::: js/src/jsapi.h
@@ +3328,5 @@
> +    JS::MutableHandleObject obj() { return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); }
> +    JS::MutableHandleValue value() { return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); }
> +    bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; }
> +    bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; }
> +    JSPropertyOp getter() const { MOZ_ASSERT(!hasGetterObject()); return desc()->getter; }

The assertion condition looks like it's the wrong way round to me (same on next line).
Attachment #737058 - Flags: review?(jcoppeard) → review+
(In reply to Jon Coppeard (:jonco) from comment #10)

> > +    JSPropertyOp getter() const { MOZ_ASSERT(!hasGetterObject()); return desc()->getter; }
> 
> The assertion condition looks like it's the wrong way round to me (same on
> next line).

Disregard this one, I realised that getter/setter are used for different types depending on the flags in attrs.

One more thing though, in the XrayWrapper code it would be useful to have a way to get attrs, as well as to set getter and setter.
Blocks: 861887
(In reply to Jon Coppeard (:jonco) from comment #10)
> ::: js/src/gc/RootMarking.cpp
> @@ +67,5 @@
> >        case THING_ROOT_VALUE:       MarkValueRoot(trc, (Value *)addr, "exact-value"); break;
> >        case THING_ROOT_ID:          MarkIdRoot(trc, (jsid *)addr, "exact-id"); break;
> >        case THING_ROOT_PROPERTY_ID: MarkIdRoot(trc, &((js::PropertyId *)addr)->asId(), "exact-propertyid"); break;
> >        case THING_ROOT_BINDINGS:    ((Bindings *)addr)->trace(trc); break;
> > +      case THING_ROOT_BINDINGS:    ((JSPropertyDescriptor *)addr)->trace(trc); break;
> 
> I think you mean THING_ROOT_PROPERTY_DESCRIPTOR here.

D'oh!
 
(In reply to Jon Coppeard (:jonco) from comment #11)
> (In reply to Jon Coppeard (:jonco) from comment #10)
> Disregard this one, I realised that getter/setter are used for different
> types depending on the flags in attrs.

Yeah, this is, in my opinion, the worst GC issue in SpiderMonkey: for example, for Shapes we also have to special-case the post barrier because of this.

A quick survey of PropertyDescriptor seems to show that all of the SpiderMonkey uses are on the stack as well. I'll file a new bug to remove the AutoRooter.

> One more thing though, in the XrayWrapper code it would be useful to have a
> way to get attrs, as well as to set getter and setter.

Good point! In the long run we'd like JSPropertyDescriptor to match the spec's concept of a PropertyDescriptor. However, after talking this over with Waldo, we concluded that this is long enough off that a suite of dumb wrappers of the existing functionality would be beneficial.
Okay, not really sure why the compiler only reported one of the two name-masking errors here. Lets spin the warning-as-errors wheel again:
https://tbpl.mozilla.org/?tree=Try&rev=de71aa1c35c9
https://hg.mozilla.org/mozilla-central/rev/49dbf1510125
https://hg.mozilla.org/mozilla-central/rev/e1939f325abb
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: