Bug 743615 - Hook up worker ImageData to the structured clone stream. r=bent

This commit is contained in:
Bobby Holley 2012-04-24 00:53:37 +02:00
parent 52fb059174
commit 6dad3c142d

View File

@ -79,6 +79,7 @@
#include "Events.h"
#include "Exceptions.h"
#include "File.h"
#include "ImageData.h"
#include "Principal.h"
#include "RuntimeService.h"
#include "ScriptLoader.h"
@ -103,6 +104,7 @@ using mozilla::dom::workers::exceptions::ThrowDOMExceptionForCode;
USING_WORKERS_NAMESPACE
using namespace mozilla::dom::workers::events;
using namespace mozilla::dom;
namespace {
@ -333,6 +335,25 @@ struct WorkerStructuredCloneCallbacks
return jsBlob;
}
}
// See if the object is an ImageData.
else if (aTag == SCTAG_DOM_IMAGEDATA) {
JS_ASSERT(!aData);
// Read the information out of the stream.
uint32_t width, height;
jsval dataArray;
if (!JS_ReadUint32Pair(aReader, &width, &height) ||
!JS_ReadTypedArray(aReader, &dataArray))
{
return nsnull;
}
MOZ_ASSERT(dataArray.isObject());
// Construct the ImageData.
JSObject* obj = imagedata::Create(aCx, width, height,
JSVAL_TO_OBJECT(dataArray));
return obj;
}
Error(aCx, 0);
return nsnull;
@ -374,6 +395,19 @@ struct WorkerStructuredCloneCallbacks
}
}
// See if this is an ImageData object.
if (imagedata::IsImageData(aObj)) {
// Pull the properties off the object.
uint32_t width = imagedata::GetWidth(aObj);
uint32_t height = imagedata::GetHeight(aObj);
JSObject* data = imagedata::GetData(aObj);
// Write the structured clone.
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) &&
JS_WriteUint32Pair(aWriter, width, height) &&
JS_WriteTypedArray(aWriter, OBJECT_TO_JSVAL(data));
}
Error(aCx, 0);
return false;
}