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

XS does not apply runtime strict mode restrictions to async functions #334

Closed
jugglinmike opened this issue Mar 5, 2020 · 0 comments
Closed
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.

Comments

@jugglinmike
Copy link

For async functions defined in strict mode, XS does not enforce the relevant runtime restrictions:

$ ~/.jsvu/xs -e '"use strict"; (async function () { notStrict = true })().then(() => print("okay"));'
okay
$ ~/.jsvu/xs -e '"use strict"; (async () => { notStrict = true })().then(() => print("okay"));'
okay
$ ~/.jsvu/xs -e '"use strict"; (async () => notStrict = true)().then(() => print("okay"));'
okay
$ ~/.jsvu/xs -e '"use strict"; (async function () { "".notStrict = true })().then(() => print("okay"));'
okay
$ ~/.jsvu/xs -e '"use strict"; (async () => { "".notStrict = true })().then(() => print("okay"));'
okay
$ ~/.jsvu/xs -e '"use strict"; (async () => "".notStrict = true)().then(() => print("okay"));'
okay

This is also the case when the function itself enables strict mode:

$ ~/.jsvu/xs -e '(async function () { "use strict"; notStrict = true })().then(() => print("okay"));'
okay

...but XS does correctly apply syntactic restrictions:

$ ~/.jsvu/xs -e '"use strict"; (async () => static)().then(() => print("okay"));'
SyntaxError: missing expression

XS correctly enforces strict mode in synchronous functions:

$ ~/.jsvu/xs -e '"use strict"; (() => notStrict = true)();'
ReferenceError: ?: set notStrict: undefined variable
$ ~/.jsvu/xs -e '"use strict"; (() => { notStrict = true })();'
ReferenceError: ?: set notStrict: undefined variable
$ ~/.jsvu/xs -e '"use strict"; (function () { notStrict = true })();'
ReferenceError: ?: set notStrict: undefined variable

Interestingly, strict mode is also correctly applied for synchronous functions defined within the erroneously-non-strict async functions:

$ ~/.jsvu/xs -e '"use strict"; (async () => { (() => notStrict = true)(); })().then(() => print("okay"), (err) => print(err));' 
ReferenceError: ?: set notStrict: undefined variable

This behavior was observed using the xst binary as provided by jsvu.

$ ~/.jsvu/xs -v
XS 10.0.0
$ uname -a
Linux bruce 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
@phoddie phoddie added the confirmed issue reported has been reproduced label Aug 26, 2020
mkellner pushed a commit that referenced this issue Oct 14, 2020
@phoddie phoddie added the fixed - please verify Issue has been fixed. Please verify and close. label Oct 14, 2020
@phoddie phoddie closed this as completed Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.
Projects
None yet
Development

No branches or pull requests

2 participants