Bug 723676, crash writing to startup cache when an empty method body is used, r=bz
authorNeil Deakin <neil@mozilla.com>
Mon, 13 Feb 2012 14:24:28 -0500
changeset 86738 a98cf6ce2f0a09eebc150b49beedd18217e7ad9e
parent 86737 862dec07105b34e7701b06dece9658bc1a019021
child 86739 5185e21c55ec3abacf098b4069e0fd953a6353e1
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs723676
milestone13.0a1
Bug 723676, crash writing to startup cache when an empty method body is used, r=bz
content/xbl/src/nsXBLProtoImplMethod.cpp
content/xbl/test/Makefile.in
content/xbl/test/test_bug723676.xul
--- a/content/xbl/src/nsXBLProtoImplMethod.cpp
+++ b/content/xbl/src/nsXBLProtoImplMethod.cpp
@@ -284,23 +284,27 @@ nsXBLProtoImplMethod::Read(nsIScriptCont
 
   return NS_OK;
 }
 
 nsresult
 nsXBLProtoImplMethod::Write(nsIScriptContext* aContext,
                             nsIObjectOutputStream* aStream)
 {
-  nsresult rv = aStream->Write8(XBLBinding_Serialize_Method);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (mJSMethodObject) {
+    nsresult rv = aStream->Write8(XBLBinding_Serialize_Method);
+    NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = aStream->WriteWStringZ(mName);
-  NS_ENSURE_SUCCESS(rv, rv);
+    rv = aStream->WriteWStringZ(mName);
+    NS_ENSURE_SUCCESS(rv, rv);
 
-  return XBL_SerializeFunction(aContext, aStream, mJSMethodObject);
+    return XBL_SerializeFunction(aContext, aStream, mJSMethodObject);
+  }
+
+  return NS_OK;
 }
 
 nsresult
 nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
 {
   NS_PRECONDITION(IsCompiled(), "Can't execute uncompiled method");
   
   if (!mJSMethodObject) {
--- a/content/xbl/test/Makefile.in
+++ b/content/xbl/test/Makefile.in
@@ -75,16 +75,17 @@ include $(topsrcdir)/config/rules.mk
 		$(NULL)
 
 _CHROME_FILES = \
 		test_bug296375.xul \
 		test_bug378518.xul \
 		test_bug398135.xul \
 		test_bug398492.xul \
 		test_bug721452.xul \
+		test_bug723676.xul \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
 libs:: $(_CHROME_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
 
new file mode 100644
--- /dev/null
+++ b/content/xbl/test/test_bug723676.xul
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
+
+<script>
+ok(true, "Method with empty body didn't crash");
+</script>
+
+<body xmlns="http://www.w3.org/1999/xhtml"/>
+
+<box style="-moz-binding: url(#binding)"/>
+
+<xbl:bindings xmlns:xbl="http://www.mozilla.org/xbl">
+  <xbl:binding id="binding">
+    <xbl:implementation>
+      <xbl:method name="init"/>
+    </xbl:implementation>
+  </xbl:binding>
+</xbl:bindings>
+
+
+</window>