Bug 1146235 - Part 2: Expose @@iterator aliases on XrayWrappers. r=peterv

This commit is contained in:
Cameron McCormack 2015-03-28 11:44:44 +11:00
parent 8e8b4598a7
commit 89f3438815
3 changed files with 21 additions and 2 deletions

View File

@ -1164,7 +1164,16 @@ XrayResolveProperty(JSContext* cx, JS::Handle<JSObject*> wrapper,
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;
}

View File

@ -2150,7 +2150,8 @@ class MethodDefiner(PropertyDefiner):
"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)
@ -2492,6 +2493,12 @@ class CGNativeProperties(CGList):
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")

View File

@ -123,6 +123,9 @@ struct NativeProperties
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