Skip to content

Commit

Permalink
fixup! review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Sep 4, 2024
1 parent eafaf24 commit f4334eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/ses/src/shim-arraybuffer-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ export const shimArrayBufferTransfer = () => {
}
const clone = globalThis.structuredClone;
if (typeof clone !== 'function') {
// Indeed, Node <= 16 has neither.
throw TypeError(
`Can only shim missing ArrayBuffer.prototype.transfer on a platform with "structuredClone"`,
);
// On a platform with neither `Array.prototype.transfer`
// nor `structuredClone`, this shim does nothing.
// For example, Node <= 16 has neither.
//
// Empty object because this shim has nothing for `addIntrinsics` to add.
return {};
// TODO Rather than doing nothing, should the endo ses-shim throw
// in this case?
// throw TypeError(
// `Can only shim missing ArrayBuffer.prototype.transfer on a platform with "structuredClone"`,
// );
// For example, endo no longer supports Node <= 16. All browsers have
// `structuredClone`. XS has `Array.prototype.transfer`. Are there still
// any platforms without both that Endo should still support?
// What about Hermes?
}

/**
Expand All @@ -43,7 +54,7 @@ export const shimArrayBufferTransfer = () => {
return clone(this, { transfer: [this] });
}
if (typeof newLength !== 'number') {
throw new TypeError(`transfer newLength if provided must be a number`);
throw TypeError(`transfer newLength if provided must be a number`);
}
if (newLength > oldLength) {
const result = new ArrayBuffer(newLength);
Expand Down
10 changes: 10 additions & 0 deletions packages/ses/test/shim-arraybuffer-transfer.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global globalThis */
import test from 'ava';
import '../index.js';

Expand Down Expand Up @@ -25,6 +26,15 @@ test('ArrayBuffer.p.transfer', t => {
t.is(taX[2], 12);
t.is(taX[3], undefined);

if (!('transfer' in ArrayBuffer.prototype)) {
t.false('structuredClone' in globalThis);
// Currently, shim-arraybuffer-transfer.shim, when run on a platform
// with neither `Array.prototype.transfer` nor `structuredClone` does
// not shim `Array.prototype.transfer`. Thus, we currently do not
// consider this absence to be a non-conformance to the endo ses-shim.
return;
}

// because this test must run on platforms prior to
// ArrayBuffer.prototype.detached, we test detachment by other means.

Expand Down

0 comments on commit f4334eb

Please sign in to comment.