Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add primordials #530

Merged
merged 8 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/browser
/lib
/docs
/docs
/test
/tools
nightwatch.conf.js
rollup.config.js
45 changes: 45 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,51 @@
"indent": ["error", 2, { "SwitchCase": 1 }],
"no-debugger": "warn",
"no-undef": "error",
"no-restricted-globals": [
"error",
"Array",
"ArrayBuffer",
"BigInt",
"BigInt64Array",
"BigUint64Array",
"Boolean",
"DataView",
"Date",
"Error",
"EvalError",
"Float32Array",
"Float64Array",
"Function",
"Int16Array",
"Int32Array",
"Int8Array",
"isFinite",
"isNaN",
"JSON",
"Map",
"Math",
"Number",
"Object",
"Promise",
"RangeError",
"ReferenceError",
"Reflect",
"RegExp",
"Set",
"String",
"Symbol",
"SyntaxError",
"TypeError",
"URIError",
"Uint16Array",
"Uint32Array",
"Uint8Array",
"Uint8ClampedArray",
"WeakMap",
"WeakSet",
"parseFloat",
"parseInt"
],
"no-restricted-syntax": [
"error",
{
Expand Down
2 changes: 0 additions & 2 deletions nightwatch.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-env node */

"use strict";

const {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"docs:test": "mkdir -p docs/test && cp browser/float16.js docs/test/float16.js; yarn run docs:test:assets; yarn run docs:test:dependencies",
"docs:test:assets": "cp test/*.js docs/test && tools/power; cp test/browser/*.html docs/test",
"docs:test:dependencies": "cp node_modules/mocha/mocha.js node_modules/mocha/mocha.css node_modules/power-assert/build/power-assert.js docs/test",
"lint:eslint": "eslint *.js src/**/*.mjs test/**/*.js test/**/*.mjs",
"lint:eslint": "eslint src/**/*.mjs",
"lint:unused": "find-unused-exports --module-glob 'src/**/*.mjs'",
"prepublishOnly": "yarn run lint && yarn test",
"refresh": "yarn run clean && yarn run build && yarn run docs",
Expand Down
3 changes: 0 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-env node */
/* eslint-disable import/no-default-export */

import { execSync } from "child_process";

const name = process.env.npm_package_name;
Expand Down
26 changes: 14 additions & 12 deletions src/DataView.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { convertToNumber, roundToFloat16Bits } from "./_converter.mjs";
import { isDataView } from "./_util/is.mjs";
import { convertToNumber, roundToFloat16Bits } from "./_util/converter.mjs";
import {
DataViewPrototypeGetUint16,
DataViewPrototypeSetUint16,
} from "./_util/primordials.mjs";

/**
* returns an unsigned 16-bit float at the specified byte offset from the start of the DataView.
Expand All @@ -10,11 +13,9 @@ import { isDataView } from "./_util/is.mjs";
* @returns {number}
*/
export function getFloat16(dataView, byteOffset, ...opts) {
if (!isDataView(dataView)) {
throw new TypeError("First argument to getFloat16 must be a DataView");
}

return convertToNumber(dataView.getUint16(byteOffset, ...opts));
return convertToNumber(
DataViewPrototypeGetUint16(dataView, byteOffset, ...opts),
);
}

/**
Expand All @@ -26,9 +27,10 @@ export function getFloat16(dataView, byteOffset, ...opts) {
* @param {[boolean]} opts
*/
export function setFloat16(dataView, byteOffset, value, ...opts) {
if (!isDataView(dataView)) {
throw new TypeError("First argument to setFloat16 must be a DataView");
}

dataView.setUint16(byteOffset, roundToFloat16Bits(value), ...opts);
return DataViewPrototypeSetUint16(
dataView,
byteOffset,
roundToFloat16Bits(value),
...opts,
);
}
Loading