Bug 1521848 - Replace nsTArrayToJSArray with ToJSValue. r=bzbarsky
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 22 Jan 2019 18:36:07 +0000
changeset 514856 5b00d3ce8cc6f72badc02588c6d85469ccd15600
parent 514855 3bdf5922a67c02fda006de28f60e91845b9944f7
child 514857 e73aadc3a039337689f63caedf78e7c31cacda0a
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1521848
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 1521848 - Replace nsTArrayToJSArray with ToJSValue. r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D17263
dom/base/nsDOMWindowUtils.cpp
dom/html/TextTrackManager.cpp
js/xpconnect/public/moz.build
js/xpconnect/public/nsTArrayHelpers.h
toolkit/components/sessionstore/SessionStoreUtils.cpp
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -49,17 +49,16 @@
 #include "mozilla/TouchEvents.h"
 
 #include "nsViewManager.h"
 
 #include "nsLayoutUtils.h"
 #include "nsComputedDOMStyle.h"
 #include "nsIPresShell.h"
 #include "nsCSSProps.h"
-#include "nsTArrayHelpers.h"
 #include "nsIDocShell.h"
 #include "nsIContentViewer.h"
 #include "mozilla/StyleAnimationValue.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/FileBinding.h"
 #include "mozilla/dom/DOMRect.h"
 #include <algorithm>
 
@@ -2951,22 +2950,17 @@ NS_IMETHODIMP
 nsDOMWindowUtils::GetPlugins(JSContext* cx,
                              JS::MutableHandle<JS::Value> aPlugins) {
   nsCOMPtr<Document> doc = GetDocument();
   NS_ENSURE_STATE(doc);
 
   nsTArray<nsIObjectLoadingContent*> plugins;
   doc->GetPlugins(plugins);
 
-  JS::Rooted<JSObject*> jsPlugins(cx);
-  nsresult rv = nsTArrayToJSArray(cx, plugins, &jsPlugins);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  aPlugins.setObject(*jsPlugins);
-  return NS_OK;
+  return ToJSValue(cx, plugins, aPlugins) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::SetVisualViewportSize(float aWidth, float aHeight) {
   if (!(aWidth >= 0.0 && aHeight >= 0.0)) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -13,17 +13,16 @@
 #include "mozilla/dom/HTMLTrackElement.h"
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "mozilla/dom/TextTrack.h"
 #include "mozilla/dom/TextTrackCue.h"
 #include "nsComponentManagerUtils.h"
 #include "nsGlobalWindow.h"
 #include "nsIFrame.h"
 #include "nsIWebVTTParserWrapper.h"
-#include "nsTArrayHelpers.h"
 #include "nsVariant.h"
 #include "nsVideoFrame.h"
 
 static mozilla::LazyLogModule gTextTrackLog("TextTrackManager");
 #define WEBVTT_LOG(...) MOZ_LOG(gTextTrackLog, LogLevel::Debug, (__VA_ARGS__))
 #define WEBVTT_LOGV(...) \
   MOZ_LOG(gTextTrackLog, LogLevel::Verbose, (__VA_ARGS__))
 
--- a/js/xpconnect/public/moz.build
+++ b/js/xpconnect/public/moz.build
@@ -1,12 +1,11 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 EXPORTS += [
-    'nsTArrayHelpers.h',
     'xpc_make_class.h',
     'xpc_map_end.h',
 ]
 
deleted file mode 100644
--- a/js/xpconnect/public/nsTArrayHelpers.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef __NSTARRAYHELPERS_H__
-#define __NSTARRAYHELPERS_H__
-
-#include "jsapi.h"
-#include "nsContentUtils.h"
-#include "nsTArray.h"
-
-template <class T>
-inline nsresult nsTArrayToJSArray(JSContext* aCx,
-                                  const nsTArray<T>& aSourceArray,
-                                  JS::MutableHandle<JSObject*> aResultArray) {
-  MOZ_ASSERT(aCx);
-
-  JS::Rooted<JSObject*> arrayObj(aCx,
-                                 JS_NewArrayObject(aCx, aSourceArray.Length()));
-  if (!arrayObj) {
-    NS_WARNING("JS_NewArrayObject failed!");
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  for (uint32_t index = 0; index < aSourceArray.Length(); index++) {
-    nsCOMPtr<nsISupports> obj;
-    nsresult rv = aSourceArray[index]->QueryInterface(NS_GET_IID(nsISupports),
-                                                      getter_AddRefs(obj));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    JS::RootedValue wrappedVal(aCx);
-    rv = nsContentUtils::WrapNative(aCx, obj, &wrappedVal);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (!JS_DefineElement(aCx, arrayObj, index, wrappedVal, JSPROP_ENUMERATE)) {
-      NS_WARNING("JS_DefineElement failed!");
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  if (!JS_FreezeObject(aCx, arrayObj)) {
-    NS_WARNING("JS_FreezeObject failed!");
-    return NS_ERROR_FAILURE;
-  }
-
-  aResultArray.set(arrayObj);
-  return NS_OK;
-}
-
-template <>
-inline nsresult nsTArrayToJSArray<nsString>(
-    JSContext* aCx, const nsTArray<nsString>& aSourceArray,
-    JS::MutableHandle<JSObject*> aResultArray) {
-  MOZ_ASSERT(aCx);
-
-  JS::Rooted<JSObject*> arrayObj(aCx,
-                                 JS_NewArrayObject(aCx, aSourceArray.Length()));
-  if (!arrayObj) {
-    NS_WARNING("JS_NewArrayObject failed!");
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  JS::Rooted<JSString*> s(aCx);
-  for (uint32_t index = 0; index < aSourceArray.Length(); index++) {
-    s = JS_NewUCStringCopyN(aCx, aSourceArray[index].BeginReading(),
-                            aSourceArray[index].Length());
-
-    if (!s) {
-      NS_WARNING("Memory allocation error!");
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-    if (!JS_DefineElement(aCx, arrayObj, index, s, JSPROP_ENUMERATE)) {
-      NS_WARNING("JS_DefineElement failed!");
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  if (!JS_FreezeObject(aCx, arrayObj)) {
-    NS_WARNING("JS_FreezeObject failed!");
-    return NS_ERROR_FAILURE;
-  }
-
-  aResultArray.set(arrayObj);
-  return NS_OK;
-}
-
-#endif /* __NSTARRAYHELPERS_H__ */
--- a/toolkit/components/sessionstore/SessionStoreUtils.cpp
+++ b/toolkit/components/sessionstore/SessionStoreUtils.cpp
@@ -13,17 +13,16 @@
 #include "nsContentUtils.h"
 #include "nsFocusManager.h"
 #include "nsGlobalWindowOuter.h"
 #include "nsIDocShell.h"
 #include "nsIFormControl.h"
 #include "nsIScrollableFrame.h"
 #include "nsPresContext.h"
 #include "nsPrintfCString.h"
-#include "nsTArrayHelpers.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 namespace {
 
 class DynamicFrameEventFilter final : public nsIDOMEventListener {
  public: