| 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 | 12 |
| 13 // ------------------------------------------------------------------- | 13 // ------------------------------------------------------------------- |
| 14 | 14 |
| 15 // Proposed for ES7 | 15 // Proposed for ES7 |
| 16 // https://github.com/tc39/Array.prototype.includes | 16 // https://github.com/tc39/Array.prototype.includes |
| 17 // 46c7532ec8499dea3e51aeb940d09e07547ed3f5 | 17 // 46c7532ec8499dea3e51aeb940d09e07547ed3f5 |
| 18 function InnerArrayIncludes(searchElement, fromIndex, array, length) { | 18 function InnerArrayIncludes(searchElement, fromIndex, array, length) { |
| 19 if (length === 0) { | 19 if (length === 0) { |
| 20 return false; | 20 return false; |
| 21 } | 21 } |
| 22 | 22 |
| 23 var n = $toInteger(fromIndex); | 23 var n = TO_INTEGER(fromIndex); |
| 24 | 24 |
| 25 var k; | 25 var k; |
| 26 if (n >= 0) { | 26 if (n >= 0) { |
| 27 k = n; | 27 k = n; |
| 28 } else { | 28 } else { |
| 29 k = length + n; | 29 k = length + n; |
| 30 if (k < 0) { | 30 if (k < 0) { |
| 31 k = 0; | 31 k = 0; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 while (k < length) { | 35 while (k < length) { |
| 36 var elementK = array[k]; | 36 var elementK = array[k]; |
| 37 if ($sameValueZero(searchElement, elementK)) { | 37 if ($sameValueZero(searchElement, elementK)) { |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 ++k; | 41 ++k; |
| 42 } | 42 } |
| 43 | 43 |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 function ArrayIncludes(searchElement, fromIndex) { | 48 function ArrayIncludes(searchElement, fromIndex) { |
| 49 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.includes"); | 49 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.includes"); |
| 50 | 50 |
| 51 var array = TO_OBJECT(this); | 51 var array = TO_OBJECT(this); |
| 52 var length = $toLength(array.length); | 52 var length = TO_LENGTH(array.length); |
| 53 | 53 |
| 54 return InnerArrayIncludes(searchElement, fromIndex, array, length); | 54 return InnerArrayIncludes(searchElement, fromIndex, array, length); |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 function TypedArrayIncludes(searchElement, fromIndex) { | 58 function TypedArrayIncludes(searchElement, fromIndex) { |
| 59 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 59 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 60 | 60 |
| 61 var length = %_TypedArrayGetLength(this); | 61 var length = %_TypedArrayGetLength(this); |
| 62 | 62 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Set up non-enumerable functions on the prototype object. | 99 // Set up non-enumerable functions on the prototype object. |
| 100 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 100 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
| 101 "includes", TypedArrayIncludes | 101 "includes", TypedArrayIncludes |
| 102 ]); | 102 ]); |
| 103 endmacro | 103 endmacro |
| 104 | 104 |
| 105 TYPED_ARRAYS(DECLARE_GLOBALS) | 105 TYPED_ARRAYS(DECLARE_GLOBALS) |
| 106 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 106 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
| 107 | 107 |
| 108 }) | 108 }) |
| OLD | NEW |