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

fix(repl): prevent panic when deleting globalThis.closed property #24014

Merged

Conversation

safaa-mojahed
Copy link
Contributor

@safaa-mojahed safaa-mojahed commented May 28, 2024

This PR fixes #23422.

When the user deletes the globalThis.closed property, a panic occurs due to the closing function iteratively reading this.closed value in the REPL. This pull request prevents such panics by adding a reference for the closed property in the get_prelude() function for the REPL_INTERNALS_NAME object. The closing function now reads this property from the REPL_INTERNALS_NAME object instead of directly from this.closed.

@CLAassistant
Copy link

CLAassistant commented May 28, 2024

CLA assistant check
All committers have signed the CLA.

let closed = self
.evaluate_expression("(this.closed)")
.evaluate_expression(&expression)
Copy link
Member

Choose a reason for hiding this comment

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

What sets this value now?

Copy link
Member

Choose a reason for hiding this comment

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

@dsherret it's still set by calling close().

Copy link
Member

Choose a reason for hiding this comment

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

Won't that only set on globalThis?

Copy link
Member

Choose a reason for hiding this comment

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

It would, but if you delete it then calling close() will just throw an error saying that it's not defined. Which is okay. But since we check value of globalThis.closed in the REPL look it causes a panic when deleting globalThis.

Copy link
Member

@dsherret dsherret May 28, 2024

Choose a reason for hiding this comment

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

Yeah, but this code always returns false now because it's only set on startup. It seems the repl::close_command test is failing now because this is never set to true.

Copy link
Contributor Author

@safaa-mojahed safaa-mojahed May 28, 2024

Choose a reason for hiding this comment

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

I thought this.closed is always evaluated on every access since it is a getter, but from the test I can see that it is only evaluated once. I think I will change this line "closed: this.closed" to getter so it should be evaluated every access. But when the closed property is deleted should I set a default value to return or what??

@dsherret

Copy link
Member

Choose a reason for hiding this comment

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

I guess another option that we can try is to save the reference to globalThis in the "internals" object and then access the getter from this saved reference.

Copy link
Contributor Author

@safaa-mojahed safaa-mojahed May 29, 2024

Choose a reason for hiding this comment

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

@bartlomieju Using the getter won't prevent the panic issue. Alternatively, should I return a default value if this.closed is returned undefined?

image

@safaa-mojahed safaa-mojahed force-pushed the fix-panic-delete-closed-property branch from c388c5a to 53b8dee Compare May 29, 2024 08:30
safaa-mojahed and others added 2 commits May 29, 2024 11:36
…adding a reference in the REPL_INTERNALS_NAME object and return default value in case closed property is deleted.
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@dsherret dsherret merged commit 4b83ce8 into denoland:main Jun 18, 2024
17 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.

delete globalThis.closed panics REPL
4 participants