| Index: src/harmony-array-includes.js
|
| diff --git a/src/harmony-array-includes.js b/src/harmony-array-includes.js
|
| index 8710d9a300d13386cbc140dfcfeab0c569bdefa6..124edf62ecd405d9796043e486f0892710c521f6 100644
|
| --- a/src/harmony-array-includes.js
|
| +++ b/src/harmony-array-includes.js
|
| @@ -14,12 +14,9 @@ var GlobalArray = global.Array;
|
|
|
| // Proposed for ES7
|
| // https://github.com/tc39/Array.prototype.includes
|
| -// 6e3b78c927aeda20b9d40e81303f9d44596cd904
|
| -function ArrayIncludes(searchElement, fromIndex) {
|
| - var array = TO_OBJECT(this);
|
| - var len = $toLength(array.length);
|
| -
|
| - if (len === 0) {
|
| +// 46c7532ec8499dea3e51aeb940d09e07547ed3f5
|
| +function InnerArrayIncludes(searchElement, fromIndex, array, length) {
|
| + if (length === 0) {
|
| return false;
|
| }
|
|
|
| @@ -29,13 +26,13 @@ function ArrayIncludes(searchElement, fromIndex) {
|
| if (n >= 0) {
|
| k = n;
|
| } else {
|
| - k = len + n;
|
| + k = length + n;
|
| if (k < 0) {
|
| k = 0;
|
| }
|
| }
|
|
|
| - while (k < len) {
|
| + while (k < length) {
|
| var elementK = array[k];
|
| if ($sameValueZero(searchElement, elementK)) {
|
| return true;
|
| @@ -47,13 +44,65 @@ function ArrayIncludes(searchElement, fromIndex) {
|
| return false;
|
| }
|
|
|
| +
|
| +function ArrayIncludes(searchElement, fromIndex) {
|
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.includes");
|
| +
|
| + var array = TO_OBJECT(this);
|
| + var length = $toLength(array.length);
|
| +
|
| + return InnerArrayIncludes(searchElement, fromIndex, array, length);
|
| +}
|
| +
|
| +
|
| +function TypedArrayIncludes(searchElement, fromIndex) {
|
| + if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
|
| +
|
| + var length = %_TypedArrayGetLength(this);
|
| +
|
| + return InnerArrayIncludes(searchElement, fromIndex, this, length);
|
| +}
|
| +
|
| // -------------------------------------------------------------------
|
|
|
| %FunctionSetLength(ArrayIncludes, 1);
|
| +%FunctionSetLength(TypedArrayIncludes, 1);
|
|
|
| -// Set up the non-enumerable functions on the Array prototype object.
|
| +// Set up the non-enumerable function on the Array prototype object.
|
| utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
|
| "includes", ArrayIncludes
|
| ]);
|
|
|
| +// Set up the non-enumerable function on the typed array prototypes.
|
| +// This duplicates some of the machinery in harmony-typedarray.js in order to
|
| +// keep includes behind the separate --harmony-array-includes flag.
|
| +// TODO(littledan): Fix the TypedArray proto chain (bug v8:4085).
|
| +
|
| +macro TYPED_ARRAYS(FUNCTION)
|
| +// arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
|
| +FUNCTION(Uint8Array)
|
| +FUNCTION(Int8Array)
|
| +FUNCTION(Uint16Array)
|
| +FUNCTION(Int16Array)
|
| +FUNCTION(Uint32Array)
|
| +FUNCTION(Int32Array)
|
| +FUNCTION(Float32Array)
|
| +FUNCTION(Float64Array)
|
| +FUNCTION(Uint8ClampedArray)
|
| +endmacro
|
| +
|
| +macro DECLARE_GLOBALS(NAME)
|
| +var GlobalNAME = global.NAME;
|
| +endmacro
|
| +
|
| +macro EXTEND_TYPED_ARRAY(NAME)
|
| +// Set up non-enumerable functions on the prototype object.
|
| +utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
|
| + "includes", TypedArrayIncludes
|
| +]);
|
| +endmacro
|
| +
|
| +TYPED_ARRAYS(DECLARE_GLOBALS)
|
| +TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
|
| +
|
| })
|
|
|