| 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, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 FUNCTION(8, Float64Array, 8) | 30 FUNCTION(8, Float64Array, 8) |
| 31 FUNCTION(9, Uint8ClampedArray, 1) | 31 FUNCTION(9, Uint8ClampedArray, 1) |
| 32 endmacro | 32 endmacro |
| 33 | 33 |
| 34 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) | 34 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) |
| 35 var GlobalNAME = global.NAME; | 35 var GlobalNAME = global.NAME; |
| 36 endmacro | 36 endmacro |
| 37 | 37 |
| 38 TYPED_ARRAYS(DECLARE_GLOBALS) | 38 TYPED_ARRAYS(DECLARE_GLOBALS) |
| 39 | 39 |
| 40 var MathMax; | |
| 41 var MathMin; | |
| 42 var ToNumber; | 40 var ToNumber; |
| 43 | 41 |
| 44 utils.Import(function(from) { | 42 utils.Import(function(from) { |
| 45 MathMax = from.MathMax; | |
| 46 MathMin = from.MathMin; | |
| 47 ToNumber = from.ToNumber; | 43 ToNumber = from.ToNumber; |
| 48 }); | 44 }); |
| 49 | 45 |
| 50 var InternalArray = utils.InternalArray; | 46 var InternalArray = utils.InternalArray; |
| 51 | 47 |
| 52 // --------------- Typed Arrays --------------------- | 48 // --------------- Typed Arrays --------------------- |
| 53 | 49 |
| 54 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 55 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| 56 if (!IS_UNDEFINED(byteOffset)) { | 52 if (!IS_UNDEFINED(byteOffset)) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 199 } |
| 204 return %_TypedArrayGetLength(this); | 200 return %_TypedArrayGetLength(this); |
| 205 } | 201 } |
| 206 | 202 |
| 207 function NAMESubArray(begin, end) { | 203 function NAMESubArray(begin, end) { |
| 208 if (!(%_ClassOf(this) === 'NAME')) { | 204 if (!(%_ClassOf(this) === 'NAME')) { |
| 209 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); | 205 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); |
| 210 } | 206 } |
| 211 var beginInt = TO_INTEGER(begin); | 207 var beginInt = TO_INTEGER(begin); |
| 212 if (!IS_UNDEFINED(end)) { | 208 if (!IS_UNDEFINED(end)) { |
| 213 end = TO_INTEGER(end); | 209 var endInt = TO_INTEGER(end); |
| 210 var srcLength = %_TypedArrayGetLength(this); |
| 211 } else { |
| 212 var srcLength = %_TypedArrayGetLength(this); |
| 213 var endInt = srcLength; |
| 214 } | 214 } |
| 215 | 215 |
| 216 var srcLength = %_TypedArrayGetLength(this); | |
| 217 if (beginInt < 0) { | 216 if (beginInt < 0) { |
| 218 beginInt = MathMax(0, srcLength + beginInt); | 217 beginInt = MAX_SIMPLE(0, srcLength + beginInt); |
| 219 } else { | 218 } else { |
| 220 beginInt = MathMin(srcLength, beginInt); | 219 beginInt = MIN_SIMPLE(beginInt, srcLength); |
| 221 } | 220 } |
| 222 | 221 |
| 223 var endInt = IS_UNDEFINED(end) ? srcLength : end; | |
| 224 if (endInt < 0) { | 222 if (endInt < 0) { |
| 225 endInt = MathMax(0, srcLength + endInt); | 223 endInt = MAX_SIMPLE(0, srcLength + endInt); |
| 226 } else { | 224 } else { |
| 227 endInt = MathMin(endInt, srcLength); | 225 endInt = MIN_SIMPLE(endInt, srcLength); |
| 228 } | 226 } |
| 227 |
| 229 if (endInt < beginInt) { | 228 if (endInt < beginInt) { |
| 230 endInt = beginInt; | 229 endInt = beginInt; |
| 231 } | 230 } |
| 231 |
| 232 var newLength = endInt - beginInt; | 232 var newLength = endInt - beginInt; |
| 233 var beginByteOffset = | 233 var beginByteOffset = |
| 234 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; | 234 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
| 235 return new GlobalNAME(%TypedArrayGetBuffer(this), | 235 return new GlobalNAME(%TypedArrayGetBuffer(this), |
| 236 beginByteOffset, newLength); | 236 beginByteOffset, newLength); |
| 237 } | 237 } |
| 238 endmacro | 238 endmacro |
| 239 | 239 |
| 240 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | 240 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| 241 | 241 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 "setUint32", DataViewSetUint32JS, | 505 "setUint32", DataViewSetUint32JS, |
| 506 | 506 |
| 507 "getFloat32", DataViewGetFloat32JS, | 507 "getFloat32", DataViewGetFloat32JS, |
| 508 "setFloat32", DataViewSetFloat32JS, | 508 "setFloat32", DataViewSetFloat32JS, |
| 509 | 509 |
| 510 "getFloat64", DataViewGetFloat64JS, | 510 "getFloat64", DataViewGetFloat64JS, |
| 511 "setFloat64", DataViewSetFloat64JS | 511 "setFloat64", DataViewSetFloat64JS |
| 512 ]); | 512 ]); |
| 513 | 513 |
| 514 }) | 514 }) |
| OLD | NEW |