Bug 942631 part 3. Preserve the wrapper when caching things in its slots if we're an nsWrapperCache. r=peterv

This commit is contained in:
Boris Zbarsky 2013-12-04 08:02:18 -05:00
Родитель 3c9332eaf8
Коммит a55415242a
1 изменённых файлов: 15 добавлений и 1 удалений

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

@ -5025,6 +5025,19 @@ if (!${obj}) {
self.descriptor.getDescriptor(self.returnType.unroll().inner.identifier.name).nativeOwnership == 'owned')) self.descriptor.getDescriptor(self.returnType.unroll().inner.identifier.name).nativeOwnership == 'owned'))
if self.idlNode.isAttr() and self.idlNode.slotIndex is not None: if self.idlNode.isAttr() and self.idlNode.slotIndex is not None:
# For the case of Cached attributes, go ahead and preserve our
# wrapper if needed. We need to do this because otherwise the
# wrapper could get garbage-collected and the cached value would
# suddenly disappear, but the whole premise of cached values is that
# they never change without explicit action on someone's part. We
# don't do this for StoreInSlot, since those get dealt with during
# wrapper setup, and failure would involve us trying to clear an
# already-preserved wrapper.
if (self.idlNode.getExtendedAttribute("Cached") and
self.descriptor.wrapperCache):
preserveWrapper = " PreserveWrapper(self);\n"
else:
preserveWrapper = ""
successCode = ( successCode = (
"// Be careful here: Have to wrap the value into the\n" "// Be careful here: Have to wrap the value into the\n"
"// compartment of reflector before storing, since we might\n" "// compartment of reflector before storing, since we might\n"
@ -5037,9 +5050,10 @@ if (!${obj}) {
" return false;\n" " return false;\n"
" }\n" " }\n"
" js::SetReservedSlot(reflector, %d, tempVal);\n" " js::SetReservedSlot(reflector, %d, tempVal);\n"
"%s"
"}\n" "}\n"
"return true;" % "return true;" %
memberReservedSlot(self.idlNode)) (memberReservedSlot(self.idlNode), preserveWrapper))
else: else:
successCode = None successCode = None