@@ -550,7 +550,8 @@ WrapNewBindingForSameCompartment(JSContext* cx, JSObject* obj,
550550// having "value" inherit from nsWrapperCache.
551551template <class T >
552552MOZ_ALWAYS_INLINE bool
553- WrapNewBindingObject (JSContext* cx, JSObject* scope, T* value, JS ::Value* vp)
553+ WrapNewBindingObject (JSContext* cx, JS ::Handle<JSObject*> scope, T* value,
554+ JS ::Value* vp)
554555{
555556 MOZ_ASSERT (value);
556557 JSObject* obj = value->GetWrapperPreserveColor ();
@@ -612,8 +613,9 @@ WrapNewBindingObject(JSContext* cx, JSObject* scope, T* value, JS::Value* vp)
612613// WrapObject() method taking a JSContext and a scope.
613614template <class T >
614615inline bool
615- WrapNewBindingNonWrapperCachedObject (JSContext* cx, JSObject* scope, T* value,
616- JS ::Value* vp)
616+ WrapNewBindingNonWrapperCachedObject (JSContext* cx,
617+ JS ::Handle<JSObject*> scopeArg,
618+ T* value, JS ::Value* vp)
617619{
618620 MOZ_ASSERT (value);
619621 // We try to wrap in the compartment of the underlying object of "scope"
@@ -622,6 +624,10 @@ WrapNewBindingNonWrapperCachedObject(JSContext* cx, JSObject* scope, T* value,
622624 // scope for the JSAutoCompartment so that we restore the compartment
623625 // before we call JS_WrapValue.
624626 Maybe<JSAutoCompartment> ac;
627+ // Maybe<Handle> doesn't so much work, and in any case, adding
628+ // more Maybe (one for a Rooted and one for a Handle) adds more
629+ // code (and branches!) than just adding a single rooted.
630+ JS ::Rooted<JSObject*> scope (cx, scopeArg);
625631 if (js::IsWrapper (scope)) {
626632 scope = js::CheckedUnwrap (scope, /* stopAtOuter = */ false );
627633 if (!scope)
@@ -648,7 +654,8 @@ WrapNewBindingNonWrapperCachedObject(JSContext* cx, JSObject* scope, T* value,
648654// is true if the JSObject took ownership
649655template <class T >
650656inline bool
651- WrapNewBindingNonWrapperCachedOwnedObject (JSContext* cx, JSObject* scope,
657+ WrapNewBindingNonWrapperCachedOwnedObject (JSContext* cx,
658+ JS ::Handle<JSObject*> scopeArg,
652659 nsAutoPtr<T>& value, JS ::Value* vp)
653660{
654661 // We do a runtime check on value, because otherwise we might in
@@ -662,6 +669,10 @@ WrapNewBindingNonWrapperCachedOwnedObject(JSContext* cx, JSObject* scope,
662669 // scope for the JSAutoCompartment so that we restore the compartment
663670 // before we call JS_WrapValue.
664671 Maybe<JSAutoCompartment> ac;
672+ // Maybe<Handle> doesn't so much work, and in any case, adding
673+ // more Maybe (one for a Rooted and one for a Handle) adds more
674+ // code (and branches!) than just adding a single rooted.
675+ JS ::Rooted<JSObject*> scope (cx, scopeArg);
665676 if (js::IsWrapper (scope)) {
666677 scope = js::CheckedUnwrap (scope, /* stopAtOuter = */ false );
667678 if (!scope)
@@ -692,7 +703,7 @@ WrapNewBindingNonWrapperCachedOwnedObject(JSContext* cx, JSObject* scope,
692703// Helper for smart pointers (nsAutoPtr/nsRefPtr/nsCOMPtr).
693704template <template <typename > class SmartPtr , typename T>
694705inline bool
695- WrapNewBindingNonWrapperCachedObject (JSContext* cx, JSObject* scope,
706+ WrapNewBindingNonWrapperCachedObject (JSContext* cx, JS ::Handle< JSObject*> scope,
696707 const SmartPtr<T>& value, JS ::Value* vp)
697708{
698709 return WrapNewBindingNonWrapperCachedObject (cx, scope, value.get (), vp);
@@ -1055,8 +1066,8 @@ struct WrapNativeParentFallback<T, true >
10551066template <typename T, bool hasWrapObject=HasWrapObject<T>::Value >
10561067struct WrapNativeParentHelper
10571068{
1058- static inline JSObject* Wrap (JSContext* cx, JSObject* scope, T* parent ,
1059- nsWrapperCache* cache)
1069+ static inline JSObject* Wrap (JSContext* cx, JS ::Handle< JSObject*> scope,
1070+ T* parent, nsWrapperCache* cache)
10601071 {
10611072 MOZ_ASSERT (cache);
10621073
@@ -1081,8 +1092,8 @@ struct WrapNativeParentHelper
10811092template <typename T>
10821093struct WrapNativeParentHelper <T, false >
10831094{
1084- static inline JSObject* Wrap (JSContext* cx, JSObject* scope, T* parent ,
1085- nsWrapperCache* cache)
1095+ static inline JSObject* Wrap (JSContext* cx, JS ::Handle< JSObject*> scope,
1096+ T* parent, nsWrapperCache* cache)
10861097 {
10871098 JSObject* obj;
10881099 if (cache && (obj = cache->GetWrapper ())) {
@@ -1100,7 +1111,8 @@ struct WrapNativeParentHelper<T, false >
11001111// Wrapping of our native parent.
11011112template <typename T>
11021113static inline JSObject*
1103- WrapNativeParent (JSContext* cx, JSObject* scope, T* p, nsWrapperCache* cache)
1114+ WrapNativeParent (JSContext* cx, JS ::Handle<JSObject*> scope, T* p,
1115+ nsWrapperCache* cache)
11041116{
11051117 if (!p) {
11061118 return scope;
@@ -1113,7 +1125,7 @@ WrapNativeParent(JSContext* cx, JSObject* scope, T* p, nsWrapperCache* cache)
11131125// things like the nsWrapperCache for it.
11141126template <typename T>
11151127static inline JSObject*
1116- WrapNativeParent (JSContext* cx, JSObject* scope, const T& p)
1128+ WrapNativeParent (JSContext* cx, JS ::Handle< JSObject*> scope, const T& p)
11171129{
11181130 return WrapNativeParent (cx, scope, GetParentPointer (p), GetWrapperCache (p));
11191131}
@@ -1123,7 +1135,7 @@ HAS_MEMBER(GetParentObject)
11231135template <typename T, bool WrapperCached=HasGetParentObjectMember<T>::Value>
11241136struct GetParentObject
11251137{
1126- static JSObject* Get (JSContext* cx, JSObject* obj)
1138+ static JSObject* Get (JSContext* cx, JS ::Handle< JSObject*> obj)
11271139 {
11281140 T* native = UnwrapDOMObject<T>(obj);
11291141 return WrapNativeParent (cx, obj, native->GetParentObject ());
@@ -1133,7 +1145,7 @@ struct GetParentObject
11331145template <typename T>
11341146struct GetParentObject <T, false >
11351147{
1136- static JSObject* Get (JSContext* cx, JSObject* obj)
1148+ static JSObject* Get (JSContext* cx, JS ::Handle< JSObject*> obj)
11371149 {
11381150 MOZ_CRASH ();
11391151 return nullptr ;
@@ -1154,7 +1166,7 @@ JSObject* GetJSObjectFromCallback(void* noncallback)
11541166
11551167template <typename T>
11561168static inline JSObject*
1157- WrapCallThisObject (JSContext* cx, JSObject* scope, const T& p)
1169+ WrapCallThisObject (JSContext* cx, JS ::Handle< JSObject*> scope, const T& p)
11581170{
11591171 // Callbacks are nsISupports, so WrapNativeParent will just happily wrap them
11601172 // up as an nsISupports XPCWrappedNative... which is not at all what we want.
@@ -1182,8 +1194,8 @@ WrapCallThisObject(JSContext* cx, JSObject* scope, const T& p)
11821194template <class T , bool isSmartPtr=HasgetMember<T>::Value>
11831195struct WrapNewBindingObjectHelper
11841196{
1185- static inline bool Wrap (JSContext* cx, JSObject* scope, const T& value ,
1186- JS ::Value* vp)
1197+ static inline bool Wrap (JSContext* cx, JS ::Handle< JSObject*> scope,
1198+ const T& value, JS ::Value* vp)
11871199 {
11881200 return WrapNewBindingObject (cx, scope, value.get (), vp);
11891201 }
@@ -1192,7 +1204,7 @@ struct WrapNewBindingObjectHelper
11921204template <class T >
11931205struct WrapNewBindingObjectHelper <T, false >
11941206{
1195- static inline bool Wrap (JSContext* cx, JSObject* scope, T& value,
1207+ static inline bool Wrap (JSContext* cx, JS ::Handle< JSObject*> scope, T& value,
11961208 JS ::Value* vp)
11971209 {
11981210 return WrapNewBindingObject (cx, scope, &value, vp);
@@ -1201,7 +1213,7 @@ struct WrapNewBindingObjectHelper<T, false>
12011213
12021214template <class T >
12031215inline bool
1204- WrapNewBindingObject (JSContext* cx, JSObject* scope, T& value,
1216+ WrapNewBindingObject (JSContext* cx, JS ::Handle< JSObject*> scope, T& value,
12051217 JS ::Value* vp)
12061218{
12071219 return WrapNewBindingObjectHelper<T>::Wrap (cx, scope, value, vp);
0 commit comments