X Tutup
Skip to content

Use optional chaining for getMemoryUsage in GcTimer#63226

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

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"]

@microsoft-github-policy-service

@phitonias the command you issued was incorrect. Please try again.

Examples are:

@microsoft-github-policy-service agree

and

@microsoft-github-policy-service agree company="your company"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup