Skip to content

Use optional chaining for getMemoryUsage in GcTimer#63226

Closed
phitonias wants to merge 3 commits intomicrosoft:mainfrom
phitonias:claude/small-enhancement-Qz6bS
Closed

Use optional chaining for getMemoryUsage in GcTimer#63226
phitonias wants to merge 3 commits intomicrosoft:mainfrom
phitonias:claude/small-enhancement-Qz6bS

Conversation

@phitonias
Copy link

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 #

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
Copilot AI review requested due to automatic review settings March 9, 2026 20:06
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Mar 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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!() with self.host.getMemoryUsage?.() for the before measurement (line 70)
  • Replace self.host.getMemoryUsage!() with self.host.getMemoryUsage?.() for the after measurement (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
@phitonias
Copy link
Author

@microsoft-github-policy-service agree [company="stb"]

@MartinJohns
Copy link
Contributor

Your changes don't align with your description.

@jakebailey jakebailey closed this Mar 10, 2026
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants