Back out another suspect just in case. CLOSED TREE. a=orange

This commit is contained in:
Jonas Sicking 2011-05-20 17:20:37 -07:00
Родитель 5f5e5a0fc2
Коммит 9f4a100ada
4 изменённых файлов: 11 добавлений и 161 удалений

Просмотреть файл

@ -41,11 +41,9 @@ interface nsIDOMEventListener;
interface nsIDOMBlob;
interface nsIDOMFileError;
[scriptable, uuid(3d77e784-1459-4206-b8a2-0855d826f569)]
[scriptable, uuid(f186170f-f07c-4f0b-9e3c-08f7dd496e74)]
interface nsIDOMFileReader : nsISupports
{
[implicit_jscontext]
void readAsArrayBuffer(in nsIDOMBlob filedata);
void readAsBinaryString(in nsIDOMBlob filedata);
void readAsText(in nsIDOMBlob filedata, [optional] in DOMString encoding);
void readAsDataURL(in nsIDOMBlob file);
@ -57,8 +55,7 @@ interface nsIDOMFileReader : nsISupports
const unsigned short DONE = 2;
readonly attribute unsigned short readyState;
[implicit_jscontext]
readonly attribute jsval result;
readonly attribute DOMString result;
readonly attribute nsIDOMFileError error;
};

Просмотреть файл

