Bug 1588861 - Part 2: Pull CreateArray out of ModuleBuilder and into js namespace. r=iain
authorcaroline <cullen.caroline@gmail.com>
Tue, 10 Dec 2019 02:52:30 +0000
changeset 506301 639290e9ff226088f9d3e1d5f710e6c4a1cde03e
parent 506300 c1eec2b6d898e16f25e8c19dd0e99dc2a1953e7b
child 506302 2a0aacbd11dee6907445c902aa088ab4b9492d6b
push id102799
push useriireland@mozilla.com
push dateTue, 10 Dec 2019 18:22:40 +0000
treeherderautoland@815a452c73af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersiain
bugs1588861
milestone73.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 1588861 - Part 2: Pull CreateArray out of ModuleBuilder and into js namespace. r=iain Differential Revision: https://phabricator.services.mozilla.com/D53755
js/src/builtin/ModuleObject.cpp
js/src/vm/ModuleBuilder.h
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -1241,38 +1241,41 @@ bool ModuleBuilder::buildTables() {
       }
     }
   }
 
   return true;
 }
 
 bool ModuleBuilder::initModule() {
-  RootedArrayObject requestedModules(cx_, createArray(requestedModules_));
+  RootedArrayObject requestedModules(cx_,
+                                     js::CreateArray(cx_, requestedModules_));
   if (!requestedModules) {
     return false;
   }
 
-  RootedArrayObject importEntries(cx_, createArray(importEntries_));
+  RootedArrayObject importEntries(cx_, createArrayFromHashMap(importEntries_));
   if (!importEntries) {
     return false;
   }
 
-  RootedArrayObject localExportEntries(cx_, createArray(localExportEntries_));
+  RootedArrayObject localExportEntries(
+      cx_, js::CreateArray(cx_, localExportEntries_));
   if (!localExportEntries) {
     return false;
   }
 
-  RootedArrayObject indirectExportEntries(cx_,
-                                          createArray(indirectExportEntries_));
+  RootedArrayObject indirectExportEntries(
+      cx_, js::CreateArray(cx_, indirectExportEntries_));
   if (!indirectExportEntries) {
     return false;
   }
 
-  RootedArrayObject starExportEntries(cx_, createArray(starExportEntries_));
+  RootedArrayObject starExportEntries(cx_,
+                                      js::CreateArray(cx_, starExportEntries_));
   if (!starExportEntries) {
     return false;
   }
 
   module_->initImportExportData(requestedModules, importEntries,
                                 localExportEntries, indirectExportEntries,
                                 starExportEntries);
 
@@ -1617,33 +1620,34 @@ bool ModuleBuilder::maybeAppendRequested
     return false;
   }
 
   return FreezeObject(cx, req) && requestedModules_.append(req) &&
          requestedModuleSpecifiers_.put(specifier);
 }
 
 template <typename T>
-ArrayObject* ModuleBuilder::createArray(const JS::Rooted<GCVector<T>>& vector) {
+ArrayObject* js::CreateArray(JSContext* cx,
+                             const JS::Rooted<GCVector<T>>& vector) {
   uint32_t length = vector.length();
-  RootedArrayObject array(cx_, NewDenseFullyAllocatedArray(cx_, length));
+  RootedArrayObject array(cx, NewDenseFullyAllocatedArray(cx, length));
   if (!array) {
     return nullptr;
   }
 
   array->setDenseInitializedLength(length);
   for (uint32_t i = 0; i < length; i++) {
     array->initDenseElement(i, ObjectValue(*vector[i]));
   }
 
   return array;
 }
 
 template <typename K, typename V>
-ArrayObject* ModuleBuilder::createArray(
+ArrayObject* ModuleBuilder::createArrayFromHashMap(
     const JS::Rooted<GCHashMap<K, V>>& map) {
   uint32_t length = map.count();
   RootedArrayObject array(cx_, NewDenseFullyAllocatedArray(cx_, length));
   if (!array) {
     return nullptr;
   }
 
   array->setDenseInitializedLength(length);
--- a/js/src/vm/ModuleBuilder.h
+++ b/js/src/vm/ModuleBuilder.h
@@ -94,17 +94,20 @@ class MOZ_STACK_CLASS ModuleBuilder {
                              JS::Handle<JSAtom*> importName,
                              frontend::ParseNode* node);
 
   bool appendExportEntryObject(JS::Handle<ExportEntryObject*> exportEntry);
 
   bool maybeAppendRequestedModule(JS::Handle<JSAtom*> specifier,
                                   frontend::ParseNode* node);
 
-  template <typename T>
-  ArrayObject* createArray(const JS::Rooted<JS::GCVector<T>>& vector);
   template <typename K, typename V>
-  ArrayObject* createArray(const JS::Rooted<JS::GCHashMap<K, V>>& map);
+  ArrayObject* createArrayFromHashMap(
+      const JS::Rooted<JS::GCHashMap<K, V>>& map);
 };
 
+template <typename T>
+ArrayObject* CreateArray(JSContext* cx,
+                         const JS::Rooted<JS::GCVector<T>>& vector);
+
 }  // namespace js
 
 #endif  // vm_ModuleBuilder_h