Skip to content

TypedArray and ArrayBuffer bodies must be cloned instead of taking a reference #4995

@npaun

Description

@npaun

See fetch/api/body/cloned-any.js:

  const body = new Uint8Array([97]); // a
  const res = new Response(body);
  const req = new Request(url, { method, body });
  body[0] = 98; // b
  assert_true(await res.text() === 'a');
  assert_true(await req.text() === 'a');

We have a problem: We're only taking a reference to body, and so we end up with res.text() === 'b' etc.

Fixing this will probably require a compat flag. To do this efficiently, we might consider copy-on-write.

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