Skip to content

Missing checks for immutable objects returned from species constructors #46

@anba

Description

@anba

https://tc39.es/ecma262/#sec-%typedarray%.prototype.filter:

  1. Let A be ? TypedArraySpeciesCreate(O, « 𝔽(captured) »).
  2. Let n be 0.
  3. For each element e of kept, do
    a. Perform ! Set(A, ! ToString(𝔽(n)), e, true).
    b. Set n to n + 1.

If A is an immutable TypedArray object, then Set can return with an abrupt completion, so using ! Set is no longer correct.

Other callers to TypedArraySpeciesCreate:


I guess the simplest fix is to update https://tc39.es/ecma262/#sec-typedarraycreatefromconstructor and add a new step 3.d:

3.d. If IsImmutableBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception

Or rewriting TypedArrayCreateFromConstructor to pass the correct access-mode:

  1. If the number of elements in argumentList is 1 and argumentList[0] is a Number, then
    a. Let accessMode be WRITE.
  2. Else,
    b. Let accessMode be READ.
  3. Let newTypedArray be ? Construct(constructor, argumentList).
  4. Let taRecord be ? ValidateTypedArray(newTypedArray, seq-cst, accessMode).
  5. If accessMode is WRITE, then
    a. Assert: IsTypedArrayOutOfBounds(taRecord) is false.
    b. Let length be TypedArrayLength(taRecord).
    c. If length < ℝ(argumentList[0]), throw a TypeError exception.
  6. Return newTypedArray.

Drive-by change: Update step 5.a. to use Assert, because ValidateTypedArray already throws for out-of-bounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions