2014-12-10 08:58:04 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
(function(global, utils) {
|
2015-04-21 09:42:16 +00:00
|
|
|
|
2014-12-10 08:58:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-04-21 09:42:16 +00:00
|
|
|
%CheckIsBootstrapping();
|
|
|
|
|
|
|
|
var GlobalArray = global.Array;
|
2014-12-10 08:58:04 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Proposed for ES7
|
|
|
|
// https://github.com/tc39/Array.prototype.includes
|
|
|
|
// 6e3b78c927aeda20b9d40e81303f9d44596cd904
|
|
|
|
function ArrayIncludes(searchElement, fromIndex) {
|
2015-05-07 08:39:53 +00:00
|
|
|
var array = $toObject(this);
|
|
|
|
var len = $toLength(array.length);
|
2014-12-10 08:58:04 +00:00
|
|
|
|
|
|
|
if (len === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-07 08:39:53 +00:00
|
|
|
var n = $toInteger(fromIndex);
|
2014-12-10 08:58:04 +00:00
|
|
|
|
|
|
|
var k;
|
|
|
|
if (n >= 0) {
|
|
|
|
k = n;
|
|
|
|
} else {
|
|
|
|
k = len + n;
|
|
|
|
if (k < 0) {
|
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (k < len) {
|
|
|
|
var elementK = array[k];
|
2015-05-07 08:39:53 +00:00
|
|
|
if ($sameValueZero(searchElement, elementK)) {
|
2014-12-10 08:58:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2015-04-21 09:42:16 +00:00
|
|
|
%FunctionSetLength(ArrayIncludes, 1);
|
2014-12-10 08:58:04 +00:00
|
|
|
|
2015-04-21 09:42:16 +00:00
|
|
|
// Set up the non-enumerable functions on the Array prototype object.
|
2015-05-26 07:24:13 +00:00
|
|
|
utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
|
2015-04-21 09:42:16 +00:00
|
|
|
"includes", ArrayIncludes
|
|
|
|
]);
|
2014-12-10 08:58:04 +00:00
|
|
|
|
2015-05-11 08:14:54 +00:00
|
|
|
})
|