// // FunctionPromise: possibly-asynchronous function constructor. // // This is a prototype polyfill for a FunctionPromise object as described in: // // https://bugzilla.mozilla.org/show_bug.cgi?id=854627 // // Where possible it will arrange for the function body to be parsed/compiled // off of the main thread, with the function object returned asynchronously // via a promise. The fallback implementation processes just falls back to // the standard synchronous Function() constructor. // // It doesn't (yet) have the following features from the linked proposal: // // * ability to copy to different workers // * ability to store in IndexedDB // function FunctionPromise(/* [args1[, args2[, ...argN]],], functionBody) */) { var useFallback = typeof window === "undefined" || window.FunctionPromise !== FunctionPromise || typeof document === "undefined" || typeof document.createElement === "undefined" || typeof document.head === "undefined" || typeof document.head.appendChild === "undefined" || typeof Blob === "undefined" || typeof URL === "undefined" || typeof URL.createObjectURL === "undefined"; var args = Array.prototype.slice.call(arguments); // For the fallback case, we just use the normal Function constructor. if (useFallback) { try { var fn = Function.apply(null, args); return Promise.resolve(fn); } catch (err) { return Promise.reject(err); } } // If we have all the necessary pieces, we can do this asynchronously // by writing a