Bug 1363208 part 1. Add a MaybeWrapObject function that works on JSObject* instead of JS::Value. r=peterv,bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 21 Jan 2019 03:24:42 +0000
changeset 454643 8c6fcfca64219879ccdefa96ee04a33d39216fbe
parent 454642 8d644de8941b6fec72deda5826976d6b07f87c90
child 454644 52f7c0595d0df20d7e47685443ccae340b0c9ab4
push id35409
push userrmaries@mozilla.com
push dateMon, 21 Jan 2019 17:48:45 +0000
treeherdermozilla-central@4977d02e1191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv, bholley
bugs1363208
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1363208 part 1. Add a MaybeWrapObject function that works on JSObject* instead of JS::Value. r=peterv,bholley Differential Revision: https://phabricator.services.mozilla.com/D15424
dom/bindings/BindingUtils.h
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -777,16 +777,26 @@ inline bool TryToOuterize(JS::MutableHan
     JSObject* obj = js::ToWindowProxyIfWindow(&rval.toObject());
     MOZ_ASSERT(obj);
     rval.set(JS::ObjectValue(*obj));
   }
 
   return true;
 }
 
+inline bool TryToOuterize(JS::MutableHandle<JSObject*> obj) {
+  if (js::IsWindow(obj)) {
+    JSObject* proxy = js::ToWindowProxyIfWindow(obj);
+    MOZ_ASSERT(proxy);
+    obj.set(proxy);
+  }
+
+  return true;
+}
+
 // Make sure to wrap the given string value into the right compartment, as
 // needed.
 MOZ_ALWAYS_INLINE
 bool MaybeWrapStringValue(JSContext* cx, JS::MutableHandle<JS::Value> rval) {
   MOZ_ASSERT(rval.isString());
   JSString* str = rval.toString();
   if (JS::GetStringZone(str) != js::GetContextZone(cx)) {
     return JS_WrapValue(cx, rval);
@@ -812,16 +822,35 @@ bool MaybeWrapObjectValue(JSContext* cx,
     return TryToOuterize(rval);
   }
 
   // It's not a WebIDL object, so it's OK to just leave it as-is: only WebIDL
   // objects (specifically only windows) require outerization.
   return true;
 }
 
+// Like MaybeWrapObjectValue, but working with a
+// JS::MutableHandle<JSObject*> which must be non-null.
+MOZ_ALWAYS_INLINE
+bool MaybeWrapObject(JSContext* cx, JS::MutableHandle<JSObject*> obj) {
+  if (js::GetObjectCompartment(obj) != js::GetContextCompartment(cx)) {
+    return JS_WrapObject(cx, obj);
+  }
+
+  // We're same-compartment, but even then we might need to wrap
+  // objects specially.  Check for that.
+  if (IsDOMObject(obj)) {
+    return TryToOuterize(obj);
+  }
+
+  // It's not a WebIDL object, so it's OK to just leave it as-is: only WebIDL
+  // objects (specifically only windows) require outerization.
+  return true;
+}
+
 // Like MaybeWrapObjectValue, but also allows null
 MOZ_ALWAYS_INLINE
 bool MaybeWrapObjectOrNullValue(JSContext* cx,
                                 JS::MutableHandle<JS::Value> rval) {
   MOZ_ASSERT(rval.isObjectOrNull());
   if (rval.isNull()) {
     return true;
   }