Skip to content
Open
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
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
20 changes: 0 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
46 changes: 0 additions & 46 deletions test/buffer-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
13 changes: 0 additions & 13 deletions test/dom-time-stamp.js

This file was deleted.