Skip to content

Commit

Permalink
feat(pass-style,marshal): ByteArray, a binary Passable
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Aug 16, 2024
1 parent 7bc95fc commit eed07e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/pass-style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@endo/env-options": "^1.1.5",
"@endo/errors": "^1.2.4",
"@endo/eventual-send": "^1.2.4",
"@endo/immutable-arraybuffer": "^0.1.0",
"@endo/promise-kit": "^1.1.4",
"@fast-check/ava": "^1.1.5"
},
Expand Down
12 changes: 7 additions & 5 deletions packages/pass-style/src/byteArray.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { X } from '@endo/errors';
import {
transferBufferToImmutable,
isBufferImmutable,
} from '@endo/immutable-arraybuffer';
import { assertChecker } from './passStyle-helpers.js';

const { getPrototypeOf, getOwnPropertyDescriptor } = Object;
const { ownKeys, apply } = Reflect;

// @ts-expect-error TODO How do I add it to the ArrayBuffer type?
const AnImmutableArrayBuffer = new ArrayBuffer(0).transferToImmutable();
const AnImmutableArrayBuffer = transferBufferToImmutable(new ArrayBuffer(0));

/**
* As proposed, this will be the same as `ArrayBuffer.prototype`. As shimmed,
* this will be a hidden intrinsic that inherits from `ArrayBuffer.prototype`.
Expand All @@ -26,9 +30,7 @@ const immutableGetter = getOwnPropertyDescriptor(
* @returns {boolean}
*/
const canBeValid = (candidate, check = undefined) =>
(candidate instanceof ArrayBuffer &&
// @ts-expect-error TODO How do I add it to the ArrayBuffer type?
candidate.immutable) ||
(candidate instanceof ArrayBuffer && isBufferImmutable(candidate)) ||
(!!check && check(false, X`Immutable ArrayBuffer expected: ${candidate}`));

/**
Expand Down

0 comments on commit eed07e2

Please sign in to comment.