[backend] fix: 修复异常处理和类型转换问题

This commit is contained in:
xsl
2026-01-26 11:53:40 +08:00
parent 7ccc2a6ac6
commit 83e05bf85f
28639 changed files with 2506458 additions and 93 deletions
+12
View File
@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/array-includes
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+187
View File
@@ -0,0 +1,187 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v3.1.9](https://github.com/es-shims/array-includes/compare/v3.1.8...v3.1.9) - 2025-06-01
### Commits
- [Deps] update `call-bind`, `es-abstract`, `es-object-atoms`, `get-intrinsic`, `is-string` [`3b934ae`](https://github.com/es-shims/array-includes/commit/3b934ae87a602798775c04dbeb4cb9e9f1805610)
- [Refactor] use `call-bound` and `math-intrinsics` directly [`160ea60`](https://github.com/es-shims/array-includes/commit/160ea60f7d9b205e516915558b503d078945dea3)
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `auto-changelog`, `hastrict-mode`, `tape` [`4e4c67d`](https://github.com/es-shims/array-includes/commit/4e4c67dd976b7ee56e12b7eabb3ad4ab4881f4e5)
- [Tests] replace `aud` with `npm audit` [`9c5ec1c`](https://github.com/es-shims/array-includes/commit/9c5ec1c160e0f7adeebb78350675465003b2d888)
- [Dev Deps] add missing peer dep [`863d207`](https://github.com/es-shims/array-includes/commit/863d207753789757edded151ab3d62ae5033c021)
## [v3.1.8](https://github.com/es-shims/array-includes/compare/v3.1.7...v3.1.8) - 2024-03-20
### Commits
- [Deps] update `call-bind`, `define-properties`, `es-abstract`, `get-intrinsic` [`b105f3a`](https://github.com/es-shims/array-includes/commit/b105f3a0ad1801aabf47bafd788482d8866ef0c9)
- [actions] remove redundant finisher [`fa1111d`](https://github.com/es-shims/array-includes/commit/fa1111d6d41381e4bd484e8f6d5896172874d6e7)
- [Dev Deps] update `aud`, `npmignore`, `tape` [`499e7e9`](https://github.com/es-shims/array-includes/commit/499e7e9e952faab35740dfbe0b355183100e40b7)
- [Refactor] use `es-object-atoms` where possible [`e4bd17f`](https://github.com/es-shims/array-includes/commit/e4bd17f980b557fdf2b39eb552bafedd8a8f6bfb)
- [Tests] use `call-bind` instead of `function-bind` [`3dbe456`](https://github.com/es-shims/array-includes/commit/3dbe456f14c94a5d119b35ac41712c7faea93afd)
## [v3.1.7](https://github.com/es-shims/array-includes/compare/v3.1.6...v3.1.7) - 2023-09-03
### Commits
- [Deps] update `define-properties`, `es-abstract`, `get-intrinsic` [`e217b1e`](https://github.com/es-shims/array-includes/commit/e217b1ebfe90a7425654f0fa72c59f59930d4dd8)
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `tape` [`93465c3`](https://github.com/es-shims/array-includes/commit/93465c3da3bd6ea0670a0bd12dc9adc9085e8130)
## [v3.1.6](https://github.com/es-shims/array-includes/compare/v3.1.5...v3.1.6) - 2022-11-07
### Commits
- [meta] add `auto-changelog` [`c5fbe72`](https://github.com/es-shims/array-includes/commit/c5fbe728395deff641d756cc9d398a949076c180)
- [meta] use `npmignore` to autogenerate an npmignore file [`dbd6dc8`](https://github.com/es-shims/array-includes/commit/dbd6dc8f8906cca6b0b493e308686c4fd05bea15)
- [Deps] update `es-abstract`, `get-intrinsic` [`b819e3b`](https://github.com/es-shims/array-includes/commit/b819e3b3dd1adce0b3359529b0276a416efce351)
- [actions] update rebase action to use reusable workflow [`6e241d5`](https://github.com/es-shims/array-includes/commit/6e241d5177513cfb0261d0fbe0c8c98daf5c5eab)
- [Dev Deps] update `aud`, `tape` [`9b2a931`](https://github.com/es-shims/array-includes/commit/9b2a931aee6fc8195a349c6fe7894445a911223f)
- [readme] note that FF 102+ no longer needs this package [`0a0c758`](https://github.com/es-shims/array-includes/commit/0a0c758ed52808428314ffe53ea8278297170c84)
<!-- auto-changelog-above -->
3.1.5 / 2022-05-03
=================
* [Fix] install polyfill on FF 99+
* [Deps] update `define-properties`, `es-abstract`
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `functions-have-names`, `safe-publish-latest`, `tape`
* [actions] reuse common workflows
* [actions] update codecov uploader
3.1.4 / 2021-10-04
=================
* [Robustness] avoid a runtime `Math.max` call
* [readme] add github actions/codecov badges
* [readme] fix repo URLs; remove travis badge
* [Deps] update `es-abstract`, `is-string`
* [meta] use `prepublishOnly` script for npm 7+
* [actions] update workflows
* [actions] use `node/install` instead of `node/run`; use `codecov` action
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `tape`
3.1.3 / 2021-02-20
=================
* [Deps] update `call-bind`, `es-abstract`, `get-intrinsic`
* [meta] do not publish github action workflow files
* [meta] gitignore coverage output
* [actions] update workflows
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `functions-have-names`, `has-strict-mode`, `tape`
* [Tests] increase coverage
3.1.2 / 2020-11-24
=================
* [Robustness] remove dependency on `.apply`
* [Deps] update `es-abstract`; use `call-bind` and `get-intrinsic` where applicable
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `functions-have-names`, `tape`; add `aud`, `safe-publish-latest`
* [actions] add "Allow Edits" workflow
* [actions] switch Automatic Rebase workflow to `pull_request_target` event
* [Tests] migrate tests to Github Actions
* [Tests] run `nyc` on all tests
* [Tests] add `implementation` test; run `es-shim-api` in postlint; use `tape` runner
3.1.1 / 2019-12-21
=================
* [Fix] IE < 9 does not have index access on strings
* [Deps] update `es-abstract`
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`
* [meta] remove unused Makefile and associated utilities
* [Tests] add string tests
3.1.0 / 2019-12-11
=================
* [New] add `auto` entry point
* [Refactor] use split-up `es-abstract` (68% bundle size decrease)
* [readme] fix repo URLs, remove testling, fix readme parsing
* [Deps] update `es-abstract`, `define-properties`
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `evalmd`, `covert`, `functions-have-names`, `replace`, `semver`, `tape`, `@es-shims/api`, `function-bind`
* [meta] add `funding` field, FUNDING.yml
* [meta] Only apps should have lockfiles
* [Tests] add more `fromIndex` tests
* [Tests] use shared travis-ci configs
* [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops
* [Tests] remove `jscs`
* [Tests] use `functions-have-names`
* [Tests] use `npm audit` instead of `nsp`
* [Tests] remove `jscs`
* [actions] add automatic rebasing / merge commit blocking
3.0.3 / 2017-04-18
=================
* [Fix] ensure that `shim.js` actually shims when the polyfill differs from native
* [Tests] up to `node` `v7.9`, `v6.10`, `v4.8`; comment out OS X builds; improve test matrix
* [Dev Deps] update `nsp`, `eslint`, `@ljharb/eslint-config`, `tape`, `jscs`, `semver`, `function-bind`, `@es-shims/api`
* [Deps] update `es-abstract`
* [Docs] update readme: add “getting started” and “usage” (#19)
3.0.2 / 2015-06-06
=================
* Use the polyfill, not the implementation, as the default export
* [Deps] update `es-abstract`
* [Dev Deps] update `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config`, `semver`
* [Tests] up to `node` `v5.5`
* [Tests] keep tests passing in `node` `v0.8`
* [Tests] Only run `evalmd` as part of the full test suite, since it's more like a linter
* [Tests] fix npm upgrades for older nodes
3.0.1 / 2015-05-23
=================
* [Fix] in "shim", assign the polyfill, not the implementation
3.0.0 / 2015-05-23
=================
* [Breaking] Implement the [es-shim API](es-shims/api)
* [Deps] update `define-properties`, `es-abstract`
* [Dev Deps] update `eslint`, `semver`, `nsp`, `semver`, `jscs`
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
* [Tests] use my personal shared `eslint` config
* [Tests] up to `io.js` `v3.0`
2.0.0 / 2015-05-23
=================
* Fix to not skip holes, per https://github.com/tc39/Array.prototype.includes/issues/15
1.1.1 / 2015-05-23
=================
* Test up to `io.js` `v2.0`
* Update `es-abstract`, `tape`, `eslint`, `semver`, `jscs`, `semver`
1.1.0 / 2015-03-19
=================
* Update `es-abstract`, `editorconfig-tools`, `nsp`, `eslint`, `semver`
1.0.6 / 2015-02-17
=================
* All grade A-supported `node`/`iojs` versions now ship with an `npm` that understands `^`.
* Run `travis-ci` tests on `iojs` and `node` v0.12; allow 0.8 failures.
* Update `tape`, `jscs`, `es-abstract`, remove `is`.
1.0.5 / 2015-01-30
=================
* Update `tape`, `jscs`, `nsp`, `eslint`, `es-abstract`
1.0.4 / 2015-01-10
=================
* Use `es-abstract` for ECMAScript spec internal abstract operations
1.0.3 / 2015-01-06
=================
* Speed optimization: use Array#indexOf when available
* Fix ES3, IE 6-8, Opera 10.6, Opera 11.1 support
* Run testling on both sets of tests
1.0.2 / 2015-01-05
=================
* Ensure tests are includes in the module on `npm`
1.0.1 / 2015-01-04
=================
* Remove mistaken auto-shim.
1.0.0 / 2015-01-04
=================
* v1.0.0
+105
View File
@@ -0,0 +1,105 @@
# array-includes <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
An ES7/ES2016 spec-compliant `Array.prototype.includes` shim/polyfill/replacement that works as far down as ES3.
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the proposed [spec](https://262.ecma-international.org/6.0/).
Because `Array.prototype.includes` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument.
Engines that need this package include:
- IE (all versions)
- Safari < 9
- Firefox < 43, and 99-101
- Chrome < 47
- Edge < 14
- node < 6
## Getting started
```sh
npm install --save array-includes
```
## Usage
Basic usage: **includes(array, value[, fromIndex=0])**
```js
var includes = require('array-includes');
var assert = require('assert');
var arr = [ 'one', 'two' ];
includes(arr, 'one'); // true
includes(arr, 'three'); // false
includes(arr, 'one', 1); // false
```
## Example
```js
var arr = [
1,
'foo',
NaN,
-0
];
assert.equal(arr.indexOf(0) > -1, true);
assert.equal(arr.indexOf(-0) > -1, true);
assert.equal(includes(arr, 0), true);
assert.equal(includes(arr, -0), true);
assert.equal(arr.indexOf(NaN) > -1, false);
assert.equal(includes(arr, NaN), true);
assert.equal(includes(arr, 'foo', 0), true);
assert.equal(includes(arr, 'foo', 1), true);
assert.equal(includes(arr, 'foo', 2), false);
```
```js
/* when Array#includes is not present */
delete Array.prototype.includes;
var shimmedIncludes = includes.shim();
assert.equal(shimmedIncludes, includes.getPolyfill());
assert.equal(arr.includes('foo', 1), includes(arr, 'foo', 1));
```
```js
/* when Array#includes is present */
var shimmedIncludes = includes.shim();
assert.equal(shimmedIncludes, Array.prototype.includes);
assert.equal(arr.includes(1, 'foo'), includes(arr, 1, 'foo'));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/array-includes
[npm-version-svg]: https://versionbadg.es/es-shims/array-includes.svg
[deps-svg]: https://david-dm.org/es-shims/array-includes.svg
[deps-url]: https://david-dm.org/es-shims/array-includes
[dev-deps-svg]: https://david-dm.org/es-shims/array-includes/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/array-includes#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/array-includes.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/array-includes.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/array-includes.svg
[downloads-url]: https://npm-stat.com/charts.html?package=array-includes
[codecov-image]: https://codecov.io/gh/es-shims/array-includes/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/array-includes/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/array-includes
[actions-url]: https://github.com/es-shims/array-includes/actions
+36
View File
@@ -0,0 +1,36 @@
'use strict';
var ToIntegerOrInfinity = require('es-abstract/2025/ToIntegerOrInfinity');
var ToLength = require('es-abstract/2025/ToLength');
var ToObject = require('es-object-atoms/ToObject');
var SameValueZero = require('es-abstract/2025/SameValueZero');
var $isNaN = require('math-intrinsics/isNaN');
var $isFinite = require('math-intrinsics/isFinite');
var GetIntrinsic = require('get-intrinsic');
var callBound = require('call-bound');
var isString = require('is-string');
var $charAt = callBound('String.prototype.charAt');
var $indexOf = GetIntrinsic('%Array.prototype.indexOf%'); // TODO: use callBind.apply without breaking IE 8
var $max = GetIntrinsic('%Math.max%');
module.exports = function includes(searchElement) {
var fromIndex = arguments.length > 1 ? ToIntegerOrInfinity(arguments[1]) : 0;
if ($indexOf && !$isNaN(searchElement) && $isFinite(fromIndex) && typeof searchElement !== 'undefined') {
return $indexOf.apply(this, arguments) > -1;
}
var O = ToObject(this);
var length = ToLength(O.length);
if (length === 0) {
return false;
}
var k = fromIndex >= 0 ? fromIndex : $max(0, length + fromIndex);
while (k < length) {
if (SameValueZero(searchElement, isString(O) ? $charAt(O, k) : O[k])) {
return true;
}
k += 1;
}
return false;
};
+27
View File
@@ -0,0 +1,27 @@
'use strict';
var define = require('define-properties');
var RequireObjectCoercible = require('es-object-atoms/RequireObjectCoercible');
var callBind = require('call-bind');
var callBound = require('call-bound');
var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var polyfill = callBind.apply(getPolyfill());
var shim = require('./shim');
var $slice = callBound('Array.prototype.slice');
/* eslint-disable no-unused-vars */
var boundShim = function includes(array, searchElement) {
/* eslint-enable no-unused-vars */
RequireObjectCoercible(array);
return polyfill(array, $slice(arguments, 1));
};
define(boundShim, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});
module.exports = boundShim;
+115
View File
@@ -0,0 +1,115 @@
{
"name": "array-includes",
"version": "3.1.9",
"author": {
"name": "Jordan Harband",
"email": "ljharb@gmail.com",
"url": "http://ljharb.codes"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"contributors": [
{
"name": "Jordan Harband",
"email": "ljharb@gmail.com",
"url": "http://ljharb.codes"
}
],
"description": "An ES7/ES2016 spec-compliant `Array.prototype.includes` shim/polyfill/replacement that works as far down as ES3.",
"license": "MIT",
"main": "index.js",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"pretest": "npm run --silent lint",
"test": "npm run --silent tests-only",
"posttest": "npx npm@\">= 10.2\" audit --production",
"tests-only": "nyc tape 'test/**/*.js'",
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "es-shim-api --bound",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git://github.com/es-shims/array-includes.git"
},
"keywords": [
"Array.prototype.includes",
"includes",
"array",
"ES7",
"shim",
"polyfill",
"contains",
"Array.prototype.contains",
"es-shim API"
],
"dependencies": {
"call-bind": "^1.0.8",
"call-bound": "^1.0.4",
"define-properties": "^1.2.1",
"es-abstract": "^1.24.0",
"es-object-atoms": "^1.1.1",
"get-intrinsic": "^1.3.0",
"is-string": "^1.1.1",
"math-intrinsics": "^1.1.0"
},
"devDependencies": {
"@es-shims/api": "^2.5.1",
"@ljharb/eslint-config": "^21.1.1",
"auto-changelog": "^2.5.0",
"encoding": "^0.1.13",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"functions-have-names": "^1.2.3",
"has-strict-mode": "^1.1.0",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0"
},
"testling": {
"files": [
"test/index.js",
"test/implementation.js",
"test/shimmed.js"
],
"browsers": [
"iexplore/6.0..latest",
"firefox/3.0..6.0",
"firefox/15.0..latest",
"firefox/nightly",
"chrome/4.0..10.0",
"chrome/20.0..latest",
"chrome/canary",
"opera/10.0..latest",
"opera/next",
"safari/4.0..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2"
]
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true,
"startingVersion": "3.1.6"
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
+13
View File
@@ -0,0 +1,13 @@
'use strict';
var implementation = require('./implementation');
module.exports = function getPolyfill() {
if (
Array.prototype.includes
&& Array(1).includes(undefined) // https://bugzilla.mozilla.org/show_bug.cgi?id=1767541
) {
return Array.prototype.includes;
}
return implementation;
};
+14
View File
@@ -0,0 +1,14 @@
'use strict';
var define = require('define-properties');
var getPolyfill = require('./polyfill');
module.exports = function shimArrayPrototypeIncludes() {
var polyfill = getPolyfill();
define(
Array.prototype,
{ includes: polyfill },
{ includes: function () { return Array.prototype.includes !== polyfill; } }
);
return polyfill;
};
+20
View File
@@ -0,0 +1,20 @@
'use strict';
var implementation = require('../implementation');
var callBind = require('call-bind');
var test = require('tape');
var hasStrictMode = require('has-strict-mode')();
var runTests = require('./tests');
test('as a function', function (t) {
t.test('bad array/this value', { skip: !hasStrictMode }, function (st) {
/* eslint no-useless-call: 0 */
st['throws'](function () { implementation.call(undefined); }, TypeError, 'undefined is not an object');
st['throws'](function () { implementation.call(null); }, TypeError, 'null is not an object');
st.end();
});
runTests(callBind(implementation), t);
t.end();
});
+17
View File
@@ -0,0 +1,17 @@
'use strict';
var includes = require('../');
var test = require('tape');
var runTests = require('./tests');
test('as a function', function (t) {
t.test('bad array/this value', function (st) {
st['throws'](function () { includes(undefined, 'a'); }, TypeError, 'undefined is not an object');
st['throws'](function () { includes(null, 'a'); }, TypeError, 'null is not an object');
st.end();
});
runTests(includes, t);
t.end();
});
+39
View File
@@ -0,0 +1,39 @@
'use strict';
var orig = Array.prototype.includes;
require('../auto');
var test = require('tape');
var defineProperties = require('define-properties');
var callBind = require('call-bind');
var isEnumerable = Object.prototype.propertyIsEnumerable;
var functionsHaveNames = require('functions-have-names')();
var runTests = require('./tests');
test('shimmed', function (t) {
t.comment('shimmed: ' + (orig === Array.prototype.includes ? 'no' : 'yes'));
t.equal(Array.prototype.includes.length, 1, 'Array#includes has a length of 1');
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
st.equal(Array.prototype.includes.name, 'includes', 'Array#includes has name "includes"');
st.end();
});
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
et.equal(false, isEnumerable.call(Array.prototype, 'includes'), 'Array#includes is not enumerable');
et.end();
});
var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
t.test('bad array/this value', { skip: !supportsStrictMode }, function (st) {
st['throws'](function () { return Array.prototype.includes.call(undefined, 'a'); }, TypeError, 'undefined is not an object');
st['throws'](function () { return Array.prototype.includes.call(null, 'a'); }, TypeError, 'null is not an object');
st.end();
});
runTests(callBind(Array.prototype.includes), t);
t.end();
});
+94
View File
@@ -0,0 +1,94 @@
'use strict';
module.exports = function (includes, t) {
var sparseish = { length: 5, 0: 'a', 1: 'b' };
var overfullarrayish = { length: 2, 0: 'a', 1: 'b', 2: 'c' };
var thrower = { valueOf: function () { throw new RangeError('whoa'); } };
var numberish = { valueOf: function () { return 2; } };
t.test('simple examples', function (st) {
st.equal(true, includes([1, 2, 3], 1), '[1, 2, 3] includes 1');
st.equal(false, includes([1, 2, 3], 4), '[1, 2, 3] does not include 4');
st.equal(true, includes([NaN], NaN), '[NaN] includes NaN');
st.end();
});
t.test('does not skip holes', function (st) {
st.equal(true, includes(Array(1)), 'Array(1) includes undefined');
st.end();
});
t.test('exceptions', function (et) {
et.test('fromIndex conversion', function (st) {
st['throws'](function () { includes([0], 0, thrower); }, RangeError, 'fromIndex conversion throws');
st.end();
});
et.test('ToLength', function (st) {
st['throws'](function () { includes({ length: thrower, 0: true }, true); }, RangeError, 'ToLength conversion throws');
st.end();
});
et.end();
});
t.test('arraylike', function (st) {
st.equal(true, includes(sparseish, 'a'), 'sparse array-like object includes "a"');
st.equal(false, includes(sparseish, 'c'), 'sparse array-like object does not include "c"');
st.equal(true, includes(overfullarrayish, 'b'), 'sparse array-like object includes "b"');
st.equal(false, includes(overfullarrayish, 'c'), 'sparse array-like object does not include "c"');
st.end();
});
t.test('fromIndex', function (ft) {
ft.equal(true, includes([1], 1, NaN), 'NaN fromIndex -> 0 fromIndex');
ft.equal(true, includes([0, 1, 2], 1, 0), 'starting from 0 finds index 1');
ft.equal(true, includes([0, 1, 2], 1, 1), 'starting from 1 finds index 1');
ft.equal(false, includes([0, 1, 2], 1, 2), 'starting from 2 does not find index 1');
ft.test('number coercion', function (st) {
st.equal(false, includes(['a', 'b', 'c'], 'a', numberish), 'does not find "a" with object fromIndex coercing to 2');
st.equal(false, includes(['a', 'b', 'c'], 'a', '2'), 'does not find "a" with string fromIndex coercing to 2');
st.equal(true, includes(['a', 'b', 'c'], 'c', numberish), 'finds "c" with object fromIndex coercing to 2');
st.equal(true, includes(['a', 'b', 'c'], 'c', '2'), 'finds "c" with string fromIndex coercing to 2');
st.end();
});
ft.test('fromIndex greater than length', function (st) {
st.equal(false, includes([1], 1, 2), 'array of length 1 is not searched if fromIndex is > 1');
st.equal(false, includes([1], 1, 1), 'array of length 1 is not searched if fromIndex is >= 1');
st.equal(false, includes([1], 1, 1.1), 'array of length 1 is not searched if fromIndex is 1.1');
st.equal(false, includes([1], 1, Infinity), 'array of length 1 is not searched if fromIndex is Infinity');
st.end();
});
ft.test('negative fromIndex', function (st) {
st.equal(true, includes([1, 3], 1, -4), 'computed length would be negative; fromIndex is thus 0');
st.equal(true, includes([1, 3], 3, -4), 'computed length would be negative; fromIndex is thus 0');
st.equal(true, includes([1, 3], 1, -Infinity), 'computed length would be negative; fromIndex is thus 0');
st.equal(true, includes([12, 13], 13, -1), 'finds -1st item with -1 fromIndex');
st.equal(false, includes([12, 13], 12, -1), 'does not find -2nd item with -1 fromIndex');
st.equal(true, includes([12, 13], 13, -2), 'finds -2nd item with -2 fromIndex');
st.equal(true, includes(sparseish, 'b', -4), 'finds -4th item with -4 fromIndex');
st.equal(false, includes(sparseish, 'a', -4), 'does not find -5th item with -4 fromIndex');
st.equal(true, includes(sparseish, 'a', -5), 'finds -5th item with -5 fromIndex');
st.end();
});
ft.end();
});
t.test('strings', function (st) {
st.equal(true, includes('abc', 'c'), 'string includes one of its chars');
st.equal(false, includes('abc', 'd'), 'string does not include a char it should not');
st.equal(true, includes(Object('abc'), 'c'), 'boxed string includes one of its chars');
st.equal(false, includes(Object('abc'), 'd'), 'boxed string does not include a char it should not');
st.end();
});
};