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

Runtime is not strict mode compliant #165

Closed
appden opened this issue Jan 13, 2015 · 6 comments · Fixed by #167
Closed

Runtime is not strict mode compliant #165

appden opened this issue Jan 13, 2015 · 6 comments · Fixed by #167

Comments

@appden
Copy link

appden commented Jan 13, 2015

To reproduce: node --use_strict regenerator/runtime.js. This is a problem when compiling with 6to5, as it will automatically include the strict header.

Error Output
regenerator/runtime.js:318
        function next() {
        ^^^^^^^^
SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:929:3
Minor Performance Opportunity?

While on this topic, shouldn't the runtime include the "use strict" header so that it can take advantage of performance optimizations that v8 and other engines likely provide?

@sebmck
Copy link
Contributor

sebmck commented Jan 13, 2015

@appden In what scenario does 6to5 include "use strict"; in the regenerator runtime?

@appden
Copy link
Author

appden commented Jan 13, 2015

@sebmck This is not the default behavior, but happened as a result of my crazy build configuration to get my project packaged up correctly as a self-contained library. So yes, most users won't encounter this particular issue with 6to5.

@sebmck
Copy link
Contributor

sebmck commented Jan 13, 2015

@appden Ah right okay. Just wanted to check if there were any potential bugs on our end.

@benjamn
Copy link
Collaborator

benjamn commented Jan 13, 2015

That particular problem is easy enough to fix, but I'm not sure what to do about the current technique of assigning to the undeclared regeneratorRuntime variable to make it global. It seems like that's not allowed in strict mode? If so, that's too bad, because it will be difficult to get a reference to the global object in a way that's CSP-compliant. Any ideas about that are welcome!

@sebmck
Copy link
Contributor

sebmck commented Jan 13, 2015

Yeah, it's illegal to assign to undeclared variables in strict mode. A reliable way to get the current global scope (at least in my experience) has been typeof self === "undefined" ? global : self. self will support web workers, browsers etc while global will catch node, browserify etc.

benjamn added a commit that referenced this issue Jan 14, 2015
benjamn added a commit that referenced this issue Jan 14, 2015
benjamn added a commit that referenced this issue Jan 14, 2015
Specifically, you can now require("regenerator/runtime-module") if you
want to access the runtime without relying on the global namespace.

Note that runtime.js is now fully strict-mode-compliant.

Fixes #165.
Fixes #166.
benjamn added a commit that referenced this issue Jan 14, 2015
Specifically, you can now require("regenerator/runtime-module") if you
want to access the runtime without relying on the global namespace.

Note that runtime.js is now fully strict-mode-compliant.

Fixes #165.
Fixes #166.
benjamn added a commit that referenced this issue Jan 14, 2015
Specifically, you can now require("regenerator/runtime-module") if you
want to access the runtime without relying on the global namespace.

Note that runtime.js is now fully strict-mode-compliant.

Fixes #165.
Fixes #166.
@appden
Copy link
Author

appden commented Jan 14, 2015

@benjamn thank you for fixing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants