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

Use the canonical value of undefined in generated JavaScript code. #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dhil
Copy link
Collaborator

@dhil dhil commented Aug 9, 2019

Using undefined in generated code is fragile as it is global mutable
variable, not a constant. As a consequence a buggy equality test such
as if (foo = undefined) { ... } or similar in generated code or any
third-party code can inadvertently break the entire runtime. Such bugs
can be difficult to localise.

To make the runtime more robust this patch introduces a slight change
to the JavaScript code generator such that the emitted code uses the
canonical value of undefined rather than the variable name
undefined. The canonical value can be obtain via the odd expression
(void 0). Since void is a keyword and 0 is a numeric literal it
is not possible for user-code to override their semantics, hence the
expression is resilient against mutations such as monkey-patching.

Using `undefined` in generated code is fragile as it is global mutable
variable, not a constant. As a consequence a buggy equality test such
as `if (foo = undefined) { ... }` or similar in generated code or any
third-party code can inadvertently break the entire runtime. Such bugs
can be difficult to localise.

To make the runtime more robust this patch introduces a slight change
to the JavaScript code generator such that the emitted code uses the
canonical value of `undefined` rather than the variable name
`undefined`. The canonical value can be obtain via the odd expression
`(void 0)`. Since `void` is a keyword and `0` is a numeric literal it
is not possible for user-code to override their semantics, hence the
expression is resilient against mutations such as monkey-patching.
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.

None yet

1 participant