Bug 1146235 - Part 2: Expose @@iterator aliases on XrayWrappers. r=peterv
authorCameron McCormack <cam@mcc.id.au>
Sat, 28 Mar 2015 11:44:44 +1100
changeset 266659 665c141c2479169301d8a2a967fb20f3d2e2152c
parent 266658 d135a7b7864fdd9cf5043e1a70cca339aea5fa55
child 266660 d1e9b787eaebb8cd0c2cc638f56e7ccc7f84cc5c
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1146235
milestone39.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 1146235 - Part 2: Expose @@iterator aliases on XrayWrappers. r=peterv
dom/bindings/BindingUtils.cpp
dom/bindings/Codegen.py
dom/bindings/DOMJSClass.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -1159,17 +1159,26 @@ XrayResolveProperty(JSContext* cx, JS::H
     methodIds = nativeProperties->staticMethodIds;
     methodSpecs = nativeProperties->staticMethodSpecs;
   } else {
     methods = nativeProperties->methods;
     methodIds = nativeProperties->methodIds;
     methodSpecs = nativeProperties->methodSpecs;
   }
   if (methods) {
-    if (!XrayResolveMethod(cx, wrapper, obj, id, methods, methodIds,
+    JS::Rooted<jsid> methodId(cx);
+    if (nativeProperties->iteratorAliasMethodIndex != -1 &&
+        id == SYMBOL_TO_JSID(
+                JS::GetWellKnownSymbol(cx, JS::SymbolCode::iterator))) {
+      methodId =
+        nativeProperties->methodIds[nativeProperties->iteratorAliasMethodIndex];
+    } else {
+      methodId = id;
+    }
+    if (!XrayResolveMethod(cx, wrapper, obj, methodId, methods, methodIds,
                            methodSpecs, desc, cacheOnHolder)) {
       return false;
     }
     if (desc.object()) {
       return true;
     }
   }
 
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -2145,17 +2145,18 @@ class MethodDefiner(PropertyDefiner):
 
             method = {
                 "name": m.identifier.name,
                 "methodInfo": not m.isStatic(),
                 "length": methodLength(m),
                 "flags": "JSPROP_ENUMERATE",
                 "condition": PropertyDefiner.getControllingCondition(m, descriptor),
                 "allowCrossOriginThis": m.getExtendedAttribute("CrossOriginCallable"),
-                "returnsPromise": m.returnsPromise()
+                "returnsPromise": m.returnsPromise(),
+                "hasIteratorAlias": "@@iterator" in m.aliases
             }
             if isChromeOnly(m):
                 self.chrome.append(method)
             else:
                 self.regular.append(method)
 
         # FIXME Check for an existing iterator on the interface first.
         if (any(m.isGetter() and m.isIndexed() for m in methods) and
@@ -2487,16 +2488,22 @@ class CGNativeProperties(CGList):
                         ids = "%(name)s_ids"
                     else:
                         ids = "nullptr"
                     props = "%(name)s, " + ids + ", %(name)s_specs"
                     props = (props % {'name': propertyArray.variableName(chrome)})
                 else:
                     props = "nullptr, nullptr, nullptr"
                 nativeProps.append(CGGeneric(props))
+            iteratorAliasIndex = -1
+            for index, item in enumerate(properties.methods.regular):
+                if item.get("hasIteratorAlias"):
+                    iteratorAliasIndex = index
+                    break
+            nativeProps.append(CGGeneric(str(iteratorAliasIndex)));
             return CGWrapper(CGIndenter(CGList(nativeProps, ",\n")),
                              pre="static const NativeProperties %s = {\n" % name,
                              post="\n};\n")
 
         nativeProperties = []
         if properties.hasNonChromeOnly():
             nativeProperties.append(
                 generateNativeProperties("sNativeProperties", False))
--- a/dom/bindings/DOMJSClass.h
+++ b/dom/bindings/DOMJSClass.h
@@ -118,16 +118,19 @@ struct NativeProperties
 
   const Prefable<const JSPropertySpec>* unforgeableAttributes;
   jsid* unforgeableAttributeIds;
   const JSPropertySpec* unforgeableAttributeSpecs;
 
   const Prefable<const ConstantSpec>* constants;
   jsid* constantIds;
   const ConstantSpec* constantSpecs;
+
+  // Index into methods for the entry that is [Alias="@@iterator"], -1 if none
+  int32_t iteratorAliasMethodIndex;
 };
 
 struct NativePropertiesHolder
 {
   const NativeProperties* regular;
   const NativeProperties* chromeOnly;
 };