Skip to content

Testing plan for Immutable ArrayBuffers #4509

Open
@gibson042

Description

@gibson042

Proposal repo: https://github.com/tc39/proposal-immutable-arraybuffer

Existing ArrayBuffer.prototype properties

  • ArrayBuffer.prototype.resize

    • throws TypeError for an immutable receiver, before touching any argument
  • ArrayBuffer.prototype.slice

    • throws a TypeError if the receiver constructs an immutable ArrayBuffer
  • ArrayBuffer.prototype.transfer

    • throws TypeError for an immutable receiver, after processing newLength (note the unusual receiver-after-argument order)
  • ArrayBuffer.prototype.transferToFixedLength

    • throws TypeError for an immutable receiver, after processing newLength (note the unusual receiver-after-argument order)

New ArrayBuffer.prototype properties

  • ArrayBuffer.prototype.immutable

    • getter-only accessor, enumerable false and configurable true
    • name "get immutable" and length 0
    • brand-checking (throws TypeError unless receiver is an ArrayBuffer and not a SharedArrayBuffer)
    • returns true for an immutable receiver and false for a non-immutable one
    • does not throw for a detached receiver
  • ArrayBuffer.prototype.sliceToImmutable

    • verifyPrimordialCallableProperty(ArrayBuffer.prototype, "sliceToImmutable", "sliceToImmutable", 2);
    • brand-checking (throws TypeError unless receiver is an ArrayBuffer and not a SharedArrayBuffer), before resolving bounds
    • throws TypeError if receiver is detached, before resolving bounds
    • resolves bounds after passing the preceding checks—first start, clamping negative values to [0, len - 1] and positive values to [0, len], then end, defaulting to len and clamping negative values to [0, len - 1] and positive values to [0, len] (and capturing len before coercing either start or end)
    • throws TypeError if receiver was detached by bounds resolution, after bounds resolution
    • throws RangeError if length < specified upper bound, after passing the second detachment check and even if length was ≥ specified upper bound until bounds resolution
    • returns an immutable ArrayBuffer with the correct length and contents (both unaffected by subsequent changes to the original receiver, including detachment)
  • ArrayBuffer.prototype.transferToImmutable

    • verifyPrimordialCallableProperty(ArrayBuffer.prototype, "transferToImmutable", "transferToImmutable", 0);
    • brand-checking (throws TypeError unless receiver is an ArrayBuffer and not a SharedArrayBuffer), before coercing newLength
    • defaults newLength to [[ArrayBufferByteLength]]
    • if newLength is not undefined, casts it to an index (integral number from 0 to 2**53 - 1 inclusive) or throws a RangeError for out-of-range values, after brand-checking
    • throws TypeError if receiver is detached or immutable, after processing newLength (note the unusual receiver-after-argument order)
    • detaches the receiver
    • returns an immutable ArrayBuffer with the correct length
    • if newLength ≤ [[ArrayBufferByteLength]], returns an ArrayBuffer with contents matching the appropriate prefix of the receiver up to exclusive index newLength
    • if newLength > [[ArrayBufferByteLength]], returns an ArrayBuffer with contents matching those of the receiver, followed by the appropriate count of zeros

%TypedArray% static properties

  • %TypedArray%.from

    • throws a TypeError if the receiver constructs an immutable ArrayBuffer, after determining the length from source but before checking if the constructed ArrayBuffer is too short or (more testably) calling mapper
  • %TypedArray%.of

    • throws a TypeError if the receiver constructs an immutable ArrayBuffer, after determining the length from source but before checking if the constructed ArrayBuffer is too short or (more testably) coercing any value to bigint/number

%TypedArray%.prototype properties

  • %TypedArray%.prototype.{copyWithin,fill,reverse,set}

    • throws a TypeError if the receiver is backed by an immutable ArrayBuffer, before touching any argument
    • ...even if the targeted range is of length 0
  • %TypedArray%.prototype.filter

    • throws a TypeError if the receiver constructs an instance backed by an immutable ArrayBuffer, after determining contents
  • %TypedArray%.prototype.map

    • throws a TypeError if the receiver constructs an instance backed by an immutable ArrayBuffer, after validating that callback is callable but before invoking it
  • %TypedArray%.prototype.slice

    • throws a TypeError if the receiver constructs an instance backed by an immutable ArrayBuffer, after coercing bounds
  • %TypedArray%.prototype.sort

    • throws a TypeError if the receiver is backed by an immutable ArrayBuffer, after validating that comparator is callable (note the unusual receiver-after-argument order)
    • ...even if the receiver is of length 0
  • all other %TypedArray%.prototype properties

    • work as expected if the receiver is backed by an immutable ArrayBuffer

%TypedArray% instance operations

  • [[GetOwnProperty]]

    • property descriptors for in-bounds indexes of a typed array backed by an immutable ArrayBuffer are reported as writable false, enumerable true, configurable false
  • [[DefineOwnProperty]]

    • attempts to redefine own properties for in-bounds indexes of a typed array backed by an immutable ArrayBuffer are validated against descriptors for immutable properties
      • presence of writable: true, enumerable: false, configurable: true, get, and/or set results in rejection
      • presence of value with any value that is not treated as identical to the current value by Object.is results in rejection (e.g., value: -0 and value: "0" are rejected when the current value is 0)
      • all other property descriptors (e.g., any subset of { writable: false, enumerable: true, configurable: false, value: $currentValue }) are accepted but do not result in observable changes
  • [[Set]]

    • any attempt to set the value for a property whose name is a canonical numeric index string (including non-index values such as "-0", "1.5", "590295810358705700000", "5e-324", "1.7976931348623157e+308", "Infinity", and "NaN") on a typed array backed by an immutable ArrayBuffer is rejected, even if the new value is identical to the current value
    • likewise for attempts on a receiver having such a typed array in its prototype chain when the [[Set]] makes it to the typed array

DataView

  • DataView.prototype.set…
    • throws a TypeError if the receiver is backed by an immutable ArrayBuffer, before touching any argument

Atomics

  • Atomics.{add,and,compareExchange,exchange,or,store,sub,xor}

    • throws a TypeError if typedArray is an immutable ArrayBuffer, before coercing index
  • Atomics.load

    • works as expected if typedArray is an immutable ArrayBuffer
  • Atomics.notify

    • works as expected if typedArray is an immutable ArrayBuffer, returning 0 when index is in range and coercing count is successful

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions