@petamoriken/float16
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1150,2 +1150,7 @@ (function (exports) { | ||
function isDefaultFloat16ArrayMethods(target) { | ||
return typeof target === "function" && defaultFloat16ArrayMethods.has(target); | ||
} | ||
function copyToArray(float16bits) { | ||
@@ -1166,4 +1171,6 @@ const length = float16bits.length; | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
let wrapper = null; | ||
if(!isTypedArrayIndexedPropertyWritable) { | ||
target = _(target).target; | ||
wrapper = target; | ||
target = _(wrapper).target; | ||
} | ||
@@ -1175,3 +1182,3 @@ | ||
} else { | ||
const ret = Reflect.get(target, key); | ||
const ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key); | ||
@@ -1187,7 +1194,7 @@ if(typeof ret !== "function") | ||
apply(func, thisArg, args) { | ||
if(!isFloat16Array(thisArg)) | ||
return Reflect.apply(func, thisArg, args); | ||
// peel off proxy | ||
if(isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func)) | ||
return Reflect.apply(func, _(thisArg).target, args); | ||
// peel off proxy | ||
return Reflect.apply(func, _(thisArg).target, args); | ||
return Reflect.apply(func, thisArg, args); | ||
} | ||
@@ -1202,7 +1209,20 @@ }); | ||
set(target, key, value) { | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
let wrapper = null; | ||
if(!isTypedArrayIndexedPropertyWritable) { | ||
wrapper = target; | ||
target = _(wrapper).target; | ||
} | ||
if(isNumberKey(key)) { | ||
Reflect.set(target, key, roundToFloat16Bits(value)); | ||
return Reflect.set(target, key, roundToFloat16Bits(value)); | ||
} else { | ||
Reflect.set(target, key, value); | ||
// frozen object can't change prototype property | ||
if(wrapper !== null && (!Reflect.has(target, key) || Object.isFrozen(wrapper))) { | ||
return Reflect.set(wrapper, key, value); | ||
} else { | ||
return Reflect.set(target, key, value); | ||
} | ||
} | ||
@@ -1213,11 +1233,21 @@ } | ||
if(!isTypedArrayIndexedPropertyWritable) { | ||
handler.getPrototypeOf = target => Reflect.getPrototypeOf( _(target).target ); | ||
handler.setPrototypeOf = (target, prototype) => Reflect.setPrototypeOf( _(target).target, prototype ); | ||
handler.isExtensible = target => Reflect.isExtensible( _(target).target ); | ||
handler.preventExtensions = target => Reflect.preventExtensions( _(target).target ); | ||
handler.getOwnPropertyDescriptor = (target, key) => Reflect.getOwnPropertyDescriptor( _(target).target, key ); | ||
handler.defineProperty = (target, key, descriptor) => Reflect.defineProperty( _(target).target, key, descriptor ); | ||
handler.deleteProperty = (target, key) => Reflect.deleteProperty( _(target).target, key ); | ||
handler.has = (target, key) => Reflect.has( _(target).target, key ); | ||
handler.ownKeys = target => Reflect.ownKeys( _(target).target ); | ||
handler.getPrototypeOf = wrapper => Reflect.getPrototypeOf( _(wrapper).target ); | ||
handler.setPrototypeOf = (wrapper, prototype) => Reflect.setPrototypeOf( _(wrapper).target, prototype ); | ||
handler.defineProperty = (wrapper, key, descriptor) => { | ||
const target = _(wrapper).target; | ||
return !Reflect.has(target, key) || Object.isFrozen(wrapper) ? Reflect.defineProperty( wrapper, key, descriptor ) : Reflect.defineProperty( target, key, descriptor ); | ||
}; | ||
handler.deleteProperty = (wrapper, key) => { | ||
const target = _(wrapper).target; | ||
return Reflect.has(wrapper, key) ? Reflect.deleteProperty( wrapper, key ) : Reflect.deleteProperty( target, key ); | ||
}; | ||
handler.has = (wrapper, key) => Reflect.has( wrapper, key ) || Reflect.has( _(wrapper).target, key ); | ||
handler.isExtensible = wrapper => Reflect.isExtensible( wrapper ); | ||
handler.preventExtensions = wrapper => Reflect.preventExtensions( wrapper ); | ||
handler.getOwnPropertyDescriptor = (wrapper, key) => Reflect.getOwnPropertyDescriptor( wrapper, key ); | ||
handler.ownKeys = wrapper => Reflect.ownKeys( wrapper ); | ||
} | ||
@@ -1311,3 +1341,5 @@ | ||
// keys | ||
keys() { | ||
return super.keys(); | ||
} | ||
@@ -1457,5 +1489,7 @@ * values() { | ||
// change element methods | ||
set(input, offset = 0) { | ||
set(input, ...opts) { | ||
assertFloat16Array(this); | ||
const offset = opts[0]; | ||
let float16bits; | ||
@@ -1651,8 +1685,2 @@ | ||
toString() { | ||
const array = copyToArray(this); | ||
return array.toString(); | ||
} | ||
get [Symbol.toStringTag]() { | ||
@@ -1665,2 +1693,11 @@ if(isFloat16Array(this)) | ||
const Float16Array$prototype = Float16Array.prototype; | ||
const defaultFloat16ArrayMethods = new WeakSet(); | ||
for(const key of Reflect.ownKeys(Float16Array$prototype)) { | ||
const val = Float16Array$prototype[key]; | ||
if(typeof val === "function") | ||
defaultFloat16ArrayMethods.add(val); | ||
} | ||
/** | ||
@@ -1667,0 +1704,0 @@ * returns an unsigned 16-bit float at the specified byte offset from the start of the DataView. |
@@ -39,2 +39,6 @@ "use strict"; | ||
function isDefaultFloat16ArrayMethods(target) { | ||
return typeof target === "function" && defaultFloat16ArrayMethods.has(target); | ||
} | ||
function copyToArray(float16bits) { | ||
@@ -55,4 +59,6 @@ const length = float16bits.length; | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
let wrapper = null; | ||
if (!isTypedArrayIndexedPropertyWritable) { | ||
target = _(target).target; | ||
wrapper = target; | ||
target = _(wrapper).target; | ||
} | ||
@@ -63,3 +69,3 @@ | ||
} else { | ||
const ret = Reflect.get(target, key); | ||
const ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key); | ||
@@ -74,6 +80,6 @@ if (typeof ret !== "function") return ret; | ||
apply(func, thisArg, args) { | ||
if (!isFloat16Array(thisArg)) return Reflect.apply(func, thisArg, args); | ||
// peel off proxy | ||
if (isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func)) return Reflect.apply(func, _(thisArg).target, args); | ||
// peel off proxy | ||
return Reflect.apply(func, _(thisArg).target, args); | ||
return Reflect.apply(func, thisArg, args); | ||
} | ||
@@ -88,6 +94,18 @@ }); | ||
set(target, key, value) { | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
let wrapper = null; | ||
if (!isTypedArrayIndexedPropertyWritable) { | ||
wrapper = target; | ||
target = _(wrapper).target; | ||
} | ||
if ((0, _is.isNumberKey)(key)) { | ||
Reflect.set(target, key, (0, _lib.roundToFloat16Bits)(value)); | ||
return Reflect.set(target, key, (0, _lib.roundToFloat16Bits)(value)); | ||
} else { | ||
Reflect.set(target, key, value); | ||
// frozen object can't change prototype property | ||
if (wrapper !== null && (!Reflect.has(target, key) || Object.isFrozen(wrapper))) { | ||
return Reflect.set(wrapper, key, value); | ||
} else { | ||
return Reflect.set(target, key, value); | ||
} | ||
} | ||
@@ -98,11 +116,21 @@ } | ||
if (!isTypedArrayIndexedPropertyWritable) { | ||
handler.getPrototypeOf = target => Reflect.getPrototypeOf(_(target).target); | ||
handler.setPrototypeOf = (target, prototype) => Reflect.setPrototypeOf(_(target).target, prototype); | ||
handler.isExtensible = target => Reflect.isExtensible(_(target).target); | ||
handler.preventExtensions = target => Reflect.preventExtensions(_(target).target); | ||
handler.getOwnPropertyDescriptor = (target, key) => Reflect.getOwnPropertyDescriptor(_(target).target, key); | ||
handler.defineProperty = (target, key, descriptor) => Reflect.defineProperty(_(target).target, key, descriptor); | ||
handler.deleteProperty = (target, key) => Reflect.deleteProperty(_(target).target, key); | ||
handler.has = (target, key) => Reflect.has(_(target).target, key); | ||
handler.ownKeys = target => Reflect.ownKeys(_(target).target); | ||
handler.getPrototypeOf = wrapper => Reflect.getPrototypeOf(_(wrapper).target); | ||
handler.setPrototypeOf = (wrapper, prototype) => Reflect.setPrototypeOf(_(wrapper).target, prototype); | ||
handler.defineProperty = (wrapper, key, descriptor) => { | ||
const target = _(wrapper).target; | ||
return !Reflect.has(target, key) || Object.isFrozen(wrapper) ? Reflect.defineProperty(wrapper, key, descriptor) : Reflect.defineProperty(target, key, descriptor); | ||
}; | ||
handler.deleteProperty = (wrapper, key) => { | ||
const target = _(wrapper).target; | ||
return Reflect.has(wrapper, key) ? Reflect.deleteProperty(wrapper, key) : Reflect.deleteProperty(target, key); | ||
}; | ||
handler.has = (wrapper, key) => Reflect.has(wrapper, key) || Reflect.has(_(wrapper).target, key); | ||
handler.isExtensible = wrapper => Reflect.isExtensible(wrapper); | ||
handler.preventExtensions = wrapper => Reflect.preventExtensions(wrapper); | ||
handler.getOwnPropertyDescriptor = (wrapper, key) => Reflect.getOwnPropertyDescriptor(wrapper, key); | ||
handler.ownKeys = wrapper => Reflect.ownKeys(wrapper); | ||
} | ||
@@ -223,3 +251,5 @@ | ||
// keys | ||
keys() { | ||
return super.keys(); | ||
} | ||
@@ -416,6 +446,6 @@ *values() { | ||
set(input) { | ||
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
assertFloat16Array(this); | ||
const offset = arguments.length <= 1 ? undefined : arguments[1]; | ||
let float16bits; | ||
@@ -613,8 +643,2 @@ | ||
toString() { | ||
const array = copyToArray(this); | ||
return array.toString(); | ||
} | ||
get [Symbol.toStringTag]() { | ||
@@ -625,3 +649,33 @@ if (isFloat16Array(this)) return "Float16Array"; | ||
} | ||
exports.default = Float16Array; | ||
const Float16Array$prototype = Float16Array.prototype; | ||
const defaultFloat16ArrayMethods = new WeakSet(); | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
try { | ||
for (var _iterator4 = Reflect.ownKeys(Float16Array$prototype)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
const key = _step4.value; | ||
const val = Float16Array$prototype[key]; | ||
if (typeof val === "function") defaultFloat16ArrayMethods.add(val); | ||
} | ||
} catch (err) { | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
} | ||
} | ||
} | ||
module.exports = exports["default"]; |
{ | ||
"name": "@petamoriken/float16", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "lib/index.js", | ||
"jsnext:main": "src/index.js", | ||
"author": "Kenta Moriuchi <moriken@kimamass.com> (https://moriken.kimamass.com)", | ||
"bugs": { | ||
"url": "https://github.com/petamoriken/float16/issues" | ||
}, | ||
"homepage": "https://github.com/petamoriken/float16", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/petamoriken/float16.git" | ||
}, | ||
"files": [ | ||
@@ -22,2 +30,10 @@ "package.json", | ||
], | ||
"keywords": [ | ||
"float16", | ||
"half-precision", | ||
"Float16Array", | ||
"TypedArray", | ||
"DataView", | ||
"hfround" | ||
], | ||
"scripts": { | ||
@@ -27,7 +43,14 @@ "build": "yarn run build:lib && yarn run build:browser", | ||
"build:browser": "rollup -c", | ||
"docs": "yarn run docs:test", | ||
"docs:test": "cp browser/float16.js docs/test/float16.js && yarn run docs:test:unit && yarn run docs:test:dependencies", | ||
"docs:test:unit": "cp test/*.js docs/test && yarn run docs:test:unit:power", | ||
"docs:test:unit:power": "find test/*.js -execdir bash -c \"eval espower test/{} | exorcist docs/test/power.{}.map > docs/test/power.{}\" \\;", | ||
"docs:test:dependencies": "cp $(npm root)/mocha/mocha.js $(npm root)/mocha/mocha.css $(npm root)/power-assert/build/power-assert.js docs/test", | ||
"lint": "eslint src", | ||
"test": "yarn run lint && yarn run test:lib", | ||
"test:lib": "mocha", | ||
"clean": "rm -rf lib browser", | ||
"prepublish": "yarn run clean && yarn run build && yarn test" | ||
"test:browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,safari,safari_el", | ||
"clean": "rm -rf lib browser docs/test/*.css docs/test/*.js docs/test/*.map", | ||
"refresh": "yarn run clean && yarn run build && yarn run docs", | ||
"prepublish": "in-publish && yarn run clean && yarn run build && yarn test || not-in-publish" | ||
}, | ||
@@ -42,7 +65,12 @@ "devDependencies": { | ||
"eslint": "^3.19.0", | ||
"espower-cli": "^1.1.0", | ||
"exorcist": "^0.4.0", | ||
"in-publish": "^2.0.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"mocha": "^3.3.0", | ||
"nightwatch": "^0.9.15", | ||
"power-assert": "^1.4.2", | ||
"rollup": "^0.41.6", | ||
"rollup-plugin-node-resolve": "^3.0.0" | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"saucelabs": "^1.4.0" | ||
}, | ||
@@ -49,0 +77,0 @@ "dependencies": { |
@@ -5,8 +5,25 @@ # float16 | ||
## support | ||
[![license](https://img.shields.io/npm/l/@petamoriken/float16.svg?style=flat-square)]() | ||
[![GitHub issues](https://img.shields.io/github/issues/petamoriken/float16.svg?style=flat-square)]() | ||
[![npm](https://img.shields.io/npm/v/@petamoriken/float16.svg?style=flat-square)]() | ||
[![npm downloads](https://img.shields.io/npm/dt/@petamoriken/float16.svg?style=flat-square)]() | ||
[![Travis](https://img.shields.io/travis/petamoriken/float16.svg?style=flat-square)]() | ||
[![dependencies Status](https://david-dm.org/petamoriken/float16/status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16) | ||
[![devDependencies Status](https://david-dm.org/petamoriken/float16/dev-status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16?type=dev) | ||
Latest 2 versions of modern browser (Chrome, Firefox, Safari, Edge, Opera) and Node v7. | ||
## Supports (at least) | ||
Last 2 versions of modern browser (Chrome, Firefox) and latest version of default browser on Windows 10 or macOS (Edge, Safari) and Node latest. | ||
* Chrome: Last 2 versions | ||
* Firefox: Last 2 versions and ESR | ||
* Edge: Latest version | ||
* Safari: Latest version | ||
* Node.js: Latest version | ||
This library's `Float16Array` uses `Proxy`, so IE11 is never supported. | ||
## install | ||
## Install | ||
@@ -23,7 +40,7 @@ ```bash | ||
## require | ||
## Require | ||
```js | ||
// ES6 Modules | ||
import { hfround, Float16Array, getFloat16, setFloat16 } from "@petamoriken/float16"; | ||
import { Float16Array, getFloat16, setFloat16, hfround } from "@petamoriken/float16"; | ||
``` | ||
@@ -35,3 +52,3 @@ | ||
// CommonJS | ||
const { hfround, Float16Array, getFloat16, setFloat16 } = require("@petamoriken/float16"); | ||
const { Float16Array, getFloat16, setFloat16, hfround } = require("@petamoriken/float16"); | ||
``` | ||
@@ -43,41 +60,43 @@ | ||
This API is similar to `TypedArray` such as `Float32Array`. | ||
This API is similar to `TypedArray` such as `Float32Array`. | ||
```js | ||
let float16 = new Float16Array([1.0, 1.1, 1.2]); | ||
for(const val of float16) { | ||
console.log(val); // => 1, 1.099609375, 1.19921875 | ||
} | ||
``` | ||
```js | ||
let float16 = new Float16Array([1.0, 1.1, 1.2]); | ||
for(const val of float16) { | ||
console.log(val); // => 1, 1.099609375, 1.19921875 | ||
} | ||
float16.reduce((prev, current) => prev + current); // 3.298828125 | ||
``` | ||
* `getFloat16(view: DataView, byteOffset: number [, littleEndian: boolean])` | ||
* `setFloat16(view: DataView, byteOffset: number, value: number [, littleEndian: boolean])` | ||
This API is similar to `DataView` methods such as `DataView#getFloat32`. | ||
These APIs are similar to `DataView` methods such as `DataView#getFloat32` and `DataView#setFloat32`. | ||
```js | ||
let buffer = new ArrayBuffer(10); | ||
let view = new DataView(buffer); | ||
```js | ||
let buffer = new ArrayBuffer(10); | ||
let view = new DataView(buffer); | ||
view.setUint16(0, 0x1234); | ||
getFloat16(view, 0); // 0.0007572174072265625 | ||
view.setUint16(0, 0x1234); | ||
getFloat16(view, 0); // 0.0007572174072265625 | ||
// You can append DataView methods | ||
view.getFloat16 = getFloat16.bind(null, view); | ||
view.setFloat16 = setFloat16.bind(null, view); | ||
// You can append to DataView instance | ||
view.getFloat16 = getFloat16.bind(null, view); | ||
view.setFloat16 = setFloat16.bind(null, view); | ||
view.getFloat16(0); // 0.0007572174072265625 | ||
view.getFloat16(0); // 0.0007572174072265625 | ||
view.setFloat16(0, Math.PI); | ||
view.getFloat16(0); // 3.140625 | ||
``` | ||
view.setFloat16(0, Math.PI, true); | ||
view.getFloat16(0, true); // 3.140625 | ||
``` | ||
* hfround | ||
* `hfround(x: number)` | ||
This API is similar to `Math.frond` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)). | ||
This function returns nearest half precision float representation of a number. | ||
This API is similar to `Math.fround` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)). | ||
This function returns nearest half precision float representation of a number. | ||
```js | ||
Math.frond(1.337); // 1.3370000123977661 | ||
hfround(1.337); // 1.3369140625 | ||
``` | ||
```js | ||
Math.fround(1.337); // 1.3370000123977661 | ||
hfround(1.337); // 1.3369140625 | ||
``` |
@@ -27,2 +27,7 @@ "use strict"; | ||
function isDefaultFloat16ArrayMethods(target) { | ||
return typeof target === "function" && defaultFloat16ArrayMethods.has(target); | ||
} | ||
function copyToArray(float16bits) { | ||
@@ -43,4 +48,6 @@ const length = float16bits.length; | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
let wrapper = null; | ||
if(!isTypedArrayIndexedPropertyWritable) { | ||
target = _(target).target; | ||
wrapper = target; | ||
target = _(wrapper).target; | ||
} | ||
@@ -52,3 +59,3 @@ | ||
} else { | ||
const ret = Reflect.get(target, key); | ||
const ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key); | ||
@@ -64,7 +71,7 @@ if(typeof ret !== "function") | ||
apply(func, thisArg, args) { | ||
if(!isFloat16Array(thisArg)) | ||
return Reflect.apply(func, thisArg, args); | ||
// peel off proxy | ||
if(isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func)) | ||
return Reflect.apply(func, _(thisArg).target, args); | ||
// peel off proxy | ||
return Reflect.apply(func, _(thisArg).target, args); | ||
return Reflect.apply(func, thisArg, args); | ||
} | ||
@@ -79,7 +86,20 @@ }); | ||
set(target, key, value) { | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
let wrapper = null; | ||
if(!isTypedArrayIndexedPropertyWritable) { | ||
wrapper = target; | ||
target = _(wrapper).target; | ||
} | ||
if(isNumberKey(key)) { | ||
Reflect.set(target, key, roundToFloat16Bits(value)); | ||
return Reflect.set(target, key, roundToFloat16Bits(value)); | ||
} else { | ||
Reflect.set(target, key, value); | ||
// frozen object can't change prototype property | ||
if(wrapper !== null && (!Reflect.has(target, key) || Object.isFrozen(wrapper))) { | ||
return Reflect.set(wrapper, key, value); | ||
} else { | ||
return Reflect.set(target, key, value); | ||
} | ||
} | ||
@@ -90,11 +110,21 @@ } | ||
if(!isTypedArrayIndexedPropertyWritable) { | ||
handler.getPrototypeOf = target => Reflect.getPrototypeOf( _(target).target ); | ||
handler.setPrototypeOf = (target, prototype) => Reflect.setPrototypeOf( _(target).target, prototype ); | ||
handler.isExtensible = target => Reflect.isExtensible( _(target).target ); | ||
handler.preventExtensions = target => Reflect.preventExtensions( _(target).target ); | ||
handler.getOwnPropertyDescriptor = (target, key) => Reflect.getOwnPropertyDescriptor( _(target).target, key ); | ||
handler.defineProperty = (target, key, descriptor) => Reflect.defineProperty( _(target).target, key, descriptor ); | ||
handler.deleteProperty = (target, key) => Reflect.deleteProperty( _(target).target, key ); | ||
handler.has = (target, key) => Reflect.has( _(target).target, key ); | ||
handler.ownKeys = target => Reflect.ownKeys( _(target).target ); | ||
handler.getPrototypeOf = wrapper => Reflect.getPrototypeOf( _(wrapper).target ); | ||
handler.setPrototypeOf = (wrapper, prototype) => Reflect.setPrototypeOf( _(wrapper).target, prototype ); | ||
handler.defineProperty = (wrapper, key, descriptor) => { | ||
const target = _(wrapper).target; | ||
return !Reflect.has(target, key) || Object.isFrozen(wrapper) ? Reflect.defineProperty( wrapper, key, descriptor ) : Reflect.defineProperty( target, key, descriptor ); | ||
}; | ||
handler.deleteProperty = (wrapper, key) => { | ||
const target = _(wrapper).target; | ||
return Reflect.has(wrapper, key) ? Reflect.deleteProperty( wrapper, key ) : Reflect.deleteProperty( target, key ); | ||
}; | ||
handler.has = (wrapper, key) => Reflect.has( wrapper, key ) || Reflect.has( _(wrapper).target, key ); | ||
handler.isExtensible = wrapper => Reflect.isExtensible( wrapper ); | ||
handler.preventExtensions = wrapper => Reflect.preventExtensions( wrapper ); | ||
handler.getOwnPropertyDescriptor = (wrapper, key) => Reflect.getOwnPropertyDescriptor( wrapper, key ); | ||
handler.ownKeys = wrapper => Reflect.ownKeys( wrapper ); | ||
} | ||
@@ -188,3 +218,5 @@ | ||
// keys | ||
keys() { | ||
return super.keys(); | ||
} | ||
@@ -334,5 +366,7 @@ * values() { | ||
// change element methods | ||
set(input, offset = 0) { | ||
set(input, ...opts) { | ||
assertFloat16Array(this); | ||
const offset = opts[0]; | ||
let float16bits; | ||
@@ -528,8 +562,2 @@ | ||
toString() { | ||
const array = copyToArray(this); | ||
return array.toString(); | ||
} | ||
get [Symbol.toStringTag]() { | ||
@@ -540,2 +568,11 @@ if(isFloat16Array(this)) | ||
} | ||
const Float16Array$prototype = Float16Array.prototype; | ||
const defaultFloat16ArrayMethods = new WeakSet(); | ||
for(const key of Reflect.ownKeys(Float16Array$prototype)) { | ||
const val = Float16Array$prototype[key]; | ||
if(typeof val === "function") | ||
defaultFloat16ArrayMethods.add(val); | ||
} |
(function() { | ||
const isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable; | ||
function isPlusZero(num) { | ||
@@ -146,5 +148,49 @@ return num === 0 && 1 / num === Infinity; | ||
it("prototype methods are same as themselves", () => { | ||
it("can't be frozen with elements", function() { | ||
assert.doesNotThrow(() => Object.freeze( new Float16Array() )); | ||
if(!isTypedArrayIndexedPropertyWritable) | ||
this.skip(); | ||
assert.throws(() => Object.freeze( new Float16Array(10) ), TypeError); | ||
}); | ||
it("can't change property & prototype property if it frozen", function() { | ||
// "use strict"; | ||
const float16 = new Float16Array(); | ||
float16.hoge = "hoge"; | ||
assert( float16.hoge === "hoge" ); | ||
Object.freeze( float16 ); | ||
// JavaScriptCore bug | ||
// assert.throws(() => float16.fuga = "fuga", TypeError); | ||
// assert.throws(() => float16.map = "map", TypeError); | ||
float16.fuga = "fuga"; | ||
assert( float16.fuga === undefined ); | ||
float16.map = "map"; | ||
assert( typeof float16.map === "function" ); | ||
}); | ||
it("append custom methods (not using `super`)", () => { | ||
const float16 = new Float16Array([1, 2, 3]); | ||
float16.sum = function() { | ||
let ret = 0; | ||
for(let i = 0, l = this.length; i < l; ++i) { | ||
ret += this[i]; | ||
} | ||
return ret; | ||
}; | ||
assert( float16.sum() === 6 ); | ||
}); | ||
it("prototype methods are as same as themselves", () => { | ||
const float16 = new Float16Array(); | ||
assert( float16.map === float16.map ); | ||
@@ -947,2 +993,14 @@ }); | ||
it("call Array#toString by Float16Array", () => { | ||
const float16 = new Float16Array([1, 2, 3]); | ||
assert( Array.prototype.toString.call(float16) === "1,2,3" ); | ||
}); | ||
it("call Float16Array#toString by Array", () => { | ||
const array = [1, 2, 3]; | ||
assert( Float16Array.prototype.toString.call(array) === "1,2,3" ); | ||
}); | ||
}); | ||
@@ -949,0 +1007,0 @@ |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
252800
3690
0
1
98
0
17