| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 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 |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef DataView_h | 26 #ifndef DataView_h |
| 27 #define DataView_h | 27 #define DataView_h |
| 28 | 28 |
| 29 #include "bindings/core/v8/ScriptWrappable.h" | |
| 30 #include "wtf/ArrayBufferView.h" | 29 #include "wtf/ArrayBufferView.h" |
| 31 #include "wtf/PassRefPtr.h" | |
| 32 | 30 |
| 33 namespace blink { | 31 namespace blink { |
| 34 | 32 |
| 35 class ExceptionState; | 33 class ExceptionState; |
| 36 | 34 |
| 37 class DataView final : public ArrayBufferView, public ScriptWrappable { | 35 class DataView final : public ArrayBufferView { |
| 38 DEFINE_WRAPPERTYPEINFO(); | |
| 39 public: | 36 public: |
| 40 static PassRefPtr<DataView> create(unsigned length); | 37 static PassRefPtr<DataView> create(unsigned length); |
| 41 static PassRefPtr<DataView> create(PassRefPtr<ArrayBuffer>, unsigned byteOff
set, unsigned byteLength); | 38 static PassRefPtr<DataView> create(PassRefPtr<ArrayBuffer>, unsigned byteOff
set, unsigned byteLength); |
| 42 | 39 |
| 43 virtual unsigned byteLength() const override { return m_byteLength; } | 40 virtual unsigned byteLength() const override { return m_byteLength; } |
| 41 virtual ViewType type() const override { return TypeDataView; } |
| 44 | 42 |
| 45 int8_t getInt8(unsigned byteOffset, ExceptionState&); | 43 int8_t getInt8(unsigned byteOffset, ExceptionState&); |
| 46 uint8_t getUint8(unsigned byteOffset, ExceptionState&); | 44 uint8_t getUint8(unsigned byteOffset, ExceptionState&); |
| 47 int16_t getInt16(unsigned byteOffset, ExceptionState& ec) { return getInt16(
byteOffset, false, ec); } | 45 int16_t getInt16(unsigned byteOffset, ExceptionState& ec) { return getInt16(
byteOffset, false, ec); } |
| 48 int16_t getInt16(unsigned byteOffset, bool littleEndian, ExceptionState&); | 46 int16_t getInt16(unsigned byteOffset, bool littleEndian, ExceptionState&); |
| 49 uint16_t getUint16(unsigned byteOffset, ExceptionState& ec) { return getUint
16(byteOffset, false, ec); } | 47 uint16_t getUint16(unsigned byteOffset, ExceptionState& ec) { return getUint
16(byteOffset, false, ec); } |
| 50 uint16_t getUint16(unsigned byteOffset, bool littleEndian, ExceptionState&); | 48 uint16_t getUint16(unsigned byteOffset, bool littleEndian, ExceptionState&); |
| 51 int32_t getInt32(unsigned byteOffset, ExceptionState& ec) { return getInt32(
byteOffset, false, ec); } | 49 int32_t getInt32(unsigned byteOffset, ExceptionState& ec) { return getInt32(
byteOffset, false, ec); } |
| 52 int32_t getInt32(unsigned byteOffset, bool littleEndian, ExceptionState&); | 50 int32_t getInt32(unsigned byteOffset, bool littleEndian, ExceptionState&); |
| 53 uint32_t getUint32(unsigned byteOffset, ExceptionState& ec) { return getUint
32(byteOffset, false, ec); } | 51 uint32_t getUint32(unsigned byteOffset, ExceptionState& ec) { return getUint
32(byteOffset, false, ec); } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 void setUint16(unsigned byteOffset, uint16_t value, bool littleEndian, Excep
tionState&); | 63 void setUint16(unsigned byteOffset, uint16_t value, bool littleEndian, Excep
tionState&); |
| 66 void setInt32(unsigned byteOffset, int32_t value, ExceptionState& ec) { setI
nt32(byteOffset, value, false, ec); } | 64 void setInt32(unsigned byteOffset, int32_t value, ExceptionState& ec) { setI
nt32(byteOffset, value, false, ec); } |
| 67 void setInt32(unsigned byteOffset, int32_t value, bool littleEndian, Excepti
onState&); | 65 void setInt32(unsigned byteOffset, int32_t value, bool littleEndian, Excepti
onState&); |
| 68 void setUint32(unsigned byteOffset, uint32_t value, ExceptionState& ec) { se
tUint32(byteOffset, value, false, ec); } | 66 void setUint32(unsigned byteOffset, uint32_t value, ExceptionState& ec) { se
tUint32(byteOffset, value, false, ec); } |
| 69 void setUint32(unsigned byteOffset, uint32_t value, bool littleEndian, Excep
tionState&); | 67 void setUint32(unsigned byteOffset, uint32_t value, bool littleEndian, Excep
tionState&); |
| 70 void setFloat32(unsigned byteOffset, float value, ExceptionState& ec) { setF
loat32(byteOffset, value, false, ec); } | 68 void setFloat32(unsigned byteOffset, float value, ExceptionState& ec) { setF
loat32(byteOffset, value, false, ec); } |
| 71 void setFloat32(unsigned byteOffset, float value, bool littleEndian, Excepti
onState&); | 69 void setFloat32(unsigned byteOffset, float value, bool littleEndian, Excepti
onState&); |
| 72 void setFloat64(unsigned byteOffset, double value, ExceptionState& ec) { set
Float64(byteOffset, value, false, ec); } | 70 void setFloat64(unsigned byteOffset, double value, ExceptionState& ec) { set
Float64(byteOffset, value, false, ec); } |
| 73 void setFloat64(unsigned byteOffset, double value, bool littleEndian, Except
ionState&); | 71 void setFloat64(unsigned byteOffset, double value, bool littleEndian, Except
ionState&); |
| 74 | 72 |
| 75 virtual ViewType type() const override | |
| 76 { | |
| 77 return TypeDataView; | |
| 78 } | |
| 79 | |
| 80 virtual v8::Handle<v8::Object> wrap(v8::Handle<v8::Object> creationContext,
v8::Isolate*) override; | |
| 81 | |
| 82 protected: | 73 protected: |
| 83 virtual void neuter() override; | 74 virtual void neuter() override; |
| 84 | 75 |
| 85 private: | 76 private: |
| 86 DataView(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned byteLength); | 77 DataView(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned byteLength); |
| 87 | 78 |
| 88 template<typename T> | 79 template<typename T> |
| 89 inline bool beyondRange(unsigned byteOffset) const { return byteOffset >= m_
byteLength || byteOffset + sizeof(T) > m_byteLength; } | 80 bool beyondRange(unsigned byteOffset) const { return byteOffset >= m_byteLen
gth || byteOffset + sizeof(T) > m_byteLength; } |
| 90 | 81 |
| 91 template<typename T> | 82 template<typename T> |
| 92 T getData(unsigned byteOffset, bool littleEndian, ExceptionState&) const; | 83 T getData(unsigned byteOffset, bool littleEndian, ExceptionState&) const; |
| 93 | 84 |
| 94 template<typename T> | 85 template<typename T> |
| 95 void setData(unsigned byteOffset, T value, bool littleEndian, ExceptionState
&); | 86 void setData(unsigned byteOffset, T value, bool littleEndian, ExceptionState
&); |
| 96 | 87 |
| 97 unsigned m_byteLength; | 88 unsigned m_byteLength; |
| 98 }; | 89 }; |
| 99 | 90 |
| 100 } // namespace blink | 91 } // namespace blink |
| 101 | 92 |
| 102 #endif // DataView_h | 93 #endif // DataView_h |
| OLD | NEW |