Bug 696603: Handle null being passed to BlobBuilder.append. r=sicking
authorKyle Huey <khuey@kylehuey.com>
Mon, 24 Oct 2011 09:38:41 -0400
changeset 79136 58eb2ebcc7d2dcea0a8b2c01908513e204cfdd4d
parent 79135 07dc138667561d34e26c6d722a4015aed63466bd
child 79137 26ac81280f33998ce7492691ecabc0e872d007a2
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssicking
bugs696603
milestone10.0a1
Bug 696603: Handle null being passed to BlobBuilder.append. r=sicking
content/base/src/nsDOMBlobBuilder.cpp
content/base/test/test_blobbuilder.html
--- a/content/base/src/nsDOMBlobBuilder.cpp
+++ b/content/base/src/nsDOMBlobBuilder.cpp
@@ -367,17 +367,20 @@ nsDOMBlobBuilder::GetFile(const nsAStrin
 NS_IMETHODIMP
 nsDOMBlobBuilder::Append(const jsval& aData, JSContext* aCx)
 {
   // We need to figure out what our jsval is
 
   // Is it an object?
   if (JSVAL_IS_OBJECT(aData)) {
     JSObject* obj = JSVAL_TO_OBJECT(aData);
-    NS_ASSERTION(obj, "Er, what?");
+    if (!obj) {
+      // We got passed null.  Just do nothing.
+      return NS_OK;
+    }
 
     // Is it a Blob?
     nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(
       nsContentUtils::XPConnect()->
         GetNativeOfWrapper(aCx, obj));
     if (blob)
       return AppendBlob(blob);
 
--- a/content/base/test/test_blobbuilder.html
+++ b/content/base/test/test_blobbuilder.html
@@ -32,16 +32,19 @@ ok(blobBuilder.getFile, "BlobBuilder sho
 
 try {
 blobBuilder.append();
 ok(false, "NOT REACHED");
 } catch(e) {
 ok(true, "an empty argument to append should throw");
 }
 
+blobBuilder.append(null);
+// Yay we didn't crash.
+
 blobBuilder.append("squiggle");
 let blob1 = blobBuilder.getBlob();
 ok(blob1 instanceof Blob, "getBlob should produce Blobs");
 ok(!(blob1 instanceof File), "getBlob should not produce Files");
 is(blob1.type, "", "getBlob with no argument should return Blob with empty type");
 is(blob1.size, 8, "getBlob should return Blob with correct size");
 
 blobBuilder.append("ohai");