From 75c2c19da0babfd7925b2bdd37d5e0c573e4152f Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 2 Jan 2026 22:12:56 +0900 Subject: [PATCH] Remove most typedefs These are no longer used by jsdom/webidl2js, and are conceptually a bit unclean to keep around. ArrayBufferView remains since webidl2js still uses it for a special-case shortcut. --- README.md | 10 ++++----- lib/index.js | 20 ------------------ test/buffer-source.js | 46 ------------------------------------------ test/dom-time-stamp.js | 13 ------------ 4 files changed, 4 insertions(+), 85 deletions(-) delete mode 100644 test/dom-time-stamp.js diff --git a/README.md b/README.md index 17342a8..51b197d 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,11 @@ Conversions for all of the basic types from the Web IDL specification are implem - [`object`](https://webidl.spec.whatwg.org/#js-object) - [Buffer source types](https://webidl.spec.whatwg.org/#js-buffer-source-types), some of which can additionally be provided with the boolean options `{ allowShared, allowResizable }` as a second parameter -Additionally, for convenience, the following derived type definitions are implemented: +Additionally, for convenience, the following derived type definition is implemented: - [`ArrayBufferView`](https://webidl.spec.whatwg.org/#ArrayBufferView), which can additionally be provided with the boolean options `{ allowShared, allowResizable }` as a second parameter -- [`BufferSource`](https://webidl.spec.whatwg.org/#BufferSource) -- [`DOMTimeStamp`](https://webidl.spec.whatwg.org/#DOMTimeStamp) -Derived types, such as nullable types, promise types, sequences, records, etc. are not handled by this library. You may wish to investigate the [webidl2js](https://github.com/jsdom/webidl2js) project. +Other derived types, such as nullable types, promise types, sequences, records, etc. are not handled by this library. You may wish to investigate the [webidl2js](https://github.com/jsdom/webidl2js) project. ### A note on the `long long` types @@ -74,9 +72,9 @@ To mitigate this, we could return the raw BigInt value from the conversion funct On the other hand, `long long` conversion is always accurate, since the input value can never be more precise than the output value. -### A note on `BufferSource` types +### A note on buffer source types -All of the `BufferSource` types will throw when the relevant `ArrayBuffer` has been detached. This technically is not part of the [specified conversion algorithm](https://webidl.spec.whatwg.org/#js-buffer-source-types), but instead part of the [getting a reference/getting a copy](https://webidl.spec.whatwg.org/#ref-for-dfn-get-buffer-source-reference%E2%91%A0) algorithms. We've consolidated them here for convenience and ease of implementation, but if there is a need to separate them in the future, please open an issue so we can investigate. +All of the buffer source types will throw when the relevant `ArrayBuffer` has been detached. This technically is not part of the [specified conversion algorithm](https://webidl.spec.whatwg.org/#js-buffer-source-types), but instead part of the [getting a reference/getting a copy](https://webidl.spec.whatwg.org/#ref-for-dfn-get-buffer-source-reference%E2%91%A0) algorithms. We've consolidated them here for convenience and ease of implementation, but if there is a need to separate them in the future, please open an issue so we can investigate. ## Background diff --git a/lib/index.js b/lib/index.js index 2b96a69..62d215e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -414,23 +414,3 @@ exports.ArrayBufferView = (value, options = {}) => { } return value; }; - -exports.BufferSource = (value, options = {}) => { - if (ArrayBuffer.isView(value)) { - return exports.ArrayBufferView(value, options); - } - - if (isNonSharedArrayBuffer(value)) { - return exports.ArrayBuffer(value, options); - } else if (options.allowShared && isSharedArrayBuffer(value)) { - return exports.SharedArrayBuffer(value, options); - } - - if (options.allowShared) { - throw makeException(TypeError, "is not an ArrayBuffer, SharedArrayBuffer, or a view on one", options); - } else { - throw makeException(TypeError, "is not an ArrayBuffer or a view on one", options); - } -}; - -exports.DOMTimeStamp = exports["unsigned long long"]; diff --git a/test/buffer-source.js b/test/buffer-source.js index 55436e7..ab816ee 100644 --- a/test/buffer-source.js +++ b/test/buffer-source.js @@ -443,49 +443,3 @@ describe("WebIDL ArrayBufferView type", () => { commonNotOk(allowResizableSUT); }); }); - -describe("WebIDL BufferSource type", () => { - const sut = conversions.BufferSource; - - for (const { label, creator, isShared, isResizable, isDetached, isForged } of bufferSourceCreators) { - const testFunction = !isShared && !isResizable && !isDetached && !isForged ? testOk : testNotOk; - testFunction(label, sut, creator); - } - - commonNotOk(sut); - - describe("with [AllowShared]", () => { - const allowSharedSUT = (v, opts) => conversions.BufferSource(v, { ...opts, allowShared: true }); - - for (const { label, creator, isResizable, isDetached, isForged } of bufferSourceCreators) { - const testFunction = !isResizable && !isDetached && !isForged ? testOk : testNotOk; - testFunction(label, allowSharedSUT, creator); - } - - commonNotOk(allowSharedSUT); - }); - - describe("with [AllowResizable]", () => { - const allowResizableSUT = (v, opts) => conversions.BufferSource(v, { ...opts, allowResizable: true }); - - for (const { label, creator, isShared, isDetached, isForged } of bufferSourceCreators) { - const testFunction = !isShared && !isDetached && !isForged ? testOk : testNotOk; - testFunction(label, allowResizableSUT, creator); - } - - commonNotOk(allowResizableSUT); - }); - - describe("with [AllowShared, AllowResizable]", () => { - const allowResizableSUT = (v, opts) => { - return conversions.BufferSource(v, { ...opts, allowShared: true, allowResizable: true }); - }; - - for (const { label, creator, isDetached, isForged } of bufferSourceCreators) { - const testFunction = !isDetached && !isForged ? testOk : testNotOk; - testFunction(label, allowResizableSUT, creator); - } - - commonNotOk(allowResizableSUT); - }); -}); diff --git a/test/dom-time-stamp.js b/test/dom-time-stamp.js deleted file mode 100644 index f24e1d0..0000000 --- a/test/dom-time-stamp.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -const { describe, it } = require("node:test"); -const assert = require("node:assert/strict"); - -const conversions = require(".."); - -describe("WebIDL DOMTimeStamp type", () => { - const sut = conversions.DOMTimeStamp; - - it("should have the same conversion routine as unsigned long long type", () => { - assert.equal(sut, conversions["unsigned long long"]); - }); -});