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 var $innerArrayCopyWithin; | 5 var $innerArrayCopyWithin; |
6 var $innerArrayFill; | 6 var $innerArrayFill; |
7 var $innerArrayFind; | 7 var $innerArrayFind; |
8 var $innerArrayFindIndex; | 8 var $innerArrayFindIndex; |
9 var $arrayFrom; | 9 var $arrayFrom; |
10 | 10 |
11 (function(global, exports) { | 11 (function(global, utils) { |
12 | 12 |
13 'use strict'; | 13 'use strict'; |
14 | 14 |
15 %CheckIsBootstrapping(); | 15 %CheckIsBootstrapping(); |
16 | 16 |
| 17 // ------------------------------------------------------------------- |
| 18 // Imports |
| 19 |
17 var GlobalArray = global.Array; | 20 var GlobalArray = global.Array; |
18 var GlobalSymbol = global.Symbol; | 21 var GlobalSymbol = global.Symbol; |
19 | 22 |
| 23 var MathMax; |
| 24 var MathMin; |
| 25 |
| 26 utils.Import(function(from) { |
| 27 MathMax = from.MathMax; |
| 28 MathMin = from.MathMin; |
| 29 }); |
| 30 |
20 // ------------------------------------------------------------------- | 31 // ------------------------------------------------------------------- |
21 | 32 |
22 function InnerArrayCopyWithin(target, start, end, array, length) { | 33 function InnerArrayCopyWithin(target, start, end, array, length) { |
23 target = TO_INTEGER(target); | 34 target = TO_INTEGER(target); |
24 var to; | 35 var to; |
25 if (target < 0) { | 36 if (target < 0) { |
26 to = $max(length + target, 0); | 37 to = MathMax(length + target, 0); |
27 } else { | 38 } else { |
28 to = $min(target, length); | 39 to = MathMin(target, length); |
29 } | 40 } |
30 | 41 |
31 start = TO_INTEGER(start); | 42 start = TO_INTEGER(start); |
32 var from; | 43 var from; |
33 if (start < 0) { | 44 if (start < 0) { |
34 from = $max(length + start, 0); | 45 from = MathMax(length + start, 0); |
35 } else { | 46 } else { |
36 from = $min(start, length); | 47 from = MathMin(start, length); |
37 } | 48 } |
38 | 49 |
39 end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); | 50 end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); |
40 var final; | 51 var final; |
41 if (end < 0) { | 52 if (end < 0) { |
42 final = $max(length + end, 0); | 53 final = MathMax(length + end, 0); |
43 } else { | 54 } else { |
44 final = $min(end, length); | 55 final = MathMin(end, length); |
45 } | 56 } |
46 | 57 |
47 var count = $min(final - from, length - to); | 58 var count = MathMin(final - from, length - to); |
48 var direction = 1; | 59 var direction = 1; |
49 if (from < to && to < (from + count)) { | 60 if (from < to && to < (from + count)) { |
50 direction = -1; | 61 direction = -1; |
51 from = from + count - 1; | 62 from = from + count - 1; |
52 to = to + count - 1; | 63 to = to + count - 1; |
53 } | 64 } |
54 | 65 |
55 while (count > 0) { | 66 while (count > 0) { |
56 if (from in array) { | 67 if (from in array) { |
57 array[to] = array[from]; | 68 array[to] = array[from]; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 302 |
292 // Set up the non-enumerable functions on the Array prototype object. | 303 // Set up the non-enumerable functions on the Array prototype object. |
293 $installFunctions(GlobalArray.prototype, DONT_ENUM, [ | 304 $installFunctions(GlobalArray.prototype, DONT_ENUM, [ |
294 "copyWithin", ArrayCopyWithin, | 305 "copyWithin", ArrayCopyWithin, |
295 "find", ArrayFind, | 306 "find", ArrayFind, |
296 "findIndex", ArrayFindIndex, | 307 "findIndex", ArrayFindIndex, |
297 "fill", ArrayFill | 308 "fill", ArrayFill |
298 ]); | 309 ]); |
299 | 310 |
300 }) | 311 }) |
OLD | NEW |