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: Support absence of TextEncoder/TextDecoder/console #1820

Merged
merged 3 commits into from
Oct 12, 2023

Conversation

gibson042
Copy link
Contributor

Fix #1819

Description

Tolerate the absence of non-ECMA-262 web platform APIs.

Security Considerations

This follows existing patterns and hardens all introduced new non-primitive values. It will result in calls to a global print function that would not have otherwise happened, but only when it exists and console is undefined (but I believe any code capable of creating those circumstances could have overridden console anyway).

Scaling Considerations

n/a

Documentation Considerations

The non-web-platform environments of eshost invocations are sufficiently esoteric that I don't think documentation needs updating.

Testing Considerations

For similar reasons, I have not introduced new tests (although I suspect that could be done).

Upgrade Considerations

None.

Copy link
Contributor

@erights erights 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!

@@ -174,6 +174,10 @@ freeze(ErrorInfo);

/** @type {MakeCausalConsole} */
Copy link
Contributor

Choose a reason for hiding this comment

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

Please adjust the type MakeCausalConsole to @returns {VirtualConsole | undefined}

@@ -174,6 +174,10 @@ freeze(ErrorInfo);

/** @type {MakeCausalConsole} */
const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
if (!baseConsole) {
return baseConsole;
Copy link
Contributor

Choose a reason for hiding this comment

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

For the sake of being sounder wrt the type I suggest above, what do you think of changing this to

Suggested change
return baseConsole;
return undefined;

? Or do I miss the intent of this code?

? console
: typeof print === 'function'
? // Make a good-enough console for eshost.
(p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a console with only these methods good enough for eshost? Is eshost likely to be the only case this code needs to accommodate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the answer to both questions is "yes"—this is all the simple console logging functions (i.e., those that only forward their arguments to Logger with the corresponding log level), and a superset of those potentially encountered by lockdown (log, warn, and error). I've improved the comment accordingly.

@gibson042 gibson042 force-pushed the gibson-1819-lockdown-eshost branch from a74f5d3 to a2fd851 Compare October 12, 2023 15:45
@gibson042 gibson042 merged commit 41e1215 into master Oct 12, 2023
14 checks passed
@gibson042 gibson042 deleted the gibson-1819-lockdown-eshost branch October 12, 2023 15:55
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.

lockdown() fails in eshost environments
2 participants