OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 |
11 var GlobalArray = global.Array; | 11 var GlobalArray = global.Array; |
| 12 var SameValueZero; |
| 13 |
| 14 utils.Import(function(from) { |
| 15 SameValueZero = from.SameValueZero; |
| 16 }); |
12 | 17 |
13 // ------------------------------------------------------------------- | 18 // ------------------------------------------------------------------- |
14 | 19 |
15 // Proposed for ES7 | 20 // Proposed for ES7 |
16 // https://github.com/tc39/Array.prototype.includes | 21 // https://github.com/tc39/Array.prototype.includes |
17 // 46c7532ec8499dea3e51aeb940d09e07547ed3f5 | 22 // 46c7532ec8499dea3e51aeb940d09e07547ed3f5 |
18 function InnerArrayIncludes(searchElement, fromIndex, array, length) { | 23 function InnerArrayIncludes(searchElement, fromIndex, array, length) { |
19 if (length === 0) { | 24 if (length === 0) { |
20 return false; | 25 return false; |
21 } | 26 } |
22 | 27 |
23 var n = TO_INTEGER(fromIndex); | 28 var n = TO_INTEGER(fromIndex); |
24 | 29 |
25 var k; | 30 var k; |
26 if (n >= 0) { | 31 if (n >= 0) { |
27 k = n; | 32 k = n; |
28 } else { | 33 } else { |
29 k = length + n; | 34 k = length + n; |
30 if (k < 0) { | 35 if (k < 0) { |
31 k = 0; | 36 k = 0; |
32 } | 37 } |
33 } | 38 } |
34 | 39 |
35 while (k < length) { | 40 while (k < length) { |
36 var elementK = array[k]; | 41 var elementK = array[k]; |
37 if ($sameValueZero(searchElement, elementK)) { | 42 if (SameValueZero(searchElement, elementK)) { |
38 return true; | 43 return true; |
39 } | 44 } |
40 | 45 |
41 ++k; | 46 ++k; |
42 } | 47 } |
43 | 48 |
44 return false; | 49 return false; |
45 } | 50 } |
46 | 51 |
47 | 52 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Set up non-enumerable functions on the prototype object. | 104 // Set up non-enumerable functions on the prototype object. |
100 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 105 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
101 "includes", TypedArrayIncludes | 106 "includes", TypedArrayIncludes |
102 ]); | 107 ]); |
103 endmacro | 108 endmacro |
104 | 109 |
105 TYPED_ARRAYS(DECLARE_GLOBALS) | 110 TYPED_ARRAYS(DECLARE_GLOBALS) |
106 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 111 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
107 | 112 |
108 }) | 113 }) |
OLD | NEW |