| 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 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 case 8: | 123 case 8: |
| 124 flipBytesFor64Bits(value); | 124 flipBytesFor64Bits(value); |
| 125 break; | 125 break; |
| 126 default: | 126 default: |
| 127 ASSERT_NOT_REACHED(); | 127 ASSERT_NOT_REACHED(); |
| 128 break; | 128 break; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 template<typename T> | 132 template<typename T> |
| 133 T DataView::getData(unsigned byteOffset, bool littleEndian, ExceptionState& es)
const | 133 T DataView::getData(unsigned byteOffset, bool littleEndian, ExceptionState& exce
ptionState) const |
| 134 { | 134 { |
| 135 if (beyondRange<T>(byteOffset)) { | 135 if (beyondRange<T>(byteOffset)) { |
| 136 es.throwUninformativeAndGenericDOMException(IndexSizeError); | 136 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); |
| 137 return 0; | 137 return 0; |
| 138 } | 138 } |
| 139 | 139 |
| 140 // We do not want to load the data directly since it would cause a bus error
on architectures that don't support unaligned loads. | 140 // We do not want to load the data directly since it would cause a bus error
on architectures that don't support unaligned loads. |
| 141 Value<T> value; | 141 Value<T> value; |
| 142 memcpy(value.bytes, static_cast<const char*>(m_baseAddress) + byteOffset, si
zeof(T)); | 142 memcpy(value.bytes, static_cast<const char*>(m_baseAddress) + byteOffset, si
zeof(T)); |
| 143 flipBytesIfNeeded(value.bytes, sizeof(T), littleEndian); | 143 flipBytesIfNeeded(value.bytes, sizeof(T), littleEndian); |
| 144 return value.data; | 144 return value.data; |
| 145 } | 145 } |
| 146 | 146 |
| 147 template<typename T> | 147 template<typename T> |
| 148 void DataView::setData(unsigned byteOffset, T value, bool littleEndian, Exceptio
nState& es) | 148 void DataView::setData(unsigned byteOffset, T value, bool littleEndian, Exceptio
nState& exceptionState) |
| 149 { | 149 { |
| 150 if (beyondRange<T>(byteOffset)) { | 150 if (beyondRange<T>(byteOffset)) { |
| 151 es.throwUninformativeAndGenericDOMException(IndexSizeError); | 151 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 // We do not want to store the data directly since it would cause a bus erro
r on architectures that don't support unaligned stores. | 155 // We do not want to store the data directly since it would cause a bus erro
r on architectures that don't support unaligned stores. |
| 156 Value<T> tempValue; | 156 Value<T> tempValue; |
| 157 tempValue.data = value; | 157 tempValue.data = value; |
| 158 flipBytesIfNeeded(tempValue.bytes, sizeof(T), littleEndian); | 158 flipBytesIfNeeded(tempValue.bytes, sizeof(T), littleEndian); |
| 159 memcpy(static_cast<char*>(m_baseAddress) + byteOffset, tempValue.bytes, size
of(T)); | 159 memcpy(static_cast<char*>(m_baseAddress) + byteOffset, tempValue.bytes, size
of(T)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 int8_t DataView::getInt8(unsigned byteOffset, ExceptionState& es) | 162 int8_t DataView::getInt8(unsigned byteOffset, ExceptionState& exceptionState) |
| 163 { | 163 { |
| 164 return getData<int8_t>(byteOffset, false, es); | 164 return getData<int8_t>(byteOffset, false, exceptionState); |
| 165 } | 165 } |
| 166 | 166 |
| 167 uint8_t DataView::getUint8(unsigned byteOffset, ExceptionState& es) | 167 uint8_t DataView::getUint8(unsigned byteOffset, ExceptionState& exceptionState) |
| 168 { | 168 { |
| 169 return getData<uint8_t>(byteOffset, false, es); | 169 return getData<uint8_t>(byteOffset, false, exceptionState); |
| 170 } | 170 } |
| 171 | 171 |
| 172 int16_t DataView::getInt16(unsigned byteOffset, bool littleEndian, ExceptionStat
e& es) | 172 int16_t DataView::getInt16(unsigned byteOffset, bool littleEndian, ExceptionStat
e& exceptionState) |
| 173 { | 173 { |
| 174 return getData<int16_t>(byteOffset, littleEndian, es); | 174 return getData<int16_t>(byteOffset, littleEndian, exceptionState); |
| 175 } | 175 } |
| 176 | 176 |
| 177 uint16_t DataView::getUint16(unsigned byteOffset, bool littleEndian, ExceptionSt
ate& es) | 177 uint16_t DataView::getUint16(unsigned byteOffset, bool littleEndian, ExceptionSt
ate& exceptionState) |
| 178 { | 178 { |
| 179 return getData<uint16_t>(byteOffset, littleEndian, es); | 179 return getData<uint16_t>(byteOffset, littleEndian, exceptionState); |
| 180 } | 180 } |
| 181 | 181 |
| 182 int32_t DataView::getInt32(unsigned byteOffset, bool littleEndian, ExceptionStat
e& es) | 182 int32_t DataView::getInt32(unsigned byteOffset, bool littleEndian, ExceptionStat
e& exceptionState) |
| 183 { | 183 { |
| 184 return getData<int32_t>(byteOffset, littleEndian, es); | 184 return getData<int32_t>(byteOffset, littleEndian, exceptionState); |
| 185 } | 185 } |
| 186 | 186 |
| 187 uint32_t DataView::getUint32(unsigned byteOffset, bool littleEndian, ExceptionSt
ate& es) | 187 uint32_t DataView::getUint32(unsigned byteOffset, bool littleEndian, ExceptionSt
ate& exceptionState) |
| 188 { | 188 { |
| 189 return getData<uint32_t>(byteOffset, littleEndian, es); | 189 return getData<uint32_t>(byteOffset, littleEndian, exceptionState); |
| 190 } | 190 } |
| 191 | 191 |
| 192 float DataView::getFloat32(unsigned byteOffset, bool littleEndian, ExceptionStat
e& es) | 192 float DataView::getFloat32(unsigned byteOffset, bool littleEndian, ExceptionStat
e& exceptionState) |
| 193 { | 193 { |
| 194 return getData<float>(byteOffset, littleEndian, es); | 194 return getData<float>(byteOffset, littleEndian, exceptionState); |
| 195 } | 195 } |
| 196 | 196 |
| 197 double DataView::getFloat64(unsigned byteOffset, bool littleEndian, ExceptionSta
te& es) | 197 double DataView::getFloat64(unsigned byteOffset, bool littleEndian, ExceptionSta
te& exceptionState) |
| 198 { | 198 { |
| 199 return getData<double>(byteOffset, littleEndian, es); | 199 return getData<double>(byteOffset, littleEndian, exceptionState); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void DataView::setInt8(unsigned byteOffset, int8_t value, ExceptionState& es) | 202 void DataView::setInt8(unsigned byteOffset, int8_t value, ExceptionState& except
ionState) |
| 203 { | 203 { |
| 204 setData<int8_t>(byteOffset, value, false, es); | 204 setData<int8_t>(byteOffset, value, false, exceptionState); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void DataView::setUint8(unsigned byteOffset, uint8_t value, ExceptionState& es) | 207 void DataView::setUint8(unsigned byteOffset, uint8_t value, ExceptionState& exce
ptionState) |
| 208 { | 208 { |
| 209 setData<uint8_t>(byteOffset, value, false, es); | 209 setData<uint8_t>(byteOffset, value, false, exceptionState); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void DataView::setInt16(unsigned byteOffset, short value, bool littleEndian, Exc
eptionState& es) | 212 void DataView::setInt16(unsigned byteOffset, short value, bool littleEndian, Exc
eptionState& exceptionState) |
| 213 { | 213 { |
| 214 setData<int16_t>(byteOffset, value, littleEndian, es); | 214 setData<int16_t>(byteOffset, value, littleEndian, exceptionState); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void DataView::setUint16(unsigned byteOffset, uint16_t value, bool littleEndian,
ExceptionState& es) | 217 void DataView::setUint16(unsigned byteOffset, uint16_t value, bool littleEndian,
ExceptionState& exceptionState) |
| 218 { | 218 { |
| 219 setData<uint16_t>(byteOffset, value, littleEndian, es); | 219 setData<uint16_t>(byteOffset, value, littleEndian, exceptionState); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void DataView::setInt32(unsigned byteOffset, int32_t value, bool littleEndian, E
xceptionState& es) | 222 void DataView::setInt32(unsigned byteOffset, int32_t value, bool littleEndian, E
xceptionState& exceptionState) |
| 223 { | 223 { |
| 224 setData<int32_t>(byteOffset, value, littleEndian, es); | 224 setData<int32_t>(byteOffset, value, littleEndian, exceptionState); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void DataView::setUint32(unsigned byteOffset, uint32_t value, bool littleEndian,
ExceptionState& es) | 227 void DataView::setUint32(unsigned byteOffset, uint32_t value, bool littleEndian,
ExceptionState& exceptionState) |
| 228 { | 228 { |
| 229 setData<uint32_t>(byteOffset, value, littleEndian, es); | 229 setData<uint32_t>(byteOffset, value, littleEndian, exceptionState); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void DataView::setFloat32(unsigned byteOffset, float value, bool littleEndian, E
xceptionState& es) | 232 void DataView::setFloat32(unsigned byteOffset, float value, bool littleEndian, E
xceptionState& exceptionState) |
| 233 { | 233 { |
| 234 setData<float>(byteOffset, value, littleEndian, es); | 234 setData<float>(byteOffset, value, littleEndian, exceptionState); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void DataView::setFloat64(unsigned byteOffset, double value, bool littleEndian,
ExceptionState& es) | 237 void DataView::setFloat64(unsigned byteOffset, double value, bool littleEndian,
ExceptionState& exceptionState) |
| 238 { | 238 { |
| 239 setData<double>(byteOffset, value, littleEndian, es); | 239 setData<double>(byteOffset, value, littleEndian, exceptionState); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void DataView::neuter() | 242 void DataView::neuter() |
| 243 { | 243 { |
| 244 ArrayBufferView::neuter(); | 244 ArrayBufferView::neuter(); |
| 245 m_byteLength = 0; | 245 m_byteLength = 0; |
| 246 } | 246 } |
| 247 | 247 |
| 248 } | 248 } |
| OLD | NEW |