@ -77,9 +77,6 @@
#include "nsLayoutStatics.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsFileDataProtocolHandler.h"
#include "xpcprivate.h"
#include "xpcquickstubs.h"
#include "jstypedarray.h"
#define LOAD_STR "load"
#define ERROR_STR "error"
@ -96,7 +93,6 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMFileReader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMFileReader,
nsXHREventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFile)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mProgressNotifier)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrincipal)
@ -105,22 +101,12 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMFileReader,
nsXHREventTarget)
if (tmp->mResultArrayBufferRooted) {
tmp->UnrootResultArrayBuffer();
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFile)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mProgressNotifier)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChannel)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMFileReader)
if(tmp->mResultArrayBuffer) {
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mResultArrayBuffer,
"mResultArrayBuffer")
}
NS_IMPL_CYCLE_COLLECTION_TRACE_END
DOMCI_DATA(FileReader, nsDOMFileReader)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMFileReader)
@ -137,24 +123,6 @@ NS_INTERFACE_MAP_END_INHERITING(nsXHREventTarget)
NS_IMPL_ADDREF_INHERITED(nsDOMFileReader, nsXHREventTarget)
NS_IMPL_RELEASE_INHERITED(nsDOMFileReader, nsXHREventTarget)
//array buffer holder root/unroot
void
nsDOMFileReader::RootResultArrayBuffer()
{
NS_ASSERTION(!mResultArrayBufferRooted, "This should be false!");
NS_HOLD_JS_OBJECTS(this, nsDOMFileReader);
mResultArrayBufferRooted = true;
}
void
nsDOMFileReader::UnrootResultArrayBuffer()
{
NS_ASSERTION(mResultArrayBufferRooted, "This should be true!");
NS_DROP_JS_OBJECTS(this, nsDOMFileReader);
mResultArrayBufferRooted = false;
mResultArrayBuffer = nsnull;
}
//nsICharsetDetectionObserver
NS_IMETHODIMP
@ -169,22 +137,16 @@ nsDOMFileReader::Notify(const char *aCharset, nsDetectionConfident aConf)
nsDOMFileReader::nsDOMFileReader()
: mFileData(nsnull),
mDataLen(0), mDataFormat(FILE_AS_BINARY),
mResultArrayBuffer(nsnull),
mResultArrayBufferRooted(false),
mReadyState(nsIDOMFileReader::EMPTY),
mProgressEventWasDelayed(PR_FALSE),
mTimerIsActive(PR_FALSE),
mReadTotal(0), mReadTransferred(0)
{
nsLayoutStatics::AddRef();
SetDOMStringToNull(mResult);
}
nsDOMFileReader::~nsDOMFileReader()
{
if (mResultArrayBufferRooted) {
UnrootResultArrayBuffer();
}
if (mListenerManager)
mListenerManager->Disconnect();
@ -273,20 +235,9 @@ nsDOMFileReader::GetReadyState(PRUint16 *aReadyState)
}
NS_IMETHODIMP
nsDOMFileReader::GetResult(JSContext* aCx, jsval* aResult)
nsDOMFileReader::GetResult(nsAString& aResult)
{
if (mDataFormat == FILE_AS_ARRAYBUFFER) {
if (mReadyState == nsIDOMFileReader::DONE) {
*aResult = OBJECT_TO_JSVAL(mResultArrayBuffer);
} else {
*aResult = JSVAL_NULL;
}
return NS_OK;
}
if (!xpc_qsStringToJsval(aCx, mResult, aResult)) {
return NS_ERROR_FAILURE;
}
aResult = mResult;
return NS_OK;
}
@ -297,29 +248,23 @@ nsDOMFileReader::GetError(nsIDOMFileError** aError)
return NS_OK;
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aFile, JSContext* aCx)
{
return ReadFileContent(aCx, aFile, EmptyString(), FILE_AS_ARRAYBUFFER);
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsBinaryString(nsIDOMBlob* aFile)
{
return ReadFileContent(nsnull, aFile, EmptyString(), FILE_AS_BINARY);
return ReadFileContent(aFile, EmptyString(), FILE_AS_BINARY);
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsText(nsIDOMBlob* aFile,
const nsAString &aCharset)
{
return ReadFileContent(nsnull, aFile, aCharset, FILE_AS_TEXT);
return ReadFileContent(aFile, aCharset, FILE_AS_TEXT);
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aFile)
{
return ReadFileContent(nsnull, aFile, EmptyString(), FILE_AS_DATAURL);
return ReadFileContent(aFile, EmptyString(), FILE_AS_DATAURL);
}
NS_IMETHODIMP
@ -337,9 +282,6 @@ nsDOMFileReader::Abort()
//Revert status, result and readystate attributes
SetDOMStringToNull(mResult);
if (mResultArrayBufferRooted) {
UnrootResultArrayBuffer();
}
mReadyState = nsIDOMFileReader::DONE;
mError = new nsDOMFileError(nsIDOMFileError::ABORT_ERR);
@ -442,14 +384,6 @@ nsDOMFileReader::OnDataAvailable(nsIRequest *aRequest,
&bytesRead);
NS_ASSERTION(bytesRead == aCount, "failed to read data");
}
else if (mDataFormat == FILE_AS_ARRAYBUFFER) {
js::ArrayBuffer* abuf = js::ArrayBuffer::fromJSObject(mResultArrayBuffer);
NS_ASSERTION(abuf, "What happened?");
PRUint32 bytesRead = 0;
aInputStream->Read((char*)abuf->data + aOffset, aCount, &bytesRead);
NS_ASSERTION(bytesRead == aCount, "failed to read data");
}
else {
//Update memory buffer to reflect the contents of the file
mFileData = (char *)PR_Realloc(mFileData, aOffset + aCount);
@ -505,8 +439,6 @@ nsDOMFileReader::OnStopRequest(nsIRequest *aRequest,
nsresult rv = NS_OK;
switch (mDataFormat) {
case FILE_AS_ARRAYBUFFER:
break; //Already accumulated mResultArrayBuffer
case FILE_AS_BINARY:
break; //Already accumulated mResult
case FILE_AS_TEXT:
@ -536,8 +468,7 @@ nsDOMFileReader::OnStopRequest(nsIRequest *aRequest,
// Helper methods
nsresult
nsDOMFileReader::ReadFileContent(JSContext* aCx,
nsIDOMBlob* aFile,
nsDOMFileReader::ReadFileContent(nsIDOMBlob* aFile,
const nsAString &aCharset,
eDataFormat aDataFormat)
{
@ -582,15 +513,6 @@ nsDOMFileReader::ReadFileContent(JSContext* aCx,
//FileReader should be in loading state here
mReadyState = nsIDOMFileReader::LOADING;
DispatchProgressEvent(NS_LITERAL_STRING(LOADSTART_STR));
if (mDataFormat == FILE_AS_ARRAYBUFFER) {
mResultArrayBuffer = js_CreateArrayBuffer(aCx, mReadTotal);
if (!mResultArrayBuffer) {
NS_WARNING("Failed to create JS array buffer");
return NS_ERROR_FAILURE;
}
RootResultArrayBuffer();
}
return NS_OK;
}

Просмотреть файл

@ -80,8 +80,7 @@ public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMFILEREADER
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsDOMFileReader,
nsXHREventTarget)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMFileReader, nsXHREventTarget)
NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(nsXHREventTarget::);
@ -110,19 +109,15 @@ public:
void DispatchProgressEvent(const nsAString& aType);
nsresult Init();
void RootResultArrayBuffer();
void UnrootResultArrayBuffer();
protected:
enum eDataFormat {
FILE_AS_ARRAYBUFFER,
FILE_AS_BINARY,
FILE_AS_TEXT,
FILE_AS_DATAURL
};
nsresult ReadFileContent(JSContext* aCx, nsIDOMBlob *aFile, const nsAString &aCharset, eDataFormat aDataFormat);
nsresult ReadFileContent(nsIDOMBlob *aFile, const nsAString &aCharset, eDataFormat aDataFormat);
nsresult GetAsText(const nsACString &aCharset,
const char *aFileData, PRUint32 aDataLen, nsAString &aResult);
nsresult GetAsDataURL(nsIDOMBlob *aFile, const char *aFileData, PRUint32 aDataLen, nsAString &aResult);
@ -144,9 +139,6 @@ protected:
eDataFormat mDataFormat;
JSObject* mResultArrayBuffer;
bool mResultArrayBufferRooted;
nsString mResult;
PRUint16 mReadyState;

Просмотреть файл

@ -98,18 +98,6 @@ is(onloadHasRunBinary, false, "binary loading must be async");
is(onloadStartHasRunBinary, true, "binary loadstart should fire sync");
expectedTestCount++;
var onloadHasRunArrayBuffer = false;
var onloadStartHasRunArrayBuffer = false;
r = new FileReader();
is(r.readyState, FileReader.EMPTY, "correct initial arrayBuffer readyState");
r.addEventListener("load", function() { onloadHasRunArrayBuffer = true }, false);
r.addEventListener("loadstart", function() { onloadStartHasRunArrayBuffer = true }, false);
r.readAsArrayBuffer(binaryFile);
r.onload = getLoadHandlerForArrayBuffer(testBinaryData, testBinaryData.length, "array buffer reading");
is(r.readyState, FileReader.LOADING, "correct loading arrayBuffer readyState");
is(onloadHasRunArrayBuffer, false, "arrayBuffer loading must be async");
is(onloadStartHasRunArrayBuffer, true, "arrayBuffer loadstart should fire sync");
expectedTestCount++;
// Test a variety of encodings, and make sure they work properly
r = new FileReader();
@ -136,14 +124,6 @@ r.onload = getLoadHandler(testTextData,
"utf16 reading");
expectedTestCount++;
// Test get result without reading
r = new FileReader();
is(r.readyState, FileReader.EMPTY,
"readyState in test reader get result without reading");
is(r.error, null,
"no error in test reader get result without reading");
is(r.result, null,
"result in test reader get result without reading");
// Test loading an empty file works (and doesn't crash!)
var emptyFile = createFileWithData("");
@ -168,11 +148,6 @@ r.onload = getLoadHandler("", 0, "empty binary string reading");
r.readAsBinaryString(emptyFile);
expectedTestCount++;
r = new FileReader();
r.onload = getLoadHandlerForArrayBuffer("", 0, "empty array buffer reading");
r.readAsArrayBuffer(emptyFile);
expectedTestCount++;
r = new FileReader();
r.onload = getLoadHandler(convertToDataURL(""), 0, "empt binary string reading");
r.readAsDataURL(emptyFile);
@ -228,21 +203,6 @@ r.addEventListener("load", makeAnotherReadListener3, false);
r.readAsDataURL(binaryFile);
expectedTestCount += 2;
r = new FileReader();
r.onload = getLoadHandlerForArrayBuffer(testBinaryData,
testBinaryData.length,
"to-be-reused reading arrayBuffer")
var makeAnotherReadListener4 = function(event) {
r = event.target;
r.removeEventListener("load", makeAnotherReadListener4, false);
r.onload = getLoadHandlerForArrayBuffer(testBinaryData,
testBinaryData.length,
"reused reading arrayBuffer");
r.readAsArrayBuffer(binaryFile);
};
r.addEventListener("load", makeAnotherReadListener4, false);
r.readAsArrayBuffer(binaryFile);
expectedTestCount += 2;
//Test data-URI encoding on differing file sizes
dataurldata = testBinaryData.substr(0, testBinaryData.length -
@ -350,30 +310,9 @@ function getLoadHandler(expectedResult, expectedLength, testName) {
is(event.lengthComputable, true,
"lengthComputable in test " + testName);
is(event.loaded, expectedLength,
"loaded in test " + testName);
is(event.total, expectedLength,
"total in test " + testName);
testHasRun();
}
}
function getLoadHandlerForArrayBuffer(expectedResult, expectedLength, testName) {
return function (event) {
is(event.target.readyState, FileReader.DONE,
"readyState in test " + testName);
is(event.target.error, null,
"no error in test " + testName);
is(event.lengthComputable, true,
"lengthComputable in test " + testName);
is(event.loaded, expectedLength,
"loaded in test " + testName);
is(event.total, expectedLength,
"total in test " + testName);
is(event.target.result.byteLength, expectedLength,
"array buffer size in test " + testName);
var u8v = new Uint8Array(event.target.result);
is(String.fromCharCode.apply(String, u8v), expectedResult,
"array buffer contents in test " + testName);
"lengthComputable in test " + testName);
testHasRun();
}
}