4161b54d58
Requires adding a SameValueZero implementation. LOG=Y BUG=v8:3575 R=dslomov@chromium.org, arv@chromium.org TEST=added to test262 Review URL: https://codereview.chromium.org/771863002 Cr-Commit-Position: refs/heads/master@{#25735}
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
// 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.
|
|
|
|
'use strict';
|
|
|
|
// This file relies on the fact that the following declaration has been made
|
|
// in runtime.js:
|
|
// var $Array = global.Array;
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Proposed for ES7
|
|
// https://github.com/tc39/Array.prototype.includes
|
|
// 6e3b78c927aeda20b9d40e81303f9d44596cd904
|
|
function ArrayIncludes(searchElement, fromIndex) {
|
|
var array = ToObject(this);
|
|
var len = ToLength(array.length);
|
|
|
|
if (len === 0) {
|
|
return false;
|
|
}
|
|
|
|
var n = ToInteger(fromIndex);
|
|
|
|
var k;
|
|
if (n >= 0) {
|
|
k = n;
|
|
} else {
|
|
k = len + n;
|
|
if (k < 0) {
|
|
k = 0;
|
|
}
|
|
}
|
|
|
|
while (k < len) {
|
|
var elementK = array[k];
|
|
if (SameValueZero(searchElement, elementK)) {
|
|
return true;
|
|
}
|
|
|
|
++k;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
function HarmonyArrayIncludesExtendArrayPrototype() {
|
|
%CheckIsBootstrapping();
|
|
|
|
%FunctionSetLength(ArrayIncludes, 1);
|
|
|
|
// Set up the non-enumerable functions on the Array prototype object.
|
|
InstallFunctions($Array.prototype, DONT_ENUM, $Array(
|
|
"includes", ArrayIncludes
|
|
));
|
|
}
|
|
|
|
HarmonyArrayIncludesExtendArrayPrototype();
|