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