Title: [166246] trunk
Revision
166246
Author
k...@webkit.org
Date
2014-03-25 13:24:14 -0700 (Tue, 25 Mar 2014)

Log Message

Implement ImageData constructors and WebWorkers exposure
https://bugs.webkit.org/show_bug.cgi?id=130668

Reviewed by Dean Jackson.

Source/WebCore:

Add new constructors for ImageData.

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#pixel-manipulation

Test: fast/canvas/canvas-imageData.html

* html/ImageData.cpp:
(WebCore::ImageData::create):
* html/ImageData.h:
* html/ImageData.idl:

LayoutTests:

Tests for ImageData constructors. Remove a false tests for constructors
from Philip's test suite.

* fast/canvas/canvas-imageData-expected.txt: Added.
* fast/canvas/canvas-imageData.html: Added.
* fast/canvas/script-tests/canvas-imageData.js: Added.
(testTransparentBlack):
* LayoutTests/canvas/philip/tests/2d.imageData.object.ctor.html: Removed.
* LayoutTests/canvas/philip/tests/2d.imageData.object.ctor-expected.txt: Removed.
* LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt
* LayoutTests/js/dom/global-constructors-attributes-shared-worker-expected.txt

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (166245 => 166246)


--- trunk/LayoutTests/ChangeLog	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/LayoutTests/ChangeLog	2014-03-25 20:24:14 UTC (rev 166246)
@@ -1,3 +1,22 @@
+2014-03-25  Dirk Schulze  <k...@webkit.org>
+
+        Implement ImageData constructors and WebWorkers exposure
+        https://bugs.webkit.org/show_bug.cgi?id=130668
+
+        Reviewed by Dean Jackson.
+
+        Tests for ImageData constructors. Remove a false tests for constructors
+        from Philip's test suite.
+
+        * fast/canvas/canvas-imageData-expected.txt: Added.
+        * fast/canvas/canvas-imageData.html: Added.
+        * fast/canvas/script-tests/canvas-imageData.js: Added.
+        (testTransparentBlack):
+        * LayoutTests/canvas/philip/tests/2d.imageData.object.ctor.html: Removed.
+        * LayoutTests/canvas/philip/tests/2d.imageData.object.ctor-expected.txt: Removed.
+        * LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt
+        * LayoutTests/js/dom/global-constructors-attributes-shared-worker-expected.txt
+
 2014-03-25  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         InlineIterator position (unsigned int) variable can wrap around

Deleted: trunk/LayoutTests/canvas/philip/tests/2d.imageData.object.ctor-expected.txt (166245 => 166246)


--- trunk/LayoutTests/canvas/philip/tests/2d.imageData.object.ctor-expected.txt	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/LayoutTests/canvas/philip/tests/2d.imageData.object.ctor-expected.txt	2014-03-25 20:24:14 UTC (rev 166246)
@@ -1 +0,0 @@
-Passed

Deleted: trunk/LayoutTests/canvas/philip/tests/2d.imageData.object.ctor.html (166245 => 166246)


--- trunk/LayoutTests/canvas/philip/tests/2d.imageData.object.ctor.html	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/LayoutTests/canvas/philip/tests/2d.imageData.object.ctor.html	2014-03-25 20:24:14 UTC (rev 166246)
@@ -1,21 +0,0 @@
-<!DOCTYPE html>
-<title>Canvas test: 2d.imageData.object.ctor</title>
-<script src=""
-<link rel="stylesheet" href=""
-<body>
-<p id="passtext">Pass</p>
-<p id="failtext">Fail</p>
-<p class="output">These images should be identical:</p>
-<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
-
-<ul id="d"></ul>
-<script>
-_addTest(function(canvas, ctx) {
-
-_assertDifferent(window.ImageData, undefined, "window.ImageData", "undefined");
-try { var _thrown = false; new window.ImageData(1,1); } catch (e) { _thrown = true; } finally { _assert(_thrown, "should throw exception: new window.ImageData(1,1)"); }
-
-
-});
-</script>
-

Added: trunk/LayoutTests/fast/canvas/canvas-imageData-expected.txt (0 => 166246)


--- trunk/LayoutTests/fast/canvas/canvas-imageData-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-imageData-expected.txt	2014-03-25 20:24:14 UTC (rev 166246)
@@ -0,0 +1,46 @@
+Test constructors of ImageData.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test invalid ImageData constructor arguments.
+PASS new ImageData() threw exception TypeError: Not enough arguments.
+PASS new ImageData(1) threw exception TypeError: Not enough arguments.
+PASS new ImageData(new Uint8ClampedArray([1,2,3,4])); threw exception TypeError: Not enough arguments.
+PASS new ImageData(0, 0) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(20, 0) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(0, 20) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(-20, 20) threw exception TypeError: Type error.
+PASS new ImageData(20, -20) threw exception TypeError: Type error.
+PASS new ImageData(null, 20) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(32768, 32768) threw exception TypeError: Type error.
+PASS new ImageData(null, 20, 20) threw exception TypeError: Type error.
+PASS new ImageData(imageData, 20, 20) threw exception TypeError: Type error.
+PASS new ImageData(imageData, 0) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(imageData, 20, 0) threw exception TypeError: Type error.
+PASS new ImageData(imageData, 0, 20) threw exception TypeError: Type error.
+PASS new ImageData(imageData, 10, 5) threw exception TypeError: Type error.
+PASS new ImageData(imageData.data, 10, 5) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(imageData.data, -10, 5) threw exception Error: InvalidStateError: DOM Exception 11.
+PASS new ImageData(imageData.data, 10, -10) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2); threw exception Error: InvalidStateError: DOM Exception 11.
+PASS new ImageData({},2,2); threw exception TypeError: Type error.
+PASS new ImageData(undefined,2,2); threw exception TypeError: Type error.
+PASS new ImageData("none",2,2); threw exception TypeError: Type error.
+PASS new ImageData(0,2,2); threw exception TypeError: Type error.
+PASS new ImageData(imageData.data, 32768, 32768) threw exception Error: InvalidStateError: DOM Exception 11.
+PASS new ImageData(imageData.data, Infinity, Infinity) threw exception Error: IndexSizeError: DOM Exception 1.
+PASS new ImageData(imageData.data, NaN, NaN) threw exception Error: IndexSizeError: DOM Exception 1.
+
+Test valid ImageData constructors.
+Test that we got the pixel array from imageData.
+PASS imageData.data[1] is 128
+
+Test that we got a reference rather than a copy.
+PASS imageData.data[1] is 100
+
+PASS testTransparentBlack(imageData2.data) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/canvas-imageData.html (0 => 166246)


--- trunk/LayoutTests/fast/canvas/canvas-imageData.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-imageData.html	2014-03-25 20:24:14 UTC (rev 166246)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-imageData.js (0 => 166246)


--- trunk/LayoutTests/fast/canvas/script-tests/canvas-imageData.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-imageData.js	2014-03-25 20:24:14 UTC (rev 166246)
@@ -0,0 +1,64 @@
+description('Test constructors of ImageData.');
+
+ctx = document.createElement('canvas').getContext('2d');
+ctx.fillStyle = 'green';
+ctx.fillRect(0,0,10,10);
+var imageData = ctx.getImageData(0,0,10,10);
+
+debug('Test invalid ImageData constructor arguments.')
+shouldThrow('new ImageData()', '"TypeError: Not enough arguments"');
+shouldThrow('new ImageData(1)', '"TypeError: Not enough arguments"');
+shouldThrow('new ImageData(new Uint8ClampedArray([1,2,3,4]));', '"TypeError: Not enough arguments"');
+shouldThrow('new ImageData(0, 0)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(20, 0)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(0, 20)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(-20, 20)', '"TypeError: Type error"');
+shouldThrow('new ImageData(20, -20)', '"TypeError: Type error"');
+shouldThrow('new ImageData(null, 20)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(32768, 32768)', '"TypeError: Type error"');
+shouldThrow('new ImageData(null, 20, 20)', '"TypeError: Type error"');
+shouldThrow('new ImageData(imageData, 20, 20)', '"TypeError: Type error"');
+shouldThrow('new ImageData(imageData, 0)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(imageData, 20, 0)', '"TypeError: Type error"');
+shouldThrow('new ImageData(imageData, 0, 20)', '"TypeError: Type error"');
+shouldThrow('new ImageData(imageData, 10, 5)', '"TypeError: Type error"');
+shouldThrow('new ImageData(imageData.data, 10, 5)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(imageData.data, -10, 5)', '"Error: InvalidStateError: DOM Exception 11"');
+shouldThrow('new ImageData(imageData.data, 10, -10)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2);', '"Error: InvalidStateError: DOM Exception 11"');
+shouldThrow('new ImageData({},2,2);', '"TypeError: Type error"');
+shouldThrow('new ImageData(undefined,2,2);', '"TypeError: Type error"');
+shouldThrow('new ImageData("none",2,2);', '"TypeError: Type error"');
+shouldThrow('new ImageData(0,2,2);', '"TypeError: Type error"');
+shouldThrow('new ImageData(imageData.data, 32768, 32768)', '"Error: InvalidStateError: DOM Exception 11"');
+shouldThrow('new ImageData(imageData.data, Infinity, Infinity)', '"Error: IndexSizeError: DOM Exception 1"');
+shouldThrow('new ImageData(imageData.data, NaN, NaN)', '"Error: IndexSizeError: DOM Exception 1"');
+debug('');
+
+debug('Test valid ImageData constructors.')
+new ImageData(10, 10);
+new ImageData(imageData.data, 10, 10);
+new ImageData(imageData.data, 10);
+// This should throw but doesn't because of a CodeGeneratorJS bug.
+new ImageData(imageData.data, 10, 0);
+
+debug('Test that we got the pixel array from imageData.');
+var newImageData = new ImageData(imageData.data, 10, 10);
+shouldBe('imageData.data[1]', '128');
+debug('');
+
+debug('Test that we got a reference rather than a copy.')
+newImageData.data[1] = 100;
+shouldBe('imageData.data[1]','100');
+debug('');
+
+function testTransparentBlack(data) {
+    for (var i = 0; i < data.length; ++i) {
+        if (data[i] != 0)
+            return false;
+    }   
+    return true;
+}
+
+var imageData2 = new ImageData(100,100);
+shouldBeTrue('testTransparentBlack(imageData2.data)');
\ No newline at end of file

Modified: trunk/LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt (166245 => 166246)


--- trunk/LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt	2014-03-25 20:24:14 UTC (rev 166246)
@@ -84,6 +84,11 @@
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'IDBVersionChangeEvent').hasOwnProperty('set') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'IDBVersionChangeEvent').enumerable is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'IDBVersionChangeEvent').configurable is true
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').value is ImageData
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').hasOwnProperty('get') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').hasOwnProperty('set') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').enumerable is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').configurable is true
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'MessageChannel').value is MessageChannel
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'MessageChannel').hasOwnProperty('get') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'MessageChannel').hasOwnProperty('set') is false

Modified: trunk/LayoutTests/js/dom/global-constructors-attributes-shared-worker-expected.txt (166245 => 166246)


--- trunk/LayoutTests/js/dom/global-constructors-attributes-shared-worker-expected.txt	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/LayoutTests/js/dom/global-constructors-attributes-shared-worker-expected.txt	2014-03-25 20:24:14 UTC (rev 166246)
@@ -79,6 +79,11 @@
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'IDBVersionChangeEvent').hasOwnProperty('set') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'IDBVersionChangeEvent').enumerable is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'IDBVersionChangeEvent').configurable is true
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').value is ImageData
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').hasOwnProperty('get') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').hasOwnProperty('set') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').enumerable is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'ImageData').configurable is true
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'MessageChannel').value is MessageChannel
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'MessageChannel').hasOwnProperty('get') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'MessageChannel').hasOwnProperty('set') is false

Modified: trunk/Source/WebCore/ChangeLog (166245 => 166246)


--- trunk/Source/WebCore/ChangeLog	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/Source/WebCore/ChangeLog	2014-03-25 20:24:14 UTC (rev 166246)
@@ -1,3 +1,21 @@
+2014-03-25  Dirk Schulze  <k...@webkit.org>
+
+        Implement ImageData constructors and WebWorkers exposure
+        https://bugs.webkit.org/show_bug.cgi?id=130668
+
+        Reviewed by Dean Jackson.
+
+        Add new constructors for ImageData.
+
+        http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#pixel-manipulation
+
+        Test: fast/canvas/canvas-imageData.html
+
+        * html/ImageData.cpp: 
+        (WebCore::ImageData::create):
+        * html/ImageData.h:
+        * html/ImageData.idl:
+
 2014-03-25  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         InlineIterator position (unsigned int) variable can wrap around

