Commit 22ba59d6 authored by oliver@apple.com's avatar oliver@apple.com

2010-02-10 Oliver Hunt <oliver@apple.com>

        Reviewed by Gavin Barraclough.

        postMessage does not send ImageData
        https://bugs.webkit.org/show_bug.cgi?id=34825

        Add test for postMessage passing ImageData

        Update a few other tests to cover the fact that ImageData's constructor
        is now available on the window object.

        * fast/dom/Window/window-postmessage-clone-expected.txt:
        * fast/dom/Window/window-postmessage-clone.html:
        * fast/dom/Window/window-properties-expected.txt:
        * fast/dom/Window/window-property-descriptors-expected.txt:
        * fast/dom/prototype-inheritance-2-expected.txt:
        * fast/dom/prototype-inheritance-expected.txt:
        * fast/js/global-constructors-expected.txt:
2010-02-10  Oliver Hunt  <oliver@apple.com>

        Reviewed by Gavin Barraclough.

        postMessage does not send ImageData
        https://bugs.webkit.org/show_bug.cgi?id=34825

        Implement serialisation of ImageData, and for testing reasons
        expose the ImageData constructor (which should already have
        been exposed).

        * bindings/js/SerializedScriptValue.cpp:
        (WebCore::SerializedImageData::create):
        (WebCore::SerializedImageData::width):
        (WebCore::SerializedImageData::height):
        (WebCore::SerializedImageData::data):
        (WebCore::SerializedImageData::SerializedImageData):
        (WebCore::SerializedScriptValueData::SerializedScriptValueData):
        (WebCore::SharedSerializedData::asImageData):
        (WebCore::SerializingTreeWalker::convertIfTerminal):
        (WebCore::DeserializingTreeWalker::convertIfTerminal):
        (WebCore::TeardownTreeWalker::convertIfTerminal):
        * bindings/js/SerializedScriptValue.h:
        (WebCore::SerializedScriptValueData::):
        (WebCore::SerializedScriptValueData::asImageData):
        * html/canvas/CanvasPixelArray.h:
        (WebCore::CanvasPixelArray::data):
        * page/DOMWindow.idl:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54646 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9de082c2
2010-02-10 Oliver Hunt <oliver@apple.com>
Reviewed by Gavin Barraclough.
postMessage does not send ImageData
https://bugs.webkit.org/show_bug.cgi?id=34825
Add test for postMessage passing ImageData
Update a few other tests to cover the fact that ImageData's constructor
is now available on the window object.
* fast/dom/Window/window-postmessage-clone-expected.txt:
* fast/dom/Window/window-postmessage-clone.html:
* fast/dom/Window/window-properties-expected.txt:
* fast/dom/Window/window-property-descriptors-expected.txt:
* fast/dom/prototype-inheritance-2-expected.txt:
* fast/dom/prototype-inheritance-expected.txt:
* fast/js/global-constructors-expected.txt:
2010-02-10 Beth Dakin <bdakin@apple.com>
Reviewed by Simon Fraser and Darin Adler.
......
......@@ -18,5 +18,7 @@ PASS: eventData is 2009-02-13T23:31:30.000Z of type object
PASS: eventData is [object Array](default toString threw RangeError: Maximum call stack size exceeded.) of type object
PASS: eventData is [object File] of type object
PASS: eventData is [object FileList] of type object
PASS: eventData is [object ImageData] of type object
PASS: eventData is [object ImageData] of type object
PASS: eventData is done of type string
......@@ -16,10 +16,10 @@ var messages = [];
function equal(actual, expected)
{
if (typeof actual !== typeof expected)
return false;
if (actual === expected)
return true;
if (typeof actual !== typeof expected)
return false;
if ((actual instanceof Date) || (expected instanceof Date)) {
if ((actual instanceof Date) && (expected instanceof Date))
return (expected instanceof Date) && actual.getTime() == expected.getTime();
......@@ -40,9 +40,17 @@ function equal(actual, expected)
}
if (actual.constructor !== expected.constructor)
return false;
var keys = Object.keys(actual);
try {
var keys = Object.keys(actual);
} catch(e) {
return false;
}
try {
if (!equal(keys, Object.keys(expected)))
return false;
} catch(e) {
return false;
}
for (var i = 0; i < keys.length; i++) {
if (!equal(actual[keys[i]], expected[keys[i]]))
return false;
......@@ -75,7 +83,7 @@ function shouldBe(actual, expected)
function onmessage(evt) {
eventData = evt.data;
if (evt.data !== evt.data)
console.innerHTML += "MessageEvent.data does not produce the same value on multiple queries.";
console.innerHTML += "MessageEvent.data does not produce the same value on multiple queries.<br>";
shouldBe("eventData", messages.shift());
if (safeToString(evt.data) == 'done' && window.layoutTestController)
......@@ -129,15 +137,27 @@ for (var i = 0; i < 100000; i++)
tryPostMessage('reallyDeepArray', true);
tryPostMessage('window', true);
var fileInput = document.getElementById("fileInput");
var fileRect = fileInput.getClientRects()[0];
var targetX = fileRect.left + fileRect.width / 2;
var targetY = fileRect.top + fileRect.height / 2;
eventSender.beginDragWithFiles(['get-file-upload.html']);
eventSender.mouseMoveTo(targetX, targetY);
eventSender.mouseUp();
tryPostMessage('fileInput.files[0]', false, fileInput.files[0]);
tryPostMessage('fileInput.files', false, fileInput.files);
if (window.eventSender) {
var fileInput = document.getElementById("fileInput");
var fileRect = fileInput.getClientRects()[0];
var targetX = fileRect.left + fileRect.width / 2;
var targetY = fileRect.top + fileRect.height / 2;
eventSender.beginDragWithFiles(['get-file-upload.html']);
eventSender.mouseMoveTo(targetX, targetY);
eventSender.mouseUp();
tryPostMessage('fileInput.files[0]', false, fileInput.files[0]);
tryPostMessage('fileInput.files', false, fileInput.files);
}
var imageData = document.createElement("canvas").getContext("2d").createImageData(10,10);
for (var i = 0; i < imageData.data.length * 4; i++)
imageData.data[i] = i % 256;
var mutatedImageData = document.createElement("canvas").getContext("2d").createImageData(10,10);
for (var i = 0; i < imageData.data.length * 4; i++)
mutatedImageData.data[i] = i % 256;
tryPostMessage('imageData', false, imageData);
tryPostMessage('mutatedImageData', false, imageData);
for (var i = 0; i < imageData.data.length * 4; i++)
mutatedImageData.data[i] = 0;
tryPostMessage('"done"');
</script>
......
......@@ -1044,6 +1044,8 @@ window.HTMLVideoElement [object HTMLVideoElementConstructor]
window.HTMLVideoElement.prototype [printed above as window.Element.prototype]
window.Image [object ImageConstructor]
window.Image.prototype [printed above as window.Element.prototype]
window.ImageData [object ImageDataConstructor]
window.ImageData.prototype [object ImageDataPrototype]
window.KeyboardEvent [object KeyboardEventConstructor]
window.KeyboardEvent.prototype [printed above as window.Event.prototype]
window.MediaError [object MediaErrorConstructor]
......
......@@ -114,6 +114,7 @@ PASS typeof Object.getOwnPropertyDescriptor(window, 'HTMLTitleElement') is 'obje
PASS typeof Object.getOwnPropertyDescriptor(window, 'HTMLUListElement') is 'object'
PASS typeof Object.getOwnPropertyDescriptor(window, 'HTMLVideoElement') is 'object'
PASS typeof Object.getOwnPropertyDescriptor(window, 'Image') is 'object'
PASS typeof Object.getOwnPropertyDescriptor(window, 'ImageData') is 'object'
PASS typeof Object.getOwnPropertyDescriptor(window, 'Infinity') is 'object'
PASS typeof Object.getOwnPropertyDescriptor(window, 'JSON') is 'object'
PASS typeof Object.getOwnPropertyDescriptor(window, 'KeyboardEvent') is 'object'
......
......@@ -264,6 +264,7 @@ Never found HTMLTableElement
Never found HTMLTableRowElement
Never found HTMLTableSectionElement
Never found Image
Never found ImageData
Never found MessageChannel
Never found MessagePort
Never found Node
......
......@@ -215,6 +215,8 @@ PASS inner.HTMLVideoElement.isInner is true
PASS inner.HTMLVideoElement.constructor.isInner is true
PASS inner.Image.isInner is true
PASS inner.Image.constructor.isInner is true
PASS inner.ImageData.isInner is true
PASS inner.ImageData.constructor.isInner is true
PASS inner.KeyboardEvent.isInner is true
PASS inner.KeyboardEvent.constructor.isInner is true
PASS inner.MediaError.isInner is true
......
......@@ -107,6 +107,7 @@ PASS HTMLTitleElement.toString() is '[object HTMLTitleElementConstructor]'
PASS HTMLUListElement.toString() is '[object HTMLUListElementConstructor]'
PASS HTMLVideoElement.toString() is '[object HTMLVideoElementConstructor]'
PASS Image.toString() is '[object ImageConstructor]'
PASS ImageData.toString() is '[object ImageDataConstructor]'
PASS KeyboardEvent.toString() is '[object KeyboardEventConstructor]'
PASS MediaError.toString() is '[object MediaErrorConstructor]'
PASS MediaList.toString() is '[object MediaListConstructor]'
......
2010-02-10 Oliver Hunt <oliver@apple.com>
Reviewed by Gavin Barraclough.
postMessage does not send ImageData
https://bugs.webkit.org/show_bug.cgi?id=34825
Implement serialisation of ImageData, and for testing reasons
expose the ImageData constructor (which should already have
been exposed).
* bindings/js/SerializedScriptValue.cpp:
(WebCore::SerializedImageData::create):
(WebCore::SerializedImageData::width):
(WebCore::SerializedImageData::height):
(WebCore::SerializedImageData::data):
(WebCore::SerializedImageData::SerializedImageData):
(WebCore::SerializedScriptValueData::SerializedScriptValueData):
(WebCore::SharedSerializedData::asImageData):
(WebCore::SerializingTreeWalker::convertIfTerminal):
(WebCore::DeserializingTreeWalker::convertIfTerminal):
(WebCore::TeardownTreeWalker::convertIfTerminal):
* bindings/js/SerializedScriptValue.h:
(WebCore::SerializedScriptValueData::):
(WebCore::SerializedScriptValueData::asImageData):
* html/canvas/CanvasPixelArray.h:
(WebCore::CanvasPixelArray::data):
* page/DOMWindow.idl:
2010-02-10 Adam Barth <abarth@webkit.org>
Reviewed by Darin Adler.
......
......@@ -29,14 +29,17 @@
#include "File.h"
#include "FileList.h"
#include "ImageData.h"
#include "JSDOMGlobalObject.h"
#include "JSFile.h"
#include "JSFileList.h"
#include "JSImageData.h"
#include <JavaScriptCore/APICast.h>
#include <runtime/DateInstance.h>
#include <runtime/ExceptionHelpers.h>
#include <runtime/JSLock.h>
#include <runtime/PropertyNameArray.h>
#include <wtf/ByteArray.h>
#include <wtf/HashTraits.h>
#include <wtf/Vector.h>
......@@ -165,6 +168,30 @@ private:
Vector<String> m_files;
};
class SerializedImageData : public SharedSerializedData {
public:
static PassRefPtr<SerializedImageData> create(const ImageData* imageData)
{
return adoptRef(new SerializedImageData(imageData));
}
unsigned width() const { return m_width; }
unsigned height() const { return m_height; }
WTF::ByteArray* data() const { return m_storage.get(); }
private:
SerializedImageData(const ImageData* imageData)
: m_width(imageData->width())
, m_height(imageData->height())
{
WTF::ByteArray* array = imageData->data()->data();
m_storage = WTF::ByteArray::create(array->length());
memcpy(m_storage->data(), array->data(), array->length());
}
unsigned m_width;
unsigned m_height;
RefPtr<WTF::ByteArray> m_storage;
};
SerializedScriptValueData::SerializedScriptValueData(RefPtr<SerializedObject> data)
: m_type(ObjectType)
, m_sharedData(data)
......@@ -183,6 +210,12 @@ SerializedScriptValueData::SerializedScriptValueData(const FileList* fileList)
{
}
SerializedScriptValueData::SerializedScriptValueData(const ImageData* imageData)
: m_type(ImageDataType)
, m_sharedData(SerializedImageData::create(imageData))
{
}
SerializedScriptValueData::SerializedScriptValueData(const File* file)
: m_type(FileType)
, m_string(file->path().crossThreadString())
......@@ -204,6 +237,11 @@ SerializedFileList* SharedSerializedData::asFileList()
return static_cast<SerializedFileList*>(this);
}
SerializedImageData* SharedSerializedData::asImageData()
{
return static_cast<SerializedImageData*>(this);
}
static const unsigned maximumFilterRecursion = 40000;
enum WalkerState { StateUnknown, ArrayStartState, ArrayStartVisitMember, ArrayEndVisitMember,
ObjectStartState, ObjectStartVisitMember, ObjectEndVisitMember };
......@@ -533,6 +571,8 @@ struct SerializingTreeWalker : public BaseWalker {
return SerializedScriptValueData(toFile(obj));
if (obj->inherits(&JSFileList::s_info))
return SerializedScriptValueData(toFileList(obj));
if (obj->inherits(&JSImageData::s_info))
return SerializedScriptValueData(toImageData(obj));
CallData unusedData;
if (value.getCallData(unusedData) == CallTypeNone)
......@@ -709,6 +749,14 @@ struct DeserializingTreeWalker : public BaseWalker {
result->append(File::create(serializedFileList->item(i)));
return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), result.get());
}
case SerializedScriptValueData::ImageDataType: {
if (!m_isDOMGlobalObject)
return jsNull();
SerializedImageData* serializedImageData = value.asImageData();
RefPtr<ImageData> result = ImageData::create(serializedImageData->width(), serializedImageData->height());
memcpy(result->data()->data()->data(), serializedImageData->data()->data(), serializedImageData->data()->length());
return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), result.get());
}
case SerializedScriptValueData::EmptyType:
ASSERT_NOT_REACHED();
return jsNull();
......@@ -868,6 +916,7 @@ struct TeardownTreeWalker {
case SerializedScriptValueData::EmptyType:
case SerializedScriptValueData::FileType:
case SerializedScriptValueData::FileListType:
case SerializedScriptValueData::ImageDataType:
return true;
}
ASSERT_NOT_REACHED();
......
......@@ -35,8 +35,10 @@ typedef const struct OpaqueJSValue* JSValueRef;
namespace WebCore {
class File;
class FileList;
class ImageData;
class SerializedArray;
class SerializedFileList;
class SerializedImageData;
class SerializedObject;
class SharedSerializedData : public RefCounted<SharedSerializedData> {
......@@ -45,6 +47,7 @@ namespace WebCore {
SerializedArray* asArray();
SerializedObject* asObject();
SerializedFileList* asFileList();
SerializedImageData* asImageData();
};
class SerializedScriptValue;
......@@ -60,7 +63,8 @@ namespace WebCore {
ArrayType,
StringType,
FileType,
FileListType
FileListType,
ImageDataType
};
SerializedType type() const { return m_type; }
......@@ -86,6 +90,7 @@ namespace WebCore {
explicit SerializedScriptValueData(const File*);
explicit SerializedScriptValueData(const FileList*);
explicit SerializedScriptValueData(const ImageData*);
explicit SerializedScriptValueData(JSC::JSValue value)
: m_type(ImmediateType)
......@@ -141,6 +146,13 @@ namespace WebCore {
ASSERT(m_sharedData);
return m_sharedData->asFileList();
}
SerializedImageData* asImageData() const
{
ASSERT(m_type == ImageDataType);
ASSERT(m_sharedData);
return m_sharedData->asImageData();
}
operator bool() const { return m_type != EmptyType; }
......
......@@ -42,6 +42,7 @@ namespace WebCore {
static PassRefPtr<CanvasPixelArray> create(unsigned length);
WTF::ByteArray* data() { return m_data.get(); }
const WTF::ByteArray* data() const { return m_data.get(); }
unsigned length() const { return m_data->length(); }
void set(unsigned index, double value)
......
......@@ -441,6 +441,7 @@ module window {
attribute [CustomGetter] HTMLOptionElementConstructor Option; // Usable with new operator
attribute CanvasRenderingContext2DConstructor CanvasRenderingContext2D;
attribute ImageDataConstructor ImageData;
attribute [Conditional=3D_CANVAS] WebGLRenderingContextConstructor WebGLRenderingContext;
attribute TextMetricsConstructor TextMetrics;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment