pax_global_header00006660000000000000000000000064143214663330014517gustar00rootroot0000000000000052 comment=bfa163321b8ccab9c5351ff7fa71826a9355614d typedarray-0.0.7/000077500000000000000000000000001432146633300137075ustar00rootroot00000000000000typedarray-0.0.7/.eslintrc000066400000000000000000000011561432146633300155360ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "camelcase": 1, "func-name-matching": 1, "func-style": [2, "declaration"], "max-lines": 0, "max-lines-per-function": 0, "max-statements": 0, "max-statements-per-line": 1, "multiline-comment-style": 0, "new-cap": 1, "no-mixed-operators": 1, "no-param-reassign": 1, "no-restricted-properties": 1, "no-restricted-syntax": 1, "no-underscore-dangle": 1, "sort-keys": 0, "strict": 1, }, "overrides": [ { "files": "example/**", "rules": { "no-console": 0, }, }, ], } typedarray-0.0.7/.github/000077500000000000000000000000001432146633300152475ustar00rootroot00000000000000typedarray-0.0.7/.github/FUNDING.yml000066400000000000000000000011141432146633300170610ustar00rootroot00000000000000# 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/es-value-fixtures 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'] typedarray-0.0.7/.github/workflows/000077500000000000000000000000001432146633300173045ustar00rootroot00000000000000typedarray-0.0.7/.github/workflows/node-aught.yml000066400000000000000000000005161432146633300220640ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '< 10' type: minors command: npm run tests-only node: name: 'node < 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' typedarray-0.0.7/.github/workflows/node-pretest.yml000066400000000000000000000002061432146633300224360ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main typedarray-0.0.7/.github/workflows/node-tens.yml000066400000000000000000000005211432146633300217210ustar00rootroot00000000000000name: 'Tests: node.js >= 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10' type: minors command: npm run tests-only node: name: 'node >= 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' typedarray-0.0.7/.github/workflows/rebase.yml000066400000000000000000000004111432146633300212640ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} typedarray-0.0.7/.github/workflows/require-allow-edits.yml000066400000000000000000000003031432146633300237210ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main typedarray-0.0.7/.gitignore000066400000000000000000000001721432146633300156770ustar00rootroot00000000000000# gitignore node_modules/ # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore typedarray-0.0.7/.npmrc000066400000000000000000000000671432146633300150320ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s typedarray-0.0.7/CHANGELOG.md000066400000000000000000000115461432146633300155270ustar00rootroot00000000000000# 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). ## [v0.0.7](https://github.com/ljharb/typedarray/compare/v0.0.6...v0.0.7) - 2022-10-12 ### Commits - [eslint] fix indentation [`2e83ef6`](https://github.com/ljharb/typedarray/commit/2e83ef6f221111efb96ea5b0adf892d6522d3dc0) - [eslint] add eslint [`592fe17`](https://github.com/ljharb/typedarray/commit/592fe17392bcd9c2484316d9ae40d9488782b65f) - [readme] rename, add badges [`c5a4998`](https://github.com/ljharb/typedarray/commit/c5a499849d1217aa15cbfedd904ef3c644c33d61) - [meta] add `auto-changelog` [`c77cc4a`](https://github.com/ljharb/typedarray/commit/c77cc4a3e1000b21a05010baee21557356893436) - [actions] add reusable workflows [`5a874a6`](https://github.com/ljharb/typedarray/commit/5a874a6c334e1e91b535147f0bd70ec1d2e1404a) - [meta] create FUNDING.yml; add `funding` in package.json [`5421bfb`](https://github.com/ljharb/typedarray/commit/5421bfbe20052d6b375e42a2628daf934940cc1a) - [meta] use `npmignore` to autogenerate an npmignore file [`85f441b`](https://github.com/ljharb/typedarray/commit/85f441bea6ac3689ad69a24bd363807edc5b3d68) - Only apps should have lockfiles [`c7cee04`](https://github.com/ljharb/typedarray/commit/c7cee0462c9ce831e53125692382339a2c4871db) - [meta] update URLs [`bd1ee94`](https://github.com/ljharb/typedarray/commit/bd1ee944f9627d4604e6c3e3bbd0289ff870bb54) - [Dev Deps] update `tape` [`8aaa43b`](https://github.com/ljharb/typedarray/commit/8aaa43b549ffe33d6b7af799784961803b47a151) - [meta] add `safe-publish-latest` [`809caf9`](https://github.com/ljharb/typedarray/commit/809caf950e901fd140c28c04ecf0bd9a1bf41a29) - [Tests] add `aud` in `posttest` [`c8f7ac5`](https://github.com/ljharb/typedarray/commit/c8f7ac532cd361c9374864bab55ead8e6e0f44e7) ## [v0.0.6](https://github.com/ljharb/typedarray/compare/v0.0.5...v0.0.6) - 2014-05-17 ### Commits - link to browserify cdn [`f5be9e4`](https://github.com/ljharb/typedarray/commit/f5be9e4263964f9d711e42d0f5f0bd40b9e38cf8) - upgrade tape [`56bd728`](https://github.com/ljharb/typedarray/commit/56bd728e1891a0501de8a7deb181641a51050c0d) ## [v0.0.5](https://github.com/ljharb/typedarray/compare/v0.0.4...v0.0.5) - 2013-12-12 ### Commits - Ensure defineProp is always defined [`316be36`](https://github.com/ljharb/typedarray/commit/316be36ac631521ccbf00a9557a2dda0c3e5b17e) ## [v0.0.4](https://github.com/ljharb/typedarray/compare/v0.0.3...v0.0.4) - 2013-12-10 ### Commits - Remove "reserved words" variable names (for IE6-8) [`60869cc`](https://github.com/ljharb/typedarray/commit/60869cc3f8c32fe43dc912a9f9e186d0545e425c) ## [v0.0.3](https://github.com/ljharb/typedarray/compare/v0.0.2...v0.0.3) - 2013-12-10 ### Commits - Fix more ReferenceError bugs in DataView [`ddb968a`](https://github.com/ljharb/typedarray/commit/ddb968af2d186b57d4e59371d232df435ac56004) ## [v0.0.2](https://github.com/ljharb/typedarray/compare/v0.0.1...v0.0.2) - 2013-12-10 ### Commits - Fix "ReferenceError: 'ArrayBuffer' is undefined" when initializing a DataView [`1ffacbc`](https://github.com/ljharb/typedarray/commit/1ffacbcef06f1c9d699242cb7a1f65d32b101ee5) ## [v0.0.1](https://github.com/ljharb/typedarray/compare/v0.0.0...v0.0.1) - 2013-12-10 ### Fixed - 0.0.1 [`#1`](https://github.com/ljharb/typedarray/issues/1) ### Commits - removing `.` in error message [`62210c3`](https://github.com/ljharb/typedarray/commit/62210c32f4f946652f3acede6a60023c4259fab2) - test ie6+ [`f041445`](https://github.com/ljharb/typedarray/commit/f041445bf8d45b8024ca2fcd2b31e19c15240579) ## v0.0.0 - 2013-12-09 ### Commits - remove use of `global` [`a72dae8`](https://github.com/ljharb/typedarray/commit/a72dae8f5f5b1e3379a1ca357c0858201766730d) - initial code ripped from https://raw.github.com/inexorabletash/polyfill/master/typedarray.js [`1b9b2c1`](https://github.com/ljharb/typedarray/commit/1b9b2c173d23345fc9d944b1ef6de9f91d677420) - examples, readme, package.json [`9d1f718`](https://github.com/ljharb/typedarray/commit/9d1f71824a6edbc6e6763da9c5d74837f32acd1b) - get rid of global setting of object function shims for defineProperty and getOwnPropertyNames [`33d79b8`](https://github.com/ljharb/typedarray/commit/33d79b8342e7c185183f17fe95cb2508fb43701a) - explicit global references, undef_globals test passes [`621d039`](https://github.com/ljharb/typedarray/commit/621d039595265d46dd2575d9ccbcf15a04d2b978) - testling, travis [`424dc38`](https://github.com/ljharb/typedarray/commit/424dc389295d9db5a06488695c0df598f8c75c0e) - failing test since `global` assignment in index relies on global for scoping [`05be36a`](https://github.com/ljharb/typedarray/commit/05be36afd4197cddbc4387506690107aee43b2c9) - tiny passing uint8array test [`6b2f8f1`](https://github.com/ljharb/typedarray/commit/6b2f8f12c99d35f2a88080ddfa8ddea3d60cbd6f) typedarray-0.0.7/LICENSE000066400000000000000000000030351432146633300147150ustar00rootroot00000000000000/* Copyright (c) 2010, Linden Research, Inc. Copyright (c) 2012, Joshua Bell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. $/LicenseInfo$ */ // Original can be found at: // https://bitbucket.org/lindenlab/llsd // Modifications by Joshua Bell inexorabletash@gmail.com // https://github.com/inexorabletash/polyfill // ES3/ES5 implementation of the Krhonos Typed Array Specification // Ref: http://www.khronos.org/registry/typedarray/specs/latest/ // Date: 2011-02-01 // // Variations: // * Allows typed_array.get/set() as alias for subscripts (typed_array[]) typedarray-0.0.7/README.md000066400000000000000000000044631432146633300151750ustar00rootroot00000000000000# typedarray [![Version Badge][npm-version-svg]][package-url] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][npm-badge-png]][package-url] TypedArray polyfill ripped from [this module](https://raw.github.com/inexorabletash/polyfill). [![build status](https://secure.travis-ci.org/es-shims/typedarray.png)](http://travis-ci.org/es-shims/typedarray) [![testling badge](https://ci.testling.com/es-shims/typedarray.png)](https://ci.testling.com/es-shims/typedarray) # example ``` js var Uint8Array = require('typedarray').Uint8Array; var ua = new Uint8Array(5); ua[1] = 256 + 55; console.log(ua[1]); ``` output: ``` 55 ``` # methods ``` js var TA = require('typedarray') ``` The `TA` object has the following constructors: * TA.ArrayBuffer * TA.DataView * TA.Float32Array * TA.Float64Array * TA.Int8Array * TA.Int16Array * TA.Int32Array * TA.Uint8Array * TA.Uint8ClampedArray * TA.Uint16Array * TA.Uint32Array # install With [npm](https://npmjs.org) do: ``` npm install typedarray ``` To use this module in the browser, compile with [browserify](http://browserify.org) or download a UMD build from browserify CDN: http://wzrd.in/standalone/typedarray@latest # license MIT [package-url]: https://npmjs.org/package/typedarray [npm-version-svg]: https://versionbadg.es/es-shims/typedarray.svg [deps-svg]: https://david-dm.org/es-shims/typedarray.svg [deps-url]: https://david-dm.org/es-shims/typedarray [dev-deps-svg]: https://david-dm.org/es-shims/typedarray/dev-status.svg [dev-deps-url]: https://david-dm.org/es-shims/typedarray#info=devDependencies [npm-badge-png]: https://nodei.co/npm/typedarray.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/typedarray.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/typedarray.svg [downloads-url]: https://npm-stat.com/charts.html?package=typedarray [codecov-image]: https://codecov.io/gh/es-shims/typedarray/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/es-shims/typedarray/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/typedarray [actions-url]: https://github.com/es-shims/typedarray/actions typedarray-0.0.7/example/000077500000000000000000000000001432146633300153425ustar00rootroot00000000000000typedarray-0.0.7/example/tarray.js000066400000000000000000000001561432146633300172040ustar00rootroot00000000000000var Uint8Array = require('../').Uint8Array; var ua = new Uint8Array(5); ua[1] = 256 + 55; console.log(ua[1]); typedarray-0.0.7/index.js000066400000000000000000000473161432146633300153670ustar00rootroot00000000000000// Beyond this value, index getters/setters (i.e. array[0], array[1]) are so slow to // create, and consume so much memory, that the browser appears frozen. var MAX_ARRAY_LENGTH = 1e5; // Approximations of internal ECMAScript conversion functions var ECMAScript = (function () { // Stash a copy in case other scripts modify these var opts = Object.prototype.toString; var ophop = Object.prototype.hasOwnProperty; return { // Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues: Class: function (v) { return opts.call(v).replace(/^\[object *|\]$/g, ''); }, HasProperty: function (o, p) { return p in o; }, HasOwnProperty: function (o, p) { return ophop.call(o, p); }, IsCallable: function (o) { return typeof o === 'function'; }, ToInt32: function (v) { return v >> 0; }, ToUint32: function (v) { return v >>> 0; } }; }()); // Snapshot intrinsics var LN2 = Math.LN2; var abs = Math.abs; var floor = Math.floor; var log = Math.log; var min = Math.min; var pow = Math.pow; var round = Math.round; function clamp(v, minimum, max) { return v < minimum ? minimum : v > max ? max : v; } var getOwnPropNames = Object.getOwnPropertyNames || function (o) { if (o !== Object(o)) { throw new TypeError('Object.getOwnPropertyNames called on non-object'); } var props = [], p; for (p in o) { if (ECMAScript.HasOwnProperty(o, p)) { props.push(p); } } return props; }; // emulate ES5 getter/setter API using legacy APIs // http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx // (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but // note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless) var defineProp; if (Object.defineProperty && (function () { try { Object.defineProperty({}, 'x', {}); return true; } catch (e) { return false; } }())) { defineProp = Object.defineProperty; } else { defineProp = function (o, p, desc) { if (!o === Object(o)) { throw new TypeError('Object.defineProperty called on non-object'); } if (ECMAScript.HasProperty(desc, 'get') && Object.prototype.__defineGetter__) { Object.prototype.__defineGetter__.call(o, p, desc.get); } if (ECMAScript.HasProperty(desc, 'set') && Object.prototype.__defineSetter__) { Object.prototype.__defineSetter__.call(o, p, desc.set); } if (ECMAScript.HasProperty(desc, 'value')) { o[p] = desc.value; } return o; }; } // ES5: lock down object properties function configureProperties(obj) { if (getOwnPropNames && defineProp) { var props = getOwnPropNames(obj), i; for (i = 0; i < props.length; i += 1) { defineProp(obj, props[i], { value: obj[props[i]], writable: false, enumerable: false, configurable: false }); } } } // ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value) // for index in 0 ... obj.length function makeArrayAccessors(obj) { if (!defineProp) { return; } if (obj.length > MAX_ARRAY_LENGTH) { throw new RangeError('Array too large for polyfill'); } function makeArrayAccessor(index) { defineProp(obj, index, { get: function () { return obj._getter(index); }, set: function (v) { obj._setter(index, v); }, enumerable: true, configurable: false }); } var i; for (i = 0; i < obj.length; i += 1) { makeArrayAccessor(i); } } // Internal conversion functions: // pack() - take a number (interpreted as Type), output a byte array // unpack() - take a byte array, output a Type-like number function as_signed(value, bits) { var s = 32 - bits; return (value << s) >> s; } function as_unsigned(value, bits) { var s = 32 - bits; return (value << s) >>> s; } function packI8(n) { return [n & 0xff]; } function unpackI8(bytes) { return as_signed(bytes[0], 8); } function packU8(n) { return [n & 0xff]; } function unpackU8(bytes) { return as_unsigned(bytes[0], 8); } function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; } function packI16(n) { return [(n >> 8) & 0xff, n & 0xff]; } function unpackI16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); } function packU16(n) { return [(n >> 8) & 0xff, n & 0xff]; } function unpackU16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); } function packI32(n) { return [ (n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff ]; } function unpackI32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); } function packU32(n) { return [ (n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff ]; } function unpackU32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); } function packIEEE754(v, ebits, fbits) { var bias = (1 << (ebits - 1)) - 1; var s, e, f, i, bits, str, bytes; function roundToEven(n) { var w = floor(n); var fl = n - w; if (fl < 0.5) { return w; } if (fl > 0.5) { return w + 1; } return w % 2 ? w + 1 : w; } // Compute sign, exponent, fraction if (v !== v) { // NaN // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping e = (1 << ebits) - 1; f = pow(2, fbits - 1); s = 0; } else if (v === Infinity || v === -Infinity) { e = (1 << ebits) - 1; f = 0; s = v < 0 ? 1 : 0; } else if (v === 0) { e = 0; f = 0; s = 1 / v === -Infinity ? 1 : 0; } else { s = v < 0; v = abs(v); if (v >= pow(2, 1 - bias)) { e = min(floor(log(v) / LN2), 1023); f = roundToEven(v / pow(2, e) * pow(2, fbits)); if (f / pow(2, fbits) >= 2) { e = e + 1; f = 1; } if (e > bias) { // Overflow e = (1 << ebits) - 1; f = 0; } else { // Normalized e = e + bias; f = f - pow(2, fbits); } } else { // Denormalized e = 0; f = roundToEven(v / pow(2, 1 - bias - fbits)); } } // Pack sign, exponent, fraction bits = []; for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); } for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); } bits.push(s ? 1 : 0); bits.reverse(); str = bits.join(''); // Bits to bytes bytes = []; while (str.length) { bytes.push(parseInt(str.substring(0, 8), 2)); str = str.substring(8); } return bytes; } function unpackIEEE754(bytes, ebits, fbits) { // Bytes to bits var bits = [], i, j, b, str, bias, s, e, f; for (i = bytes.length; i; i -= 1) { b = bytes[i - 1]; for (j = 8; j; j -= 1) { bits.push(b % 2 ? 1 : 0); b = b >> 1; } } bits.reverse(); str = bits.join(''); // Unpack sign, exponent, fraction bias = (1 << (ebits - 1)) - 1; s = parseInt(str.substring(0, 1), 2) ? -1 : 1; e = parseInt(str.substring(1, 1 + ebits), 2); f = parseInt(str.substring(1 + ebits), 2); // Produce number if (e === (1 << ebits) - 1) { return f === 0 ? s * Infinity : NaN; } else if (e > 0) { // Normalized return s * pow(2, e - bias) * (1 + (f / pow(2, fbits))); } else if (f !== 0) { // Denormalized return s * pow(2, -(bias - 1)) * (f / pow(2, fbits)); } return s < 0 ? -0 : 0; } function unpackF64(b) { return unpackIEEE754(b, 11, 52); } function packF64(v) { return packIEEE754(v, 11, 52); } function unpackF32(b) { return unpackIEEE754(b, 8, 23); } function packF32(v) { return packIEEE754(v, 8, 23); } // // 3 The ArrayBuffer Type // (function () { /** @constructor */ function ArrayBuffer(length) { length = ECMAScript.ToInt32(length); if (length < 0) { throw new RangeError('ArrayBuffer size is not a small enough positive integer'); } this.byteLength = length; this._bytes = []; this._bytes.length = length; var i; for (i = 0; i < this.byteLength; i += 1) { this._bytes[i] = 0; } configureProperties(this); } exports.ArrayBuffer = exports.ArrayBuffer || ArrayBuffer; // // 4 The ArrayBufferView Type // // NOTE: this constructor is not exported /** @constructor */ function ArrayBufferView() { // this.buffer = null; // this.byteOffset = 0; // this.byteLength = 0; } // // 5 The Typed Array View Types // function makeConstructor(bytesPerElement, pack, unpack) { // Each TypedArray type requires a distinct constructor instance with // identical logic, which this produces. var ctor; ctor = function (buffer, byteOffset, length) { var array, sequence, i, s; if (!arguments.length || typeof arguments[0] === 'number') { // Constructor(unsigned long length) this.length = ECMAScript.ToInt32(arguments[0]); if (length < 0) { throw new RangeError('ArrayBufferView size is not a small enough positive integer'); } this.byteLength = this.length * this.BYTES_PER_ELEMENT; this.buffer = new ArrayBuffer(this.byteLength); this.byteOffset = 0; } else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) { // Constructor(TypedArray array) array = arguments[0]; this.length = array.length; this.byteLength = this.length * this.BYTES_PER_ELEMENT; this.buffer = new ArrayBuffer(this.byteLength); this.byteOffset = 0; for (i = 0; i < this.length; i += 1) { this._setter(i, array._getter(i)); } } else if (typeof arguments[0] === 'object' && !(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) { // Constructor(sequence array) sequence = arguments[0]; this.length = ECMAScript.ToUint32(sequence.length); this.byteLength = this.length * this.BYTES_PER_ELEMENT; this.buffer = new ArrayBuffer(this.byteLength); this.byteOffset = 0; for (i = 0; i < this.length; i += 1) { s = sequence[i]; this._setter(i, Number(s)); } } else if (typeof arguments[0] === 'object' && (arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) { // Constructor(ArrayBuffer buffer, // optional unsigned long byteOffset, optional unsigned long length) this.buffer = buffer; this.byteOffset = ECMAScript.ToUint32(byteOffset); if (this.byteOffset > this.buffer.byteLength) { throw new RangeError('byteOffset out of range'); } if (this.byteOffset % this.BYTES_PER_ELEMENT) { // The given byteOffset must be a multiple of the element // size of the specific type, otherwise an exception is raised. throw new RangeError('ArrayBuffer length minus the byteOffset is not a multiple of the element size.'); } if (arguments.length < 3) { this.byteLength = this.buffer.byteLength - this.byteOffset; if (this.byteLength % this.BYTES_PER_ELEMENT) { throw new RangeError('length of buffer minus byteOffset not a multiple of the element size'); } this.length = this.byteLength / this.BYTES_PER_ELEMENT; } else { this.length = ECMAScript.ToUint32(length); this.byteLength = this.length * this.BYTES_PER_ELEMENT; } if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) { throw new RangeError('byteOffset and length reference an area beyond the end of the buffer'); } } else { throw new TypeError('Unexpected argument type(s)'); } this.constructor = ctor; configureProperties(this); makeArrayAccessors(this); }; ctor.prototype = new ArrayBufferView(); ctor.prototype.BYTES_PER_ELEMENT = bytesPerElement; ctor.prototype._pack = pack; ctor.prototype._unpack = unpack; ctor.BYTES_PER_ELEMENT = bytesPerElement; // getter type (unsigned long index); ctor.prototype._getter = function (index) { if (arguments.length < 1) { throw new SyntaxError('Not enough arguments'); } index = ECMAScript.ToUint32(index); if (index >= this.length) { return undefined; } var bytes = []; for (var i = 0, o = this.byteOffset + (index * this.BYTES_PER_ELEMENT); i < this.BYTES_PER_ELEMENT; i += 1, o += 1) { bytes.push(this.buffer._bytes[o]); } return this._unpack(bytes); }; // NONSTANDARD: convenience alias for getter: type get(unsigned long index); ctor.prototype.get = ctor.prototype._getter; // setter void (unsigned long index, type value); ctor.prototype._setter = function (index, value) { if (arguments.length < 2) { throw new SyntaxError('Not enough arguments'); } index = ECMAScript.ToUint32(index); if (index < this.length) { var bytes = this._pack(value); var i; var o; for (i = 0, o = this.byteOffset + (index * this.BYTES_PER_ELEMENT); i < this.BYTES_PER_ELEMENT; i += 1, o += 1) { this.buffer._bytes[o] = bytes[i]; } } }; // void set(TypedArray array, optional unsigned long offset); // void set(sequence array, optional unsigned long offset); ctor.prototype.set = function (index, value) { // eslint-disable-line no-unused-vars if (arguments.length < 1) { throw new SyntaxError('Not enough arguments'); } var array, sequence, offset, len, i, s, d, byteOffset, byteLength, tmp; if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) { // void set(TypedArray array, optional unsigned long offset); array = arguments[0]; offset = ECMAScript.ToUint32(arguments[1]); if (offset + array.length > this.length) { throw new RangeError('Offset plus length of array is out of range'); } byteOffset = this.byteOffset + (offset * this.BYTES_PER_ELEMENT); byteLength = array.length * this.BYTES_PER_ELEMENT; if (array.buffer === this.buffer) { tmp = []; for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) { tmp[i] = array.buffer._bytes[s]; } for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) { this.buffer._bytes[d] = tmp[i]; } } else { for (i = 0, s = array.byteOffset, d = byteOffset; i < byteLength; i += 1, s += 1, d += 1) { this.buffer._bytes[d] = array.buffer._bytes[s]; } } } else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') { // void set(sequence array, optional unsigned long offset); sequence = arguments[0]; len = ECMAScript.ToUint32(sequence.length); offset = ECMAScript.ToUint32(arguments[1]); if (offset + len > this.length) { throw new RangeError('Offset plus length of array is out of range'); } for (i = 0; i < len; i += 1) { s = sequence[i]; this._setter(offset + i, Number(s)); } } else { throw new TypeError('Unexpected argument type(s)'); } }; // TypedArray subarray(long begin, optional long end); ctor.prototype.subarray = function (start, end) { start = ECMAScript.ToInt32(start); end = ECMAScript.ToInt32(end); if (arguments.length < 1) { start = 0; } if (arguments.length < 2) { end = this.length; } if (start < 0) { start = this.length + start; } if (end < 0) { end = this.length + end; } start = clamp(start, 0, this.length); end = clamp(end, 0, this.length); var len = end - start; if (len < 0) { len = 0; } return new this.constructor(this.buffer, this.byteOffset + (start * this.BYTES_PER_ELEMENT), len); }; return ctor; } var Int8Array = makeConstructor(1, packI8, unpackI8); var Uint8Array = makeConstructor(1, packU8, unpackU8); var Uint8ClampedArray = makeConstructor(1, packU8Clamped, unpackU8); var Int16Array = makeConstructor(2, packI16, unpackI16); var Uint16Array = makeConstructor(2, packU16, unpackU16); var Int32Array = makeConstructor(4, packI32, unpackI32); var Uint32Array = makeConstructor(4, packU32, unpackU32); var Float32Array = makeConstructor(4, packF32, unpackF32); var Float64Array = makeConstructor(8, packF64, unpackF64); exports.Int8Array = exports.Int8Array || Int8Array; exports.Uint8Array = exports.Uint8Array || Uint8Array; exports.Uint8ClampedArray = exports.Uint8ClampedArray || Uint8ClampedArray; exports.Int16Array = exports.Int16Array || Int16Array; exports.Uint16Array = exports.Uint16Array || Uint16Array; exports.Int32Array = exports.Int32Array || Int32Array; exports.Uint32Array = exports.Uint32Array || Uint32Array; exports.Float32Array = exports.Float32Array || Float32Array; exports.Float64Array = exports.Float64Array || Float64Array; }()); // // 6 The DataView View Type // (function () { function r(array, index) { return ECMAScript.IsCallable(array.get) ? array.get(index) : array[index]; } var IS_BIG_ENDIAN = (function () { var u16array = new exports.Uint16Array([0x1234]), u8array = new exports.Uint8Array(u16array.buffer); return r(u8array, 0) === 0x12; }()); // Constructor(ArrayBuffer buffer, // optional unsigned long byteOffset, // optional unsigned long byteLength) /** @constructor */ function DataView(buffer, byteOffset, byteLength) { if (arguments.length === 0) { buffer = new exports.ArrayBuffer(0); } else if (!(buffer instanceof exports.ArrayBuffer || ECMAScript.Class(buffer) === 'ArrayBuffer')) { throw new TypeError('TypeError'); } this.buffer = buffer || new exports.ArrayBuffer(0); this.byteOffset = ECMAScript.ToUint32(byteOffset); if (this.byteOffset > this.buffer.byteLength) { throw new RangeError('byteOffset out of range'); } if (arguments.length < 3) { this.byteLength = this.buffer.byteLength - this.byteOffset; } else { this.byteLength = ECMAScript.ToUint32(byteLength); } if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) { throw new RangeError('byteOffset and length reference an area beyond the end of the buffer'); } configureProperties(this); } function makeGetter(arrayType) { return function (byteOffset, littleEndian) { byteOffset = ECMAScript.ToUint32(byteOffset); if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) { throw new RangeError('Array index out of range'); } byteOffset += this.byteOffset; var uint8Array = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT), bytes = [], i; for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) { bytes.push(r(uint8Array, i)); } if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) { bytes.reverse(); } return r(new arrayType(new exports.Uint8Array(bytes).buffer), 0); }; } DataView.prototype.getUint8 = makeGetter(exports.Uint8Array); DataView.prototype.getInt8 = makeGetter(exports.Int8Array); DataView.prototype.getUint16 = makeGetter(exports.Uint16Array); DataView.prototype.getInt16 = makeGetter(exports.Int16Array); DataView.prototype.getUint32 = makeGetter(exports.Uint32Array); DataView.prototype.getInt32 = makeGetter(exports.Int32Array); DataView.prototype.getFloat32 = makeGetter(exports.Float32Array); DataView.prototype.getFloat64 = makeGetter(exports.Float64Array); function makeSetter(arrayType) { return function (byteOffset, value, littleEndian) { byteOffset = ECMAScript.ToUint32(byteOffset); if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) { throw new RangeError('Array index out of range'); } // Get bytes var typeArray = new arrayType([value]), byteArray = new exports.Uint8Array(typeArray.buffer), bytes = [], i, byteView; for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) { bytes.push(r(byteArray, i)); } // Flip if necessary if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) { bytes.reverse(); } // Write them byteView = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT); byteView.set(bytes); }; } DataView.prototype.setUint8 = makeSetter(exports.Uint8Array); DataView.prototype.setInt8 = makeSetter(exports.Int8Array); DataView.prototype.setUint16 = makeSetter(exports.Uint16Array); DataView.prototype.setInt16 = makeSetter(exports.Int16Array); DataView.prototype.setUint32 = makeSetter(exports.Uint32Array); DataView.prototype.setInt32 = makeSetter(exports.Int32Array); DataView.prototype.setFloat32 = makeSetter(exports.Float32Array); DataView.prototype.setFloat64 = makeSetter(exports.Float64Array); exports.DataView = exports.DataView || DataView; }()); typedarray-0.0.7/package.json000066400000000000000000000040421432146633300161750ustar00rootroot00000000000000{ "name": "typedarray", "version": "0.0.7", "description": "TypedArray polyfill for old browsers", "main": "index.js", "devDependencies": { "@ljharb/eslint-config": "^21.0.0", "aud": "^2.0.1", "auto-changelog": "^2.4.0", "eslint": "=8.8.0", "in-publish": "^2.0.1", "npmignore": "^0.3.0", "safe-publish-latest": "^2.0.0", "tape": "^5.6.1" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "tests-only": "tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "aud --production", "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/typedarray.git" }, "homepage": "https://github.com/es-shims/typedarray", "keywords": [ "ArrayBuffer", "DataView", "Float32Array", "Float64Array", "Int8Array", "Int16Array", "Int32Array", "Uint8Array", "Uint8ClampedArray", "Uint16Array", "Uint32Array", "typed", "array", "polyfill" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "funding": { "url": "https://github.com/sponsors/ljharb" }, "license": "MIT", "testling": { "files": "test/*.js", "browsers": [ "ie/6..latest", "firefox/16..latest", "firefox/nightly", "chrome/22..latest", "chrome/canary", "opera/12..latest", "opera/next", "safari/5.1..latest", "ipad/6.0..latest", "iphone/6.0..latest", "android-browser/4.2..latest" ] }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "publishConfig": { "ignore": [ ".github/workflows" ] } } typedarray-0.0.7/test/000077500000000000000000000000001432146633300146665ustar00rootroot00000000000000typedarray-0.0.7/test/server/000077500000000000000000000000001432146633300161745ustar00rootroot00000000000000typedarray-0.0.7/test/server/undef_globals.js000066400000000000000000000006521432146633300213410ustar00rootroot00000000000000var test = require('tape'); var vm = require('vm'); var fs = require('fs'); var src = fs.readFileSync(__dirname + '/../../index.js', 'utf8'); test('u8a without globals', function (t) { var c = { module: { exports: {} } }; c.exports = c.module.exports; vm.runInNewContext(src, c); var TA = c.module.exports; var ua = new TA.Uint8Array(5); t.equal(ua.length, 5); ua[1] = 256 + 55; t.equal(ua[1], 55); t.end(); }); typedarray-0.0.7/test/tarray.js000066400000000000000000000003111432146633300165210ustar00rootroot00000000000000var TA = require('../'); var test = require('tape'); test('tiny u8a test', function (t) { var ua = new TA.Uint8Array(5); t.equal(ua.length, 5); ua[1] = 256 + 55; t.equal(ua[1], 55); t.end(); });