-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(immutable-arraybuffer): transferToImmutable ponyfill and shim #2399
Conversation
d40f56f
to
d610950
Compare
d610950
to
e4be967
Compare
b71e84c
to
c1d8ab4
Compare
c1d8ab4
to
f531bc8
Compare
OCapN meeting coming up on Tuesday. So if there's no problem with this, I'd like to make progress before then. Ping ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks reasonable, but I feel pretty strongly that we should not have a polyfill at all... liveslots will need to use a new endo to take advantage of this anyway, and it IMO should explicitly propagate transferBufferToImmutable
and isBufferImmutable
as globals into all descendant compartments rather than manipulating a built-in prototype and creating compatibility concerns.
f531bc8
to
262bcf0
Compare
Closes: #XXXX
Refs: #1538 #1331 #2309 #2311
Description
Introduces the
@endo/immutable-arraybuffer
package, the ponyfill exports of@endo/immutable-arraybuffer
, and the shim obtained by importing@endo/immutable-arraybuffer/shim.js
.Alternative to #2309 as suggested by @phoddie at #2309 (comment)
We plan to fix #1331 in a stack of PRs starting with this one
Passable
type,ByteArray
, corresponding to the OCapNByteArray
.ByteArray
objects.See the README.md in this PR for more.
Security Considerations
Better support for immutability generally helps security. The imperfections of the shim are a leaky abstraction in all the ways explained in the Caveats section of the README.md. For example, objects that are purely artifacts of the emulation, like the
immutableArrayBufferPrototype
, are easily discoverable, revealing the emulation's mechanisms.As a pure JavaScript polyfill/shim, this
@endo/immutable-arraybuffer
package does not harden the objects it exposes. Thus, by itself it does not provide much security -- like the initial state of JavaScript does not by itself provide much security. Rather, both provide securability, depending on Hardened JavaScript to harden early as needed to provide the security. See #2311Once hardened early, the abstraction will still be leaky as above, but the immutability of the buffer contents are robustly enforced.
Scaling Considerations
This ponyfill/shim is a zero-copy implementation, meaning that it does no more buffer copying than expected of a native implementation.
Compatibility and Documentation Considerations
This ponyfill/shim implements zero-copy by relying on the platform to provide one of two primitives:
structuredClone
orArrayBuffer.prototype.transfer
. Neither exist on Node <= 16. Without either, this ponyfill/shim will fail to initialize.This PR sets the stage for writing an Immutable ArrayBuffer proposal, proposing it to tc39, and including it in our own documentation.
Testing Considerations
Ideally, we should identify the subset of test262
ArrayBuffer
tests that should be applicable to immutable ArrayBuffers, and duplicate them for that purpose.Upgrade Considerations
Nothing breaking.