tc39 / proposal-immutable-arraybuffer

A TC39 proposal for immutable ArrayBuffers
http://tc39.es/proposal-immutable-arraybuffer/
MIT License
12 stars 1 forks source link

Normative: Make index properties for immutable-backed TypedArrays non-configurable and non-writable #6

Closed gibson042 closed 3 weeks ago

gibson042 commented 3 weeks ago

...allowing such TypedArrays to be frozen.

GFM rendering of this PR's diff from upstream ECMA-262: removals, additions

10.4.5 TypedArray Exotic Objects

10.4.5.1 [[GetOwnProperty]] ( P )

The [[GetOwnProperty]] internal method of a TypedArray O takes argument P (a property key) and returns a normal completion containing either a Property Descriptor or undefined. It performs the following steps when called:

  1. If P is a String, then
    1. Let numericIndex be CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. Let value be TypedArrayGetElement(O, numericIndex).
      2. If value is undefined, return undefined.
      3. Let mutable be true.
      4. If IsImmutableBuffer(O.[[ViewedArrayBuffer]]) is true, set mutable to false.
      5. Return the PropertyDescriptor { [[Value]]: value, [[Writable]]: true mutable, [[Enumerable]]: true, [[Configurable]]: true mutable }.
  2. Return OrdinaryGetOwnProperty(O, P).

10.4.5.3 [[DefineOwnProperty]] ( P, Desc )

The [[DefineOwnProperty]] internal method of a TypedArray O takes arguments P (a property key) and Desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. If P is a String, then
    1. Let numericIndex be CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. If IsValidIntegerIndex(O, numericIndex) is false, return false.
      2. Let mutable be true.
      3. If IsImmutableBuffer(O.[[ViewedArrayBuffer]]) is true, set mutable to false.
      4. If Desc has a [[Configurable]] field and Desc.[[Configurable]] is false not mutable, return false.
      5. If Desc has an [[Enumerable]] field and Desc.[[Enumerable]] is false, return false.
      6. If IsAccessorDescriptor(Desc) is true, return false.
      7. If Desc has a [[Writable]] field and Desc.[[Writable]] is false not mutable, return false.
      8. If Desc has a [[Value]] field and mutable is false and SameValue(Desc.[[Value]], TypedArrayGetElement(O, numericIndex)) is false, return false.
      9. If Desc has a [[Value]] field and mutable is true, perform ? TypedArraySetElement(O, numericIndex, Desc.[[Value]]).
      10. Return true.
  2. Return ! OrdinaryDefineOwnProperty(O, P, Desc).

10.4.5.5 [[Set]] ( P, V, Receiver )

The [[Set]] internal method of a TypedArray O takes arguments P (a property key), V (an ECMAScript language value), and Receiver (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. If P is a String, then
    1. Let numericIndex be CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. If SameValue(O, Receiver) is true, then
        1. IsValidIntegerIndex(O, numericIndex) is true and IsImmutableBuffer(O.[[ViewedArrayBuffer]]) is true, return false.
        2. Perform ? TypedArraySetElement(O, numericIndex, V).
        3. Return true.
      2. If IsValidIntegerIndex(O, numericIndex) is false, return true.
  2. Return ? OrdinarySet(O, P, V, Receiver).
erights commented 3 weeks ago

Read the render, thanks. Lgtm