| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (c) 2010, Google Inc. All rights reserved. | 3 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 : ArrayBufferView(buffer, byteOffset) | 86 : ArrayBufferView(buffer, byteOffset) |
| 87 , m_length(length) | 87 , m_length(length) |
| 88 { | 88 { |
| 89 } | 89 } |
| 90 | 90 |
| 91 template <class Subclass> | 91 template <class Subclass> |
| 92 static PassRefPtr<Subclass> create(unsigned length) | 92 static PassRefPtr<Subclass> create(unsigned length) |
| 93 { | 93 { |
| 94 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, sizeof(T)); | 94 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, sizeof(T)); |
| 95 if (!buffer.get()) | 95 if (!buffer.get()) |
| 96 return 0; | 96 return nullptr; |
| 97 return create<Subclass>(buffer, 0, length); | 97 return create<Subclass>(buffer, 0, length); |
| 98 } | 98 } |
| 99 | 99 |
| 100 template <class Subclass> | 100 template <class Subclass> |
| 101 static PassRefPtr<Subclass> create(const T* array, unsigned length) | 101 static PassRefPtr<Subclass> create(const T* array, unsigned length) |
| 102 { | 102 { |
| 103 RefPtr<Subclass> a = create<Subclass>(length); | 103 RefPtr<Subclass> a = create<Subclass>(length); |
| 104 if (a) | 104 if (a) |
| 105 for (unsigned i = 0; i < length; ++i) | 105 for (unsigned i = 0; i < length; ++i) |
| 106 a->set(i, array[i]); | 106 a->set(i, array[i]); |
| 107 return a; | 107 return a; |
| 108 } | 108 } |
| 109 | 109 |
| 110 template <class Subclass> | 110 template <class Subclass> |
| 111 static PassRefPtr<Subclass> create(PassRefPtr<ArrayBuffer> buffer, | 111 static PassRefPtr<Subclass> create(PassRefPtr<ArrayBuffer> buffer, |
| 112 unsigned byteOffset, | 112 unsigned byteOffset, |
| 113 unsigned length) | 113 unsigned length) |
| 114 { | 114 { |
| 115 RefPtr<ArrayBuffer> buf(buffer); | 115 RefPtr<ArrayBuffer> buf(buffer); |
| 116 if (!verifySubRange<T>(buf, byteOffset, length)) | 116 if (!verifySubRange<T>(buf, byteOffset, length)) |
| 117 return 0; | 117 return nullptr; |
| 118 | 118 |
| 119 return adoptRef(new Subclass(buf, byteOffset, length)); | 119 return adoptRef(new Subclass(buf, byteOffset, length)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 template <class Subclass> | 122 template <class Subclass> |
| 123 static PassRefPtr<Subclass> createUninitialized(unsigned length) | 123 static PassRefPtr<Subclass> createUninitialized(unsigned length) |
| 124 { | 124 { |
| 125 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(length, si
zeof(T)); | 125 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(length, si
zeof(T)); |
| 126 if (!buffer.get()) | 126 if (!buffer.get()) |
| 127 return 0; | 127 return nullptr; |
| 128 return create<Subclass>(buffer, 0, length); | 128 return create<Subclass>(buffer, 0, length); |
| 129 } | 129 } |
| 130 | 130 |
| 131 template <class Subclass> | 131 template <class Subclass> |
| 132 PassRefPtr<Subclass> subarrayImpl(int start, int end) const | 132 PassRefPtr<Subclass> subarrayImpl(int start, int end) const |
| 133 { | 133 { |
| 134 unsigned offset, length; | 134 unsigned offset, length; |
| 135 calculateOffsetAndLength(start, end, m_length, &offset, &length); | 135 calculateOffsetAndLength(start, end, m_length, &offset, &length); |
| 136 clampOffsetAndNumElements<T>(buffer(), m_byteOffset, &offset, &length); | 136 clampOffsetAndNumElements<T>(buffer(), m_byteOffset, &offset, &length); |
| 137 return create<Subclass>(buffer(), offset, length); | 137 return create<Subclass>(buffer(), offset, length); |
| 138 } | 138 } |
| 139 | 139 |
| 140 virtual void neuter() OVERRIDE FINAL | 140 virtual void neuter() OVERRIDE FINAL |
| 141 { | 141 { |
| 142 ArrayBufferView::neuter(); | 142 ArrayBufferView::neuter(); |
| 143 m_length = 0; | 143 m_length = 0; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // We do not want to have to access this via a virtual function in subclasse
s, | 146 // We do not want to have to access this via a virtual function in subclasse
s, |
| 147 // which is why it is protected rather than private. | 147 // which is why it is protected rather than private. |
| 148 unsigned m_length; | 148 unsigned m_length; |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 } // namespace WTF | 151 } // namespace WTF |
| 152 | 152 |
| 153 using WTF::TypedArrayBase; | 153 using WTF::TypedArrayBase; |
| 154 | 154 |
| 155 #endif // TypedArrayBase_h | 155 #endif // TypedArrayBase_h |
| OLD | NEW |