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

Hide API implementation proxies, add tests to check for "proxy leakage" #115530

Merged
merged 11 commits into from
Feb 3, 2021

Conversation

jrieken
Copy link
Member

@jrieken jrieken commented Feb 1, 2021

Our vscode API is mostly implemented through RPC'ing to the renderer. That's done through a protocol implementation and objects that represent a slice of the API, aka proxies, like MainThreadTextEditorsShape. These proxies usually mirror the capabilities of the API but are often more powerful.

This PR adds marker properties to proxies and the rpc-objects. It also adds a test-util that tries to reach these proxies using the API instance as entry point. In the name of being very strict, it's a test failure when any rpc object can be reached.

Note that the test can only checks on existing objects, e.g if vscode.window.activeTextEditor is undefined it cannot be traversed. That's why a check is performed during teardown of a single test. That increases the coverage but doesn't guarantee that everything is checked.

The PR also changes how some APIs are implemented (so that proxies aren't accessible anymore). There is two strategies

  1. Use a true private property, e.g #proxy, so that reflection doesn't find them. However, note that the emitted polyfill is significantly slower
  2. Use an object that only implements the API shape and has access to "internals" via scope variables. I have done that in most cases via the a value property, e.g ExtHostTerminal#value. There is another benefit to this approach which is TS checking that the literal only implements what is defined in the API, so accidental API leakage is checked by the compiler

@jrieken jrieken changed the title Hide API implementation proxies, add tests for check for "leakage" Hide API implementation proxies, add tests to check for "proxy leakage" Feb 1, 2021
@jrieken jrieken added the debt Code quality issues label Feb 1, 2021
@jrieken jrieken self-assigned this Feb 1, 2021
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

Nice work, terminal looks good 👍

@alexr00 alexr00 self-requested a review February 2, 2021 15:09
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Tasks looks good, thank you!

@jrieken jrieken merged commit 74937e0 into master Feb 3, 2021
@jrieken jrieken deleted the joh/norpc branch February 3, 2021 08:17
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants