Bug 1041261, part 4 - Use foundVar and resultVar to move a few declarations in DOM binding code. r=peterv.

Now the "bool found;" and "bool result;" declarations are added in the outermost scope where they're going to be used, rather than the scope of the method call that sets them. Until now, those have always been the same scope; part 5 will put an if-block around certain method calls, making these two different scopes.

--HG--
extra : rebase_source : df60ef4c2ef400caaeb16a4950c86f5ba4c31319
This commit is contained in:
Jason Orendorff 2014-08-05 09:10:29 -05:00
Родитель 84968c47b4
Коммит 244b95dfbf
1 изменённых файлов: 39 добавлений и 20 удалений

Просмотреть файл

@ -9548,7 +9548,7 @@ class CGProxyIndexedPresenceChecker(CGProxyIndexedGetter):
foundVar: See the docstring for CGProxySpecialOperation. foundVar: See the docstring for CGProxySpecialOperation.
""" """
def __init__(self, descriptor, foundVar=None): def __init__(self, descriptor, foundVar):
CGProxyIndexedGetter.__init__(self, descriptor, foundVar=foundVar) CGProxyIndexedGetter.__init__(self, descriptor, foundVar=foundVar)
self.cgRoot.append(CGGeneric("(void)result;\n")) self.cgRoot.append(CGGeneric("(void)result;\n"))
@ -9934,13 +9934,14 @@ class CGDOMJSProxyHandler_defineProperty(ClassMethod):
if self.descriptor.supportsNamedProperties(): if self.descriptor.supportsNamedProperties():
set += fill( set += fill(
""" """
bool found;
$*{presenceChecker} $*{presenceChecker}
if (found) { if (found) {
return js::IsInNonStrictPropertySet(cx) || ThrowErrorMessage(cx, MSG_NO_NAMED_SETTER, "${name}"); return js::IsInNonStrictPropertySet(cx) || ThrowErrorMessage(cx, MSG_NO_NAMED_SETTER, "${name}");
} }
""", """,
presenceChecker=CGProxyNamedPresenceChecker(self.descriptor).define(), presenceChecker=CGProxyNamedPresenceChecker(self.descriptor, foundVar="found").define(),
name=self.descriptor.name) name=self.descriptor.name)
set += ("return mozilla::dom::DOMProxyHandler::defineProperty(%s);\n" % set += ("return mozilla::dom::DOMProxyHandler::defineProperty(%s);\n" %
", ".join(a.name for a in self.args)) ", ".join(a.name for a in self.args))
@ -9958,40 +9959,51 @@ class CGDOMJSProxyHandler_delete(ClassMethod):
self.descriptor = descriptor self.descriptor = descriptor
def getBody(self): def getBody(self):
def getDeleterBody(type): def getDeleterBody(type, foundVar=None):
""" """
type should be "Named" or "Indexed" type should be "Named" or "Indexed"
""" """
assert type in ("Named", "Indexed") assert type in ("Named", "Indexed")
deleter = self.descriptor.operations[type + 'Deleter'] deleter = self.descriptor.operations[type + 'Deleter']
if deleter: if deleter:
decls = ""
if (not deleter.signatures()[0][0].isPrimitive() or if (not deleter.signatures()[0][0].isPrimitive() or
deleter.signatures()[0][0].nullable() or deleter.signatures()[0][0].nullable() or
deleter.signatures()[0][0].tag() != IDLType.Tags.bool): deleter.signatures()[0][0].tag() != IDLType.Tags.bool):
setBp = "*bp = true;\n" setBp = "*bp = true;\n"
else: else:
setBp = dedent(""" decls += "bool result;\n"
if (found) { if foundVar is None:
foundVar = "found"
decls += "bool found;\n"
setBp = fill(
"""
if (${foundVar}) {
*bp = result; *bp = result;
} else { } else {
*bp = true; *bp = true;
} }
""") """,
foundVar=foundVar)
deleterClass = globals()["CGProxy%sDeleter" % type] deleterClass = globals()["CGProxy%sDeleter" % type]
body = (deleterClass(self.descriptor).define() + body = (decls +
deleterClass(self.descriptor, resultVar="result", foundVar=foundVar).define() +
setBp) setBp)
elif getattr(self.descriptor, "supports%sProperties" % type)(): elif getattr(self.descriptor, "supports%sProperties" % type)():
presenceCheckerClass = globals()["CGProxy%sPresenceChecker" % type] presenceCheckerClass = globals()["CGProxy%sPresenceChecker" % type]
foundDecl = ""
if foundVar is None:
foundVar = "found"
foundDecl = "bool found;\n"
body = fill( body = fill(
""" """
$*{foundDecl}
$*{presenceChecker} $*{presenceChecker}
if (found) { *bp = !${foundVar};
*bp = false;
} else {
*bp = true;
}
""", """,
presenceChecker=presenceCheckerClass(self.descriptor).define()) foundDecl=foundDecl,
presenceChecker=presenceCheckerClass(self.descriptor, foundVar=foundVar).define(),
foundVar=foundVar)
else: else:
body = None body = None
return body return body
@ -10029,15 +10041,20 @@ class CGDOMJSProxyHandler_delete(ClassMethod):
delete += CallOnUnforgeableHolder(self.descriptor, unforgeable) delete += CallOnUnforgeableHolder(self.descriptor, unforgeable)
delete += "\n" delete += "\n"
namedBody = getDeleterBody("Named") namedBody = getDeleterBody("Named", foundVar="found")
if namedBody is not None: if namedBody is not None:
# We always return above for an index id in the case when we support # We always return above for an index id in the case when we support
# indexed properties, so we can just treat the id as a name # indexed properties, so we can just treat the id as a name
# unconditionally here. # unconditionally here.
delete += (namedBody + delete += fill(
"if (found) {\n" """
" return true;\n" bool found;
"}\n") $*{namedBody}
if (found) {
return true;
}
""",
namedBody=namedBody)
if not self.descriptor.interface.getExtendedAttribute('OverrideBuiltins'): if not self.descriptor.interface.getExtendedAttribute('OverrideBuiltins'):
delete = CGIfWrapper(CGGeneric(delete), delete = CGIfWrapper(CGGeneric(delete),
"!HasPropertyOnPrototype(cx, proxy, id)").define() "!HasPropertyOnPrototype(cx, proxy, id)").define()
@ -10142,6 +10159,7 @@ class CGDOMJSProxyHandler_hasOwn(ClassMethod):
""" """
int32_t index = GetArrayIndexFromId(cx, id); int32_t index = GetArrayIndexFromId(cx, id);
if (IsArrayIndex(index)) { if (IsArrayIndex(index)) {
bool found;
$*{presenceChecker} $*{presenceChecker}
*bp = found; *bp = found;
@ -10149,7 +10167,7 @@ class CGDOMJSProxyHandler_hasOwn(ClassMethod):
} }
""", """,
presenceChecker=CGProxyIndexedPresenceChecker(self.descriptor).define()) presenceChecker=CGProxyIndexedPresenceChecker(self.descriptor, foundVar="found").define())
else: else:
indexed = "" indexed = ""
@ -10171,11 +10189,12 @@ class CGDOMJSProxyHandler_hasOwn(ClassMethod):
# property names, so no need to check for those here. # property names, so no need to check for those here.
named = fill( named = fill(
""" """
bool found;
$*{presenceChecker} $*{presenceChecker}
*bp = found; *bp = found;
""", """,
presenceChecker=CGProxyNamedPresenceChecker(self.descriptor).define()) presenceChecker=CGProxyNamedPresenceChecker(self.descriptor, foundVar="found").define())
if not self.descriptor.interface.getExtendedAttribute('OverrideBuiltins'): if not self.descriptor.interface.getExtendedAttribute('OverrideBuiltins'):
named = CGIfWrapper(CGGeneric(named + "return true;\n"), named = CGIfWrapper(CGGeneric(named + "return true;\n"),
"!HasPropertyOnPrototype(cx, proxy, id)").define() "!HasPropertyOnPrototype(cx, proxy, id)").define()