From 211e8c25d52644552cb37531cdb637f4f12c8782 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 26 Sep 2016 18:00:21 +0200 Subject: fix bug in retrying logic for reserve status --- lib/vendor/system-csp-production.src.js | 1621 +++++++++++++++++++------------ lib/wallet/chromeBadge.ts | 5 +- lib/wallet/wallet.ts | 12 +- 3 files changed, 1010 insertions(+), 628 deletions(-) diff --git a/lib/vendor/system-csp-production.src.js b/lib/vendor/system-csp-production.src.js index 0887780ca..9c5e56532 100644 --- a/lib/vendor/system-csp-production.src.js +++ b/lib/vendor/system-csp-production.src.js @@ -1,8 +1,71 @@ /* - * SystemJS v0.19.17 + * SystemJS v0.19.39 */ (function() { -function bootstrap() {(function(__global) { +function bootstrap() {// from https://gist.github.com/Yaffle/1088850 +(function(global) { +function URLPolyfill(url, baseURL) { + if (typeof url != 'string') + throw new TypeError('URL must be a string'); + var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/); + if (!m) + throw new RangeError('Invalid URL format'); + var protocol = m[1] || ""; + var username = m[2] || ""; + var password = m[3] || ""; + var host = m[4] || ""; + var hostname = m[5] || ""; + var port = m[6] || ""; + var pathname = m[7] || ""; + var search = m[8] || ""; + var hash = m[9] || ""; + if (baseURL !== undefined) { + var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL); + var flag = !protocol && !host && !username; + if (flag && !pathname && !search) + search = base.search; + if (flag && pathname[0] !== "/") + pathname = (pathname ? (((base.host || base.username) && !base.pathname ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname); + // dot segments removal + var output = []; + pathname.replace(/^(\.\.?(\/|$))+/, "") + .replace(/\/(\.(\/|$))+/g, "/") + .replace(/\/\.\.$/, "/../") + .replace(/\/?[^\/]*/g, function (p) { + if (p === "/..") + output.pop(); + else + output.push(p); + }); + pathname = output.join("").replace(/^\//, pathname[0] === "/" ? "/" : ""); + if (flag) { + port = base.port; + hostname = base.hostname; + host = base.host; + password = base.password; + username = base.username; + } + if (!protocol) + protocol = base.protocol; + } + + // convert URLs to use / always + pathname = pathname.replace(/\\/g, '/'); + + this.origin = host ? protocol + (protocol !== "" || host !== "" ? "//" : "") + host : ""; + this.href = protocol + (protocol && host || protocol == "file:" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash; + this.protocol = protocol; + this.username = username; + this.password = password; + this.host = host; + this.hostname = hostname; + this.port = port; + this.pathname = pathname; + this.search = search; + this.hash = hash; +} +global.URLPolyfill = URLPolyfill; +})(typeof self != 'undefined' ? self : global);(function(__global) { var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined'; var isBrowser = typeof window != 'undefined' && typeof document != 'undefined'; @@ -37,24 +100,32 @@ function bootstrap() {(function(__global) { } })(); + var errArgs = new Error(0, '_').fileName == '_'; + function addToError(err, msg) { - var newErr; - if (err instanceof Error) { - newErr = new Error(err.message, err.fileName, err.lineNumber); - if (isBrowser) { - newErr.message = err.message + '\n\t' + msg; - newErr.stack = err.stack; + // parse the stack removing loader code lines for simplification + if (!err.originalErr) { + var stack = ((err.message || err) + (err.stack ? '\n' + err.stack : '')).toString().split('\n'); + var newStack = []; + for (var i = 0; i < stack.length; i++) { + if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1) + newStack.push(stack[i]); } - else { - // node errors only look correct with the stack modified - newErr.message = err.message; - newErr.stack = err.stack + '\n\t' + msg; - } - } - else { - newErr = err + '\n\t' + msg; } - + + var newMsg = '(SystemJS) ' + (newStack ? newStack.join('\n\t') : err.message.substr(11)) + '\n\t' + msg; + + // Convert file:/// URLs to paths in Node + if (!isBrowser) + newMsg = newMsg.replace(isWindows ? /file:\/\/\//g : /file:\/\//g, ''); + + var newErr = errArgs ? new Error(newMsg, err.fileName, err.lineNumber) : new Error(newMsg); + + newErr.stack = newMsg; + + // track the original error + newErr.originalErr = err.originalErr || err; + return newErr; } @@ -68,6 +139,7 @@ function bootstrap() {(function(__global) { } var baseURI; + // environent baseURI detection if (typeof document != 'undefined' && document.getElementsByTagName) { baseURI = document.baseURI; @@ -76,8 +148,13 @@ function bootstrap() {(function(__global) { var bases = document.getElementsByTagName('base'); baseURI = bases[0] && bases[0].href || window.location.href; } + } + else if (typeof location != 'undefined') { + baseURI = __global.location.href; + } - // sanitize out the hash and querystring + // sanitize out the hash and querystring + if (baseURI) { baseURI = baseURI.split('#')[0].split('?')[0]; baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1); } @@ -86,14 +163,17 @@ function bootstrap() {(function(__global) { if (isWindows) baseURI = baseURI.replace(/\\/g, '/'); } - else if (typeof location != 'undefined') { - baseURI = __global.location.href; - } else { throw new TypeError('No environment baseURI'); } - var URL = __global.URLPolyfill || __global.URL; + try { + var nativeURL = new __global.URL('test:///').protocol == 'test:'; + } + catch(e) {} + + var URL = nativeURL ? __global.URL : __global.URLPolyfill; + /* ********************************************************************************************* @@ -239,11 +319,13 @@ function logloads(loads) { // 15.2.3.2 Load Records and LoadRequest Objects + var anonCnt = 0; + // 15.2.3.2.1 function createLoad(name) { return { status: 'loading', - name: name, + name: name || '', linkSets: [], dependencies: [], metadata: {} @@ -288,7 +370,6 @@ function logloads(loads) { load = loader.loads[i]; if (load.name != name) continue; - console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded'); return load; } @@ -328,8 +409,6 @@ function logloads(loads) { ); } - var anonCnt = 0; - // 15.2.4.5 function proceedToTranslate(loader, load, p) { p @@ -338,6 +417,8 @@ function logloads(loads) { if (load.status != 'loading') return; + load.address = load.address || load.name; + return Promise.resolve(loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source })) // 15.2.4.5.2 CallInstantiate @@ -348,38 +429,14 @@ function logloads(loads) { // 15.2.4.5.3 InstantiateSucceeded .then(function(instantiateResult) { - if (instantiateResult === undefined) { - load.address = load.address || ''; - - // instead of load.kind, use load.isDeclarative - load.isDeclarative = true; - return transpile.call(loader.loaderObj, load) - .then(function(transpiled) { - // Hijack System.register to set declare function - var curSystem = __global.System; - var curRegister = curSystem.register; - curSystem.register = function(name, deps, declare) { - if (typeof name != 'string') { - declare = deps; - deps = name; - } - // store the registered declaration as load.declare - // store the deps as load.deps - load.declare = declare; - load.depsList = deps; - } - // empty {} context is closest to undefined 'this' we can get - __eval(transpiled, load.address, {}); - curSystem.register = curRegister; - }); - } - else if (typeof instantiateResult == 'object') { - load.depsList = instantiateResult.deps || []; - load.execute = instantiateResult.execute; - load.isDeclarative = false; - } - else - throw TypeError('Invalid instantiate return value'); + if (instantiateResult === undefined) + throw new TypeError('Declarative modules unsupported in the polyfill.'); + + if (typeof instantiateResult != 'object') + throw new TypeError('Invalid instantiate return value'); + + load.depsList = instantiateResult.deps || []; + load.execute = instantiateResult.execute; }) // 15.2.4.6 ProcessLoadDependencies .then(function() { @@ -421,8 +478,6 @@ function logloads(loads) { // console.log('LoadSucceeded ' + load.name); // snapshot(loader); - console.assert(load.status == 'loading', 'is loading'); - load.status = 'loaded'; var linkSets = load.linkSets.concat([]); @@ -525,8 +580,6 @@ function logloads(loads) { if (load.status == 'failed') return; - console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded on link set'); - for (var i = 0, l = linkSet.loads.length; i < l; i++) if (linkSet.loads[i] == load) return; @@ -601,9 +654,7 @@ function logloads(loads) { var loads = [].concat(linkSet.loads); for (var i = 0, l = loads.length; i < l; i++) { var load = loads[i]; - load.module = !load.isDeclarative ? { - module: _newModule({}) - } : { + load.module = { name: load.name, module: _newModule({}), evaluated: true @@ -691,13 +742,12 @@ function logloads(loads) { depMap: depMap, address: load.address, metadata: load.metadata, - source: load.source, - kind: load.isDeclarative ? 'declarative' : 'dynamic' + source: load.source }; } // if not anonymous, add to the module table if (load.name) { - console.assert(!loader.modules[load.name], 'load not in module table'); + console.assert(!loader.modules[load.name] || loader.modules[load.name].module === load.module.module, 'load not in module table'); loader.modules[load.name] = load.module; } var loadIndex = indexOf.call(loader.loads, load); @@ -771,7 +821,6 @@ function logloads(loads) { get: function(key) { if (!this._loader.modules[key]) return; - doEnsureEvaluated(this._loader.modules[key], [], this); return this._loader.modules[key].module; }, // 26.3.3.7 @@ -791,16 +840,14 @@ function logloads(loads) { .then(function(name) { var loader = loaderObj._loader; - if (loader.modules[name]) { - doEnsureEvaluated(loader.modules[name], [], loader._loader); + if (loader.modules[name]) return loader.modules[name].module; - } return loader.importPromises[name] || createImportPromise(loaderObj, name, loadModule(loader, name, {}) .then(function(load) { delete loader.importPromises[name]; - return evaluateLoadedModule(loader, load); + return load.module.module; })); }); }, @@ -830,7 +877,7 @@ function logloads(loads) { var sourcePromise = Promise.resolve(source); var loader = this._loader; var p = linkSet.done.then(function() { - return evaluateLoadedModule(loader, load); + return load.module.module; }); proceedToTranslate(loader, load, sourcePromise); return p; @@ -855,10 +902,16 @@ function logloads(loads) { enumerable: true, get: function () { return obj[key]; + }, + set: function() { + throw new Error('Module exports cannot be changed externally.'); } }); })(pNames[i]); + if (Object.freeze) + Object.freeze(m); + return m; }, // 26.3.3.14 @@ -874,9 +927,7 @@ function logloads(loads) { // 26.3.3.17 @@toStringTag not implemented // 26.3.3.18.1 - normalize: function(name, referrerName, referrerAddress) { - return name; - }, + normalize: function(name, referrerName, referrerAddress) {}, // 26.3.3.18.2 locate: function(load) { return load.name; @@ -894,8 +945,9 @@ function logloads(loads) { }; var _newModule = Loader.prototype.newModule; + /* - * ES6 Module Declarative Linking Code - Dev Build Only + * ES6 Module Declarative Linking Code */ function link(linkSet, linkError) { @@ -922,57 +974,98 @@ function logloads(loads) { } } - function evaluateLoadedModule(loader, load) { - console.assert(load.status == 'linked', 'is linked ' + load.name); - return load.module.module; - } +})(); - function doEnsureEvaluated() {} +var System; - function transpile() { - throw new TypeError('ES6 transpilation is only provided in the dev module loader build.'); - } -})();/* -********************************************************************************************* +// SystemJS Loader Class and Extension helpers +function SystemJSLoader() { + Loader.call(this); - System Loader Implementation + this.paths = {}; + this._loader.paths = {}; - - Implemented to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js + systemJSConstructor.call(this); +} - -