From a55415242a6aabf8f87d1d67527a095df6a65eb4 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Dec 2013 08:02:18 -0500 Subject: [PATCH] Bug 942631 part 3. Preserve the wrapper when caching things in its slots if we're an nsWrapperCache. r=peterv --- dom/bindings/Codegen.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 4abbc377cec7..6c00cfa0ebf4 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -5025,6 +5025,19 @@ if (!${obj}) { self.descriptor.getDescriptor(self.returnType.unroll().inner.identifier.name).nativeOwnership == 'owned')) 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 = ( "// Be careful here: Have to wrap the value into the\n" "// compartment of reflector before storing, since we might\n" @@ -5037,9 +5050,10 @@ if (!${obj}) { " return false;\n" " }\n" " js::SetReservedSlot(reflector, %d, tempVal);\n" + "%s" "}\n" "return true;" % - memberReservedSlot(self.idlNode)) + (memberReservedSlot(self.idlNode), preserveWrapper)) else: successCode = None