зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1299306 part 1. Refactor the error handling in CGWrapNonWrapperCacheMethod and CGWrapWithCacheMethod to have less duplication. r=peterv
This commit is contained in:
Родитель
10a9e4c620
Коммит
8aef9d0ce9
|
@ -3402,7 +3402,7 @@ def InitUnforgeablePropertiesOnHolder(descriptor, properties, failureCode,
|
||||||
return CGWrapper(CGList(unforgeables), pre="\n")
|
return CGWrapper(CGList(unforgeables), pre="\n")
|
||||||
|
|
||||||
|
|
||||||
def CopyUnforgeablePropertiesToInstance(descriptor, wrapperCache):
|
def CopyUnforgeablePropertiesToInstance(descriptor, failureCode):
|
||||||
"""
|
"""
|
||||||
Copy the unforgeable properties from the unforgeable holder for
|
Copy the unforgeable properties from the unforgeable holder for
|
||||||
this interface to the instance object we have.
|
this interface to the instance object we have.
|
||||||
|
@ -3422,15 +3422,6 @@ def CopyUnforgeablePropertiesToInstance(descriptor, wrapperCache):
|
||||||
"""))
|
"""))
|
||||||
]
|
]
|
||||||
|
|
||||||
if wrapperCache:
|
|
||||||
cleanup = dedent(
|
|
||||||
"""
|
|
||||||
aCache->ReleaseWrapper(aObject);
|
|
||||||
aCache->ClearWrapper();
|
|
||||||
""")
|
|
||||||
else:
|
|
||||||
cleanup = ""
|
|
||||||
|
|
||||||
# For proxies, we want to define on the expando object, not directly on the
|
# For proxies, we want to define on the expando object, not directly on the
|
||||||
# reflector, so we can make sure we don't get confused by named getters.
|
# reflector, so we can make sure we don't get confused by named getters.
|
||||||
if descriptor.proxy:
|
if descriptor.proxy:
|
||||||
|
@ -3439,11 +3430,10 @@ def CopyUnforgeablePropertiesToInstance(descriptor, wrapperCache):
|
||||||
JS::Rooted<JSObject*> expando(aCx,
|
JS::Rooted<JSObject*> expando(aCx,
|
||||||
DOMProxyHandler::EnsureExpandoObject(aCx, aReflector));
|
DOMProxyHandler::EnsureExpandoObject(aCx, aReflector));
|
||||||
if (!expando) {
|
if (!expando) {
|
||||||
$*{cleanup}
|
$*{failureCode}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
cleanup=cleanup)))
|
failureCode=failureCode)))
|
||||||
obj = "expando"
|
obj = "expando"
|
||||||
else:
|
else:
|
||||||
obj = "aReflector"
|
obj = "aReflector"
|
||||||
|
@ -3453,12 +3443,11 @@ def CopyUnforgeablePropertiesToInstance(descriptor, wrapperCache):
|
||||||
JS::Rooted<JSObject*> unforgeableHolder(aCx,
|
JS::Rooted<JSObject*> unforgeableHolder(aCx,
|
||||||
&js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
|
&js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
|
||||||
if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, ${obj}, unforgeableHolder)) {
|
if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, ${obj}, unforgeableHolder)) {
|
||||||
$*{cleanup}
|
$*{failureCode}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
obj=obj,
|
obj=obj,
|
||||||
cleanup=cleanup)))
|
failureCode=failureCode)))
|
||||||
|
|
||||||
return CGWrapper(CGList(copyCode), pre="\n").define()
|
return CGWrapper(CGList(copyCode), pre="\n").define()
|
||||||
|
|
||||||
|
@ -3478,7 +3467,7 @@ def AssertInheritanceChain(descriptor):
|
||||||
return asserts
|
return asserts
|
||||||
|
|
||||||
|
|
||||||
def InitMemberSlots(descriptor, wrapperCache):
|
def InitMemberSlots(descriptor, failureCode):
|
||||||
"""
|
"""
|
||||||
Initialize member slots on our JS object if we're supposed to have some.
|
Initialize member slots on our JS object if we're supposed to have some.
|
||||||
|
|
||||||
|
@ -3489,22 +3478,13 @@ def InitMemberSlots(descriptor, wrapperCache):
|
||||||
"""
|
"""
|
||||||
if not descriptor.interface.hasMembersInSlots():
|
if not descriptor.interface.hasMembersInSlots():
|
||||||
return ""
|
return ""
|
||||||
if wrapperCache:
|
|
||||||
clearWrapper = dedent(
|
|
||||||
"""
|
|
||||||
aCache->ReleaseWrapper(aObject);
|
|
||||||
aCache->ClearWrapper();
|
|
||||||
""")
|
|
||||||
else:
|
|
||||||
clearWrapper = ""
|
|
||||||
return fill(
|
return fill(
|
||||||
"""
|
"""
|
||||||
if (!UpdateMemberSlots(aCx, aReflector, aObject)) {
|
if (!UpdateMemberSlots(aCx, aReflector, aObject)) {
|
||||||
$*{clearWrapper}
|
$*{failureCode}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
clearWrapper=clearWrapper)
|
failureCode=failureCode)
|
||||||
|
|
||||||
|
|
||||||
def DeclareProto():
|
def DeclareProto():
|
||||||
|
@ -3561,6 +3541,14 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
||||||
""")
|
""")
|
||||||
else:
|
else:
|
||||||
preserveWrapper = "PreserveWrapper(aObject);\n"
|
preserveWrapper = "PreserveWrapper(aObject);\n"
|
||||||
|
|
||||||
|
failureCode = dedent(
|
||||||
|
"""
|
||||||
|
aCache->ReleaseWrapper(aObject);
|
||||||
|
aCache->ClearWrapper();
|
||||||
|
return false;
|
||||||
|
""")
|
||||||
|
|
||||||
return fill(
|
return fill(
|
||||||
"""
|
"""
|
||||||
$*{assertInheritance}
|
$*{assertInheritance}
|
||||||
|
@ -3615,8 +3603,9 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
||||||
assertInheritance=AssertInheritanceChain(self.descriptor),
|
assertInheritance=AssertInheritanceChain(self.descriptor),
|
||||||
declareProto=DeclareProto(),
|
declareProto=DeclareProto(),
|
||||||
createObject=CreateBindingJSObject(self.descriptor, self.properties),
|
createObject=CreateBindingJSObject(self.descriptor, self.properties),
|
||||||
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor, True),
|
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor,
|
||||||
slots=InitMemberSlots(self.descriptor, True),
|
failureCode),
|
||||||
|
slots=InitMemberSlots(self.descriptor, failureCode),
|
||||||
preserveWrapper=preserveWrapper)
|
preserveWrapper=preserveWrapper)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3655,6 +3644,8 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
|
||||||
self.properties = properties
|
self.properties = properties
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
|
failureCode = "return false;\n"
|
||||||
|
|
||||||
return fill(
|
return fill(
|
||||||
"""
|
"""
|
||||||
$*{assertions}
|
$*{assertions}
|
||||||
|
@ -3673,8 +3664,9 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
|
||||||
assertions=AssertInheritanceChain(self.descriptor),
|
assertions=AssertInheritanceChain(self.descriptor),
|
||||||
declareProto=DeclareProto(),
|
declareProto=DeclareProto(),
|
||||||
createObject=CreateBindingJSObject(self.descriptor, self.properties),
|
createObject=CreateBindingJSObject(self.descriptor, self.properties),
|
||||||
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor, False),
|
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor,
|
||||||
slots=InitMemberSlots(self.descriptor, False))
|
failureCode),
|
||||||
|
slots=InitMemberSlots(self.descriptor, failureCode))
|
||||||
|
|
||||||
|
|
||||||
class CGWrapGlobalMethod(CGAbstractMethod):
|
class CGWrapGlobalMethod(CGAbstractMethod):
|
||||||
|
@ -3757,7 +3749,7 @@ class CGWrapGlobalMethod(CGAbstractMethod):
|
||||||
chromeProperties=chromeProperties,
|
chromeProperties=chromeProperties,
|
||||||
failureCode=failureCode,
|
failureCode=failureCode,
|
||||||
unforgeable=unforgeable,
|
unforgeable=unforgeable,
|
||||||
slots=InitMemberSlots(self.descriptor, True))
|
slots=InitMemberSlots(self.descriptor, failureCode))
|
||||||
|
|
||||||
|
|
||||||
class CGUpdateMemberSlotsMethod(CGAbstractStaticMethod):
|
class CGUpdateMemberSlotsMethod(CGAbstractStaticMethod):
|
||||||
|
|
Загрузка…
Ссылка в новой задаче