@petamoriken/float16
Advanced tools
Comparing version 3.5.5 to 3.5.6
@@ -1,2 +0,2 @@ | ||
/*! @petamoriken/float16 v3.5.5 | MIT License - https://git.io/float16 */ | ||
/*! @petamoriken/float16 v3.5.6 | MIT License - https://git.io/float16 */ | ||
@@ -58,15 +58,2 @@ const float16 = (function (exports) { | ||
// Array | ||
const NativeArray = Array; | ||
const ArrayIsArray = NativeArray.isArray; | ||
const ArrayPrototype = NativeArray.prototype; | ||
/** @type {(array: Array<unknown>, separator?: string) => string} */ | ||
const ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join); | ||
/** @type {<T>(array: Array<T>, ...items: T[]) => number} */ | ||
const ArrayPrototypePush = uncurryThis(ArrayPrototype.push); | ||
/** @type {(array: Array<unknown>) => string} */ | ||
const ArrayPrototypeToLocaleString = uncurryThis( | ||
ArrayPrototype.toLocaleString | ||
); | ||
// Object | ||
@@ -84,2 +71,18 @@ const NativeObject = Object; | ||
// Array | ||
const NativeArray = Array; | ||
const ArrayIsArray = NativeArray.isArray; | ||
const ArrayPrototype = NativeArray.prototype; | ||
/** @type {(array: ArrayLike<unknown>, separator?: string) => string} */ | ||
const ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join); | ||
/** @type {<T>(array: T[], ...items: T[]) => number} */ | ||
const ArrayPrototypePush = uncurryThis(ArrayPrototype.push); | ||
/** @type {(array: ArrayLike<unknown>) => string} */ | ||
const ArrayPrototypeToLocaleString = uncurryThis( | ||
ArrayPrototype.toLocaleString | ||
); | ||
const NativeArrayPrototypeSymbolIterator = ArrayPrototype[SymbolIterator]; | ||
/** @type {<T>(array: T[]) => IterableIterator<T>} */ | ||
const ArrayPrototypeSymbolIterator = uncurryThis(NativeArrayPrototypeSymbolIterator); | ||
// Math | ||
@@ -175,6 +178,7 @@ const MathTrunc = Math.trunc; | ||
// Iterator | ||
const IteratorPrototype = ReflectGetPrototypeOf( | ||
ReflectGetPrototypeOf([][SymbolIterator]()) | ||
); | ||
// ArrayIterator | ||
/** @type {any} */ | ||
const ArrayIteratorPrototype = ReflectGetPrototypeOf([][SymbolIterator]()); | ||
/** @type {<T>(arrayIterator: IterableIterator<T>) => IteratorResult<T>} */ | ||
const ArrayIteratorPrototypeNext = uncurryThis(ArrayIteratorPrototype.next); | ||
@@ -185,2 +189,5 @@ // Generator | ||
// Iterator | ||
const IteratorPrototype = ReflectGetPrototypeOf(ArrayIteratorPrototype); | ||
// DataView | ||
@@ -391,2 +398,26 @@ const DataViewPrototype = DataView.prototype; | ||
/** | ||
* Wrap ArrayIterator If Array.prototype [@@iterator] has been modified | ||
* | ||
* @type {<T>(array: T[]) => Iterable<T>} | ||
*/ | ||
function toSafe(array) { | ||
if (array[SymbolIterator] === NativeArrayPrototypeSymbolIterator) { | ||
return array; | ||
} | ||
const arrayIterator = ArrayPrototypeSymbolIterator(array); | ||
return ObjectFreeze(/** @type {any} */ ({ | ||
next() { | ||
return ArrayIteratorPrototypeNext(arrayIterator); | ||
}, | ||
return: undefined, | ||
throw: undefined, | ||
[SymbolIterator]() { | ||
return this; | ||
}, | ||
})); | ||
} | ||
/** @type {WeakMap<{}, Generator<any>>} */ | ||
@@ -396,3 +427,3 @@ const generators = new NativeWeakMap(); | ||
/** @see https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object */ | ||
const ArrayIteratorPrototype = ObjectCreate(IteratorPrototype, { | ||
const DummyArrayIteratorPrototype = ObjectCreate(IteratorPrototype, { | ||
next: { | ||
@@ -414,6 +445,6 @@ value: function next() { | ||
/** @type {<T>(generator: Generator<T>) => IterableIterator<T>} */ | ||
function wrapInArrayIterator(generator) { | ||
const arrayIterator = ObjectCreate(ArrayIteratorPrototype); | ||
WeakMapPrototypeSet(generators, arrayIterator, generator); | ||
return arrayIterator; | ||
function wrapGenerator(generator) { | ||
const dummy = ObjectCreate(DummyArrayIteratorPrototype); | ||
WeakMapPrototypeSet(generators, dummy, generator); | ||
return dummy; | ||
} | ||
@@ -740,3 +771,3 @@ | ||
return WeakMapPrototypeHas(float16bitsArrays, target) || | ||
(hasFloat16ArrayBrand(target) && !ArrayBufferIsView(target)); | ||
(!ArrayBufferIsView(target) && hasFloat16ArrayBrand(target)); | ||
} | ||
@@ -905,3 +936,2 @@ | ||
if (isFloat16Array(input)) { | ||
// peel off Proxy | ||
float16bitsArray = ReflectConstruct(NativeUint16Array, [getFloat16BitsArray(input)], new.target); | ||
@@ -945,2 +975,3 @@ } else if (isObject(input) && !isArrayBuffer(input)) { // object without ArrayBuffer | ||
} else { | ||
// eslint-disable-next-line no-restricted-syntax | ||
list = [...input]; | ||
@@ -1015,3 +1046,3 @@ length = list.length; | ||
return roundToFloat16Bits( | ||
ReflectApply(mapFunc, this, [val, ...args]) | ||
ReflectApply(mapFunc, this, [val, ...toSafe(args)]) | ||
); | ||
@@ -1037,2 +1068,3 @@ }, thisArg) | ||
} else { | ||
// eslint-disable-next-line no-restricted-syntax | ||
list = [...src]; | ||
@@ -1117,3 +1149,4 @@ length = list.length; | ||
return wrapInArrayIterator((function* () { | ||
return wrapGenerator((function* () { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const val of TypedArrayPrototypeValues(float16bitsArray)) { | ||
@@ -1134,7 +1167,8 @@ yield convertToNumber(val); | ||
return (wrapInArrayIterator((function* () { | ||
return wrapGenerator((function* () { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const [i, val] of TypedArrayPrototypeEntries(float16bitsArray)) { | ||
yield /** @type {[Number, number]} */ ([i, convertToNumber(val)]); | ||
} | ||
})())); | ||
})()); | ||
} | ||
@@ -1481,3 +1515,3 @@ | ||
roundToFloat16Bits(value), | ||
...opts | ||
...toSafe(opts) | ||
); | ||
@@ -1493,3 +1527,3 @@ | ||
TypedArrayPrototypeCopyWithin(float16bitsArray, target, start, ...opts); | ||
TypedArrayPrototypeCopyWithin(float16bitsArray, target, start, ...toSafe(opts)); | ||
@@ -1528,3 +1562,3 @@ return this; | ||
TypedArrayPrototypeGetBuffer( | ||
TypedArrayPrototypeSlice(uint16, ...opts) | ||
TypedArrayPrototypeSlice(uint16, ...toSafe(opts)) | ||
) | ||
@@ -1591,3 +1625,3 @@ ); | ||
); | ||
const uint16Subarray = TypedArrayPrototypeSubarray(uint16, ...opts); | ||
const uint16Subarray = TypedArrayPrototypeSubarray(uint16, ...toSafe(opts)); | ||
@@ -1707,3 +1741,3 @@ const array = new Constructor( | ||
return ArrayPrototypeJoin(array, ...opts); | ||
return ArrayPrototypeJoin(array, ...toSafe(opts)); | ||
} | ||
@@ -1719,3 +1753,3 @@ | ||
// @ts-ignore | ||
return ArrayPrototypeToLocaleString(array, ...opts); | ||
return ArrayPrototypeToLocaleString(array, ...toSafe(opts)); | ||
} | ||
@@ -1769,3 +1803,3 @@ | ||
return convertToNumber( | ||
DataViewPrototypeGetUint16(dataView, byteOffset, ...opts) | ||
DataViewPrototypeGetUint16(dataView, byteOffset, ...toSafe(opts)) | ||
); | ||
@@ -1787,3 +1821,3 @@ } | ||
roundToFloat16Bits(value), | ||
...opts | ||
...toSafe(opts) | ||
); | ||
@@ -1790,0 +1824,0 @@ } |
{ | ||
"name": "@petamoriken/float16", | ||
"version": "3.5.5", | ||
"version": "3.5.6", | ||
"description": "IEEE 754 half-precision floating-point for JavaScript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254711
6654