Changeset 39625 in webkit for trunk/JavaScriptCore/runtime/ByteArray.h
- Timestamp:
- Jan 5, 2009, 3:57:09 PM (16 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/ByteArray.h
r39624 r39625 1 1 /* 2 * Copyright (C) 200 8Apple Inc. All Rights Reserved.2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #i nclude "config.h"27 # include "JSImageData.h"26 #ifndef ByteArray_h 27 #define ByteArray_h 28 28 29 #include " ImageData.h"30 using namespace JSC; 29 #include "wtf/PassRefPtr.h" 30 #include "wtf/RefCounted.h" 31 31 32 namespace WebCore { 32 namespace JSC { 33 class ByteArray : public RefCounted<ByteArray> { 34 public: 35 unsigned length() const { return m_size; } 33 36 34 JSValue* toJS(ExecState* exec, ImageData* imageData) 35 { 36 if (!imageData) 37 return jsNull(); 38 39 DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), imageData); 40 if (wrapper) 41 return wrapper; 42 43 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, ImageData, imageData); 44 45 exec->heap()->reportExtraMemoryCost(imageData->data()->length()); 46 47 return wrapper; 37 void set(unsigned index, double value) 38 { 39 if (index >= m_size) 40 return; 41 if (!(value > 0)) // Clamp NaN to 0 42 value = 0; 43 else if (value > 255) 44 value = 255; 45 m_data[index] = static_cast<unsigned char>(value + 0.5); 46 } 47 48 bool get(unsigned index, unsigned char& result) const 49 { 50 if (index >= m_size) 51 return false; 52 result = m_data[index]; 53 return true; 54 } 55 56 unsigned char* data() { return m_data; } 57 58 static PassRefPtr<ByteArray> create(size_t size); 59 60 private: 61 ByteArray(size_t size) 62 : m_size(size) 63 { 64 } 65 size_t m_size; 66 unsigned char m_data[0]; 67 }; 48 68 } 49 69 50 } 70 #endif
Note:
See TracChangeset
for help on using the changeset viewer.