| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, shared, exports) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- |
| 12 // Imports |
| 13 |
| 11 var GlobalArray = global.Array; | 14 var GlobalArray = global.Array; |
| 12 var GlobalArrayBuffer = global.ArrayBuffer; | 15 var GlobalArrayBuffer = global.ArrayBuffer; |
| 13 var GlobalDataView = global.DataView; | 16 var GlobalDataView = global.DataView; |
| 14 var GlobalObject = global.Object; | 17 var GlobalObject = global.Object; |
| 15 | 18 |
| 19 var MathMax; |
| 20 var MathMin; |
| 21 |
| 22 utils.Import(function(from) { |
| 23 MathMax = from.MathMax; |
| 24 MathMin = from.MathMin; |
| 25 }); |
| 26 |
| 27 // ------------------------------------------------------------------- |
| 28 |
| 29 |
| 16 macro TYPED_ARRAYS(FUNCTION) | 30 macro TYPED_ARRAYS(FUNCTION) |
| 17 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 31 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 18 FUNCTION(1, Uint8Array, 1) | 32 FUNCTION(1, Uint8Array, 1) |
| 19 FUNCTION(2, Int8Array, 1) | 33 FUNCTION(2, Int8Array, 1) |
| 20 FUNCTION(3, Uint16Array, 2) | 34 FUNCTION(3, Uint16Array, 2) |
| 21 FUNCTION(4, Int16Array, 2) | 35 FUNCTION(4, Int16Array, 2) |
| 22 FUNCTION(5, Uint32Array, 4) | 36 FUNCTION(5, Uint32Array, 4) |
| 23 FUNCTION(6, Int32Array, 4) | 37 FUNCTION(6, Int32Array, 4) |
| 24 FUNCTION(7, Float32Array, 4) | 38 FUNCTION(7, Float32Array, 4) |
| 25 FUNCTION(8, Float64Array, 8) | 39 FUNCTION(8, Float64Array, 8) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (!(%_ClassOf(this) === 'NAME')) { | 172 if (!(%_ClassOf(this) === 'NAME')) { |
| 159 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); | 173 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); |
| 160 } | 174 } |
| 161 var beginInt = TO_INTEGER(begin); | 175 var beginInt = TO_INTEGER(begin); |
| 162 if (!IS_UNDEFINED(end)) { | 176 if (!IS_UNDEFINED(end)) { |
| 163 end = TO_INTEGER(end); | 177 end = TO_INTEGER(end); |
| 164 } | 178 } |
| 165 | 179 |
| 166 var srcLength = %_TypedArrayGetLength(this); | 180 var srcLength = %_TypedArrayGetLength(this); |
| 167 if (beginInt < 0) { | 181 if (beginInt < 0) { |
| 168 beginInt = $max(0, srcLength + beginInt); | 182 beginInt = MathMax(0, srcLength + beginInt); |
| 169 } else { | 183 } else { |
| 170 beginInt = $min(srcLength, beginInt); | 184 beginInt = MathMin(srcLength, beginInt); |
| 171 } | 185 } |
| 172 | 186 |
| 173 var endInt = IS_UNDEFINED(end) ? srcLength : end; | 187 var endInt = IS_UNDEFINED(end) ? srcLength : end; |
| 174 if (endInt < 0) { | 188 if (endInt < 0) { |
| 175 endInt = $max(0, srcLength + endInt); | 189 endInt = MathMax(0, srcLength + endInt); |
| 176 } else { | 190 } else { |
| 177 endInt = $min(endInt, srcLength); | 191 endInt = MathMin(endInt, srcLength); |
| 178 } | 192 } |
| 179 if (endInt < beginInt) { | 193 if (endInt < beginInt) { |
| 180 endInt = beginInt; | 194 endInt = beginInt; |
| 181 } | 195 } |
| 182 var newLength = endInt - beginInt; | 196 var newLength = endInt - beginInt; |
| 183 var beginByteOffset = | 197 var beginByteOffset = |
| 184 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; | 198 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
| 185 return new GlobalNAME(%TypedArrayGetBuffer(this), | 199 return new GlobalNAME(%TypedArrayGetBuffer(this), |
| 186 beginByteOffset, newLength); | 200 beginByteOffset, newLength); |
| 187 } | 201 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 "setUint32", DataViewSetUint32JS, | 465 "setUint32", DataViewSetUint32JS, |
| 452 | 466 |
| 453 "getFloat32", DataViewGetFloat32JS, | 467 "getFloat32", DataViewGetFloat32JS, |
| 454 "setFloat32", DataViewSetFloat32JS, | 468 "setFloat32", DataViewSetFloat32JS, |
| 455 | 469 |
| 456 "getFloat64", DataViewGetFloat64JS, | 470 "getFloat64", DataViewGetFloat64JS, |
| 457 "setFloat64", DataViewSetFloat64JS | 471 "setFloat64", DataViewSetFloat64JS |
| 458 ]); | 472 ]); |
| 459 | 473 |
| 460 }) | 474 }) |
| OLD | NEW |