@endo/immutable-arraybuffer@2.0.0
Major Changes
-
#3308
4da9a99Thanks @kriskowal! - Drop the immutable-ArrayBuffer pseudo-prototype.Emulated immutable
ArrayBuffers produced by@endo/immutable-arraybuffernow inherit directly fromArrayBuffer.prototyperather than from an intermediate prototype.Object.getPrototypeOf(immuAB) === ArrayBuffer.prototypefor both emulated immutable and genuine buffers; the brand check is the newimmutableaccessor onArrayBuffer.prototypeinstalled by the shim.The
[Symbol.toStringTag]slot is preserved as an own property on each emulated immutable buffer (not on the shared prototype), soObject.prototype.toString.call(immuAB)continues to return'[object ImmutableArrayBuffer]'(as in master) while genuine ArrayBuffers continue to read as'[object ArrayBuffer]'. This keepsconcordance(and any other downstream consumer that sniffs the toStringTag to decide whether the value is a genuine exotic) from misrouting an emulated immutable through Node'sBuffer.from, which throws because the emulated immutable is not an exotic object.@endo/immutable-arraybufferis now a side-effect-only package: its sole public export is./shim.js. Theindex.jsand the package's.entry are removed; the previously exported names (isBufferImmutable,sliceBufferToImmutable,optTransferBufferToImmutable) are no longer reachable from outside the package. Callers detect immutability via theArrayBuffer.prototype.immutableaccessor (orObject.prototype.toString.call(buffer) === '[object ImmutableArrayBuffer]'when the shim has not been loaded) and convert viabuffer.sliceToImmutable(...)andbuffer.transferToImmutable(...)on the prototype. The break is a major bump for the@endo/immutable-arraybufferpackage.@endo/bytes'sto-immutable.jsimports@endo/immutable-arraybuffer/shim.js(triggering the shim install) and callsbuffer.sliceToImmutable(...)onArrayBuffer.prototypeinstead of the previously exportedsliceBufferToImmutablefree function.The shim's install policy is now detect-then-skip rather than warn-and-overwrite: the Immutable ArrayBuffer proposal has reached stage 3, so any prior installation (native or previously loaded shim) wins. If
'sliceToImmutable' in ArrayBuffer.prototypeis already true when the shim loads, the shim does nothing.sesdrops the%ImmutableArrayBufferPrototype%permits entry, which no longer has a referent. The three permits lines inside%ArrayBufferPrototype%that declare the shim-installed methods (transferToImmutable,sliceToImmutable,immutable) stay as-is.@endo/pass-style'sbyteArraybrand check no longer routes through an intermediate prototype; it consults theimmutableaccessor onArrayBuffer.prototypedirectly. The check also tolerates the[Symbol.toStringTag]own-property on emulated immutable buffers and verifies that its value is a non-enumerable data property with a string value.