Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response.arrayBuffer() may resolve to ArrayBufferView #801

Closed
freund17 opened this issue Jul 22, 2020 · 0 comments · Fixed by #816
Closed

Response.arrayBuffer() may resolve to ArrayBufferView #801

freund17 opened this issue Jul 22, 2020 · 0 comments · Fixed by #816

Comments

@freund17
Copy link

new Response(new Uint8Array([8])).arrayBuffer();

returns a Promise, which resolves to a Uint8Array.
It should resolve to an ArrayBuffer instead.

Steps to reproduce:
Load this polyfill and paste above code into the developer console.

My hacky workaround:

After loading the polyfill add the following:

const ori = window.Response.prototype.arrayBuffer;

window.Response.prototype.arrayBuffer = function (...props) {
  return (ori.apply(this, props) as Promise<
    ArrayBuffer | ArrayBufferView
  >).then((value) => {
    if (ArrayBuffer.isView(value)) {
      return value.buffer.slice(
        value.byteOffset,
        value.byteOffset + value.byteLength
      );
    } else {
      return value;
    }
  });
};
@freund17 freund17 changed the title Response may return ArrayBufferView Response.arrayBuffer() may resolve to ArrayBufferView Jul 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2021
cr313 added a commit to cr313/fetch-Js-flow that referenced this issue Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant