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

Add option to initialize mappings wasm via ArrayBuffer #339

Merged
merged 2 commits into from
May 29, 2018

Conversation

rtsao
Copy link
Contributor

@rtsao rtsao commented May 22, 2018

This PR adds the ability to directly pass in the mappings wasm into SourceMapConsumer.initialize. This is needed for browser usage without needing to make a request (e.g. needing to work around CSP restrictions).

Example

const contents = /* the ArrayBuffer contents of mappings.wasm */

sourceMap.SourceMapConsumer.initialize({
  "lib/mappings.wasm": contents
});

I didn't implement this because it would be a breaking change, but I think a better alternative API might be something like:

const wasmUrl = "https://unpkg.com/source-map@0.7.3/lib/mappings.wasm"; 

sourceMap.SourceMapConsumer.initialize({
  "lib/mappings.wasm": fetch(wasmUrl).then(res => res.arrayBuffer())
});

@coveralls
Copy link

coveralls commented May 22, 2018

Pull Request Test Coverage Report for Build 491

  • 0 of 8 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 83.919%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/read-wasm.js 0 8 0.0%
Totals Coverage Status
Change from base Build 490: -0.2%
Covered Lines: 908
Relevant Lines: 1051

💛 - Coveralls

Copy link
Contributor

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Oh wait -- before we merge this, can you add a small test for initializing with an array buffer? Thanks!

@rtsao
Copy link
Contributor Author

rtsao commented May 29, 2018

I was going to, but with the existing test tooling, there's no way to write a test for this because sourceMap.SourceMapConsumer.initialize is a no-op in a Node.js environment. In fact, currently, it appears all browser-specific logic is entirely untested.

Do you have an opinion regarding how browser testing should be done?

@fitzgen
Copy link
Contributor

fitzgen commented May 29, 2018

Bleh, I overlooked that. We would need some kind of headless browser testing setup. If you want to dig into adding that, please be my guest :)

In the meantime, we can just merge this. Thanks again!

@fitzgen
Copy link
Contributor

fitzgen commented May 29, 2018

Can you rebase this branch on master?

@rtsao rtsao force-pushed the wasm-init-arraybuffer branch from 7cf7e82 to 6e618f5 Compare May 29, 2018 18:22
@rtsao
Copy link
Contributor Author

rtsao commented May 29, 2018

Just did, thanks! 😄

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.

3 participants