зеркало из https://github.com/mozilla/gecko-dev.git
back out probably cause of orange. a=backout
This commit is contained in:
Родитель
4cab7cce39
Коммит
591044f939
|
@ -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,21 +101,12 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMFileReader,
|
||||
nsXHREventTarget)
|
||||
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_INHERITED(nsDOMFileReader,
|
||||
nsXHREventTarget)
|
||||
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)
|
||||
|
@ -136,19 +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_HOLD_JS_OBJECTS(this, nsDOMFileReader);
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMFileReader::UnrootResultArrayBuffer()
|
||||
{
|
||||
NS_DROP_JS_OBJECTS(this, nsDOMFileReader);
|
||||
}
|
||||
|
||||
//nsICharsetDetectionObserver
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -163,20 +137,16 @@ nsDOMFileReader::Notify(const char *aCharset, nsDetectionConfident aConf)
|
|||
nsDOMFileReader::nsDOMFileReader()
|
||||
: mFileData(nsnull),
|
||||
mDataLen(0), mDataFormat(FILE_AS_BINARY),
|
||||
mResultArrayBuffer(nsnull),
|
||||
mReadyState(nsIDOMFileReader::EMPTY),
|
||||
mProgressEventWasDelayed(PR_FALSE),
|
||||
mTimerIsActive(PR_FALSE),
|
||||
mReadTotal(0), mReadTransferred(0)
|
||||
{
|
||||
nsLayoutStatics::AddRef();
|
||||
SetDOMStringToNull(mResult);
|
||||
}
|
||||
|
||||
nsDOMFileReader::~nsDOMFileReader()
|
||||
{
|
||||
UnrootResultArrayBuffer();
|
||||
|
||||
if (mListenerManager)
|
||||
mListenerManager->Disconnect();
|
||||
|
||||
|
@ -265,21 +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;
|
||||
}
|
||||
|
||||
nsString tmpResult = mResult;
|
||||
if (!xpc_qsStringToJsval(aCx, tmpResult, aResult)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aResult = mResult;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -290,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
|
||||
|
@ -330,7 +282,6 @@ nsDOMFileReader::Abort()
|
|||
|
||||
//Revert status, result and readystate attributes
|
||||
SetDOMStringToNull(mResult);
|
||||
mResultArrayBuffer = nsnull;
|
||||
mReadyState = nsIDOMFileReader::DONE;
|
||||
mError = new nsDOMFileError(nsIDOMFileError::ABORT_ERR);
|
||||
|
||||
|
@ -433,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);
|
||||
|
@ -496,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:
|
||||
|
@ -527,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)
|
||||
{
|
||||
|
@ -573,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,8 +139,6 @@ protected:
|
|||
|
||||
eDataFormat mDataFormat;
|
||||
|
||||
JSObject* mResultArrayBuffer;
|
||||
|
||||
nsString mResult;
|
||||
PRUint16 mReadyState;
|
||||
|
||||
|
|
|
@ -426,8 +426,7 @@ nsXMLHttpRequest::nsXMLHttpRequest()
|
|||
mErrorLoad(PR_FALSE), mTimerIsActive(PR_FALSE),
|
||||
mProgressEventWasDelayed(PR_FALSE),
|
||||
mLoadLengthComputable(PR_FALSE), mLoadTotal(0),
|
||||
mFirstStartRequestSeen(PR_FALSE),
|
||||
mResultArrayBuffer(nsnull)
|
||||
mFirstStartRequestSeen(PR_FALSE)
|
||||
{
|
||||
mResponseBodyUnicode.SetIsVoid(PR_TRUE);
|
||||
nsLayoutStatics::AddRef();
|
||||
|
@ -435,8 +434,6 @@ nsXMLHttpRequest::nsXMLHttpRequest()
|
|||
|
||||
nsXMLHttpRequest::~nsXMLHttpRequest()
|
||||
{
|
||||
UnrootResultArrayBuffer();
|
||||
|
||||
if (mListenerManager) {
|
||||
mListenerManager->Disconnect();
|
||||
}
|
||||
|
@ -453,19 +450,6 @@ nsXMLHttpRequest::~nsXMLHttpRequest()
|
|||
nsLayoutStatics::Release();
|
||||
}
|
||||
|
||||
void
|
||||
nsXMLHttpRequest::RootResultArrayBuffer()
|
||||
{
|
||||
NS_HOLD_JS_OBJECTS(this, nsXMLHttpRequest);
|
||||
}
|
||||
|
||||
void
|
||||
nsXMLHttpRequest::UnrootResultArrayBuffer()
|
||||
{
|
||||
NS_DROP_JS_OBJECTS(this, nsXMLHttpRequest);
|
||||
mResultArrayBuffer = nsnull;
|
||||
}
|
||||
|
||||
/**
|
||||
* This Init method is called from the factory constructor.
|
||||
*/
|
||||
|
@ -570,7 +554,6 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLHttpRequest)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLHttpRequest,
|
||||
nsXHREventTarget)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChannel)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mReadRequest)
|
||||
|
@ -589,9 +572,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLHttpRequest,
|
|||
nsIXMLHttpRequestUpload)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXMLHttpRequest,
|
||||
nsXHREventTarget)
|
||||
tmp->UnrootResultArrayBuffer();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mContext)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChannel)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mReadRequest)
|
||||
|
@ -609,14 +592,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXMLHttpRequest,
|
|||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mUpload)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsXMLHttpRequest,
|
||||
nsXHREventTarget)
|
||||
if(tmp->mResultArrayBuffer) {
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mResultArrayBuffer,
|
||||
"mResultArrayBuffer")
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
DOMCI_DATA(XMLHttpRequest, nsXMLHttpRequest)
|
||||
|
||||
// QueryInterface implementation for nsXMLHttpRequest
|
||||
|
@ -864,21 +839,27 @@ NS_IMETHODIMP nsXMLHttpRequest::GetResponseText(nsAString& aResponseText)
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsXMLHttpRequest::CreateResponseArrayBuffer(JSContext *aCx)
|
||||
nsresult nsXMLHttpRequest::GetResponseArrayBuffer(jsval *aResult)
|
||||
{
|
||||
if (!aCx)
|
||||
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mResultArrayBuffer = nsnull;
|
||||
PRInt32 dataLen = mResponseBody.Length();
|
||||
mResultArrayBuffer = js_CreateArrayBuffer(aCx, dataLen);
|
||||
if (!mResultArrayBuffer) {
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!(mState & (XML_HTTP_REQUEST_DONE |
|
||||
XML_HTTP_REQUEST_LOADING))) {
|
||||
*aResult = JSVAL_NULL;
|
||||
return NS_OK;
|
||||
}
|
||||
RootResultArrayBuffer();
|
||||
|
||||
PRInt32 dataLen = mResponseBody.Length();
|
||||
JSObject *obj = js_CreateArrayBuffer(cx, dataLen);
|
||||
if (!obj)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aResult = OBJECT_TO_JSVAL(obj);
|
||||
|
||||
if (dataLen > 0) {
|
||||
js::ArrayBuffer *abuf = js::ArrayBuffer::fromJSObject(mResultArrayBuffer);
|
||||
js::ArrayBuffer *abuf = js::ArrayBuffer::fromJSObject(obj);
|
||||
NS_ASSERTION(abuf, "What happened?");
|
||||
memcpy(abuf->data, mResponseBody.BeginReading(), dataLen);
|
||||
}
|
||||
|
@ -973,11 +954,7 @@ NS_IMETHODIMP nsXMLHttpRequest::GetResponse(JSContext *aCx, jsval *aResult)
|
|||
|
||||
case XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER:
|
||||
if (mState & XML_HTTP_REQUEST_DONE) {
|
||||
if (!mResultArrayBuffer) {
|
||||
rv = CreateResponseArrayBuffer(aCx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
*aResult = OBJECT_TO_JSVAL(mResultArrayBuffer);
|
||||
rv = GetResponseArrayBuffer(aResult);
|
||||
} else {
|
||||
*aResult = JSVAL_NULL;
|
||||
}
|
||||
|
@ -1096,8 +1073,7 @@ nsXMLHttpRequest::Abort()
|
|||
mResponseBodyUnicode.SetIsVoid(PR_TRUE);
|
||||
mResponseBlob = nsnull;
|
||||
mState |= XML_HTTP_REQUEST_ABORTED;
|
||||
mResultArrayBuffer = nsnull;
|
||||
|
||||
|
||||
if (!(mState & (XML_HTTP_REQUEST_UNSENT |
|
||||
XML_HTTP_REQUEST_OPENED |
|
||||
XML_HTTP_REQUEST_DONE))) {
|
||||
|
|
|
@ -208,12 +208,11 @@ public:
|
|||
|
||||
void SetRequestObserver(nsIRequestObserver* aObserver);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsXMLHttpRequest,
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXMLHttpRequest,
|
||||
nsXHREventTarget)
|
||||
|
||||
PRBool AllowUploadProgress();
|
||||
void RootResultArrayBuffer();
|
||||
void UnrootResultArrayBuffer();
|
||||
|
||||
|
||||
protected:
|
||||
friend class nsMultipartProxyListener;
|
||||
|
||||
|
@ -225,7 +224,7 @@ protected:
|
|||
PRUint32 toOffset,
|
||||
PRUint32 count,
|
||||
PRUint32 *writeCount);
|
||||
nsresult CreateResponseArrayBuffer(JSContext* aCx);
|
||||
nsresult GetResponseArrayBuffer(jsval *aResult);
|
||||
void CreateResponseBlob(nsIRequest *request);
|
||||
// Change the state of the object with this. The broadcast argument
|
||||
// determines if the onreadystatechange listener should be called.
|
||||
|
@ -346,8 +345,6 @@ protected:
|
|||
|
||||
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
||||
nsCOMPtr<nsIChannel> mNewRedirectChannel;
|
||||
|
||||
JSObject* mResultArrayBuffer;
|
||||
};
|
||||
|
||||
// helper class to expose a progress DOM Event
|
||||
|
|
|
@ -110,16 +110,6 @@ function arraybuffer_equals_to(ab, s) {
|
|||
is(String.fromCharCode.apply(String, u8v), s, "wrong values");
|
||||
}
|
||||
|
||||
// test if two arraybuffers are identical
|
||||
function is_identical_arraybuffer(ab1, ab2) {
|
||||
is(ab1.byteLength, ab2.byteLength, "arraybuffer byteLengths not equal");
|
||||
|
||||
u8v1 = new Uint8Array(ab1);
|
||||
u8v2 = new Uint8Array(ab2);
|
||||
is(String.fromCharCode.apply(String, u8v1),
|
||||
String.fromCharCode.apply(String, u8v2), "wrong values");
|
||||
}
|
||||
|
||||
// with a simple text file
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_pass2.txt', false);
|
||||
|
@ -144,18 +134,6 @@ ab = xhr.response;
|
|||
ok(ab != null, "should have a non-null arraybuffer");
|
||||
arraybuffer_equals_to(ab, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb");
|
||||
|
||||
// test array buffer GetResult returns the same object
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_binary1.bin', false);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.send(null)
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseTextAccessThrows(xhr);
|
||||
checkResponseXMLAccessThrows(xhr);
|
||||
ab = xhr.response;
|
||||
ab2 = xhr.response;
|
||||
is_identical_arraybuffer(ab, ab2);
|
||||
|
||||
// test response (responseType='blob')
|
||||
var onloadCount = 0;
|
||||
function checkOnloadCount() {
|
||||
|
|
|
@ -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,16 +148,12 @@ 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);
|
||||
expectedTestCount++;
|
||||
|
||||
|
||||
// Test reusing a FileReader to read multiple times
|
||||
r = new FileReader();
|
||||
r.onload = getLoadHandler(testASCIIData,
|
||||
|
@ -227,39 +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 first reading as ArrayBuffer then read as something else
|
||||
// (BinaryString) and doesn't crash
|
||||
r = new FileReader();
|
||||
r.onload = getLoadHandlerForArrayBuffer(testBinaryData,
|
||||
testBinaryData.length,
|
||||
"to-be-reused reading arrayBuffer")
|
||||
var makeAnotherReadListener5 = function(event) {
|
||||
r = event.target;
|
||||
r.removeEventListener("load", makeAnotherReadListener5, false);
|
||||
r.onload = getLoadHandler(testBinaryData,
|
||||
testBinaryData.length,
|
||||
"reused reading binary string");
|
||||
r.readAsBinaryString(binaryFile);
|
||||
};
|
||||
r.addEventListener("load", makeAnotherReadListener5, false);
|
||||
r.readAsArrayBuffer(binaryFile);
|
||||
expectedTestCount += 2;
|
||||
|
||||
//Test data-URI encoding on differing file sizes
|
||||
dataurldata = testBinaryData.substr(0, testBinaryData.length -
|
||||
|
@ -379,30 +322,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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -436,20 +436,6 @@ public:
|
|||
"not the nsISupports pointer we expect"); \
|
||||
_class *tmp = Downcast(s);
|
||||
|
||||
#define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(_class, _base_class) \
|
||||
void \
|
||||
NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace(void *p, \
|
||||
TraceCallback aCallback, \
|
||||
void *aClosure) \
|
||||
{ \
|
||||
nsISupports *s = static_cast<nsISupports*>(p); \
|
||||
NS_ASSERTION(CheckForRightISupports(s), \
|
||||
"not the nsISupports pointer we expect"); \
|
||||
_class *tmp = static_cast<_class*>(Downcast(s)); \
|
||||
NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Trace(s, \
|
||||
aCallback, \
|
||||
aClosure);
|
||||
|
||||
#define NS_IMPL_CYCLE_COLLECTION_TRACE_NATIVE_BEGIN(_class) \
|
||||
void \
|
||||
NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace(void *p, \
|
||||
|
|
Загрузка…
Ссылка в новой задаче