Bug 1281194 - Don't use for-of iteration over requested modules array r=bz
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 23 Jun 2016 11:52:51 +0100
changeset 327536 b2eb6f3b5c5e90bfacfeaef56a88764f3962411e
parent 327535 200070acb240df4253ef7a5be1d7ea376de14892
child 327537 a8f8f39d9c1cc5c9d149d0b1addc1e17205e2927
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1281194
milestone50.0a1
Bug 1281194 - Don't use for-of iteration over requested modules array r=bz
dom/base/nsScriptLoader.cpp
js/src/jsapi.h
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -860,35 +860,26 @@ ResolveRequestedModules(nsModuleLoadRequ
   JS::Rooted<JSObject*> moduleRecord(cx, ms->ModuleRecord());
   JS::Rooted<JSObject*> specifiers(cx, JS::GetRequestedModules(cx, moduleRecord));
 
   uint32_t length;
   if (!JS_GetArrayLength(cx, specifiers, &length)) {
     return NS_ERROR_FAILURE;
   }
 
-  JS::Rooted<JS::Value> arrayValue(cx, JS::ObjectValue(*specifiers));
-  JS::ForOfIterator iter(cx);
-  if (!iter.init(arrayValue)) {
-    return NS_ERROR_FAILURE;
-  }
-
   JS::Rooted<JS::Value> val(cx);
-  while (true) {
-    bool done;
-    if (!iter.next(&val, &done)) {
+  for (uint32_t i = 0; i < length; i++) {
+    if (!JS_GetElement(cx, specifiers, i, &val)) {
       return NS_ERROR_FAILURE;
     }
 
-    if (done) {
-      break;
-    }
-
     nsAutoJSString specifier;
-    specifier.init(cx, val);
+    if (!specifier.init(cx, val)) {
+      return NS_ERROR_FAILURE;
+    }
 
     // Let url be the result of resolving a module specifier given module script and requested.
     nsModuleScript* ms = aRequest->mModuleScript;
     nsCOMPtr<nsIURI> uri = ResolveModuleSpecifier(ms, specifier);
     if (!uri) {
       HandleResolveFailure(cx, ms, specifier);
       return NS_ERROR_FAILURE;
     }
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -4283,18 +4283,19 @@ ModuleDeclarationInstantiation(JSContext
  */
 extern JS_PUBLIC_API(bool)
 ModuleEvaluation(JSContext* cx, JS::HandleObject moduleRecord);
 
 /*
  * Get a list of the module specifiers used by a source text module
  * record to request importation of modules.
  *
- * The result is a JavaScript array of string values.  ForOfIterator can be used
- * to extract the individual strings.
+ * The result is a JavaScript array of string values.  To extract the individual
+ * values use only JS_GetArrayLength and JS_GetElement with indices 0 to
+ * length - 1.
  */
 extern JS_PUBLIC_API(JSObject*)
 GetRequestedModules(JSContext* cx, JS::HandleObject moduleRecord);
 
 /*
  * Get the script associated with a module.
  */
 extern JS_PUBLIC_API(JSScript*)