Bug 1353867 - Expose IsCrossOriginWhitelistedProp/AppendCrossOriginWhitelistedPropNames to DOM code. r=bzbarsky
☠☠ backed out by cc4bb8c7fa92 ☠ ☠
authorPeter Van der Beken <peterv@propagandism.org>
Mon, 31 Dec 2018 10:53:15 +0000
changeset 509295 8c05f4d3f7ad300b5ee0ac6c78cc34b19107a4e9
parent 509294 00869bed41216138d967c715a8ed601cff074720
child 509296 aa9b106b15d93573e5125356667f3a1f474d2e5a
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1353867
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 1353867 - Expose IsCrossOriginWhitelistedProp/AppendCrossOriginWhitelistedPropNames to DOM code. r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D12655
js/xpconnect/src/xpcpublic.h
js/xpconnect/wrappers/FilteringWrapper.cpp
js/xpconnect/wrappers/FilteringWrapper.h
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -718,16 +718,25 @@ class JSStackFrameBase {
  public:
   virtual void Clear() = 0;
 };
 
 void RegisterJSStackFrame(JS::Realm* aRealm, JSStackFrameBase* aStackFrame);
 void UnregisterJSStackFrame(JS::Realm* aRealm, JSStackFrameBase* aStackFrame);
 void NukeJSStackFrames(JS::Realm* aRealm);
 
+// Check whether the given jsid is a property name (string or symbol) whose
+// value can be gotten cross-origin.  Cross-origin gets always return undefined
+// as the value, unless the Xray actually provides a different value.
+bool IsCrossOriginWhitelistedProp(JSContext* cx, JS::HandleId id);
+
+// Appends to props the jsids for property names (strings or symbols) whose
+// value can be gotten cross-origin.
+bool AppendCrossOriginWhitelistedPropNames(JSContext* cx,
+                                           JS::AutoIdVector& props);
 }  // namespace xpc
 
 namespace mozilla {
 namespace dom {
 
 /**
  * A test for whether WebIDL methods that should only be visible to
  * chrome or XBL scopes should be exposed.
--- a/js/xpconnect/wrappers/FilteringWrapper.cpp
+++ b/js/xpconnect/wrappers/FilteringWrapper.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "FilteringWrapper.h"
 #include "AccessCheck.h"
 #include "ChromeObjectWrapper.h"
 #include "XrayWrapper.h"
 #include "nsJSUtils.h"
 #include "mozilla/ErrorResult.h"
+#include "xpcpublic.h"
 
 #include "jsapi.h"
 #include "js/Symbol.h"
 
 using namespace JS;
 using namespace js;
 
 namespace xpc {
@@ -38,16 +39,47 @@ static bool IsCrossOriginWhitelistedSymb
   return false;
 }
 
 bool IsCrossOriginWhitelistedProp(JSContext* cx, JS::HandleId id) {
   return id == GetJSIDByIndex(cx, XPCJSContext::IDX_THEN) ||
          IsCrossOriginWhitelistedSymbol(cx, id);
 }
 
+bool AppendCrossOriginWhitelistedPropNames(JSContext* cx,
+                                           JS::AutoIdVector& props) {
+  // Add "then" if it's not already in the list.
+  AutoIdVector thenProp(cx);
+  if (!thenProp.append(GetJSIDByIndex(cx, XPCJSContext::IDX_THEN))) {
+    return false;
+  }
+
+  if (!AppendUnique(cx, props, thenProp)) {
+    return false;
+  }
+
+  // Now add the three symbol-named props cross-origin objects have.
+#ifdef DEBUG
+  for (size_t n = 0; n < props.length(); ++n) {
+    MOZ_ASSERT(!JSID_IS_SYMBOL(props[n]),
+               "Unexpected existing symbol-name prop");
+  }
+#endif
+  if (!props.reserve(props.length() +
+                     ArrayLength(sCrossOriginWhitelistedSymbolCodes))) {
+    return false;
+  }
+
+  for (auto code : sCrossOriginWhitelistedSymbolCodes) {
+    props.infallibleAppend(SYMBOL_TO_JSID(JS::GetWellKnownSymbol(cx, code)));
+  }
+
+  return true;
+}
+
 template <typename Policy>
 static bool Filter(JSContext* cx, HandleObject wrapper, AutoIdVector& props) {
   size_t w = 0;
   RootedId id(cx);
   for (size_t n = 0; n < props.length(); ++n) {
     id = props[n];
     if (Policy::check(cx, wrapper, id, Wrapper::GET) ||
         Policy::check(cx, wrapper, id, Wrapper::SET)) {
@@ -256,43 +288,17 @@ bool CrossOriginXrayWrapper::ownProperty
                                              JS::AutoIdVector& props) const {
   // All properties on cross-origin objects are supposed |own|, despite what
   // the underlying native object may report. Override the inherited trap to
   // avoid passing JSITER_OWNONLY as a flag.
   if (!SecurityXrayDOM::getPropertyKeys(cx, wrapper, JSITER_HIDDEN, props)) {
     return false;
   }
 
-  // Add "then" if it's not already in the list.
-  AutoIdVector thenProp(cx);
-  if (!thenProp.append(GetJSIDByIndex(cx, XPCJSContext::IDX_THEN))) {
-    return false;
-  }
-
-  if (!AppendUnique(cx, props, thenProp)) {
-    return false;
-  }
-
-  // Now add the three symbol-named props cross-origin objects have.
-#ifdef DEBUG
-  for (size_t n = 0; n < props.length(); ++n) {
-    MOZ_ASSERT(!JSID_IS_SYMBOL(props[n]),
-               "Unexpected existing symbol-name prop");
-  }
-#endif
-  if (!props.reserve(props.length() +
-                     ArrayLength(sCrossOriginWhitelistedSymbolCodes))) {
-    return false;
-  }
-
-  for (auto code : sCrossOriginWhitelistedSymbolCodes) {
-    props.infallibleAppend(SYMBOL_TO_JSID(JS::GetWellKnownSymbol(cx, code)));
-  }
-
-  return true;
+  return AppendCrossOriginWhitelistedPropNames(cx, props);
 }
 
 bool CrossOriginXrayWrapper::defineProperty(JSContext* cx,
                                             JS::Handle<JSObject*> wrapper,
                                             JS::Handle<jsid> id,
                                             JS::Handle<PropertyDescriptor> desc,
                                             JS::ObjectOpResult& result) const {
   AccessCheck::reportCrossOriginDenial(cx, id, NS_LITERAL_CSTRING("define"));
--- a/js/xpconnect/wrappers/FilteringWrapper.h
+++ b/js/xpconnect/wrappers/FilteringWrapper.h
@@ -80,16 +80,11 @@ class CrossOriginXrayWrapper : public Se
       JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
       JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
 
   virtual bool setPrototype(JSContext* cx, JS::HandleObject wrapper,
                             JS::HandleObject proto,
                             JS::ObjectOpResult& result) const override;
 };
 
-// Check whether the given jsid is a property name (string or symbol) whose
-// value can be gotten cross-origin.  Cross-origin gets always return undefined
-// as the value, unless the Xray actually provides a different value.
-bool IsCrossOriginWhitelistedProp(JSContext* cx, JS::HandleId id);
-
 }  // namespace xpc
 
 #endif /* __FilteringWrapper_h__ */