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

Make sure wrapper doesn't invalidate strict mode #29

Merged
merged 2 commits into from Jan 12, 2021

Conversation

emilbroman-eqt
Copy link
Contributor

The overridden module wrapper that decorates the require function adds an assignment statement before the module script itself. If that module starts with the "use strict" directive, that needs to be at the very top of the function to have any effect. The injected assignment invalidates that.

This led to a particularly weird bug initially reported to Axios here: axios/axios#3470

The solution is to wrap the module's script into another IIFE.

Note however that this changes the semantics in another way: it adds a stack frame to all modules. This could be an issue if someone is doing something funky with new Error().stack.

@emilbroman-eqt
Copy link
Contributor Author

Please note that this can be considered severe, since it silently makes strict mode disabled for any module, first or third party, if it uses the module-wide directive. And strict/non-strict mode bugs are notoriously hard to troubleshoot. Trust me, this one was 😅

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

good spot!

LGTM

@mcollina
Copy link
Member

Unfortunately this does not pass on node v4. Would you mind updating .travis.yml dropping v4, v6, v8 and adding v12 and v14? Thanks

@codecov-io
Copy link

codecov-io commented Jan 12, 2021

Codecov Report

Merging #29 (8c1ade9) into master (eccac78) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #29   +/-   ##
=======================================
  Coverage   98.00%   98.00%           
=======================================
  Files           2        2           
  Lines          50       50           
=======================================
  Hits           49       49           
  Misses          1        1           
Impacted Files Coverage Δ
index.js 97.22% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eccac78...8c1ade9. Read the comment docs.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 858f01f into pinojs:master Jan 12, 2021
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

3 participants