зеркало из 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")
|
||||
|
||||
|
||||
def CopyUnforgeablePropertiesToInstance(descriptor, wrapperCache):
|
||||
def CopyUnforgeablePropertiesToInstance(descriptor, failureCode):
|
||||
"""
|
||||
Copy the unforgeable properties from the unforgeable holder for
|
||||
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
|
||||
# reflector, so we can make sure we don't get confused by named getters.
|
||||
if descriptor.proxy:
|
||||
|
@ -3439,11 +3430,10 @@ def CopyUnforgeablePropertiesToInstance(descriptor, wrapperCache):
|
|||
JS::Rooted<JSObject*> expando(aCx,
|
||||
DOMProxyHandler::EnsureExpandoObject(aCx, aReflector));
|
||||
if (!expando) {
|
||||
$*{cleanup}
|
||||
return false;
|
||||
$*{failureCode}
|
||||
}
|
||||
""",
|
||||
cleanup=cleanup)))
|
||||
failureCode=failureCode)))
|
||||
obj = "expando"
|
||||
else:
|
||||
obj = "aReflector"
|
||||
|
@ -3453,12 +3443,11 @@ def CopyUnforgeablePropertiesToInstance(descriptor, wrapperCache):
|
|||
JS::Rooted<JSObject*> unforgeableHolder(aCx,
|
||||
&js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
|
||||
if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, ${obj}, unforgeableHolder)) {
|
||||
$*{cleanup}
|
||||
return false;
|
||||
$*{failureCode}
|
||||
}
|
||||
""",
|
||||
obj=obj,
|
||||
cleanup=cleanup)))
|
||||
failureCode=failureCode)))
|
||||
|
||||
return CGWrapper(CGList(copyCode), pre="\n").define()
|
||||
|
||||
|
@ -3478,7 +3467,7 @@ def AssertInheritanceChain(descriptor):
|
|||
return asserts
|
||||
|
||||
|
||||
def InitMemberSlots(descriptor, wrapperCache):
|
||||
def InitMemberSlots(descriptor, failureCode):
|
||||
"""
|
||||
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():
|
||||
return ""
|
||||
if wrapperCache:
|
||||
clearWrapper = dedent(
|
||||
"""
|
||||
aCache->ReleaseWrapper(aObject);
|
||||
aCache->ClearWrapper();
|
||||
""")
|
||||
else:
|
||||
clearWrapper = ""
|
||||
return fill(
|
||||
"""
|
||||
if (!UpdateMemberSlots(aCx, aReflector, aObject)) {
|
||||
$*{clearWrapper}
|
||||
return false;
|
||||
$*{failureCode}
|
||||
}
|
||||
""",
|
||||
clearWrapper=clearWrapper)
|
||||
failureCode=failureCode)
|
||||
|
||||
|
||||
def DeclareProto():
|
||||
|
@ -3561,6 +3541,14 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
|||
""")
|
||||
else:
|
||||
preserveWrapper = "PreserveWrapper(aObject);\n"
|
||||
|
||||
failureCode = dedent(
|
||||
"""
|
||||
aCache->ReleaseWrapper(aObject);
|
||||
aCache->ClearWrapper();
|
||||
return false;
|
||||
""")
|
||||
|
||||
return fill(
|
||||
"""
|
||||
$*{assertInheritance}
|
||||
|
@ -3615,8 +3603,9 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
|||
assertInheritance=AssertInheritanceChain(self.descriptor),
|
||||
declareProto=DeclareProto(),
|
||||
createObject=CreateBindingJSObject(self.descriptor, self.properties),
|
||||
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor, True),
|
||||
slots=InitMemberSlots(self.descriptor, True),
|
||||
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor,
|
||||
failureCode),
|
||||
slots=InitMemberSlots(self.descriptor, failureCode),
|
||||
preserveWrapper=preserveWrapper)
|
||||
|
||||
|
||||
|
@ -3655,6 +3644,8 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
|
|||
self.properties = properties
|
||||
|
||||
def definition_body(self):
|
||||
failureCode = "return false;\n"
|
||||
|
||||
return fill(
|
||||
"""
|
||||
$*{assertions}
|
||||
|
@ -3673,8 +3664,9 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
|
|||
assertions=AssertInheritanceChain(self.descriptor),
|
||||
declareProto=DeclareProto(),
|
||||
createObject=CreateBindingJSObject(self.descriptor, self.properties),
|
||||
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor, False),
|
||||
slots=InitMemberSlots(self.descriptor, False))
|
||||
unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor,
|
||||
failureCode),
|
||||
slots=InitMemberSlots(self.descriptor, failureCode))
|
||||
|
||||
|
||||
class CGWrapGlobalMethod(CGAbstractMethod):
|
||||
|
@ -3757,7 +3749,7 @@ class CGWrapGlobalMethod(CGAbstractMethod):
|
|||
chromeProperties=chromeProperties,
|
||||
failureCode=failureCode,
|
||||
unforgeable=unforgeable,
|
||||
slots=InitMemberSlots(self.descriptor, True))
|
||||
slots=InitMemberSlots(self.descriptor, failureCode))
|
||||
|
||||
|
||||
class CGUpdateMemberSlotsMethod(CGAbstractStaticMethod):
|
||||
|
|
Загрузка…
Ссылка в новой задаче