typedarray.prototype.slice 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = tab;
5
+ insert_final_newline = true;
6
+ quote_type = auto;
7
+ space_after_anonymous_functions = true;
8
+ space_after_control_statements = true;
9
+ spaces_around_operators = true;
10
+ trim_trailing_whitespace = true;
11
+ spaces_in_brackets = false;
12
+ end_of_line = lf;
13
+
package/.eslintrc ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "root": true,
3
+
4
+ "extends": "@ljharb",
5
+
6
+ "globals": {
7
+ "Float32Array": false,
8
+ "Float64Array": false,
9
+ "Int16Array": false,
10
+ "Int32Array": false,
11
+ "Int8Array": false,
12
+ "Uint16Array": false,
13
+ "Uint32Array": false,
14
+ "Uint8Array": false,
15
+ "Uint8ClampedArray": false,
16
+ },
17
+
18
+ "rules": {
19
+ "func-style": 0,
20
+ "id-length": 0,
21
+ "max-lines-per-function": 0,
22
+ "max-params": 0,
23
+ "max-statements": 0,
24
+ "multiline-comment-style": 0,
25
+ "new-cap": [2, {
26
+ "capIsNewExceptions": [
27
+ "Get",
28
+ "GetIntrinsic",
29
+ "GetValueFromBuffer",
30
+ "IsDetachedBuffer",
31
+ "Set",
32
+ "SetValueInBuffer",
33
+ "ToIntegerOrInfinity",
34
+ "ToString",
35
+ "TypedArrayElementSize",
36
+ "TypedArrayElementType",
37
+ "TypedArraySpeciesCreate",
38
+ "ValidateTypedArray",
39
+ ],
40
+ }],
41
+ },
42
+
43
+ "overrides": [
44
+ {
45
+ "files": "test/**",
46
+ "globals": {
47
+ "ArrayBuffer": false,
48
+ "Uint8Array": false,
49
+ },
50
+ "rules": {
51
+ "max-lines-per-function": 0,
52
+ },
53
+ },
54
+ ],
55
+ }
package/.nycrc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "all": true,
3
+ "check-coverage": false,
4
+ "reporter": ["text-summary", "text", "html", "json"],
5
+ "exclude": [
6
+ "coverage",
7
+ "test"
8
+ ]
9
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## v1.0.0 - 2023-07-18
9
+
10
+ ### Commits
11
+
12
+ - Initial implementation, tests, readme [`7684f32`](https://github.com/es-shims/TypedArray.prototype.slice/commit/7684f32983b444734c6293af807fcf5f3e20a9ad)
13
+ - Initial commit [`e4ff962`](https://github.com/es-shims/TypedArray.prototype.slice/commit/e4ff962b319dbc568f48e312e0396130e91d5df4)
14
+ - [Fix] node v0.11.4 - 3 have an own slice method that works incorrectly [`361b2c6`](https://github.com/es-shims/TypedArray.prototype.slice/commit/361b2c6046f756fb6f6851b0d8759b5e88324521)
15
+ - [Fix] `node < v0.6` lacks proper toString behavior on Typed Arrays [`bcf30f9`](https://github.com/es-shims/TypedArray.prototype.slice/commit/bcf30f916c59d2744f5a0c2e8a9ea38da2092413)
16
+ - npm init [`a24ef46`](https://github.com/es-shims/TypedArray.prototype.slice/commit/a24ef465139926277e5b85b8d9b17e96070aa6c8)
17
+ - [Fix] update `es-abstract` and move it to runtime deps [`b70eb79`](https://github.com/es-shims/TypedArray.prototype.slice/commit/b70eb7926485148733d56bec6c9ce91ac820bd0d)
18
+ - Only apps should have lockfiles [`3361cbe`](https://github.com/es-shims/TypedArray.prototype.slice/commit/3361cbe1c5a986a194f250360cfd4a52a2e255a5)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ECMAScript Shims
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # ArrayBuffer.prototype.slice <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
+
3
+ [![github actions][actions-image]][actions-url]
4
+ [![coverage][codecov-image]][codecov-url]
5
+ [![License][license-image]][license-url]
6
+ [![Downloads][downloads-image]][downloads-url]
7
+
8
+ [![npm badge][npm-badge-png]][package-url]
9
+
10
+ An ES spec-compliant `ArrayBuffer.prototype.slice` shim. Invoke its "shim" method to shim ArrayBuffer.prototype.slice if it is unavailable.
11
+
12
+ This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES5-supported environment and complies with the [spec](https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice).
13
+
14
+ Most common usage:
15
+ ```js
16
+ var assert = require('assert');
17
+ var slice = require('typedarray.prototype.slice');
18
+
19
+ var arr = new Uint8Array([1, 2, 3]);
20
+
21
+ var arr2 = slice(arr);
22
+
23
+ arr2[0] = 2;
24
+ arr2[1] = 3;
25
+
26
+ assert.deepEqual(arr, new Uint8Array([1, 2, 3]));
27
+ assert.deepEqual(arr2, new Uint8Array([2, 3, 3]));
28
+ assert.notEqual(arr.buffer, arr2.buffer);
29
+
30
+ if (!ArrayBuffer.prototype.transfer) {
31
+ slice.shim();
32
+ }
33
+
34
+ var arr3 = arr.slice();
35
+ arr3[0] = 2;
36
+ arr3[1] = 3;
37
+
38
+ assert.deepEqual(arr, new Uint8Array([1, 2, 3]));
39
+ assert.deepEqual(arr3, new Uint8Array([2, 3, 3]));
40
+ assert.notEqual(arr.buffer, arr3.buffer);
41
+ ```
42
+
43
+ ## Engines where this is needed
44
+
45
+ - node v0.11.4 - v4: no prototype or own `slice` method
46
+ - node < v0.11.3: own `slice` method that fails to clone the underlying buffer
47
+
48
+ ## Tests
49
+ Simply clone the repo, `npm install`, and run `npm test`
50
+
51
+ [package-url]: https://npmjs.org/package/arraybuffer.prototype.slice
52
+ [npm-version-svg]: https://versionbadg.es/es-shims/ArrayBuffer.prototype.slice.svg
53
+ [deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice.svg
54
+ [deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice
55
+ [dev-deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice/dev-status.svg
56
+ [dev-deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice#info=devDependencies
57
+ [npm-badge-png]: https://nodei.co/npm/arraybuffer.prototype.slice.png?downloads=true&stars=true
58
+ [license-image]: https://img.shields.io/npm/l/arraybuffer.prototype.slice.svg
59
+ [license-url]: LICENSE
60
+ [downloads-image]: https://img.shields.io/npm/dm/arraybuffer.prototype.slice.svg
61
+ [downloads-url]: https://npm-stat.com/charts.html?package=arraybuffer.prototype.slice
62
+ [codecov-image]: https://codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/branch/main/graphs/badge.svg
63
+ [codecov-url]: https://app.codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/
64
+ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/ArrayBuffer.prototype.slice
65
+ [actions-url]: https://github.com/es-shims/ArrayBuffer.prototype.slice/actions
package/auto.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ require('./shim')();
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ var GetIntrinsic = require('get-intrinsic');
4
+
5
+ var $TypeError = GetIntrinsic('%TypeError%');
6
+
7
+ var Get = require('es-abstract/2023/Get');
8
+ var GetValueFromBuffer = require('es-abstract/2023/GetValueFromBuffer');
9
+ var IsDetachedBuffer = require('es-abstract/2023/IsDetachedBuffer');
10
+ var max = require('es-abstract/2023/max');
11
+ var min = require('es-abstract/2023/min');
12
+ var Set = require('es-abstract/2023/Set');
13
+ var SetValueInBuffer = require('es-abstract/2023/SetValueInBuffer');
14
+ var ToIntegerOrInfinity = require('es-abstract/2023/ToIntegerOrInfinity');
15
+ var ToString = require('es-abstract/2023/ToString');
16
+ var TypedArrayElementSize = require('es-abstract/2023/TypedArrayElementSize');
17
+ var TypedArrayElementType = require('es-abstract/2023/TypedArrayElementType');
18
+ var TypedArraySpeciesCreate = require('es-abstract/2023/TypedArraySpeciesCreate');
19
+ var ValidateTypedArray = require('es-abstract/2023/ValidateTypedArray');
20
+
21
+ var typedArrayBuffer = require('typed-array-buffer');
22
+ var typedArrayByteOffset = require('typed-array-byte-offset');
23
+
24
+ // https://tc39.es/ecma262/#sec-%typedarray%.prototype.slice
25
+
26
+ module.exports = function slice(start, end) {
27
+ var O = this; // step 1
28
+
29
+ ValidateTypedArray(O); // step 2
30
+
31
+ // 3. Let len be O.[[ArrayLength]].
32
+ var len = O.length; // steps 3
33
+
34
+ var relativeStart = ToIntegerOrInfinity(start); // step 4
35
+
36
+ var k;
37
+ if (relativeStart === -Infinity) {
38
+ k = 0; // step 5
39
+ } else if (relativeStart < 0) {
40
+ k = max(len + relativeStart, 0); // step 6
41
+ } else {
42
+ k = min(relativeStart, len); // step 7
43
+ }
44
+
45
+ var relativeEnd = typeof end === 'undefined' ? len : ToIntegerOrInfinity(end); // step 8
46
+
47
+ var final;
48
+ if (relativeEnd === -Infinity) {
49
+ final = 0; // step 9
50
+ } else if (relativeEnd < 0) {
51
+ final = max(len + relativeEnd, 0); // step 10
52
+ } else {
53
+ final = min(relativeEnd, len); // step 11
54
+ }
55
+
56
+ var count = max(final - k, 0); // step 12
57
+
58
+ var A = TypedArraySpeciesCreate(O, [count]); // step 13
59
+
60
+ if (count > 0) { // step 14
61
+ if (IsDetachedBuffer(typedArrayBuffer(O))) {
62
+ throw new $TypeError('Cannot use a Typed Array with an underlying ArrayBuffer that is detached'); // step 14.a
63
+ }
64
+ var srcType = TypedArrayElementType(O); // step 14.b
65
+ var targetType = TypedArrayElementType(A); // step 14.c
66
+ if (srcType === targetType) { // step 14.d
67
+ // 1. NOTE: The transfer must be performed in a manner that preserves the bit-level encoding of the source data.
68
+ var srcBuffer = typedArrayBuffer(O); // step 14.d.ii
69
+ var targetBuffer = typedArrayBuffer(A); // step 14.d.iii
70
+ var elementSize = TypedArrayElementSize(O); // step 14.d.iv
71
+ var srcByteOffset = typedArrayByteOffset(O); // step 14.d.v
72
+ var srcByteIndex = (k * elementSize) + srcByteOffset; // step 14.d.vi
73
+ var targetByteIndex = typedArrayByteOffset(A); // step 14.d.vii
74
+ var limit = targetByteIndex + (count * elementSize); // step 14.d.viii
75
+ while (targetByteIndex < limit) { // step 14.d.ix
76
+ var value = GetValueFromBuffer(srcBuffer, srcByteIndex, 'Uint8', true, 'Unordered'); // step 14.d.ix.1
77
+ SetValueInBuffer(targetBuffer, targetByteIndex, 'Uint8', value, true, 'Unordered'); // step 14.d.ix.2
78
+ srcByteIndex += 1; // step 14.d.ix.3
79
+ targetByteIndex += 1; // step 14.d.ix.4
80
+ }
81
+ } else { // step 14.e
82
+ var n = 0; // step 14.e.i
83
+ while (k < final) { // step 14.e.ii
84
+ var Pk = ToString(k); // step 14.e.ii.1
85
+ var kValue = Get(O, Pk); // step 14.e.ii.2
86
+ Set(A, ToString(n), kValue, true); // step 14.e.ii.3
87
+ k += 1; // step 14.e.ii.4
88
+ n += 1; // step 14.e.ii.5
89
+ }
90
+ }
91
+ }
92
+
93
+ return A; // step 15
94
+ };
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var define = require('define-properties');
4
+ var callBind = require('call-bind');
5
+
6
+ var implementation = require('./implementation');
7
+ var getPolyfill = require('./polyfill');
8
+ var shim = require('./shim');
9
+
10
+ var bound = callBind(getPolyfill());
11
+
12
+ define(bound, {
13
+ getPolyfill: getPolyfill,
14
+ implementation: implementation,
15
+ shim: shim
16
+ });
17
+
18
+ module.exports = bound;
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "typedarray.prototype.slice",
3
+ "version": "1.0.0",
4
+ "description": "ES spec-compliant shim for TypedArray.prototype.slice",
5
+ "author": "Jordan Harband <ljharb@gmail.com>",
6
+ "funding": {
7
+ "url": "https://github.com/sponsors/ljharb"
8
+ },
9
+ "license": "MIT",
10
+ "main": "index.js",
11
+ "exports": {
12
+ ".": "./index.js",
13
+ "./auto": "./auto.js",
14
+ "./polyfill": "./polyfill.js",
15
+ "./implementation": "./implementation.js",
16
+ "./shim": "./shim.js",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "scripts": {
20
+ "prepack": "npmignore --auto --commentLines=autogenerated",
21
+ "prepublish": "not-in-publish || npm run prepublishOnly",
22
+ "prepublishOnly": "safe-publish-latest",
23
+ "pretest": "npm run lint",
24
+ "test": "npm run tests-only",
25
+ "posttest": "aud --production",
26
+ "tests-only": "nyc tape 'test/**/*.js'",
27
+ "prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
28
+ "lint": "eslint --ext=js,mjs .",
29
+ "postlint": "evalmd README.md && es-shim-api --bound",
30
+ "version": "auto-changelog && git add CHANGELOG.md",
31
+ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/es-shims/TypedArray.prototype.slice.git"
36
+ },
37
+ "homepage": "https://github.com/es-shims/TypedArray.prototype.slice#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/es-shims/TypedArray.prototype.slice/issues"
40
+ },
41
+ "keywords": [
42
+ "javascript",
43
+ "ecmascript",
44
+ "TypedArray.prototype.slice",
45
+ "polyfill",
46
+ "shim",
47
+ "Typed Arrays",
48
+ "array",
49
+ "buffer",
50
+ "TypedArray#slice",
51
+ "slice",
52
+ "typed array",
53
+ "es-shim API"
54
+ ],
55
+ "dependencies": {
56
+ "call-bind": "^1.0.2",
57
+ "define-properties": "^1.2.0",
58
+ "es-abstract": "^1.22.1",
59
+ "get-intrinsic": "^1.2.1",
60
+ "typed-array-buffer": "^1.0.0",
61
+ "typed-array-byte-offset": "^1.0.0"
62
+ },
63
+ "devDependencies": {
64
+ "@es-shims/api": "^2.4.2",
65
+ "@ljharb/eslint-config": "^21.1.0",
66
+ "aud": "^2.0.3",
67
+ "auto-changelog": "^2.4.0",
68
+ "available-typed-arrays": "^1.0.5",
69
+ "eclint": "^2.8.1",
70
+ "es-value-fixtures": "^1.4.2",
71
+ "eslint": "=8.8.0",
72
+ "evalmd": "^0.0.19",
73
+ "for-each": "^0.3.3",
74
+ "functions-have-names": "^1.2.3",
75
+ "has-strict-mode": "^1.0.1",
76
+ "in-publish": "^2.0.1",
77
+ "npmignore": "^0.3.0",
78
+ "nyc": "^10.3.2",
79
+ "object-inspect": "^1.12.3",
80
+ "safe-publish-latest": "^2.0.0",
81
+ "tape": "^5.6.6"
82
+ },
83
+ "testling": {
84
+ "files": "test/index.js"
85
+ },
86
+ "engines": {
87
+ "node": ">= 0.4"
88
+ },
89
+ "auto-changelog": {
90
+ "output": "CHANGELOG.md",
91
+ "template": "keepachangelog",
92
+ "unreleased": false,
93
+ "commitLimit": false,
94
+ "backfillLimit": false,
95
+ "hideCredit": true
96
+ },
97
+ "publishConfig": {
98
+ "ignore": [
99
+ ".github/workflows"
100
+ ]
101
+ }
102
+ }
package/polyfill.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var implementation = require('./implementation');
4
+
5
+ module.exports = function getPolyfill() {
6
+ return (typeof Uint8Array === 'function' && Uint8Array.prototype.slice) || implementation;
7
+ };
package/shim.js ADDED
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var define = require('define-properties');
4
+ var getProto = require('es-abstract/helpers/getProto');
5
+
6
+ var getPolyfill = require('./polyfill');
7
+
8
+ module.exports = function shimTypedArraySlice() {
9
+ if (typeof Uint8Array === 'function') {
10
+ var polyfill = getPolyfill();
11
+ var proto = getProto(Uint8Array.prototype);
12
+ define(
13
+ proto,
14
+ { slice: polyfill },
15
+ { slice: function () { return proto.slice !== polyfill; } }
16
+ );
17
+ }
18
+
19
+ return polyfill;
20
+ };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var implementation = require('../implementation');
4
+ var callBind = require('call-bind');
5
+ var test = require('tape');
6
+ var hasStrictMode = require('has-strict-mode')();
7
+ var runTests = require('./tests');
8
+
9
+ test('as a function', function (t) {
10
+ t.test('bad array/this value', { skip: !hasStrictMode }, function (st) {
11
+ /* eslint no-useless-call: 0 */
12
+ st['throws'](function () { implementation.call(undefined); }, TypeError, 'undefined is not an object');
13
+ st['throws'](function () { implementation.call(null); }, TypeError, 'null is not an object');
14
+
15
+ st.end();
16
+ });
17
+
18
+ t.test('Typed Array support', { skip: typeof Uint8Array === 'undefined' }, function (st) {
19
+ runTests(callBind(implementation), st);
20
+
21
+ st.end();
22
+ });
23
+
24
+ t.end();
25
+ });
package/test/index.js ADDED
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var index = require('../');
4
+ var test = require('tape');
5
+ var runTests = require('./tests');
6
+
7
+ test('as a function', function (t) {
8
+ t.test('bad array/this value', function (st) {
9
+ st['throws'](function () { index(undefined); }, TypeError, 'undefined is not an object');
10
+ st['throws'](function () { index(null); }, TypeError, 'null is not an object');
11
+
12
+ st.end();
13
+ });
14
+
15
+ t.test('Typed Array support', { skip: typeof Uint8Array === 'undefined' }, function (st) {
16
+ runTests(index, st);
17
+
18
+ st.end();
19
+ });
20
+
21
+ t.end();
22
+ });
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ require('../auto');
4
+
5
+ var test = require('tape');
6
+ var defineProperties = require('define-properties');
7
+ var callBind = require('call-bind');
8
+
9
+ var isEnumerable = Object.prototype.propertyIsEnumerable;
10
+ var functionsHaveNames = require('functions-have-names')();
11
+ var hasStrictMode = require('has-strict-mode')();
12
+ var getProto = require('es-abstract/helpers/getProto');
13
+
14
+ var runTests = require('./tests');
15
+
16
+ test('shimmed', function (t) {
17
+ t.test('Typed Array support', { skip: typeof Uint8Array === 'undefined' }, function (st) {
18
+ var proto = getProto(Uint8Array.prototype);
19
+ var method = proto.slice;
20
+
21
+ st.equal(method.length, 2, 'TypedArray#slice has a length of 2');
22
+
23
+ st.test('Function name', { skip: !functionsHaveNames }, function (s2t) {
24
+ s2t.equal(method.name, 'slice', 'TypedArray#slice name "slice"');
25
+ s2t.end();
26
+ });
27
+
28
+ st.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
29
+ et.equal(false, isEnumerable.call(proto, 'slice'), 'TypedArray#slice is not enumerable');
30
+ et.end();
31
+ });
32
+
33
+ st.test('bad array/this value', { skip: !hasStrictMode }, function (s2t) {
34
+ /* eslint no-useless-call: 0 */
35
+ s2t['throws'](function () { return method.call(undefined); }, TypeError, 'undefined is not an object');
36
+ s2t['throws'](function () { return method.call(null); }, TypeError, 'null is not an object');
37
+ s2t.end();
38
+ });
39
+
40
+ t.test('has the correct descriptor', { skip: !Object.getOwnPropertyDescriptor }, function (s2t) {
41
+ var descriptor = Object.getOwnPropertyDescriptor(proto, 'slice');
42
+
43
+ s2t.equal(descriptor.configurable, true);
44
+ s2t.equal(descriptor.enumerable, false);
45
+ s2t.equal(typeof descriptor.value, 'function');
46
+ s2t.equal(descriptor.writable, true);
47
+ s2t.end();
48
+ });
49
+
50
+ runTests(callBind(method), st);
51
+
52
+ st.end();
53
+ });
54
+
55
+ t.end();
56
+ });
package/test/tests.js ADDED
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var inspect = require('object-inspect');
4
+ // var IsDetachedBuffer = require('es-abstract/2023/IsDetachedBuffer');
5
+
6
+ var forEach = require('for-each');
7
+ var availableTypedArrays = require('available-typed-arrays')();
8
+ var v = require('es-value-fixtures');
9
+
10
+ module.exports = function runTests(slice, t) {
11
+ forEach(v.primitives.concat(v.objects), function (nonTA) {
12
+ t['throws'](
13
+ function () { slice(nonTA); },
14
+ TypeError,
15
+ inspect(nonTA) + ' is not a Typed Array'
16
+ );
17
+ });
18
+
19
+ t.test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (st) {
20
+ forEach(availableTypedArrays, function (name) {
21
+ st.test(name, function (s2t) {
22
+ var TA = global[name];
23
+ var isBigInt = name.slice(0, 3) === 'Big';
24
+
25
+ var ta = new TA(isBigInt ? [BigInt(1), BigInt(2), BigInt(3)] : [1, 2, 3]);
26
+
27
+ var copy = slice(ta);
28
+ s2t.notEqual(copy, ta, 'returns a new instance when sliced with no args');
29
+ s2t.ok(copy instanceof TA, 'returns an instance of the same type when sliced with no args');
30
+ s2t.deepEqual(copy, ta, 'returns a new instance with the same values when sliced with no args');
31
+ s2t.notEqual(copy.buffer, ta.buffer, 'the new instance has a different buffer than the original when sliced with no args');
32
+
33
+ var subset = slice(ta, 1);
34
+ s2t.notEqual(subset, ta, 'returns a new instance when sliced with a start index');
35
+ s2t.ok(copy instanceof TA, 'returns an instance of the same type when sliced with a start index');
36
+ s2t.deepEqual(
37
+ subset,
38
+ new TA(isBigInt ? [BigInt(2), BigInt(3)] : [2, 3]),
39
+ 'returns a new instance with the expected subset of values when sliced with a start index'
40
+ );
41
+ s2t.notEqual(copy.buffer, ta.buffer, 'the new instance has a different buffer than the original when sliced with a start index');
42
+
43
+ s2t.end();
44
+ });
45
+ });
46
+
47
+ return st.end();
48
+ });
49
+ };