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

BigInt support #981

Closed
wants to merge 2 commits into from
Closed

BigInt support #981

wants to merge 2 commits into from

Conversation

Rudxain
Copy link

@Rudxain Rudxain commented Sep 5, 2021

arr[n] where arr is an Array and n is a BigInt, is supported by Chromium. arr.at(n) throws an error because toInteger doesn't support BigInts

arr[n] where `arr` is an Array and `n` is a BigInt, is supported by Chromium. arr.at(n) throws an error because `toInteger` doesn't support BigInts
@zloirock
Copy link
Owner

zloirock commented Sep 6, 2021

arr[n] where arr is an Array and n is a BigInt, is supported by Chromium

Chromium 95:
image
Chrome 93:
image
FF Nightly:
image
FF91:
image
Spec draft:
https://tc39.es/proposal-relative-indexing-method/
Spec PR:
https://github.com/tc39/ecma262/pull/2493/files

Everywhere it throws an error on bigints. Why do you think that it should support BigInt?

@zloirock zloirock closed this Sep 7, 2021
@Rudxain
Copy link
Author

Rudxain commented Sep 18, 2021

If the at method didn't support BigInts, then one of the goals of the proposal would be incomplete (I'm talking about conciseness). Developers would have to write array.at(Number(x)) (where x is negative and within valid range) to get the same behavior as array[array.length - Number(y)] (where y == abs(x)). The following is a modification I made of the polyfill, it works on MS Edge Chromium (I haven't tested EdgeHTML) Version 93.0.961.47:

//github.com/tc39/proposal-relative-indexing-method#polyfill
function at(n) {
   n = Math.trunc(Number(n)) || 0; if (n < 0) n += this.length;
   return n < 0 || n >= this.length ? undefined : this[n]
};
const TypedArray = Reflect.getPrototypeOf(Int8Array);
for (const C of [Array, String, TypedArray]) {
   Object.defineProperty(C.prototype, "at", {value: at, writable: true, enumerable: false, configurable: true})
};

2021-09-18

And I apologize for replying late, I didn't read my mail and didn't get a notification.

@zloirock
Copy link
Owner

core-js is a polyfill and should follow the spec. It's an issue for the proposal, you could write it here https://github.com/tc39/proposal-relative-indexing-method

@Rudxain
Copy link
Author

Rudxain commented Sep 18, 2021

Thanks for the info and your time. I didn't know I had to post it there. I'm relatively new to GitHub and got confused, sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants