diff options
Diffstat (limited to 'WebCore/fileapi/FileWriter.cpp')
-rw-r--r-- | WebCore/fileapi/FileWriter.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/WebCore/fileapi/FileWriter.cpp b/WebCore/fileapi/FileWriter.cpp index a9f9afd..8367bf9 100644 --- a/WebCore/fileapi/FileWriter.cpp +++ b/WebCore/fileapi/FileWriter.cpp @@ -48,6 +48,7 @@ FileWriter::FileWriter(ScriptExecutionContext* context) , m_position(0) , m_bytesWritten(0) , m_bytesToWrite(0) + , m_truncateLength(-1) { } @@ -95,7 +96,6 @@ void FileWriter::write(Blob* data, ExceptionCode& ec) m_readyState = WRITING; m_bytesWritten = 0; m_bytesToWrite = data->size(); - fireEvent(eventNames().writestartEvent); m_writer->write(m_position, data); } @@ -122,7 +122,7 @@ void FileWriter::seek(long long position, ExceptionCode& ec) void FileWriter::truncate(long long position, ExceptionCode& ec) { ASSERT(m_writer); - if (m_readyState == WRITING || position >= m_length) { + if (m_readyState == WRITING || position < 0) { ec = INVALID_STATE_ERR; m_error = FileError::create(ec); return; @@ -130,7 +130,7 @@ void FileWriter::truncate(long long position, ExceptionCode& ec) m_readyState = WRITING; m_bytesWritten = 0; m_bytesToWrite = 0; - fireEvent(eventNames().writestartEvent); + m_truncateLength = position; m_writer->truncate(position); } @@ -142,11 +142,8 @@ void FileWriter::abort(ExceptionCode& ec) m_error = FileError::create(ec); return; } + m_error = FileError::create(ABORT_ERR); - m_readyState = DONE; - fireEvent(eventNames().errorEvent); - fireEvent(eventNames().abortEvent); - fireEvent(eventNames().writeendEvent); m_writer->abort(); } @@ -155,36 +152,41 @@ void FileWriter::didWrite(long long bytes, bool complete) ASSERT(bytes > 0); ASSERT(bytes + m_bytesWritten > 0); ASSERT(bytes + m_bytesWritten <= m_bytesToWrite); + if (!m_bytesWritten) + fireEvent(eventNames().writestartEvent); m_bytesWritten += bytes; ASSERT((m_bytesWritten == m_bytesToWrite) == complete); m_position += bytes; if (m_position > m_length) m_length = m_position; - if (complete) - m_readyState = DONE; fireEvent(eventNames().writeEvent); - if (complete) + if (complete) { + m_readyState = DONE; fireEvent(eventNames().writeendEvent); + } } -void FileWriter::didTruncate(long long length) +void FileWriter::didTruncate() { - ASSERT(length > 0); - ASSERT(length >= 0); - ASSERT(length < m_length); - m_length = length; + ASSERT(m_truncateLength >= 0); + fireEvent(eventNames().writestartEvent); + m_length = m_truncateLength; if (m_position > m_length) m_position = m_length; - m_readyState = DONE; + m_truncateLength = -1; fireEvent(eventNames().writeEvent); + m_readyState = DONE; fireEvent(eventNames().writeendEvent); } void FileWriter::didFail(ExceptionCode ec) { m_error = FileError::create(ec); - m_readyState = DONE; fireEvent(eventNames().errorEvent); + if (ABORT_ERR == ec) + fireEvent(eventNames().abortEvent); + fireEvent(eventNames().errorEvent); + m_readyState = DONE; fireEvent(eventNames().writeendEvent); } |