-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pass-style,marshal): ByteArray, a new binary Passable type
- Loading branch information
Showing
19 changed files
with
222 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { X } from '@endo/errors'; | ||
import { assertChecker } from './passStyle-helpers.js'; | ||
|
||
const { getPrototypeOf } = Object; | ||
const { ownKeys } = Reflect; | ||
|
||
// @ts-expect-error TODO How do I add it to the ArrayBuffer type? | ||
const AnImmutableArrayBuffer = new ArrayBuffer(0).transferToImmutable(); | ||
/** | ||
* As proposed, this will be the same as `ArrayBuffer.prototype`. As shimmed, | ||
* this will be a hidden intrinsic that inherits from `ArrayBuffer.prototype`. | ||
* Either way, get this in a way that we can trust it after lockdown, and | ||
* require that all immutable ArrayBuffers directly inherit from it. | ||
*/ | ||
const ImmutableArrayBufferPrototype = getPrototypeOf(AnImmutableArrayBuffer); | ||
|
||
/** | ||
* @param {unknown} candidate | ||
* @param {import('./types.js').Checker} [check] | ||
* @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) || | ||
(!!check && check(false, X`Immutable ArrayBuffer expected: ${candidate}`)); | ||
|
||
/** | ||
* @type {import('./internal-types.js').PassStyleHelper} | ||
*/ | ||
export const ByteArrayHelper = harden({ | ||
styleName: 'byteArray', | ||
|
||
canBeValid, | ||
|
||
assertValid: (candidate, _passStyleOfRecur) => { | ||
canBeValid(candidate, assertChecker); | ||
getPrototypeOf(candidate) === ImmutableArrayBufferPrototype || | ||
assert.fail(X`Malformed ByteArray ${candidate}`, TypeError); | ||
ownKeys(candidate).length === 0 || | ||
assert.fail( | ||
X`ByteArrays must not have own properties: ${candidate}`, | ||
TypeError, | ||
); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.