WebCore/ChangeLog

 12010-10-08 Eric Uhrhane <ericu@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 FileWriter should hold a reference to a Blob during write
 6 https://bugs.webkit.org/show_bug.cgi?id=47318
 7
 8 Without this reference, the Blob might get garbage-collected from JS
 9 before the write has completed, which would be quite unintuitive to the
 10 user. I just grab a RefPtr to the Blob at write(), then clear it when
 11 we're done.
 12
 13 * fileapi/FileWriter.cpp:
 14 (WebCore::FileWriter::stop):
 15 (WebCore::FileWriter::write):
 16 (WebCore::FileWriter::didWrite):
 17 (WebCore::FileWriter::didFail):
 18 * fileapi/FileWriter.h:
 19
1202010-10-08 James Robinson <jamesr@chromium.org>
221
322 Reviewed by Adam Barth.
69437

WebCore/fileapi/FileWriter.cpp

@@void FileWriter::stop()
8282{
8383 if (m_writer && m_readyState == WRITING)
8484 m_writer->abort();
 85 m_blobBeingWritten.clear();
8586 m_readyState = DONE;
8687}
8788

@@void FileWriter::write(Blob* data, Excep
99100 return;
100101 }
101102
 103 m_blobBeingWritten = data;
102104 m_readyState = WRITING;
103105 m_startedWriting = false;
104106 m_bytesWritten = 0;

@@void FileWriter::didWrite(long long byte
169171 m_length = m_position;
170172 fireEvent(eventNames().writeEvent);
171173 if (complete) {
 174 m_blobBeingWritten.clear();
172175 m_readyState = DONE;
173176 fireEvent(eventNames().writeendEvent);
174177 }

@@void FileWriter::didFail(ExceptionCode e
194197 if (ABORT_ERR == ec)
195198 fireEvent(eventNames().abortEvent);
196199 fireEvent(eventNames().errorEvent);
 200 m_blobBeingWritten.clear();
197201 m_readyState = DONE;
198202 fireEvent(eventNames().writeendEvent);
199203}
69411

WebCore/fileapi/FileWriter.h

@@private:
123123 long long m_bytesWritten;
124124 long long m_bytesToWrite;
125125 long long m_truncateLength;
 126 RefPtr<Blob> m_blobBeingWritten;
126127};
127128
128129} // namespace WebCore
69411

LayoutTests/ChangeLog

 12010-10-08 Eric Uhrhane <ericu@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 FileWriter should hold a reference to a Blob during write
 6 https://bugs.webkit.org/show_bug.cgi?id=47318
 7
 8 Added the first FileWriter test to cover this.
 9 Problem #1: it's not a deterministic problem; the test might or might
 10 not catch the error, but at least it won't ever trigger a false
 11 positive.
 12 Problem #2: no platform fully implements FileWriter yet, so this test
 13 must start out completely supressed. All non-chromium platforms
 14 already skip all filesystem tests, so I'm only adding a suppression in
 15 chromium.
 16 * fast/filesystem/file-writer-gc-blob-expected.txt: Added.
 17 * fast/filesystem/file-writer-gc-blob.html: Added.
 18 * platform/chromium/test_expectations.txt:
 19
1202010-10-08 Martin Robinson <mrobinson@igalia.com>
221
322 Reviewed by Daniel Bates.
69437

LayoutTests/fast/filesystem/file-writer-gc-blob-expected.txt

 1starting test
 2PASS Successfully wrote blob.
 3PASS successfullyParsed is true
 4
 5TEST COMPLETE
0

LayoutTests/fast/filesystem/file-writer-gc-blob.html

 1<!DOCTYPE HTML>
 2<html>
 3<head>
 4<title>File Writer test</title>
 5<link rel="stylesheet" href="../js/resources/js-test-style.css">
 6<script src="../js/resources/js-test-pre.js"></script>
 7<script>
 8 var fileEntry;
 9
 10 function cleanUp() {
 11 var needToCallFinish = true;
 12 try {
 13 if (fileEntry) {
 14 fileEntry.remove(finishJSTest, finishJSTest);
 15 needToCallFinish = false;
 16 }
 17 } catch (ex) {
 18 }
 19 if (needToCallFinish) {
 20 finishJSTest();
 21 }
 22 }
 23
 24 function stringifyObj(o) {
 25 s = "";
 26 if (o)
 27 for (index in o) {
 28 s += index + ": " + o[index] + "\n";
 29 }
 30 return s;
 31 }
 32
 33 function onError(e) {
 34 debug("Caught an error.");
 35 if (e && e.code) { // Each FileError has a code.
 36 debug("Error code: " + e.code);
 37 }
 38 testFailed(stringifyObj(e));
 39 cleanUp();
 40 }
 41
 42 function onSuccess() {
 43 testPassed("Successfully wrote blob.");
 44 cleanUp();
 45 }
 46
 47 function tenXBlob(blob) {
 48 var bb = new BlobBuilder();
 49 for (var i = 0; i < 10; ++i) {
 50 bb.append(blob);
 51 }
 52 return bb.getBlob();
 53 }
 54
 55 function startWrite(writer) {
 56 // Let's make it about a megabyte.
 57 var bb = new BlobBuilder();
 58 bb.append("lorem ipsum");
 59 var blob = tenXBlob(bb.getBlob());
 60 blob = tenXBlob(bb.getBlob());
 61 blob = tenXBlob(bb.getBlob());
 62 blob = tenXBlob(bb.getBlob());
 63 blob = tenXBlob(bb.getBlob());
 64 writer.onerror = onError;
 65 writer.onwriteend = onSuccess;
 66 writer.write(blob);
 67 }
 68
 69 function useFileWriter(writer) {
 70 startWrite(writer);
 71 gc();
 72 }
 73
 74 function fileCallback(f) {
 75 fileEntry = f;
 76 fileEntry.createWriter(useFileWriter, onError);
 77 }
 78
 79 function runTest() {
 80 debug("starting test");
 81 if (requestFileSystem) {
 82 requestFileSystem(0, 1024*1024,
 83 function(fs) {
 84 fs.root.getFile("test.txt", {create:true}, fileCallback,
 85 onError);
 86 },
 87 onError);
 88 } else {
 89 debug("This test requires FileSystem API support.");
 90 }
 91 }
 92 window.successfullyParsed = true;
 93 window.jsTestIsAsync = true;
 94</script>
 95</head>
 96<body onload="runTest()">
 97 <div id="description"></div>
 98 <div id="console"></div>
 99 <script src="../js/resources/js-test-post.js"></script>
 100</body>
 101</html>
 102
0

LayoutTests/platform/chromium/test_expectations.txt

@@BUG58358 WIN LINUX : fast/css/transforme
32173217BUG58358 MAC : fast/css/transformed-mask.html = IMAGE
32183218
32193219BUG58481 WIN : fast/html/object-image-nested-fallback.html = CRASH
 3220
 3221// FileWriter isn't in TestShell yet.
 3222BUG58587 SKIP : fast/filesystem/file-writer-gc-blob.html = FAIL
69411