GoogleChromeLabs / jsbi

JSBI is a pure-JavaScript implementation of the official ECMAScript BigInt proposal.
https://v8.dev/features/bigint#polyfilling-transpiling
Apache License 2.0
919 stars 68 forks source link

Symbol.toPrimitive doesn't exist in IE11 #74

Closed 12wrigja closed 3 years ago

12wrigja commented 3 years ago

https://github.com/GoogleChromeLabs/jsbi/blob/c80c3ae61ca16fd37be76671fcf33df494369b34/lib/jsbi.ts#L1764-L1769

My understanding is that this code won't work in IE11 as neither Symbol or Symbol.toPrimitive are defined there.

Is using toPrimitive necessary, or could it be removed? If it is needed, then I would suggest wrapping it in some typeof checks:

if (typeof Symbol !== "undefined" && typeof Symbol.toPrimitive === "symbol" ) {
   ... existing code here ...
}

I can send a PR for the above, but wanted to check and see whether this code is even needed before continuing down this path.

jakobkummerow commented 3 years ago

Yes, that code is needed for spec compliance, it's an implementation of https://tc39.es/ecma262/#sec-toprimitive.

+1 to wrapping it in the checks you suggest.