Modified: trunk/Source/WebCore/html/ImageData.cpp (166245 => 166246)


--- trunk/Source/WebCore/html/ImageData.cpp	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/Source/WebCore/html/ImageData.cpp	2014-03-25 20:24:14 UTC (rev 166246)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,8 +30,31 @@
 #include "config.h"
 #include "ImageData.h"
 
+#include "ExceptionCode.h"
+
 namespace WebCore {
 
+PassRefPtr<ImageData> ImageData::create(unsigned sw, unsigned sh, ExceptionCode& ec)
+{
+    if (!sw || !sh) {
+        ec = INDEX_SIZE_ERR;
+        return nullptr;
+    }
+
+    Checked<int, RecordOverflow> dataSize = 4;
+    dataSize *= sw;
+    dataSize *= sh;
+    if (dataSize.hasOverflowed()) {
+        ec = TypeError;
+        return nullptr;
+    }
+
+    IntSize size(sw, sh);
+    RefPtr<ImageData> data = "" ImageData(size));
+    data->data()->zeroFill();
+    return data.release();
+}
+
 PassRefPtr<ImageData> ImageData::create(const IntSize& size)
 {
     Checked<int, RecordOverflow> dataSize = 4;
@@ -57,6 +81,34 @@
     return adoptRef(new ImageData(size, byteArray));
 }
 
+PassRefPtr<ImageData> ImageData::create(PassRefPtr<Uint8ClampedArray> byteArray, unsigned sw, unsigned sh, ExceptionCode& ec)
+{
+    unsigned length = byteArray->length();
+    if (!length || length % 4 != 0) {
+        ec = INVALID_STATE_ERR;
+        return nullptr;
+    }
+
+    if (!sw) {
+        ec = INDEX_SIZE_ERR;
+        return nullptr;
+    }
+
+    length /= 4;
+    if (length % sw != 0) {
+        ec = INVALID_STATE_ERR;
+        return nullptr;
+    }
+
+    unsigned height = length / sw;
+    if (sh && sh != height) {
+        ec = INDEX_SIZE_ERR;
+        return nullptr;
+    }
+
+    return create(IntSize(sw, height), byteArray);
+}
+
 ImageData::ImageData(const IntSize& size)
     : m_size(size)
     , m_data(Uint8ClampedArray::createUninitialized(size.width() * size.height() * 4))

Modified: trunk/Source/WebCore/html/ImageData.h (166245 => 166246)


--- trunk/Source/WebCore/html/ImageData.h	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/Source/WebCore/html/ImageData.h	2014-03-25 20:24:14 UTC (rev 166246)
@@ -36,10 +36,14 @@
 
 namespace WebCore {
 
+typedef int ExceptionCode;
+
 class ImageData : public RefCounted<ImageData> {
 public:
+    static PassRefPtr<ImageData> create(unsigned sw, unsigned sh, ExceptionCode&);
     static PassRefPtr<ImageData> create(const IntSize&);
     static PassRefPtr<ImageData> create(const IntSize&, PassRefPtr<Uint8ClampedArray>);
+    static PassRefPtr<ImageData> create(PassRefPtr<Uint8ClampedArray>, unsigned sw, unsigned sh, ExceptionCode&);
 
     IntSize size() const { return m_size; }
     int width() const { return m_size.width(); }

Modified: trunk/Source/WebCore/html/ImageData.idl (166245 => 166246)


--- trunk/Source/WebCore/html/ImageData.idl	2014-03-25 20:15:14 UTC (rev 166245)
+++ trunk/Source/WebCore/html/ImageData.idl	2014-03-25 20:24:14 UTC (rev 166246)
@@ -27,7 +27,14 @@
  */
 
 [
+    GlobalContext=DOMWindow&WorkerGlobalScope,
     CustomToJSObject,
+    // FIXME: Without [Default=Undefined] CodeGeneratorJS can't generate JSImageData. But with
+    // the extended attribute we accept a value of 0 for sh and don't throw.
+    // https://bugs.webkit.org/show_bug.cgi?id=130667
+    Constructor(Uint8ClampedArray data, unsigned long sw, [Default=Undefined] optional unsigned long sh),
+    Constructor(unsigned long sw, unsigned long sh),
+    ConstructorRaisesException,
     ImplementationLacksVTable
 ] interface ImageData {
     readonly attribute long width;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to