Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@petamoriken/float16

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@petamoriken/float16 - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

lib/bug.js

25

browser/float16.js

@@ -1135,7 +1135,14 @@ (function (exports) {

// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
const isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable;
// Chakra bug: https://github.com/Microsoft/ChakraCore/issues/1662
const proxy = new Proxy({}, {});
const isProxyEnableToBeWeakMapKey = new WeakMap().set(proxy, 1).get(proxy) === 1;
const _ = createPrivateStorage();
const __target__ = Symbol("target");
function isFloat16Array(target) {

@@ -1170,3 +1177,2 @@ return target instanceof Float16Array;

get(target, key) {
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
let wrapper = null;

@@ -1186,3 +1192,3 @@ if(!isTypedArrayIndexedPropertyWritable) {

return ret;
// TypedArray methods can't be called by Proxy

@@ -1194,5 +1200,6 @@ let proxy = _(ret).proxy;

apply(func, thisArg, args) {
// peel off proxy
if(isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func))
return Reflect.apply(func, _(thisArg).target, args);
return Reflect.apply(func, isProxyEnableToBeWeakMapKey ? _(thisArg).target : thisArg[__target__], args);

@@ -1209,3 +1216,2 @@ return Reflect.apply(func, thisArg, args);

set(target, key, value) {
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
let wrapper = null;

@@ -1261,3 +1267,3 @@ if(!isTypedArrayIndexedPropertyWritable) {

if(isFloat16Array(input)) {
super(_(input).target);
super(isProxyEnableToBeWeakMapKey ? _(input).target : input[__target__]);

@@ -1299,3 +1305,2 @@ // 22.2.1.3, 22.2.1.4 TypedArray, Array, ArrayLike, Iterable

// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
if(isTypedArrayIndexedPropertyWritable) {

@@ -1310,3 +1315,7 @@ proxy = new Proxy(this, handler);

// proxy private storage
_(proxy).target = this;
if(isProxyEnableToBeWeakMapKey) {
_(proxy).target = this;
} else {
this[__target__] = this;
}

@@ -1499,3 +1508,3 @@ // this private storage

if(isFloat16Array(input)) {
float16bits = _(input).target;
float16bits = isProxyEnableToBeWeakMapKey ? _(input).target : input[__target__];

@@ -1502,0 +1511,0 @@ // input others

@@ -23,8 +23,10 @@ "use strict";

var _bug = require("./bug");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable;
const _ = (0, _private.createPrivateStorage)();
const __target__ = Symbol("target");
function isFloat16Array(target) {

@@ -58,5 +60,4 @@ return target instanceof Float16Array;

get(target, key) {
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
let wrapper = null;
if (!isTypedArrayIndexedPropertyWritable) {
if (!_bug.isTypedArrayIndexedPropertyWritable) {
wrapper = target;

@@ -79,4 +80,5 @@ target = _(wrapper).target;

apply(func, thisArg, args) {
// peel off proxy
if (isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func)) return Reflect.apply(func, _(thisArg).target, args);
if (isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func)) return Reflect.apply(func, _bug.isProxyEnableToBeWeakMapKey ? _(thisArg).target : thisArg[__target__], args);

@@ -93,5 +95,4 @@ return Reflect.apply(func, thisArg, args);

set(target, key, value) {
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
let wrapper = null;
if (!isTypedArrayIndexedPropertyWritable) {
if (!_bug.isTypedArrayIndexedPropertyWritable) {
wrapper = target;

@@ -114,3 +115,3 @@ target = _(wrapper).target;

if (!isTypedArrayIndexedPropertyWritable) {
if (!_bug.isTypedArrayIndexedPropertyWritable) {
handler.getPrototypeOf = wrapper => Reflect.getPrototypeOf(_(wrapper).target);

@@ -143,3 +144,3 @@ handler.setPrototypeOf = (wrapper, prototype) => Reflect.setPrototypeOf(_(wrapper).target, prototype);

if (isFloat16Array(input)) {
super(_(input).target);
super(_bug.isProxyEnableToBeWeakMapKey ? _(input).target : input[__target__]);

@@ -181,4 +182,3 @@ // 22.2.1.3, 22.2.1.4 TypedArray, Array, ArrayLike, Iterable

// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
if (isTypedArrayIndexedPropertyWritable) {
if (_bug.isTypedArrayIndexedPropertyWritable) {
proxy = new Proxy(this, handler);

@@ -192,3 +192,7 @@ } else {

// proxy private storage
_(proxy).target = this;
if (_bug.isProxyEnableToBeWeakMapKey) {
_(proxy).target = this;
} else {
this[__target__] = this;
}

@@ -455,3 +459,3 @@ // this private storage

if (isFloat16Array(input)) {
float16bits = _(input).target;
float16bits = _bug.isProxyEnableToBeWeakMapKey ? _(input).target : input[__target__];

@@ -458,0 +462,0 @@ // input others

{
"name": "@petamoriken/float16",
"version": "0.0.2",
"description": "half precision floating point for JavaScript",
"version": "1.0.0",
"main": "lib/index.js",

@@ -35,2 +36,4 @@ "jsnext:main": "src/index.js",

"TypedArray",
"getFloat16",
"setFloat16",
"DataView",

@@ -51,3 +54,3 @@ "hfround"

"test:lib": "mocha",
"test:browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,safari,safari_el",
"test:browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,edge,safari,safari_el",
"clean": "rm -rf lib browser docs/test/*.css docs/test/*.js docs/test/*.map",

@@ -54,0 +57,0 @@ "refresh": "yarn run clean && yarn run build && yarn run docs",

@@ -5,7 +5,7 @@ # float16

[![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)]()
[![license](https://img.shields.io/npm/l/@petamoriken/float16.svg?style=flat-square)](https://github.com/petamoriken/float16/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/petamoriken/float16.svg?style=flat-square)](https://github.com/petamoriken/float16/issues)
[![npm](https://img.shields.io/npm/v/@petamoriken/float16.svg?style=flat-square)](https://www.npmjs.com/package/@petamoriken/float16)
[![npm downloads](https://img.shields.io/npm/dt/@petamoriken/float16.svg?style=flat-square)](https://www.npmjs.com/package/@petamoriken/float16)
[![Travis](https://img.shields.io/travis/petamoriken/float16.svg?style=flat-square)](https://travis-ci.org/petamoriken/float16)
[![dependencies Status](https://david-dm.org/petamoriken/float16/status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16)

@@ -30,3 +30,3 @@ [![devDependencies Status](https://david-dm.org/petamoriken/float16/dev-status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16?type=dev)

```bash
```console
yarn add @petamoriken/float16

@@ -37,3 +37,3 @@ ```

```bash
```console
npm install @petamoriken/float16 --save

@@ -101,2 +101,31 @@ ```

hfround(1.337); // 1.3369140625
```
```
## Test
First, download devDependencies.
```console
yarn
```
### Node.js Test
```console
yarn test
```
### Browser Test
Export your Sauce Labs environment variable.
```console
export SAUCE_USERNAME=<your Sauce Labs username>
export SAUCE_ACCESS_KEY=<your Sauce Labs access key>
```
Finally, exec below.
```console
yarn run test:browser
```

@@ -11,8 +11,10 @@ "use strict";

import { isTypedArrayIndexedPropertyWritable, isProxyEnableToBeWeakMapKey } from "./bug";
const isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable;
const _ = createPrivateStorage();
const __target__ = Symbol("target");
function isFloat16Array(target) {

@@ -47,3 +49,2 @@ return target instanceof Float16Array;

get(target, key) {
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
let wrapper = null;

@@ -63,3 +64,3 @@ if(!isTypedArrayIndexedPropertyWritable) {

return ret;
// TypedArray methods can't be called by Proxy

@@ -71,5 +72,6 @@ let proxy = _(ret).proxy;

apply(func, thisArg, args) {
// peel off proxy
if(isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func))
return Reflect.apply(func, _(thisArg).target, args);
return Reflect.apply(func, isProxyEnableToBeWeakMapKey ? _(thisArg).target : thisArg[__target__], args);

@@ -86,3 +88,2 @@ return Reflect.apply(func, thisArg, args);

set(target, key, value) {
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
let wrapper = null;

@@ -138,3 +139,3 @@ if(!isTypedArrayIndexedPropertyWritable) {

if(isFloat16Array(input)) {
super(_(input).target);
super(isProxyEnableToBeWeakMapKey ? _(input).target : input[__target__]);

@@ -176,3 +177,2 @@ // 22.2.1.3, 22.2.1.4 TypedArray, Array, ArrayLike, Iterable

// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
if(isTypedArrayIndexedPropertyWritable) {

@@ -187,3 +187,7 @@ proxy = new Proxy(this, handler);

// proxy private storage
_(proxy).target = this;
if(isProxyEnableToBeWeakMapKey) {
_(proxy).target = this;
} else {
this[__target__] = this;
}

@@ -376,3 +380,3 @@ // this private storage

if(isFloat16Array(input)) {
float16bits = _(input).target;
float16bits = isProxyEnableToBeWeakMapKey ? _(input).target : input[__target__];

@@ -379,0 +383,0 @@ // input others

(function() {
const isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable;
const isProxyEnableToBeWeakMapKey = (function() {
const proxy = new Proxy({}, {});
return new WeakMap().set(proxy, 1).get(proxy) === 1;
})();

@@ -178,2 +182,10 @@ function isPlusZero(num) {

it("check ownKeys", function() {
if(!isTypedArrayIndexedPropertyWritable || !isProxyEnableToBeWeakMapKey)
this.skip();
const float16 = new Float16Array([1, 2]);
deepEqualArray( Reflect.ownKeys(float16), ["0", "1"] );
});
it("append custom methods (not using `super`)", () => {

@@ -195,3 +207,2 @@ const float16 = new Float16Array([1, 2, 3]);

const float16 = new Float16Array();
assert( float16.map === float16.map );

@@ -295,3 +306,2 @@ });

const float16 = new Float16Array();
assert( float16[Symbol.toStringTag] === "Float16Array" );

@@ -467,3 +477,2 @@ });

const val = float16.reduce((prev, current) => prev + current, "");
assert( val === "123" );

@@ -511,3 +520,2 @@ });

const val = float16.reduceRight((prev, current) => prev + current, "");
assert( val === "321" );

@@ -731,4 +739,4 @@ });

assert.throws(() => float16.set(array, -1), Error); // V8 bug: RangeError by spec but throws TypeError
assert.throws(() => float16.set(array, 4), RangeError);
assert.throws(() => float16.set(array, -1), Error); // RangeError, V8 bug: throws TypeError
assert.throws(() => float16.set(array, 4), Error); // RangeError, Chakra bug: throws TypeError
});

@@ -976,3 +984,2 @@

const float16 = new Float16Array([1, 2, 3]);
assert( float16.toLocaleString() === [1, 2, 3].toLocaleString() );

@@ -995,3 +1002,2 @@ });

const float16 = new Float16Array([1, 2, 3]);
assert( float16.toString() === "1,2,3" );

@@ -1002,3 +1008,2 @@ });

const float16 = new Float16Array([1, 2, 3]);
assert( Array.prototype.toString.call(float16) === "1,2,3" );

@@ -1009,3 +1014,2 @@ });

const array = [1, 2, 3];
assert( Float16Array.prototype.toString.call(array) === "1,2,3" );

@@ -1012,0 +1016,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc