MCPcopy Create free account
hub / github.com/GoogleChrome/samples / getBinaryPromise

Function getBinaryPromise

mkbitmap/mkbitmap.js:770–801  ·  view source on GitHub ↗
(binaryFile)

Source from the content-addressed store, hash-verified

768}
769
770function getBinaryPromise(binaryFile) {
771 // If we don't have the binary yet, try to load it asynchronously.
772 // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
773 // See https://github.com/github/fetch/pull/92#issuecomment-140665932
774 // Cordova or Electron apps are typically loaded from a file:// url.
775 // So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
776 if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
777 if (typeof fetch == 'function'
778 && !isFileURI(binaryFile)
779 ) {
780 return fetch(binaryFile, { credentials: 'same-origin' }).then(function(response) {
781 if (!response['ok']) {
782 throw "failed to load wasm binary file at '" + binaryFile + "'";
783 }
784 return response['arrayBuffer']();
785 }).catch(function () {
786 return getBinary(binaryFile);
787 });
788 }
789 else {
790 if (readAsync) {
791 // fetch is not available or url is file => try XHR (readAsync uses XHR internally)
792 return new Promise(function(resolve, reject) {
793 readAsync(binaryFile, function(response) { resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))) }, reject)
794 });
795 }
796 }
797 }
798
799 // Otherwise, getBinary should be able to get it synchronously
800 return Promise.resolve().then(function() { return getBinary(binaryFile); });
801}
802
803function instantiateArrayBuffer(binaryFile, imports, receiver) {
804 return getBinaryPromise(binaryFile).then(function(binary) {

Callers 1

instantiateArrayBufferFunction · 0.70

Calls 3

resolveFunction · 0.85
isFileURIFunction · 0.70
getBinaryFunction · 0.70

Tested by

no test coverage detected