-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Use fetch()
for loading packages & shared libraries
#22002
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
Closed
Closed
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
87743d1
Adding USE_FETCH setting.
seanmorris 3d38841
Tweaks
seanmorris ffcaa3b
Adding tests.
seanmorris de79ead
Tweak.
seanmorris 139bcd4
Tweak.
seanmorris 893f361
Merge branch 'main' into sm-worker-fetch
seanmorris 0407112
Tweak.
seanmorris 24761b6
Merge branch 'sm-worker-fetch' of github.com:seanmorris/emscripten in…
seanmorris 3ead8de
Rebasing generated sizes.
seanmorris 35b593f
Reverting extraneous change.
seanmorris 5c2a7bb
Readability.
seanmorris 5631928
Testing
seanmorris ff2d142
Removing debug.
seanmorris 9e06ef2
Typo.
seanmorris 5899d3f
Parameterizing test.
seanmorris c09f2c5
Spacing.
seanmorris 2f43c20
Deduping default info in docs.
seanmorris c5ecce5
Deduping if statement.
seanmorris 7e86b5b
Correcting indentation of JS output.
seanmorris 6848055
Removing use_fetch option and XmlHttpRequest.
seanmorris 0bf9b71
Reverting extraneous changes.
seanmorris 3f765bc
Revert "Reverting extraneous changes."
seanmorris 316aa8b
Actually reverting extraneous change.
seanmorris 366b942
Merge branch 'sm-worker-fetch' into updates
seanmorris 58ab5c6
Merging main
seanmorris 5899e42
Throw error on bad fetch in runMetaWithFS
seanmorris 92ffd13
Tweaks.
seanmorris df4e1c3
Tweaks.
seanmorris bb9a69e
Use rejecting promises instead of throw.
seanmorris c8e9db9
Merge branch 'main' into sm-worker-fetch
seanmorris 272f093
Tweaks.
seanmorris 6432c5a
Adding polyfill + test.
seanmorris e870667
Adding polyfill + test.
seanmorris ce4089e
Adding polyfill + test.
seanmorris 4581d90
Adding fetch polyfill + test
seanmorris 457ef2c
Adding fetch polyfill + test
seanmorris aeac94e
Polyfill tests for browser.
seanmorris 275388a
Tweaks.
seanmorris d4a6162
Tweaks.
seanmorris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Fetch polyfill from https://github.com/developit/unfetch | ||
// License: | ||
//============================================================================== | ||
// Copyright (c) 2017 Jason Miller | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
//============================================================================== | ||
|
||
#if !POLYFILL | ||
#error "this file should never be included unless POLYFILL is set" | ||
#endif | ||
|
||
if (typeof globalThis.fetch == 'undefined') { | ||
globalThis.fetch = function (url, options) { | ||
options = options || {}; | ||
return new Promise((resolve, reject) => { | ||
const request = new XMLHttpRequest(); | ||
const keys = []; | ||
const headers = {}; | ||
|
||
request.responseType = 'arraybuffer'; | ||
|
||
const response = () => ({ | ||
ok: ((request.status / 100) | 0) == 2, // 200-299 | ||
statusText: request.statusText, | ||
status: request.status, | ||
url: request.responseURL, | ||
text: () => Promise.resolve(request.responseText), | ||
json: () => Promise.resolve(request.responseText).then(JSON.parse), | ||
blob: () => Promise.resolve(new Blob([request.response])), | ||
arrayBuffer: () => Promise.resolve(request.response), | ||
clone: response, | ||
headers: { | ||
keys: () => keys, | ||
entries: () => keys.map((n) => [n, request.getResponseHeader(n)]), | ||
get: (n) => request.getResponseHeader(n), | ||
has: (n) => request.getResponseHeader(n) != null, | ||
}, | ||
}); | ||
|
||
request.open(options.method || "get", url, true); | ||
|
||
request.onload = () => { | ||
request | ||
.getAllResponseHeaders() | ||
.toLowerCase() | ||
.replace(/^(.+?):/gm, (m, key) => { | ||
headers[key] || keys.push((headers[key] = key)); | ||
}); | ||
resolve(response()); | ||
}; | ||
|
||
request.onerror = reject; | ||
|
||
request.withCredentials = options.credentials == "include"; | ||
|
||
for (const i in options.headers) { | ||
request.setRequestHeader(i, options.headers[i]); | ||
} | ||
|
||
request.send(options.body || null); | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
31420 | ||
31418 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call
onload
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.arrayBuffer();
returns a promise that resolves to a buffer, not a literal buffer.