Bug 1477432 - Part 10: Stop using nsIJSID in nsIArray for optional IID parameters, r=kmag
authorNika Layzell <nika@thelayzells.com>
Tue, 23 Oct 2018 23:14:04 -0400
changeset 503341 29c30b62c301eacd5fefd9a78f19cf63fafd889a
parent 503340 3439b17bdc2a1bf5626355d529c9a3decf3843be
child 503342 241738774bb1b1f998770af0e0dd82c6ba8de36d
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1477432
milestone65.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 1477432 - Part 10: Stop using nsIJSID in nsIArray for optional IID parameters, r=kmag Differential Revision: https://phabricator.services.mozilla.com/D9732
dom/base/nsJSEnvironment.cpp
js/xpconnect/src/XPCWrappedNative.cpp
xpcom/ds/nsArray.cpp
xpcom/ds/nsIArray.idl
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -2943,17 +2943,17 @@ NS_IMETHODIMP nsJSArgArray::QueryElement
   return NS_ERROR_NO_INTERFACE;
 }
 
 NS_IMETHODIMP nsJSArgArray::IndexOf(uint32_t startIndex, nsISupports *element, uint32_t *_retval)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP nsJSArgArray::ScriptedEnumerate(nsIJSIID* aElemIID, uint8_t aArgc,
+NS_IMETHODIMP nsJSArgArray::ScriptedEnumerate(const nsIID& aElemIID, uint8_t aArgc,
                                               nsISimpleEnumerator** aResult)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP nsJSArgArray::EnumerateImpl(const nsID& aEntryIID, nsISimpleEnumerator **_retval)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -1590,16 +1590,27 @@ CallMethodHelper::ConvertIndependentPara
     }
 
     // All that's left to do is value conversion. Bail early if we don't need
     // to do that.
     if (!paramInfo.IsIn()) {
         return true;
     }
 
+    // Some types usually don't support default values, but we want to handle
+    // the default value if IsOptional is true.
+    if (i >= mArgc) {
+        MOZ_ASSERT(paramInfo.IsOptional(), "missing non-optional argument!");
+        if (type.Tag() == nsXPTType::T_IID) {
+            // NOTE: 'const nsIID&' is supported, so it must be allocated.
+            dp->val.p = new nsIID();
+            return true;
+        }
+    }
+
     // We're definitely some variety of 'in' now, so there's something to
     // convert. The source value for conversion depends on whether we're
     // dealing with an 'in' or an 'inout' parameter. 'inout' was handled above,
     // so all that's left is 'in'.
     if (!paramInfo.IsOut()) {
         // Handle the 'in' case.
         MOZ_ASSERT(i < mArgc || paramInfo.IsOptional(),
                    "Expected either enough arguments or an optional argument");
--- a/xpcom/ds/nsArray.cpp
+++ b/xpcom/ds/nsArray.cpp
@@ -2,17 +2,16 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsThreadUtils.h"
-#include "xpcjsid.h"
 
 NS_INTERFACE_MAP_BEGIN(nsArray)
   NS_INTERFACE_MAP_ENTRY(nsIArray)
   NS_INTERFACE_MAP_ENTRY(nsIArrayExtensions)
   NS_INTERFACE_MAP_ENTRY(nsIMutableArray)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMutableArray)
 NS_INTERFACE_MAP_END
 
@@ -75,21 +74,21 @@ nsArrayBase::IndexOf(uint32_t aStartInde
     return NS_ERROR_FAILURE;
   }
 
   *aResult = static_cast<uint32_t>(idx);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsArrayBase::ScriptedEnumerate(nsIJSIID* aElemIID, uint8_t aArgc,
+nsArrayBase::ScriptedEnumerate(const nsIID& aElemIID, uint8_t aArgc,
                                nsISimpleEnumerator** aResult)
 {
-  if (aArgc > 0 && aElemIID) {
-    return NS_NewArrayEnumerator(aResult, static_cast<nsIArray*>(this), *aElemIID->GetID());
+  if (aArgc > 0) {
+    return NS_NewArrayEnumerator(aResult, static_cast<nsIArray*>(this), aElemIID);
   }
   return NS_NewArrayEnumerator(aResult, static_cast<nsIArray*>(this));
 }
 
 
 NS_IMETHODIMP
 nsArrayBase::EnumerateImpl(const nsID& aElemIID, nsISimpleEnumerator** aResult)
 {
--- a/xpcom/ds/nsIArray.idl
+++ b/xpcom/ds/nsIArray.idl
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
-interface nsIJSIID;
 interface nsISimpleEnumerator;
 
 /**
  * nsIArray
  *
  * An indexed collection of elements. Provides basic functionality for
  * retrieving elements at a specific position, searching for
  * elements. Indexes are zero-based, such that the last element in the
@@ -43,38 +42,38 @@ interface nsIArray : nsISupports
     readonly attribute unsigned long length;
 
     /**
      * queryElementAt()
      *
      * Retrieve a specific element of the array, and QueryInterface it
      * to the specified interface. null is a valid result for
      * this method, but exceptions are thrown in other circumstances
-     * 
+     *
      * @param index position of element
      * @param uuid the IID of the requested interface
      * @param result the object, QI'd to the requested interface
      *
      * @throws NS_ERROR_NO_INTERFACE when an entry exists at the
      *         specified index, but the requested interface is not
      *         available.
      * @throws NS_ERROR_ILLEGAL_VALUE when index > length-1
      *
      */
     void queryElementAt(in unsigned long index,
                         in nsIIDRef uuid,
                         [iid_is(uuid), retval] out nsQIResult result);
-    
+
     /**
      * indexOf()
-     * 
+     *
      * Get the position of a specific element. Note that since null is
      * a valid input, exceptions are used to indicate that an element
      * is not found.
-     * 
+     *
      * @param startIndex The initial element to search in the array
      *                   To start at the beginning, use 0 as the
      *                   startIndex
      * @param element    The element you are looking for
      * @returns a number >= startIndex which is the position of the
      *          element in the array.
      * @throws NS_ERROR_FAILURE if the element was not in the array.
      */
@@ -84,17 +83,17 @@ interface nsIArray : nsISupports
     /**
      * enumerate the array
      *
      * @returns a new enumerator positioned at the start of the array
      * @throws NS_ERROR_FAILURE if the array is empty (to make it easy
      *         to detect errors), or NS_ERROR_OUT_OF_MEMORY if out of memory.
      */
     [binaryname(ScriptedEnumerate), optional_argc]
-    nsISimpleEnumerator enumerate([optional] in nsIJSIID aElemIID);
+    nsISimpleEnumerator enumerate([optional] in nsIIDRef aElemIID);
 
     [noscript]
     nsISimpleEnumerator enumerateImpl(in nsIDRef aElemIID);
 
     %{C++
     nsresult
     Enumerate(nsISimpleEnumerator** aRetVal, const nsID& aElemIID = NS_GET_IID(nsISupports))
     {