Skip to content

deprecate unsafe host-specific bindings from stdlib #7334

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

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

tsnobip
Copy link
Member

@tsnobip tsnobip commented Mar 12, 2025

@tsnobip tsnobip force-pushed the remove-host-specific-core-bindings branch 3 times, most recently from e15a2b4 to 53d89a4 Compare March 12, 2025 14:40
@tsnobip tsnobip requested a review from cometkim March 12, 2025 14:41
@val external globalThis: {..} = "globalThis"
@deprecated("Use rescript-webapi instead") @val external window: Dom.window = "window"
@deprecated("Use rescript-webapi instead") @val external document: Dom.document = "document"
@deprecated("Use rescript-webapi instead") @val external globalThis: {..} = "globalThis"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

globalThis is not host-specific but is actually part of the ECMAScript spec: https://tc39.es/ecma262/multipage/global-object.html#sec-globalthis

So maybe the deprecation warning should say Use Js.globalThis instead of recommending rescript-webapi? (a Js.globalThis binding already exists)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, actually globalThis was added by me 😅

It is intentional that it points to the {..} type. Depending on the environment, it can be a Node.js global, DedicatedWorkerGlobalScope, etc.

Others are pretty much host-specific

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I should keep globalThis?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. It's part of the JS standard and useful when dealing with global variables or classes.

Here's a case: https://forum.rescript-lang.org/t/is-it-good-idea-having-binding-to-js-this/2922

But it should not be used too often.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tsnobip tsnobip force-pushed the remove-host-specific-core-bindings branch from 53d89a4 to 8951931 Compare March 13, 2025 08:30
@tsnobip tsnobip requested a review from mediremi March 13, 2025 08:43
@tsnobip
Copy link
Member Author

tsnobip commented Mar 13, 2025

@mediremi @cometkim I removed the deprecation of GlobalThis if you want to review it again.

@tsnobip tsnobip merged commit 2a358eb into master Mar 13, 2025
20 checks passed
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.

Unsafe host-specific bindings
4 participants