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

TypeError thrown on construction #101

Closed NoUJoe closed 1 year ago

NoUJoe commented 1 year ago

The following

JSBI.BigInt ({ num: 2, [Symbol.toPrimitive]: function () {return this.num} });

Throws, Cannot read properties of undefined (reading 'num')

Because in JSBI.__toPrimitive, the object's toPrimitive method is first stored in a local var, and then called using that var. This means this is bound to undefined, and not the object.