bufbuild / protobuf-es

Protocol Buffers for ECMAScript. The only JavaScript Protobuf library that is fully-compliant with Protobuf conformance tests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Guard against `globalThis` not being defined

lukasIO opened this issue · comments

Hi!

https://github.com/bufbuild/protobuf-es/blob/main/packages/protobuf/src/proto-int64.ts#L121

checks directly on globalThis for BigInt support. But globalThis might be undefined itself (https://caniuse.com/?search=globalthis).
For the most part it seems as soon as BigInt is supported, globalThis should also be supported, only Samsung Internet rains on the parade.

I guess a naive option (ignoring BigInt support of Samsung Internet 9.2) would be to add a typeof globalThis !== undefined before the BigInt check.

Hi @lukasIO. This is probably more of an issue that should be fixed with Samsung Internet 9.2. globalThis seems to have pretty wide support among browsers so rather than handle this outlier, I'd probably recommend a polyfill in this case.

hi @smaye81 ,
thanks for the reply!
The issue is not about Samsung Internet 9.2., but about the feature check for BigInt in this library throwing an exception across all browsers if globalThis is not supported.
The target of this lib (at least as defined in tsconfig) is ES2017, globalThis is an ES2020 feature. Thus I thought it would be reasonable to add a check for that.

I opened #488 with the one-line fix that would be needed to make it ES2017 compatible.