Use optional chaining for getMemoryUsage in GcTimer#63226
Open
phitonias wants to merge 3 commits intomicrosoft:mainfrom
Open
Use optional chaining for getMemoryUsage in GcTimer#63226phitonias wants to merge 3 commits intomicrosoft:mainfrom
phitonias wants to merge 3 commits intomicrosoft:mainfrom
Conversation
Replace unsafe non-null assertions (!) with optional chaining (?.) on the optional getMemoryUsage method in GcTimer.run. Unlike gc which is guarded in scheduleCollect, getMemoryUsage had no guard and could throw at runtime if unavailable. https://claude.ai/code/session_01As1r4ZnGpdzw4gMYehgwe7
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a potential runtime crash in GcTimer.run by replacing unsafe non-null assertions (!) with optional chaining (?.) on the optional getMemoryUsage method of ServerHost. The ServerHost interface inherits getMemoryUsage?(): number as an optional method from System, so asserting it non-null with ! was incorrect and could throw a TypeError at runtime whenever a ServerHost implementation omits the method.
Changes:
- Replace
self.host.getMemoryUsage!()withself.host.getMemoryUsage?.()for thebeforemeasurement (line 70) - Replace
self.host.getMemoryUsage!()withself.host.getMemoryUsage?.()for theaftermeasurement (line 74)
You can also share your feedback on Copilot code review. Take the survey.
Modernize membership checks from `indexOf(...) === -1` and `indexOf(...) >= 0` to use `includes()` in moduleSpecifiers.ts and importFixes.ts. https://claude.ai/code/session_01As1r4ZnGpdzw4gMYehgwe7
Author
|
@microsoft-github-policy-service agree [company="stb"] |
|
@phitonias the command you issued was incorrect. Please try again. Examples are: and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace unsafe non-null assertions (!) with optional chaining (?.) on the optional getMemoryUsage method in GcTimer.run. Unlike gc which is guarded in scheduleCollect, getMemoryUsage had no guard and could throw at runtime if unavailable.
https://claude.ai/code/session_01As1r4ZnGpdzw4gMYehgwe7
Fixes #