Changeset 97893 in webkit
- Timestamp:
- Oct 19, 2011 4:31:12 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r97890 r97893 1 2011-10-19 Shinya Kawanaka <shinyak@google.com> 2 3 ArrayBuffer should have slice method. 4 https://bugs.webkit.org/show_bug.cgi?id=66646 5 6 Reviewed by Kenneth Russell. 7 8 * fast/canvas/webgl/array-unit-tests.html: Aded. 9 1 10 2011-10-19 Dirk Pranke <dpranke@chromium.org> 2 11 -
trunk/LayoutTests/fast/canvas/webgl/array-unit-tests.html
r97881 r97893 55 55 } else { 56 56 debug("TEST FAILED"); 57 } 58 } 59 60 var byteLength; 61 var subBuffer; 62 function testSlice() { 63 function test(subBuf, starts, size) { 64 byteLength = size; 65 subBuffer = eval(subBuf); 66 var subArray = new Int8Array(subBuffer); 67 assertEq(subBuf, subBuffer.byteLength, byteLength); 68 for (var i = 0; i < size; ++i) 69 assertEq('Element ' + i, starts + i, subArray[i]); 70 } 71 72 try { 73 var buffer = new ArrayBuffer(32); 74 var array = new Int8Array(buffer); 75 for (var i = 0; i < 32; ++i) 76 array[i] = i; 77 78 test("buffer.slice(0)", 0, 32); 79 test("buffer.slice(16)", 16, 16); 80 test("buffer.slice(24)", 24, 8); 81 test("buffer.slice(32)", 32, 0); 82 test("buffer.slice(40)", 32, 0); 83 test("buffer.slice(80)", 32, 0); 84 85 test("buffer.slice(-8)", 24, 8); 86 test("buffer.slice(-16)", 16, 16); 87 test("buffer.slice(-24)", 8, 24); 88 test("buffer.slice(-32)", 0, 32); 89 test("buffer.slice(-40)", 0, 32); 90 test("buffer.slice(-80)", 0, 32); 91 92 test("buffer.slice(0, 32)", 0, 32); 93 test("buffer.slice(0, 16)", 0, 16); 94 test("buffer.slice(8, 24)", 8, 16); 95 test("buffer.slice(16, 32)", 16, 16); 96 test("buffer.slice(24, 16)", 24, 0); 97 98 test("buffer.slice(16, -8)", 16, 8); 99 test("buffer.slice(-20, 30)", 12, 18); 100 101 test("buffer.slice(-8, -20)", 24, 0); 102 test("buffer.slice(-20, -8)", 12, 12); 103 test("buffer.slice(-40, 16)", 0, 16); 104 test("buffer.slice(-40, 40)", 0, 32); 105 } catch (e) { 106 fail(e); 57 107 } 58 108 } … … 825 875 function runTests() { 826 876 allPassed = true; 877 878 testSlice(); 827 879 828 880 // The "name" attribute is a concession to browsers which don't -
trunk/Source/WebCore/ChangeLog
r97892 r97893 1 2011-10-19 Shinya Kawanaka <shinyak@google.com> 2 3 ArrayBuffer should have slice method. 4 https://bugs.webkit.org/show_bug.cgi?id=66646 5 6 Reviewed by Kenneth Russell. 7 8 * html/canvas/ArrayBuffer.cpp: 9 (WebCore::clampValue): 10 (WebCore::ArrayBuffer::slice): 11 (WebCore::ArrayBuffer::sliceImpl): 12 (WebCore::ArrayBuffer::clampIndex): 13 * html/canvas/ArrayBuffer.h: Added declaration. 14 * html/canvas/ArrayBuffer.idl: Added interface. 15 1 16 2011-10-19 Mark Hahnenberg <mhahnenberg@apple.com> 2 17 -
trunk/Source/WebCore/html/canvas/ArrayBuffer.cpp
r91300 r97893 30 30 31 31 namespace WebCore { 32 33 static int clampValue(int x, int left, int right) 34 { 35 ASSERT(left <= right); 36 if (x < left) 37 x = left; 38 if (right < x) 39 x = right; 40 return x; 41 } 32 42 33 43 PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize) … … 75 85 } 76 86 87 PassRefPtr<ArrayBuffer> ArrayBuffer::slice(int begin, int end) const 88 { 89 return sliceImpl(clampIndex(begin), clampIndex(end)); 90 } 91 92 PassRefPtr<ArrayBuffer> ArrayBuffer::slice(int begin) const 93 { 94 return sliceImpl(clampIndex(begin), byteLength()); 95 } 96 97 PassRefPtr<ArrayBuffer> ArrayBuffer::sliceImpl(unsigned begin, unsigned end) const 98 { 99 unsigned size = begin <= end ? end - begin : 0; 100 return ArrayBuffer::create(static_cast<const char*>(data()) + begin, size); 101 } 102 103 unsigned ArrayBuffer::clampIndex(int index) const 104 { 105 unsigned currentLength = byteLength(); 106 if (index < 0) 107 index = currentLength + index; 108 return clampValue(index, 0, currentLength); 109 } 110 77 111 ArrayBuffer::~ArrayBuffer() 78 112 { -
trunk/Source/WebCore/html/canvas/ArrayBuffer.h
r91300 r97893 42 42 unsigned byteLength() const; 43 43 44 PassRefPtr<ArrayBuffer> slice(int begin, int end) const; 45 PassRefPtr<ArrayBuffer> slice(int begin) const; 46 44 47 ~ArrayBuffer(); 45 48 … … 48 51 ArrayBuffer(unsigned numElements, unsigned elementByteSize); 49 52 static void* tryAllocate(unsigned numElements, unsigned elementByteSize); 53 PassRefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const; 54 unsigned clampIndex(int index) const; 55 50 56 unsigned m_sizeInBytes; 51 57 void* m_data; -
trunk/Source/WebCore/html/canvas/ArrayBuffer.idl
r96788 r97893 33 33 ] ArrayBuffer { 34 34 readonly attribute int byteLength; 35 ArrayBuffer slice(in long begin, in [Optional] long end); 35 36 }; 36 37
Note: See TracChangeset
for help on using the changeset viewer.