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

Guard against globalThis not being defined #486

Closed
lukasIO opened this issue May 11, 2023 · 2 comments · Fixed by #488
Closed

Guard against globalThis not being defined #486

lukasIO opened this issue May 11, 2023 · 2 comments · Fixed by #488

Comments

@lukasIO
Copy link
Contributor

lukasIO commented May 11, 2023

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.

@smaye81
Copy link
Member

smaye81 commented May 15, 2023

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.

@lukasIO
Copy link
Contributor Author

lukasIO commented May 15, 2023

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.

smaye81 added a commit that referenced this issue Jun 12, 2023
fixes #486

---------

Co-authored-by: Steve Ayers <sayers@buf.build>
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 a pull request may close this issue.

2 participants