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