Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-module-loader

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-module-loader - npm Package Compare versions

Comparing version 0.5.3 to 0.5.4

changes.txt

5

bower.json
{
"name": "es6-module-loader",
"version": "0.5.1",
"version": "0.5.4",
"description": "An ES6 Module Loader polyfill based on the latest spec.",
"homepage": "https://github.com/ModuleLoader/es6-module-loader",
"main": "dist/es6-module-loader.js",
"dependencies": {
"traceur": "0.0.32"
},
"keywords": [

@@ -8,0 +11,0 @@ "es6",

7

dist/es6-module-loader.js
/*
* es6-module-loader v0.5.1
* es6-module-loader v0.5.4
* https://github.com/ModuleLoader/es6-module-loader

@@ -7,2 +7,5 @@ * Implemented to the 2013-12-02 ES6 module specification draft

*/
!function(a){var b="undefined"!=typeof window,c=b?function(a){setTimeout(a,1)}:process.nextTick,d=a.Promise;if(d)if(d.all&&d.resolve&&d.reject){d=a.Promise;{new d(function(a){"function"!=typeof a&&(d=null)})}}else d=null;d||(a.Promise=function(a,b,c){function d(a,b){return(typeof b)[0]==a}function e(a,h){return h=function i(j,k,l,m,n,o){function p(a){return function(b){n&&(n=0,i(d,a,b))}}if(m=i.q,j!=d)return e(function(a,b){m.push({p:this,r:a,j:b,1:j,0:k})});if(l&&d(b,l)|d(c,l))try{n=l.then}catch(q){k=0,l=q}if(d(b,n))try{n.call(l,p(1),k=p(0))}catch(q){k(q)}else for(h=f(a,l,k),o=0;o<m.length;)n=m[o++],d(b,j=n[k])?g(n.p,n.r,n.j,l,j):(k?n.r:n.j)(l)},h.q=[],a.call(a={then:function(a,b){return h(a,b)},"catch":function(a){return h(0,a)}},function(a){h(d,1,a)},function(a){h(d,0,a)}),a}function f(a,c,f){return function(h,i){return d(b,h=f?h:i)?e(function(a,b){g(this,a,b,c,h)}):a}}function g(e,f,g,h,i){a(function(){try{h=i(h),i=h&&d(c,h)|d(b,h)&&h.then,d(b,i)?h==e?g(new TypeError):i.call(h,f,g):f(h)}catch(a){g(a)}})}return e.resolve=function(a){return e(function(b){b(a)})},e.reject=function(a){return e(function(b,c){c(a)})},e.all=function(b){return new e(function(c,d){if(!b.length)return a(c);for(var e=[],f=0,g=0,h=b.length;h>g;g++)(function(a){b[a].then(function(d){e[a]=d,f++,f==b.length&&c(e)},d)})(g)})},e}(c,"f","o")),"object"==typeof exports&&(module.exports=d)}("undefined"!=typeof global?global:this),function(a){function b(a,b){b||console.log("Assertion Failed - "+a)}function c(a){return{status:"loading",name:a,metadata:{},linkSets:[]}}function d(a,d,f,g){return new y(function(b){b(a.normalize(d,f,g))}).then(function(d){var f;if(a._modules[d])return f=c(d),f.status="linked",f;for(var g=0,h=a._loads.length;h>g;g++)if(f=a._loads[g],f.name==d)return b("loading or loaded","loading"==f.status||"loaded"==f.status),f;return f=c(d),a._loads.push(f),e(a,f),f})}function e(a,b){f(a,b,y.resolve().then(function(){return a.locate({name:b.name,metadata:b.metadata})}))}function f(a,b,c){g(a,b,c.then(function(c){return"failed"==b.status?void 0:(b.address=c,a.fetch({name:b.name,metadata:b.metadata,address:c}))}))}function g(c,e,f){f.then(function(a){return"failed"==e.status?void 0:c.translate({name:e.name,metadata:e.metadata,address:e.address,source:a})}).then(function(a){return"failed"==e.status?void 0:(e.source=a,c.instantiate({name:e.name,metadata:e.metadata,address:e.address,source:a}))}).then(function(f){if("failed"==e.status)return void 0;var g;if(void 0===f){if(!a.traceur)throw new TypeError("Include Traceur for module syntax support");w||(w=a.traceur,$traceurRuntime.ModuleStore.get=$traceurRuntime.getModuleImpl=function(a){return System.get(a)}),e.address=e.address||"anon"+ ++C;var h=new w.syntax.Parser(new w.syntax.SourceFile(e.address,e.source));e.body=h.parseModule(),g=t(e.body),e.kind="declarative"}else{if("object"!=typeof f)throw TypeError("Invalid instantiate return value");g=f.deps||[],e.execute=f.execute,e.kind="dynamic"}e.dependencies={},e.depsList=g;for(var j=[],k=0,l=g.length;l>k;k++)(function(a){var f=d(c,a,e.name,e.address);f.then(function(c){if(b("not already a dependency",!e.dependencies[a]),e.dependencies[a]=c.name,"linked"!=c.status)for(var d=e.linkSets.concat([]),f=0,g=d.length;g>f;f++)i(d[f],c)}),j.push(f)})(g[k]);return y.all(j)}).then(function(){b("is loading","loading"==e.status),e.status="loaded";for(var a=e.linkSets.concat([]),c=0,d=a.length;d>c;c++)j(a[c],e)},function(a){b("is loading on fail","loading"==e.status),e.status="failed",e.exception=a;for(var c=0,d=e.linkSets.length;d>c;c++)k(e.linkSets[c],a);b("fail linkSets removed",0==e.linkSets.length)})}function h(a,b){var c,d,e=new y(function(a,b){c=a,d=b}),f={loader:a,loads:[],done:e,resolve:c,reject:d,loadingCount:0};return i(f,b),f}function i(a,c){b("loading or loaded on link set","loading"==c.status||"loaded"==c.status);for(var d=0,e=a.loads.length;e>d;d++)if(a.loads[d]==c)return;a.loads.push(c),c.linkSets.push(a),"loaded"!=c.status&&a.loadingCount++;var f=a.loader;for(var g in c.dependencies){var h=c.dependencies[g];if(!f._modules[h])for(var d=0,e=f._loads.length;e>d;d++)if(f._loads[d].name==h){i(a,f._loads[d]);break}}}function j(a,c){if(b("loaded or linked","loaded"==c.status||"linked"==c.status),a.loadingCount--,!(a.loadingCount>0)){var d=a.loads[0];try{q(a.loads,a.loader)}catch(e){return k(a,e)}b("loads cleared",0==a.loads.length),a.resolve(d)}}function k(a,c){for(var d=a.loads.concat([]),e=0,f=d.length;f>e;e++){var g=d[e],h=A.call(g.linkSets,a);if(b("link not present",-1!=h),g.linkSets.splice(h,1),0==g.linkSets.length){var i=A.call(a.loader._loads,g);-1!=i&&a.loader._loads.splice(i,1)}}a.reject(c)}function l(a,c){c.name&&(b("load not in module table",!a._modules[c.name]),a._modules[c.name]=c.module);var d=A.call(a._loads,c);-1!=d&&a._loads.splice(d,1);for(var e=0,f=c.linkSets.length;f>e;e++)d=A.call(c.linkSets[e].loads,c),c.linkSets[e].loads.splice(d,1);c.linkSets=[]}function m(a,b,c){return new y(n(a,b,c&&c.address?"fetch":"locate",void 0,c&&c.address,void 0)).then(function(a){return a})}function n(a,d,i,j,k,l){return function(m,n){if(a._modules[d])throw new TypeError('Module "'+d+'" already exists in the module table');for(var o=0,p=a._loads.length;p>o;o++)if(a._loads[o].name==d)throw new TypeError('Module "'+d+'" is already loading');var q=c(d);j&&(q.metadata=j);var r=h(a,q);a._loads.push(q),r.done.then(m,n),"locate"==i?e(a,q):"fetch"==i?f(a,q,y.resolve(k)):(b("translate step","translate"==i),q.address=k,g(a,q,y.resolve(l)))}}function o(a,c){return b("is linked "+c.name,"linked"==c.status),p(c.module,a),b("is a module",c.module.module instanceof v),c.module.module}function p(b,c){if(b.module)return b.module;for(var d in b.dependencies){var e=b.dependencies[d];c._modules[e].module||p(c._modules[e],c)}w.options.sourceMaps=!0,w.options.modules="instantiate";var f=new w.util.ErrorReporter;f.reportMessageInternal=function(a,b){throw b+"\n"+a};var g=a.System;a.System=w.System;var h=new w.codegeneration.module.AttachModuleNameTransformer(b.name).transformAny(b.body);h=new w.codegeneration.FromOptionsTransformer(f).transform(h),a.System=g,delete b.body;var i=new w.outputgeneration.SourceMapGenerator({file:b.address}),j={sourceMapGenerator:i},k=w.outputgeneration.TreeWriter.write(h,j);a.btoa&&(k+="\n//# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(j.sourceMap)))+"\n");var l=System.register;System.register=function(c,d,e){for(var f=0;f<d.length;f++)d[f]=b.dependencies[d[f]];b.module=new v(e.apply(a,d))},u(k,a,b.address,b.name),System.register=l}function q(a,b){for(var c=!1;a.length;){c=!0;a:for(var d=0;d<a.length;d++){var e=a[d],f=[];for(var g in e.dependencies){var h=e.dependencies[g];if(!b._modules[h])continue a;var i=e.depsList.indexOf(g);f[i]=h}if(c=!1,"declarative"==e.kind)e.module={name:e.name,dependencies:e.dependencies,body:e.body};else{var j=e.execute.apply(null,f);if(!(j instanceof v))throw new TypeError("Execution must define a Module instance");e.module={module:j}}e.status="linked",l(b,e)}if(c)throw new TypeError("Circular dependencies not supported by the polyfill")}}function r(a){if("object"!=typeof a)throw new TypeError("Options must be an object");a.normalize&&(this.normalize=a.normalize),a.locate&&(this.locate=a.locate),a.fetch&&(this.fetch=a.fetch),a.translate&&(this.translate=a.translate),a.instantiate&&(this.instantiate=a.instantiate),x(this,"global",{get:function(){throw new TypeError("global accessor not provided by polyfill")}}),x(this,"realm",{get:function(){throw new TypeError("Realms not implemented in polyfill")}}),this._modules={},this._loads=[]}function s(a,b,c,d){var e,f;if(b(a,c,d)!==!1)for(e in a)a.hasOwnProperty(e)&&"location"!=e&&"type"!=e&&(f=a[e],"object"==typeof f&&null!==f&&s(f,b,a,e))}function t(a){function b(a){-1==A.call(c,a)&&c.push(a)}var c=[];return s(a,function(a){"EXPORT_DECLARATION"==a.type?a.declaration.moduleSpecifier&&b(a.declaration.moduleSpecifier.token.processedValue):"IMPORT_DECLARATION"==a.type?b(a.moduleSpecifier.token.processedValue):"MODULE_DECLARATION"==a.type&&b(a.expression.token.processedValue)}),c}function u(a,b,c,d){try{Function("global",'var __moduleName = "'+(d||"").replace('"','"')+'"; with(global) { '+a+" \n }"+(c&&!a.match(/\/\/[@#] ?(sourceURL|sourceMappingURL)=([^\n]+)/)?"\n//# sourceURL="+c:"")).call(b,b)}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+c+"\n "+e.message),e}}function v(a){if("object"!=typeof a)throw new TypeError("Expected object");if(!(this instanceof v))return new v(a);var b=this;for(var c in a)!function(a,c){x(b,a,{configurable:!1,enumerable:!0,get:function(){return c}})}(c,a[c]);Object.preventExtensions&&Object.preventExtensions(this)}var w,x,y=a.Promise||require("./promise");try{Object.defineProperty({},"a",{})&&(x=Object.defineProperty)}catch(z){x=function(a,b,c){try{a[b]=c.value||c.get.call(a)}catch(d){}}}var A=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},B={};r.prototype={define:function(a,b,c){if(B[a])throw new TypeError("Module is already loading.");return B[a]=new y(n(this,a,c&&c.address?"fetch":"translate",c&&c.meta||{},c&&c.address,b)),B[a].then(function(){delete B[a]})},load:function(a,b){return this._modules[a]?(p(this._modules[a],this),y.resolve(this._modules[a].module)):B[a]?B[a]:(B[a]=m(this,a,b),B[a].then(function(){delete B[a]}))},module:function(a,b){var d=c();d.address=b&&b.address;var e=h(this,d),f=y.resolve(a),i=this,j=e.done.then(function(){return o(i,d)});return g(this,d,f),j},"import":function(a,b){if(this._modules[a])return p(this._modules[a],this),y.resolve(this._modules[a].module);var c=this;return(B[a]||(B[a]=m(this,a,b))).then(function(b){return delete B[a],o(c,b)})},eval:function(){throw new TypeError("Eval not implemented in polyfill")},get:function(a){return p(this._modules[a],this),this._modules[a].module},has:function(a){return!!this._modules[a]},set:function(a,b){if(!(b instanceof v))throw new TypeError("Set must be a module");this._modules[a]={module:b}},"delete":function(a){return this._modules[a]?delete this._modules[a]:!1},entries:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},keys:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},values:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},normalize:function(a){return a},locate:function(a){return a.name},fetch:function(){throw new TypeError("Fetch not implemented")},translate:function(a){return a.source},instantiate:function(){}};var C=0;"object"==typeof exports&&(module.exports=r),a.Loader||(a.Loader=r),a.LoaderPolyfill=r,a.Module=v}("undefined"!=typeof global?global:this),function(a){function b(a){var b=String(a).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return b?{href:b[0]||"",protocol:b[1]||"",authority:b[2]||"",host:b[3]||"",hostname:b[4]||"",port:b[5]||"",pathname:b[6]||"",search:b[7]||"",hash:b[8]||""}:null}function c(a,c){function d(a){var b=[];return a.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(a){"/.."===a?b.pop():b.push(a)}),b.join("").replace(/^\//,"/"===a.charAt(0)?"/":"")}return c=b(c||""),a=b(a||""),c&&a?(c.protocol||a.protocol)+(c.protocol||c.authority?c.authority:a.authority)+d(c.protocol||c.authority||"/"===c.pathname.charAt(0)?c.pathname:c.pathname?(a.authority&&!a.pathname?"/":"")+a.pathname.slice(0,a.pathname.lastIndexOf("/")+1)+c.pathname:a.pathname)+(c.protocol||c.authority||c.pathname?c.search:c.search||a.search)+c.hash:null}function d(){document.removeEventListener("DOMContentLoaded",d,!1),window.removeEventListener("load",d,!1),e()}function e(){for(var a=document.getElementsByTagName("script"),b=0;b<a.length;b++){var c=a[b];if("module"==c.type){var d=c.getAttribute("name"),e=c.getAttribute("src"),f=c.innerHTML;(d?k.define(d,f,{address:e}):k.module(f,{address:e})).then(function(){},function(a){nextTick(function(){throw a})})}}}var f,g="undefined"!=typeof window,h=a.Loader||require("./loader"),i=a.Promise||require("./promise");if(g)f=function(a,b,c){function d(){b(f.responseText)}function e(){c(f.statusText+": "+a||"XHR error")}var f=new XMLHttpRequest,g=!0;if(!("withCredentials"in f)){var h=/^(\w+:)?\/\/([^\/]+)/.exec(a);h&&(g=h[2]===window.location.host,h[1]&&(g&=h[1]===window.location.protocol))}g||(f=new XDomainRequest,f.onload=d,f.onerror=e,f.ontimeout=e),f.onreadystatechange=function(){4===f.readyState&&(200===f.status||0==f.status&&f.responseText?d():e())},f.open("GET",a,!0),f.send(null)};else{var j=require("fs");f=function(a,b,c){return j.readFile(a,function(a,d){return a?c(a):(b(d+""),void 0)})}}var k=new h({global:g?window:a,strict:!0,normalize:function(a,b){if("string"!=typeof a)throw new TypeError("Module name must be a string");var c=a.split("/");if(0==c.length)throw new TypeError("No module name provided");var d=0,e=!1,f=0;if("."==c[0]){if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');e=!0}else{for(;".."==c[d];)if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');d&&(e=!0),f=d}for(var g=d;g<c.length;g++){var h=c[g];if(""==h||"."==h||".."==h)throw new TypeError('Illegal module name"'+a+'"')}if(!e)return a;{var i=[],j=(b||"").split("/");j.length-1-f}return i=i.concat(j.splice(0,j.length-1-f)),i=i.concat(c.splice(d)),i.join("/")},locate:function(a){var b,d=a.name,e="";for(var f in this.paths){var g=f.split("*");if(g.length>2)throw new TypeError("Only one wildcard in a path is permitted");1==g.length?d==f&&f.length>e.length&&(e=f):d.substr(0,g[0].length)==g[0]&&d.substr(d.length-g[1].length)==g[1]&&(e=f,b=d.substr(g[0].length,d.length-g[1].length-g[0].length))}var h=this.paths[e];return b&&(h=h.replace("*",b)),c(this.baseURL,h)},fetch:function(a){var b,d,e=new i(function(a,c){b=a,d=c});return f(c(this.baseURL,a.address),function(a){b(a)},d),e}});if(g){var l=window.location.href.split("#")[0].split("?")[0];k.baseURL=l.substring(0,l.lastIndexOf("/")+1)}else k.baseURL="./";if(k.paths={"*":"*.js"},a.System=k,g){var m=document.getElementsByTagName("script");m=m[m.length-1],"complete"===document.readyState?setTimeout(e):document.addEventListener&&(document.addEventListener("DOMContentLoaded",d,!1),window.addEventListener("load",d,!1)),m.getAttribute("data-init")&&window[m.getAttribute("data-init")]()}"object"==typeof exports&&(module.exports=k)}("undefined"!=typeof global?global:this);
/*
* ES6 Promises shim from when.js, Copyright (c) 2010-2014 Brian Cavalier, John Hann, MIT License
*/
!function(){return"undefined"!=typeof Promise&&Promise.all&&Promise.resolve&&Promise.reject}()&&!function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.Promise=a():"undefined"!=typeof global?global.Promise=a():"undefined"!=typeof self&&(self.Promise=a())}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};a[g][0].call(j.exports,function(b){var c=a[g][1][b];return e(c?c:b)},j,j.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){var c=b.exports=a("../lib/Promise"),d="undefined"!=typeof global&&global||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self;"undefined"!=typeof d&&"undefined"==typeof d.Promise&&(d.Promise=c)},{"../lib/Promise":2}],2:[function(b,c){!function(a){"use strict";a(function(a){var b=a("./makePromise"),c=a("./scheduler"),d=a("./async");return b({scheduler:new c(d),monitor:"undefined"!=typeof console?console:void 0})})}("function"==typeof a&&a.amd?a:function(a){c.exports=a(b)})},{"./async":4,"./makePromise":5,"./scheduler":6}],3:[function(b,c){!function(a){"use strict";a(function(){function a(a){this.head=this.tail=this.length=0,this.buffer=new Array(1<<a)}return a.prototype.push=function(a){return this.length===this.buffer.length&&this._ensureCapacity(2*this.length),this.buffer[this.tail]=a,this.tail=this.tail+1&this.buffer.length-1,++this.length,this.length},a.prototype.shift=function(){var a=this.buffer[this.head];return this.buffer[this.head]=void 0,this.head=this.head+1&this.buffer.length-1,--this.length,a},a.prototype._ensureCapacity=function(a){var b,c=this.head,d=this.buffer,e=new Array(a),f=0;if(0===c)for(b=this.length;b>f;++f)e[f]=d[f];else{for(a=d.length,b=this.tail;a>c;++f,++c)e[f]=d[c];for(c=0;b>c;++f,++c)e[f]=d[c]}this.buffer=e,this.head=0,this.tail=this.length},a})}("function"==typeof a&&a.amd?a:function(a){c.exports=a()})},{}],4:[function(b,c){!function(a){"use strict";a(function(a){var b,c;return b="undefined"!=typeof process&&null!==process&&"function"==typeof process.nextTick?function(a){process.nextTick(a)}:(c="function"==typeof MutationObserver&&MutationObserver||"function"==typeof WebKitMutationObserver&&WebKitMutationObserver)?function(a,b){function c(){var a=d;d=void 0,a()}var d,e=a.createElement("div"),f=new b(c);return f.observe(e,{attributes:!0}),function(a){d=a,e.setAttribute("class","x")}}(document,c):function(a){try{return a("vertx").runOnLoop||a("vertx").runOnContext}catch(b){}var c=setTimeout;return function(a){c(a,0)}}(a)})}("function"==typeof a&&a.amd?a:function(a){c.exports=a(b)})},{}],5:[function(b,c){!function(a){"use strict";a(function(){return function(a){function b(a){function b(a){f._handler.resolve(a)}function d(a){f._handler.reject(a)}function e(a){f._handler.notify(a)}var f=this;this._handler=new q,c(a,b,d,e)}function c(a,b,c,d){try{a(b,c,d)}catch(e){c(e)}}function d(a){return a instanceof b?a:new j(new r(k(a)))}function e(a){return new j(new r(new v(a)))}function f(){return G}function g(){return new j(new q)}function h(a){function b(a,b,c,d){c.when(F,F,void 0,a,function(a){b[d]=a,0===--g&&this.resolve(b)},a.reject,a.notify)}var c,d,e=new q,f=a.length>>>0,g=f,h=[];for(c=0;f>c;++c)c in a?(d=a[c],C(d)?b(e,h,l(d),c):(h[c]=d,--g)):--g;return 0===g&&e.resolve(h),new j(e)}function i(a){if(Object(a)===a&&0===a.length)return f();for(var b=new q,c=0;c<a.length;++c)k(a[c]).when(F,F,void 0,b,b.resolve,b.reject);return new j(b)}function j(a){this._handler=a}function k(a,c){return a instanceof b?m(a,c):C(a)?n(a):new u(a)}function l(a){return a instanceof b?a._handler.join():n(a)}function m(a,b){var c=a._handler.join();return b===c?w():c}function n(a){try{var b=a.then;return"function"==typeof b?new t(b,a):new u(a)}catch(c){return new v(c)}}function o(){}function p(a){if(this.handler=a,this._isMonitored()){var b=this._env.promiseMonitor.captureStack();this.trace=a._addTrace(b)}}function q(a){this.consumers=[],this.receiver=a,this.handler=void 0,this.resolved=!1,this._isMonitored()&&(this.trace=this._env.promiseMonitor.captureStack())}function r(a){p.call(this,a)}function s(a,b){p.call(this,a),this.receiver=b}function t(a,b){q.call(this),this.assimilated=!1,this.untrustedThen=a,this.thenable=b}function u(a){this.value=a}function v(a){this.value=a,this.observed=!1,this._isMonitored()&&(this.key=this._env.promiseMonitor.startTrace(a))}function w(){return new v(new TypeError("Promise cycle"))}function x(a){return{state:"fulfilled",value:a}}function y(a){return{state:"rejected",reason:a}}function z(){return{state:"pending"}}function A(a,b,c,d,e,f,g,h){this.a=a,this.b=b,this.c=c,this.d=d,this.e=e,this.f=f,this.g=g,this.handler=h}function B(a,b){this.q=a,this.value=b}function C(a){return("object"==typeof a||"function"==typeof a)&&null!==a}function D(a,b,c){try{return a.call(c,b)}catch(d){return e(d)}}function E(a,b,c){try{return a.call(c,b)}catch(d){return d}}function F(){}var G,H=a.scheduler,I=Object.create||function(a){function b(){}return b.prototype=a,new b};return b.resolve=d,b.reject=e,b.never=f,b._defer=g,b.prototype.then=function(a,b,c){var d=this._handler,e=new q(d.receiver);return d.when(e.resolve,e.notify,e,d.receiver,a,b,c),new j(e)},b.prototype["catch"]=b.prototype.otherwise=function(a){return this.then(void 0,a)},b.prototype._bindContext=function(a){return new j(new s(this._handler,a))},b.all=h,b.race=i,j.prototype=I(b.prototype),o.prototype.inspect=z,o.prototype.when=F,o.prototype.resolve=F,o.prototype.reject=F,o.prototype.notify=F,o.prototype.join=function(){return this},o.prototype._env=a.monitor||b,o.prototype._addTrace=F,o.prototype._isMonitored=function(){return"undefined"!=typeof this._env.promiseMonitor},p.prototype=I(o.prototype),p.prototype.join=function(){return this.handler.join()},p.prototype.inspect=function(){return this.handler.inspect()},p.prototype._addTrace=function(a){return this.handler._addTrace(a)},q.prototype=I(o.prototype),q.prototype.inspect=function(){return this.resolved?this.handler.join().inspect():z()},q.prototype.resolve=function(a){this._join(k(a,this))},q.prototype.reject=function(a){this._join(new v(a))},q.prototype.join=function(){return this.resolved?this.handler.join():this},q.prototype.run=function(){var a=this.consumers,b=this.handler=this.handler.join();this.consumers=void 0;for(var c=0;c<a.length;c+=7)b.when(a[c],a[c+1],a[c+2],a[c+3],a[c+4],a[c+5],a[c+6])},q.prototype._join=function(a){this.resolved||(this.resolved=!0,this.handler=a,H.enqueue(this),this._isMonitored()&&(this.trace=a._addTrace(this.trace)))},q.prototype.when=function(a,b,c,d,e,f,g){this.resolved?H.enqueue(new A(a,b,c,d,e,f,g,this.handler.join())):this.consumers.push(a,b,c,d,e,f,g)},q.prototype.notify=function(a){this.resolved||H.enqueue(new B(this.consumers,a))},q.prototype._addTrace=function(a){return this.resolved?this.handler._addTrace(a):a},r.prototype=I(p.prototype),r.prototype.when=function(a,b,c,d,e,f,g){H.enqueue(new A(a,b,c,d,e,f,g,this.join()))},s.prototype=I(p.prototype),s.prototype.when=function(a,b,c,d,e,f,g){void 0!==this.receiver&&(d=this.receiver),this.join().when(a,b,c,d,e,f,g)},t.prototype=I(q.prototype),t.prototype.when=function(a,b,c,d,e,f,g){this.assimilated||(this.assimilated=!0,this._assimilate()),q.prototype.when.call(this,a,b,c,d,e,f,g)},t.prototype._assimilate=function(){function a(a){d.resolve(a)}function b(a){d.reject(a)}function c(a){d.notify(a)}var d=this;this._try(this.untrustedThen,this.thenable,a,b,c)},t.prototype._try=function(a,b,c,d,e){try{a.call(b,c,d,e)}catch(f){d(f)}},u.prototype=I(o.prototype),u.prototype.inspect=function(){return x(this.value)},u.prototype.when=function(a,b,c,d,e){var f="function"==typeof e?D(e,this.value,d):this.value;a.call(c,f)},v.prototype=I(o.prototype),v.prototype.inspect=function(){return y(this.value)},v.prototype.when=function(a,b,c,d,f,g){this._isMonitored()&&!this.observed&&this._env.promiseMonitor.removeTrace(this.key),this.observed=!0;var h="function"==typeof g?D(g,this.value,d):e(this.value);a.call(c,h)},v.prototype._addTrace=function(a){this.observed||this._env.promiseMonitor.updateTrace(this.key,a)},G=new j(new o),A.prototype.run=function(){this.handler.when(this.a,this.b,this.c,this.d,this.e,this.f,this.g)},B.prototype.run=function(){for(var a=this.q,b=1;b<a.length;b+=7)this._notify(a[b],a[b+1],a[b+2],a[b+5])},B.prototype._notify=function(a,b,c,d){var e="function"==typeof d?E(d,this.value,c):this.value;a.call(b,e)},b}})}("function"==typeof a&&a.amd?a:function(a){c.exports=a()})},{}],6:[function(b,c){!function(a){"use strict";a(function(a){function b(a){this._enqueue=a,this._handlerQueue=new c(15);var b=this;this.drainQueue=function(){b._drainQueue()}}var c=a("./Queue");return b.prototype.enqueue=function(a){1===this._handlerQueue.push(a)&&this._enqueue(this.drainQueue)},b.prototype._drainQueue=function(){for(var a=this._handlerQueue;a.length>0;)a.shift().run()},b})}("function"==typeof a&&a.amd?a:function(a){c.exports=a(b)})},{"./Queue":3}]},{},[1])(1)}),function(global){function __eval(__source,global,__sourceURL,__moduleName){try{eval('var __moduleName = "'+(__moduleName||"").replace('"','"')+'"; with(global) { (function() { '+__source+" \n }).call(global); }"+(__sourceURL&&!__source.match(/\/\/[@#] ?(sourceURL|sourceMappingURL)=([^\n]+)/)?"\n//# sourceURL="+__sourceURL:""))}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+__sourceURL+"\n "+e.message),e}}!function(){function a(a){return{status:"loading",name:a,metadata:{},linkSets:[]}}function b(b,d,e,f){return new v(function(a){a(b.normalize(d,e,f))}).then(function(d){var e;if(b._modules[d])return e=a(d),e.status="linked",e;for(var f=0,g=b._loads.length;g>f;f++)if(e=b._loads[f],e.name==d)return e;return e=a(d),b._loads.push(e),c(b,e),e})}function c(a,b){d(a,b,v.resolve().then(function(){return a.locate({name:b.name,metadata:b.metadata})}))}function d(a,b,c){e(a,b,c.then(function(c){return"failed"==b.status?void 0:(b.address=c,a.fetch({name:b.name,metadata:b.metadata,address:c}))}))}function e(a,c,d){d.then(function(b){return"failed"==c.status?void 0:a.translate({name:c.name,metadata:c.metadata,address:c.address,source:b})}).then(function(b){return"failed"==c.status?void 0:(c.source=b,a.instantiate({name:c.name,metadata:c.metadata,address:c.address,source:b}))}).then(function(d){if("failed"==c.status)return void 0;var e;if(void 0===d){if(!global.traceur)throw new TypeError("Include Traceur for module syntax support");t||(t=global.traceur,$traceurRuntime.ModuleStore.get=$traceurRuntime.getModuleImpl=function(a){return System.get(a)}),c.address=c.address||"anon"+ ++z;var f=new t.syntax.Parser(new t.syntax.SourceFile(c.address,c.source));c.body=f.parseModule(),e=r(c.body),c.kind="declarative"}else{if("object"!=typeof d)throw TypeError("Invalid instantiate return value");e=d.deps||[],c.execute=d.execute,c.kind="dynamic"}c.dependencies={},c.depsList=e;for(var h=[],i=0,j=e.length;j>i;i++)(function(d){var e=b(a,d,c.name,c.address);e.then(function(a){if(c.dependencies[d]=a.name,"linked"!=a.status)for(var b=c.linkSets.concat([]),e=0,f=b.length;f>e;e++)g(b[e],a)}),h.push(e)})(e[i]);return v.all(h)}).then(function(){c.status="loaded";for(var a=c.linkSets.concat([]),b=0,d=a.length;d>b;b++)h(a[b],c)},function(a){c.status="failed",c.exception=a;for(var b=0,d=c.linkSets.length;d>b;b++)i(c.linkSets[b],a)})}function f(a,b){var c,d,e=new v(function(a,b){c=a,d=b}),f={loader:a,loads:[],done:e,resolve:c,reject:d,loadingCount:0};return g(f,b),f}function g(a,b){for(var c=0,d=a.loads.length;d>c;c++)if(a.loads[c]==b)return;a.loads.push(b),b.linkSets.push(a),"loaded"!=b.status&&a.loadingCount++;var e=a.loader;for(var f in b.dependencies){var h=b.dependencies[f];if(!e._modules[h])for(var c=0,d=e._loads.length;d>c;c++)if(e._loads[c].name==h){g(a,e._loads[c]);break}}}function h(a,b){if(a.loadingCount--,!(a.loadingCount>0)){var c=a.loads[0];try{o(a.loads,a.loader)}catch(d){return i(a,d)}a.resolve(c)}}function i(a,b){for(var c=a.loads.concat([]),d=0,e=c.length;e>d;d++){var f=c[d],g=x.call(f.linkSets,a);if(f.linkSets.splice(g,1),0==f.linkSets.length){var h=x.call(a.loader._loads,f);-1!=h&&a.loader._loads.splice(h,1)}}a.reject(b)}function j(a,b){b.name&&(a._modules[b.name]=b.module);var c=x.call(a._loads,b);-1!=c&&a._loads.splice(c,1);for(var d=0,e=b.linkSets.length;e>d;d++)c=x.call(b.linkSets[d].loads,b),b.linkSets[d].loads.splice(c,1);b.linkSets=[]}function k(a,b,c){return new v(l(a,b,c&&c.address?"fetch":"locate",void 0,c&&c.address,void 0)).then(function(a){return a})}function l(b,g,h,i,j,k){return function(l,m){if(b._modules[g])throw new TypeError('Module "'+g+'" already exists in the module table');for(var n=0,o=b._loads.length;o>n;n++)if(b._loads[n].name==g)throw new TypeError('Module "'+g+'" is already loading');var p=a(g);i&&(p.metadata=i);var q=f(b,p);b._loads.push(p),q.done.then(l,m),"locate"==h?c(b,p):"fetch"==h?d(b,p,v.resolve(j)):(p.address=j,e(b,p,v.resolve(k)))}}function m(a,b){return n(b.module,a),b.module.module}function n(a,b){if(a.module)return a.module;for(var c in a.dependencies){var d=a.dependencies[c];b._modules[d].module||n(b._modules[d],b)}t.options.sourceMaps=!0,t.options.modules="instantiate";var e=new t.util.ErrorReporter;e.reportMessageInternal=function(a,b){throw b+"\n"+a};var f=global.System;global.System=global.traceurSystem;var g=new t.codegeneration.module.AttachModuleNameTransformer(a.name).transformAny(a.body);g=new t.codegeneration.FromOptionsTransformer(e).transform(g),global.System=f,delete a.body;var h=new t.outputgeneration.SourceMapGenerator({file:a.address}),i={sourceMapGenerator:h},j=t.outputgeneration.TreeWriter.write(g,i);global.btoa&&(j+="\n//# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(i.sourceMap)))+"\n");var k=System.register;System.register=function(b,c,d){for(var e=0;e<c.length;e++)c[e]=a.dependencies[c[e]];a.module=new s(d.apply(global,c))},__eval(j,global,a.address,a.name),System.register=k}function o(a,b){for(var c=!1;a.length;){c=!0;a:for(var d=0;d<a.length;d++){var e=a[d],f=[];for(var g in e.dependencies){var h=e.dependencies[g];if(!b._modules[h])continue a;var i=x.call(e.depsList,g);f[i]=h}if(c=!1,"declarative"==e.kind)e.module={name:e.name,dependencies:e.dependencies,body:e.body};else{var k=e.execute.apply(null,f);if(!(k instanceof s))throw new TypeError("Execution must define a Module instance");e.module={module:k}}e.status="linked",j(b,e)}if(c)throw new TypeError("Circular dependencies not supported by the polyfill")}}function p(a){if("object"!=typeof a)throw new TypeError("Options must be an object");a.normalize&&(this.normalize=a.normalize),a.locate&&(this.locate=a.locate),a.fetch&&(this.fetch=a.fetch),a.translate&&(this.translate=a.translate),a.instantiate&&(this.instantiate=a.instantiate),u(this,"global",{get:function(){throw new TypeError("global accessor not provided by polyfill")}}),u(this,"realm",{get:function(){throw new TypeError("Realms not implemented in polyfill")}}),this._modules={},this._loads=[]}function q(a,b,c,d){var e,f;if(b(a,c,d)!==!1)for(e in a)a.hasOwnProperty(e)&&"location"!=e&&"type"!=e&&(f=a[e],"object"==typeof f&&null!==f&&q(f,b,a,e))}function r(a){function b(a){-1==x.call(c,a)&&c.push(a)}var c=[];return q(a,function(a){"EXPORT_DECLARATION"==a.type?a.declaration.moduleSpecifier&&b(a.declaration.moduleSpecifier.token.processedValue):"IMPORT_DECLARATION"==a.type?b(a.moduleSpecifier.token.processedValue):"MODULE_DECLARATION"==a.type&&b(a.expression.token.processedValue)}),c}function s(a){if("object"!=typeof a)throw new TypeError("Expected object");if(!(this instanceof s))return new s(a);var b=this;for(var c in a)!function(a,c){u(b,a,{configurable:!1,enumerable:!0,get:function(){return c}})}(c,a[c]);Object.preventExtensions&&Object.preventExtensions(this)}var t,u,v=global.Promise||require("./promise");try{Object.defineProperty({},"a",{})&&(u=Object.defineProperty)}catch(w){u=function(a,b,c){try{a[b]=c.value||c.get.call(a)}catch(d){}}}console.assert=console.assert||function(){};var x=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},y={};p.prototype={define:function(a,b,c){if(y[a])throw new TypeError("Module is already loading.");return y[a]=new v(l(this,a,c&&c.address?"fetch":"translate",c&&c.meta||{},c&&c.address,b)),y[a].then(function(){delete y[a]})},load:function(a,b){return this._modules[a]?(n(this._modules[a],this),v.resolve(this._modules[a].module)):y[a]?y[a]:(y[a]=k(this,a,b),y[a].then(function(){delete y[a]}))},module:function(b,c){var d=a();d.address=c&&c.address;var g=f(this,d),h=v.resolve(b),i=this,j=g.done.then(function(){return m(i,d)});return e(this,d,h),j},"import":function(a,b){if(this._modules[a])return n(this._modules[a],this),v.resolve(this._modules[a].module);var c=this;return(y[a]||(y[a]=k(this,a,b))).then(function(b){return delete y[a],m(c,b)})},eval:function(){throw new TypeError("Eval not implemented in polyfill")},get:function(a){return n(this._modules[a],this),this._modules[a].module},has:function(a){return!!this._modules[a]},set:function(a,b){if(!(b instanceof s))throw new TypeError("Set must be a module");this._modules[a]={module:b}},"delete":function(a){return this._modules[a]?delete this._modules[a]:!1},entries:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},keys:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},values:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},normalize:function(a){return a},locate:function(a){return a.name},fetch:function(){throw new TypeError("Fetch not implemented")},translate:function(a){return a.source},instantiate:function(){}};var z=0;"object"==typeof exports&&(module.exports=p),global.Loader||(global.Loader=p),global.LoaderPolyfill=p,global.Module=s}()}("undefined"!=typeof global?global:this),function(a){function b(a){var b=String(a).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return b?{href:b[0]||"",protocol:b[1]||"",authority:b[2]||"",host:b[3]||"",hostname:b[4]||"",port:b[5]||"",pathname:b[6]||"",search:b[7]||"",hash:b[8]||""}:null}function c(a,c){function d(a){var b=[];return a.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(a){"/.."===a?b.pop():b.push(a)}),b.join("").replace(/^\//,"/"===a.charAt(0)?"/":"")}return c=b(c||""),a=b(a||""),c&&a?(c.protocol||a.protocol)+(c.protocol||c.authority?c.authority:a.authority)+d(c.protocol||c.authority||"/"===c.pathname.charAt(0)?c.pathname:c.pathname?(a.authority&&!a.pathname?"/":"")+a.pathname.slice(0,a.pathname.lastIndexOf("/")+1)+c.pathname:a.pathname)+(c.protocol||c.authority||c.pathname?c.search:c.search||a.search)+c.hash:null}function d(){document.removeEventListener("DOMContentLoaded",d,!1),window.removeEventListener("load",d,!1),e()}function e(){for(var a=document.getElementsByTagName("script"),b=0;b<a.length;b++){var c=a[b];if("module"==c.type){var d=c.getAttribute("name"),e=c.getAttribute("src"),f=c.innerHTML;(d?k.define(d,f,{address:e}):k.module(f,{address:e})).then(function(){},function(a){nextTick(function(){throw a})})}}}var f,g="undefined"!=typeof window,h=a.Loader||require("./loader"),i=a.Promise||require("./promise");if(g)f=function(a,b,c){function d(){b(f.responseText)}function e(){c(f.statusText+": "+a||"XHR error")}var f=new XMLHttpRequest,g=!0;if(!("withCredentials"in f)){var h=/^(\w+:)?\/\/([^\/]+)/.exec(a);h&&(g=h[2]===window.location.host,h[1]&&(g&=h[1]===window.location.protocol))}g||(f=new XDomainRequest,f.onload=d,f.onerror=e,f.ontimeout=e),f.onreadystatechange=function(){4===f.readyState&&(200===f.status||0==f.status&&f.responseText?d():e())},f.open("GET",a,!0),f.send(null)};else{var j=require("fs");f=function(a,b,c){return j.readFile(a,function(a,d){return a?c(a):(b(d+""),void 0)})}}var k=new h({global:g?window:a,strict:!0,normalize:function(a,b){if("string"!=typeof a)throw new TypeError("Module name must be a string");var c=a.split("/");if(0==c.length)throw new TypeError("No module name provided");var d=0,e=!1,f=0;if("."==c[0]){if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');e=!0}else{for(;".."==c[d];)if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');d&&(e=!0),f=d}for(var g=d;g<c.length;g++){var h=c[g];if(""==h||"."==h||".."==h)throw new TypeError('Illegal module name"'+a+'"')}if(!e)return a;{var i=[],j=(b||"").split("/");j.length-1-f}return i=i.concat(j.splice(0,j.length-1-f)),i=i.concat(c.splice(d,c.length-d)),i.join("/")},locate:function(a){var b,d=a.name,e="";for(var f in this.paths){var g=f.split("*");if(g.length>2)throw new TypeError("Only one wildcard in a path is permitted");1==g.length?d==f&&f.length>e.length&&(e=f):d.substr(0,g[0].length)==g[0]&&d.substr(d.length-g[1].length)==g[1]&&(e=f,b=d.substr(g[0].length,d.length-g[1].length-g[0].length))}var h=this.paths[e];return b&&(h=h.replace("*",b)),c(this.baseURL,h)},fetch:function(a){var b,d,e=new i(function(a,c){b=a,d=c});return f(c(this.baseURL,a.address),function(a){b(a)},d),e}});if(g){var l=window.location.href.split("#")[0].split("?")[0];k.baseURL=l.substring(0,l.lastIndexOf("/")+1)}else k.baseURL="./";if(k.paths={"*":"*.js"},a.System&&a.traceur&&(a.traceurSystem=a.System),a.System=k,g){var m=document.getElementsByTagName("script");m=m[m.length-1],"complete"===document.readyState?setTimeout(e):document.addEventListener&&(document.addEventListener("DOMContentLoaded",d,!1),window.addEventListener("load",d,!1)),m.getAttribute("data-init")&&window[m.getAttribute("data-init")]()}"object"==typeof exports&&(module.exports=k)}("undefined"!=typeof global?global:this);

@@ -10,3 +10,3 @@ 'use strict';

' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n */\n'
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n */'
},

@@ -27,8 +27,16 @@ jshint: {

src: [
'lib/promise.js',
'lib/module.js',
'lib/loader.js',
'lib/system.js'
'lib/promise.js',
'lib/module.js',
'lib/loader.js',
'lib/system.js'
],
dest: 'tmp/<%= pkg.name %>.js'
},
polyfillOnly: {
src: [
'lib/module.js',
'lib/loader.js',
'lib/system.js'
],
dest: 'tmp/<%= pkg.name %>-sans-promises.js'
}

@@ -38,14 +46,18 @@ },

options: {
banner: '<%= meta.banner %>'
banner: '<%= meta.banner %>\n',
compress: {
drop_console: true
}
},
dist: {
src: 'tmp/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.js'
options: {
banner: '<%= meta.banner %>\n'
+ '/*\n * ES6 Promises shim from when.js, Copyright (c) 2010-2014 Brian Cavalier, John Hann, MIT License\n */\n'
},
src: 'tmp/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.js'
},
traceur: {
options: {
banner: '/*\n Traceur Compiler 0.0.25 - https://github.com/google/traceur-compiler \n*/\n'
},
src: 'lib/traceur.js',
dest: 'dist/traceur.js'
polyfillOnly: {
src: 'tmp/<%= pkg.name %>-sans-promises.js',
dest: 'dist/<%= pkg.name %>-sans-promises.js'
}

@@ -52,0 +64,0 @@ }

@@ -57,631 +57,663 @@ /*

(function (global) {
var Promise = global.Promise || require('./promise');
(function() {
var Promise = global.Promise || require('./promise');
var traceur;
var traceur;
var defineProperty;
try {
if (!!Object.defineProperty({}, 'a', {})) {
defineProperty = Object.defineProperty;
}
} catch (e) {
defineProperty = function (obj, prop, opt) {
try {
obj[prop] = opt.value || opt.get.call(obj);
var defineProperty;
try {
if (!!Object.defineProperty({}, 'a', {})) {
defineProperty = Object.defineProperty;
}
catch(e) {}
} catch (e) {
defineProperty = function (obj, prop, opt) {
try {
obj[prop] = opt.value || opt.get.call(obj);
}
catch(e) {}
}
}
}
function assert(name, expression) {
if (!expression)
console.log('Assertion Failed - ' + name);
}
console.assert = console.assert || function() {};
// Define an IE-friendly shim good-enough for purposes
var indexOf = Array.prototype.indexOf || function (item) {
for (var i = 0, thisLen = this.length; i < thisLen; i++) {
if (this[i] === item) {
return i;
// Define an IE-friendly shim good-enough for purposes
var indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, thisLen = this.length; i < thisLen; i++) {
if (this[i] === item) {
return i;
}
}
}
return -1;
};
return -1;
};
// Load Abstract Functions
// Load Abstract Functions
function createLoad(name) {
return {
status: 'loading',
name: name,
metadata: {},
linkSets: []
};
}
function createLoad(name) {
return {
status: 'loading',
name: name,
metadata: {},
linkSets: []
};
}
// promise for a load record, can be in registry, already loading, or not
function requestLoad(loader, request, referrerName, referrerAddress) {
return new Promise(function(resolve, reject) {
// CallNormalize
resolve(loader.normalize(request, referrerName, referrerAddress));
})
// promise for a load record, can be in registry, already loading, or not
function requestLoad(loader, request, referrerName, referrerAddress) {
return new Promise(function(resolve, reject) {
// CallNormalize
resolve(loader.normalize(request, referrerName, referrerAddress));
})
// GetOrCreateLoad
.then(function(name) {
var load;
if (loader._modules[name]) {
load = createLoad(name);
load.status = 'linked';
return load;
}
for (var i = 0, l = loader._loads.length; i < l; i++) {
load = loader._loads[i];
if (load.name == name) {
assert('loading or loaded', load.status == 'loading' || load.status == 'loaded');
// GetOrCreateLoad
.then(function(name) {
var load;
if (loader._modules[name]) {
load = createLoad(name);
load.status = 'linked';
return load;
}
}
// CreateLoad
load = createLoad(name);
loader._loads.push(load);
for (var i = 0, l = loader._loads.length; i < l; i++) {
load = loader._loads[i];
if (load.name == name) {
console.assert('loading or loaded', load.status == 'loading' || load.status == 'loaded');
return load;
}
}
proceedToLocate(loader, load);
// CreateLoad
load = createLoad(name);
loader._loads.push(load);
return load;
});
}
function proceedToLocate(loader, load) {
proceedToFetch(loader, load,
Promise.resolve()
// CallLocate
.then(function() {
return loader.locate({ name: load.name, metadata: load.metadata });
})
);
}
function proceedToFetch(loader, load, p) {
proceedToTranslate(loader, load,
proceedToLocate(loader, load);
return load;
});
}
function proceedToLocate(loader, load) {
proceedToFetch(loader, load,
Promise.resolve()
// CallLocate
.then(function() {
return loader.locate({ name: load.name, metadata: load.metadata });
})
);
}
function proceedToFetch(loader, load, p) {
proceedToTranslate(loader, load,
p
// CallFetch
.then(function(address) {
if (load.status == 'failed') // NB https://github.com/jorendorff/js-loaders/issues/88
return undefined;
load.address = address;
return loader.fetch({ name: load.name, metadata: load.metadata, address: address });
})
);
}
function proceedToTranslate(loader, load, p) {
p
// CallFetch
.then(function(address) {
if (load.status == 'failed') // NB https://github.com/jorendorff/js-loaders/issues/88
// CallTranslate
.then(function(source) {
if (load.status == 'failed')
return undefined;
load.address = address;
return loader.fetch({ name: load.name, metadata: load.metadata, address: address });
return loader.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source })
})
);
}
function proceedToTranslate(loader, load, p) {
p
// CallTranslate
.then(function(source) {
if (load.status == 'failed')
return undefined;
return loader.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source })
})
// CallInstantiate
.then(function(source) {
if (load.status == 'failed')
return undefined;
load.source = source;
return loader.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
})
// CallInstantiate
.then(function(source) {
if (load.status == 'failed')
return undefined;
load.source = source;
return loader.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
})
// InstantiateSucceeded
.then(function(instantiateResult) {
if (load.status == 'failed')
return undefined;
// InstantiateSucceeded
.then(function(instantiateResult) {
if (load.status == 'failed')
return undefined;
var depsList;
if (instantiateResult === undefined) {
if (global.traceur) {
if (!traceur) {
traceur = global.traceur;
$traceurRuntime.ModuleStore.get = $traceurRuntime.getModuleImpl = function(name) {
return System.get(name);
var depsList;
if (instantiateResult === undefined) {
if (global.traceur) {
if (!traceur) {
traceur = global.traceur;
$traceurRuntime.ModuleStore.get = $traceurRuntime.getModuleImpl = function(name) {
return System.get(name);
}
}
load.address = load.address || 'anon' + ++anonCnt;
var parser = new traceur.syntax.Parser(new traceur.syntax.SourceFile(load.address, load.source));
load.body = parser.parseModule();
depsList = getImports(load.body);
}
load.address = load.address || 'anon' + ++anonCnt;
var parser = new traceur.syntax.Parser(new traceur.syntax.SourceFile(load.address, load.source));
load.body = parser.parseModule();
depsList = getImports(load.body);
else {
throw new TypeError('Include Traceur for module syntax support');
}
load.kind = 'declarative';
}
else {
throw new TypeError('Include Traceur for module syntax support');
else if (typeof instantiateResult == 'object') {
depsList = instantiateResult.deps || [];
load.execute = instantiateResult.execute;
load.kind = 'dynamic';
}
load.kind = 'declarative';
}
else if (typeof instantiateResult == 'object') {
depsList = instantiateResult.deps || [];
load.execute = instantiateResult.execute;
load.kind = 'dynamic';
}
else
throw TypeError('Invalid instantiate return value');
else
throw TypeError('Invalid instantiate return value');
// ProcessLoadDependencies
load.dependencies = {};
load.depsList = depsList;
var loadPromises = [];
for (var i = 0, l = depsList.length; i < l; i++) (function(request) {
var p = requestLoad(loader, request, load.name, load.address);
// ProcessLoadDependencies
load.dependencies = {};
load.depsList = depsList;
var loadPromises = [];
for (var i = 0, l = depsList.length; i < l; i++) (function(request) {
var p = requestLoad(loader, request, load.name, load.address);
// AddDependencyLoad (load is parentLoad)
p.then(function(depLoad) {
assert('not already a dependency', !load.dependencies[request]);
load.dependencies[request] = depLoad.name;
// AddDependencyLoad (load is parentLoad)
p.then(function(depLoad) {
console.assert('not already a dependency', !load.dependencies[request]);
load.dependencies[request] = depLoad.name;
if (depLoad.status != 'linked') {
var linkSets = load.linkSets.concat([]);
for (var i = 0, l = linkSets.length; i < l; i++)
addLoadToLinkSet(linkSets[i], depLoad);
}
});
if (depLoad.status != 'linked') {
var linkSets = load.linkSets.concat([]);
for (var i = 0, l = linkSets.length; i < l; i++)
addLoadToLinkSet(linkSets[i], depLoad);
}
});
loadPromises.push(p);
})(depsList[i]);
loadPromises.push(p);
})(depsList[i]);
return Promise.all(loadPromises);
})
return Promise.all(loadPromises);
})
// LoadSucceeded
.then(function() {
assert('is loading', load.status == 'loading');
// LoadSucceeded
.then(function() {
console.assert('is loading', load.status == 'loading');
load.status = 'loaded';
load.status = 'loaded';
// console.log('load succeeeded ' + load.name);
// snapshot(loader);
// console.log('load succeeeded ' + load.name);
// snapshot(loader);
var linkSets = load.linkSets.concat([]);
for (var i = 0, l = linkSets.length; i < l; i++)
updateLinkSetOnLoad(linkSets[i], load);
var linkSets = load.linkSets.concat([]);
for (var i = 0, l = linkSets.length; i < l; i++)
updateLinkSetOnLoad(linkSets[i], load);
}
// LoadFailed
, function(exc) {
console.assert('is loading on fail', load.status == 'loading');
load.status = 'failed';
load.exception = exc;
for (var i = 0, l = load.linkSets.length; i < l; i++)
linkSetFailed(load.linkSets[i], exc);
console.assert('fail linkSets removed', load.linkSets.length == 0);
});
}
// LoadFailed
, function(exc) {
assert('is loading on fail', load.status == 'loading');
load.status = 'failed';
load.exception = exc;
for (var i = 0, l = load.linkSets.length; i < l; i++)
linkSetFailed(load.linkSets[i], exc);
assert('fail linkSets removed', load.linkSets.length == 0);
});
}
// LinkSet Abstract Functions
function createLinkSet(loader, startingLoad) {
var resolve, reject, promise = new Promise(function(_resolve, _reject) { resolve = _resolve; reject = _reject; });
var linkSet = {
loader: loader,
loads: [],
done: promise,
resolve: resolve,
reject: reject,
loadingCount: 0
};
addLoadToLinkSet(linkSet, startingLoad);
return linkSet;
}
function addLoadToLinkSet(linkSet, load) {
console.assert('loading or loaded on link set', load.status == 'loading' || load.status == 'loaded');
// LinkSet Abstract Functions
function createLinkSet(loader, startingLoad) {
var resolve, reject, promise = new Promise(function(_resolve, _reject) { resolve = _resolve; reject = _reject; });
var linkSet = {
loader: loader,
loads: [],
done: promise,
resolve: resolve,
reject: reject,
loadingCount: 0
};
addLoadToLinkSet(linkSet, startingLoad);
return linkSet;
}
function addLoadToLinkSet(linkSet, load) {
assert('loading or loaded on link set', load.status == 'loading' || load.status == 'loaded');
for (var i = 0, l = linkSet.loads.length; i < l; i++)
if (linkSet.loads[i] == load)
return;
for (var i = 0, l = linkSet.loads.length; i < l; i++)
if (linkSet.loads[i] == load)
return;
linkSet.loads.push(load);
load.linkSets.push(linkSet);
linkSet.loads.push(load);
load.linkSets.push(linkSet);
if (load.status != 'loaded')
linkSet.loadingCount++;
if (load.status != 'loaded')
linkSet.loadingCount++;
var loader = linkSet.loader;
var loader = linkSet.loader;
for (var dep in load.dependencies) {
var name = load.dependencies[dep];
for (var dep in load.dependencies) {
var name = load.dependencies[dep];
if (loader._modules[name])
continue;
if (loader._modules[name])
continue;
for (var i = 0, l = loader._loads.length; i < l; i++)
if (loader._loads[i].name == name) {
addLoadToLinkSet(linkSet, loader._loads[i]);
break;
}
}
// console.log('add to linkset ' + load.name);
// snapshot(linkSet.loader);
}
function updateLinkSetOnLoad(linkSet, load) {
// NB https://github.com/jorendorff/js-loaders/issues/85
// console.assert('no load when updated ' + load.name, indexOf.call(linkSet.loads, load) != -1);
console.assert('loaded or linked', load.status == 'loaded' || load.status == 'linked');
for (var i = 0, l = loader._loads.length; i < l; i++)
if (loader._loads[i].name == name) {
addLoadToLinkSet(linkSet, loader._loads[i]);
break;
// console.log('update linkset on load ' + load.name);
// snapshot(linkSet.loader);
// see https://github.com/jorendorff/js-loaders/issues/80
linkSet.loadingCount--;
/* for (var i = 0; i < linkSet.loads.length; i++) {
if (linkSet.loads[i].status == 'loading') {
return;
}
}
// console.log('add to linkset ' + load.name);
// snapshot(linkSet.loader);
}
function updateLinkSetOnLoad(linkSet, load) {
// NB https://github.com/jorendorff/js-loaders/issues/85
// assert('no load when updated ' + load.name, indexOf.call(linkSet.loads, load) != -1);
assert('loaded or linked', load.status == 'loaded' || load.status == 'linked');
} */
// console.log('update linkset on load ' + load.name);
// snapshot(linkSet.loader);
if (linkSet.loadingCount > 0)
return;
// see https://github.com/jorendorff/js-loaders/issues/80
linkSet.loadingCount--;
/* for (var i = 0; i < linkSet.loads.length; i++) {
if (linkSet.loads[i].status == 'loading') {
return;
var startingLoad = linkSet.loads[0];
try {
link(linkSet.loads, linkSet.loader);
}
} */
catch(exc) {
return linkSetFailed(linkSet, exc);
}
if (linkSet.loadingCount > 0)
return;
var startingLoad = linkSet.loads[0];
try {
link(linkSet.loads, linkSet.loader);
console.assert('loads cleared', linkSet.loads.length == 0);
linkSet.resolve(startingLoad);
}
catch(exc) {
return linkSetFailed(linkSet, exc);
function linkSetFailed(linkSet, exc) {
var loads = linkSet.loads.concat([]);
for (var i = 0, l = loads.length; i < l; i++) {
var load = loads[i];
var linkIndex = indexOf.call(load.linkSets, linkSet);
console.assert('link not present', linkIndex != -1);
load.linkSets.splice(linkIndex, 1);
if (load.linkSets.length == 0) {
var globalLoadsIndex = indexOf.call(linkSet.loader._loads, load);
if (globalLoadsIndex != -1)
linkSet.loader._loads.splice(globalLoadsIndex, 1);
}
}
linkSet.reject(exc);
}
assert('loads cleared', linkSet.loads.length == 0);
linkSet.resolve(startingLoad);
}
function linkSetFailed(linkSet, exc) {
var loads = linkSet.loads.concat([]);
for (var i = 0, l = loads.length; i < l; i++) {
var load = loads[i];
var linkIndex = indexOf.call(load.linkSets, linkSet);
assert('link not present', linkIndex != -1);
load.linkSets.splice(linkIndex, 1);
if (load.linkSets.length == 0) {
var globalLoadsIndex = indexOf.call(linkSet.loader._loads, load);
if (globalLoadsIndex != -1)
linkSet.loader._loads.splice(globalLoadsIndex, 1);
function finishLoad(loader, load) {
// if not anonymous, add to the module table
if (load.name) {
console.assert('load not in module table', !loader._modules[load.name]);
loader._modules[load.name] = load.module;
}
var loadIndex = indexOf.call(loader._loads, load);
if (loadIndex != -1)
loader._loads.splice(loadIndex, 1);
for (var i = 0, l = load.linkSets.length; i < l; i++) {
loadIndex = indexOf.call(load.linkSets[i].loads, load);
load.linkSets[i].loads.splice(loadIndex, 1);
}
load.linkSets = [];
}
linkSet.reject(exc);
}
function finishLoad(loader, load) {
// if not anonymous, add to the module table
if (load.name) {
assert('load not in module table', !loader._modules[load.name]);
loader._modules[load.name] = load.module;
function loadModule(loader, name, options) {
return new Promise(asyncStartLoadPartwayThrough(loader, name, options && options.address ? 'fetch' : 'locate', undefined, options && options.address, undefined)).then(function(load) {
return load;
});
}
var loadIndex = indexOf.call(loader._loads, load);
if (loadIndex != -1)
loader._loads.splice(loadIndex, 1);
for (var i = 0, l = load.linkSets.length; i < l; i++) {
loadIndex = indexOf.call(load.linkSets[i].loads, load);
load.linkSets[i].loads.splice(loadIndex, 1);
}
load.linkSets = [];
}
function loadModule(loader, name, options) {
return new Promise(asyncStartLoadPartwayThrough(loader, name, options && options.address ? 'fetch' : 'locate', undefined, options && options.address, undefined)).then(function(load) {
return load;
});
}
function asyncStartLoadPartwayThrough(loader, name, step, meta, address, source) {
return function(resolve, reject) {
if (loader._modules[name])
throw new TypeError('Module "' + name + '" already exists in the module table');
for (var i = 0, l = loader._loads.length; i < l; i++)
if (loader._loads[i].name == name)
throw new TypeError('Module "' + name + '" is already loading');
function asyncStartLoadPartwayThrough(loader, name, step, meta, address, source) {
return function(resolve, reject) {
if (loader._modules[name])
throw new TypeError('Module "' + name + '" already exists in the module table');
for (var i = 0, l = loader._loads.length; i < l; i++)
if (loader._loads[i].name == name)
throw new TypeError('Module "' + name + '" is already loading');
var load = createLoad(name);
var load = createLoad(name);
if (meta)
load.metadata = meta;
if (meta)
load.metadata = meta;
var linkSet = createLinkSet(loader, load);
var linkSet = createLinkSet(loader, load);
loader._loads.push(load);
loader._loads.push(load);
// NB spec change as in https://github.com/jorendorff/js-loaders/issues/79
linkSet.done.then(resolve, reject);
// NB spec change as in https://github.com/jorendorff/js-loaders/issues/79
linkSet.done.then(resolve, reject);
if (step == 'locate')
proceedToLocate(loader, load);
if (step == 'locate')
proceedToLocate(loader, load);
else if (step == 'fetch')
proceedToFetch(loader, load, Promise.resolve(address));
else if (step == 'fetch')
proceedToFetch(loader, load, Promise.resolve(address));
else {
assert('translate step', step == 'translate');
load.address = address;
proceedToTranslate(loader, load, Promise.resolve(source));
else {
console.assert('translate step', step == 'translate');
load.address = address;
proceedToTranslate(loader, load, Promise.resolve(source));
}
}
}
}
function evaluateLoadedModule(loader, load) {
assert('is linked ' + load.name, load.status == 'linked');
function evaluateLoadedModule(loader, load) {
console.assert('is linked ' + load.name, load.status == 'linked');
ensureEvaluated(load.module, loader);
ensureEvaluated(load.module, loader);
assert('is a module', load.module.module instanceof Module);
console.assert('is a module', load.module.module instanceof Module);
return load.module.module;
}
function ensureEvaluated(module, loader) {
// if already executed or dynamic module exists
// dynamic modules are evaluated during linking
if (module.module)
return module.module;
// ensure all dependencies are evaluated first
for (var m in module.dependencies) {
var depName = module.dependencies[m];
// no module object means it is not executed
if (!loader._modules[depName].module)
ensureEvaluated(loader._modules[depName], loader);
return load.module.module;
}
function ensureEvaluated(module, loader) {
// now evaluate this module
traceur.options.sourceMaps = true;
traceur.options.modules = 'instantiate';
// if already executed or dynamic module exists
// dynamic modules are evaluated during linking
if (module.module)
return module.module;
// ensure all dependencies are evaluated first
for (var m in module.dependencies) {
var depName = module.dependencies[m];
// no module object means it is not executed
if (!loader._modules[depName].module)
ensureEvaluated(loader._modules[depName], loader);
}
var reporter = new traceur.util.ErrorReporter();
// now evaluate this module
traceur.options.sourceMaps = true;
traceur.options.modules = 'instantiate';
reporter.reportMessageInternal = function(location, kind, format, args) {
throw kind + '\n' + location;
}
var reporter = new traceur.util.ErrorReporter();
// transform
reporter.reportMessageInternal = function(location, kind, format, args) {
throw kind + '\n' + location;
}
// traceur expects its version of System
var sys = global.System;
global.System = traceur.System;
// transform
var tree = (new traceur.codegeneration.module.AttachModuleNameTransformer(module.name)).transformAny(module.body);
tree = (new traceur.codegeneration.FromOptionsTransformer(reporter)).transform(tree);
// traceur expects its version of System
var sys = global.System;
global.System = global.traceurSystem;
// revert system
global.System = sys;
var tree = (new traceur.codegeneration.module.AttachModuleNameTransformer(module.name)).transformAny(module.body);
tree = (new traceur.codegeneration.FromOptionsTransformer(reporter)).transform(tree);
delete module.body;
// revert system
global.System = sys;
// convert back to a source string
var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: module.address });
var options = { sourceMapGenerator: sourceMapGenerator };
delete module.body;
var source = traceur.outputgeneration.TreeWriter.write(tree, options);
if (global.btoa)
source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n';
// convert back to a source string
var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: module.address });
var options = { sourceMapGenerator: sourceMapGenerator };
var sysRegister = System.register;
System.register = function(name, deps, execute) {
for (var i = 0; i < deps.length; i++)
deps[i] = module.dependencies[deps[i]];
var source = traceur.outputgeneration.TreeWriter.write(tree, options);
if (global.btoa)
source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n';
module.module = new Module(execute.apply(global, deps));
}
var sysRegister = System.register;
System.register = function(name, deps, execute) {
for (var i = 0; i < deps.length; i++)
deps[i] = module.dependencies[deps[i]];
__eval(source, global, module.address, module.name);
module.module = new Module(execute.apply(global, deps));
}
System.register = sysRegister;
}
__eval(source, global, module.address, module.name);
// Linking
function link(loads, loader) {
// console.log('linking {' + logloads(loads) + '}');
System.register = sysRegister;
}
// continue until all linked
var circular = false;
while (loads.length) {
circular = true;
// search through to find a load with all its dependencies linked
search: for (var i = 0; i < loads.length; i++) {
var load = loads[i];
var depNames = [];
for (var d in load.dependencies) {
var depName = load.dependencies[d];
// being in the module table means it is linked
if (!loader._modules[depName])
continue search;
var index = load.depsList.indexOf(d);
depNames[index] = depName;
}
// Linking
function link(loads, loader) {
// console.log('linking {' + logloads(loads) + '}');
circular = false;
// continue until all linked
var circular = false;
while (loads.length) {
circular = true;
// search through to find a load with all its dependencies linked
search: for (var i = 0; i < loads.length; i++) {
var load = loads[i];
var depNames = [];
for (var d in load.dependencies) {
var depName = load.dependencies[d];
// being in the module table means it is linked
if (!loader._modules[depName])
continue search;
var index = indexOf.call(load.depsList, d);
depNames[index] = depName;
}
// all dependencies linked now, so we can link
circular = false;
if (load.kind == 'declarative') {
load.module = {
name: load.name,
dependencies: load.dependencies,
body: load.body
};
// all dependencies linked now, so we can link
if (load.kind == 'declarative') {
load.module = {
name: load.name,
dependencies: load.dependencies,
body: load.body
};
}
else {
var module = load.execute.apply(null, depNames);
if (!(module instanceof Module))
throw new TypeError('Execution must define a Module instance');
load.module = {
module: module
};
}
load.status = 'linked';
finishLoad(loader, load);
}
else {
var module = load.execute.apply(null, depNames);
if (!(module instanceof Module))
throw new TypeError('Execution must define a Module instance');
load.module = {
module: module
};
}
load.status = 'linked';
finishLoad(loader, load);
if (circular)
throw new TypeError('Circular dependencies not supported by the polyfill');
}
if (circular)
throw new TypeError('Circular dependencies not supported by the polyfill');
// console.log('linked');
}
// console.log('linked');
}
// Loader
function Loader(options) {
if (typeof options != 'object')
throw new TypeError('Options must be an object');
// Loader
function Loader(options) {
if (typeof options != 'object')
throw new TypeError('Options must be an object');
if (options.normalize)
this.normalize = options.normalize;
if (options.locate)
this.locate = options.locate;
if (options.fetch)
this.fetch = options.fetch;
if (options.translate)
this.translate = options.translate;
if (options.instantiate)
this.instantiate = options.instantiate;
if (options.normalize)
this.normalize = options.normalize;
if (options.locate)
this.locate = options.locate;
if (options.fetch)
this.fetch = options.fetch;
if (options.translate)
this.translate = options.translate;
if (options.instantiate)
this.instantiate = options.instantiate;
defineProperty(this, 'global', {
get: function() {
throw new TypeError('global accessor not provided by polyfill');
defineProperty(this, 'global', {
get: function() {
throw new TypeError('global accessor not provided by polyfill');
}
});
defineProperty(this, 'realm', {
get: function() {
throw new TypeError('Realms not implemented in polyfill');
}
});
this._modules = {};
this._loads = [];
}
// NB importPromises hacks ability to import a module twice without error - https://github.com/jorendorff/js-loaders/issues/60
var importPromises = {};
Loader.prototype = {
define: function(name, source, options) {
if (importPromises[name])
throw new TypeError('Module is already loading.');
importPromises[name] = new Promise(asyncStartLoadPartwayThrough(this, name, options && options.address ? 'fetch' : 'translate', options && options.meta || {}, options && options.address, source));
return importPromises[name].then(function() { delete importPromises[name]; });
},
load: function(request, options) {
if (this._modules[request]) {
ensureEvaluated(this._modules[request], this);
return Promise.resolve(this._modules[request].module);
}
if (importPromises[request])
return importPromises[request];
importPromises[request] = loadModule(this, request, options);
return importPromises[request].then(function() { delete importPromises[request]; })
},
module: function(source, options) {
var load = createLoad();
load.address = options && options.address;
var linkSet = createLinkSet(this, load);
var sourcePromise = Promise.resolve(source);
var loader = this;
var p = linkSet.done.then(function() {
return evaluateLoadedModule(loader, load);
});
proceedToTranslate(this, load, sourcePromise);
return p;
},
'import': function(name, options) {
if (this._modules[name]) {
ensureEvaluated(this._modules[name], this);
return Promise.resolve(this._modules[name].module);
}
var loader = this;
return (importPromises[name] || (importPromises[name] = loadModule(this, name, options)))
.then(function(load) {
delete importPromises[name];
return evaluateLoadedModule(loader, load);
});
},
eval: function(source) {
throw new TypeError('Eval not implemented in polyfill')
},
get: function(key) {
ensureEvaluated(this._modules[key], this);
return this._modules[key].module;
},
has: function(name) {
return !!this._modules[name];
},
set: function(name, module) {
if (!(module instanceof Module))
throw new TypeError('Set must be a module');
this._modules[name] = {
module: module
};
},
'delete': function(name) {
return this._modules[name] ? delete this._modules[name] : false;
},
// NB implement iterations
entries: function() {
throw new TypeError('Iteration not yet implemented in the polyfill');
},
keys: function() {
throw new TypeError('Iteration not yet implemented in the polyfill');
},
values: function() {
throw new TypeError('Iteration not yet implemented in the polyfill');
},
normalize: function(name, referrerName, referrerAddress) {
return name;
},
locate: function(load) {
return load.name;
},
fetch: function(load) {
throw new TypeError('Fetch not implemented');
},
translate: function(load) {
return load.source;
},
instantiate: function(load) {
}
});
defineProperty(this, 'realm', {
get: function() {
throw new TypeError('Realms not implemented in polyfill');
};
// tree traversal, NB should use visitor pattern here
function traverse(object, iterator, parent, parentProperty) {
var key, child;
if (iterator(object, parent, parentProperty) === false)
return;
for (key in object) {
if (!object.hasOwnProperty(key))
continue;
if (key == 'location' || key == 'type')
continue;
child = object[key];
if (typeof child == 'object' && child !== null)
traverse(child, iterator, object, key);
}
});
}
this._modules = {};
this._loads = [];
}
// given a syntax tree, return the import list
function getImports(moduleTree) {
var imports = [];
// NB importPromises hacks ability to import a module twice without error - https://github.com/jorendorff/js-loaders/issues/60
var importPromises = {};
Loader.prototype = {
define: function(name, source, options) {
if (importPromises[name])
throw new TypeError('Module is already loading.');
importPromises[name] = new Promise(asyncStartLoadPartwayThrough(this, name, options && options.address ? 'fetch' : 'translate', options && options.meta || {}, options && options.address, source));
return importPromises[name].then(function() { delete importPromises[name]; });
},
load: function(request, options) {
if (this._modules[request]) {
ensureEvaluated(this._modules[request], this);
return Promise.resolve(this._modules[request].module);
function addImport(name) {
if (indexOf.call(imports, name) == -1)
imports.push(name);
}
if (importPromises[request])
return importPromises[request];
importPromises[request] = loadModule(this, request, options);
return importPromises[request].then(function() { delete importPromises[request]; })
},
module: function(source, options) {
var load = createLoad();
load.address = options && options.address;
var linkSet = createLinkSet(this, load);
var sourcePromise = Promise.resolve(source);
var loader = this;
var p = linkSet.done.then(function() {
return evaluateLoadedModule(loader, load);
traverse(moduleTree, function(node) {
// import {} from 'foo';
// export * from 'foo';
// export { ... } from 'foo';
// module x from 'foo';
if (node.type == 'EXPORT_DECLARATION') {
if (node.declaration.moduleSpecifier)
addImport(node.declaration.moduleSpecifier.token.processedValue);
}
else if (node.type == 'IMPORT_DECLARATION')
addImport(node.moduleSpecifier.token.processedValue);
else if (node.type == 'MODULE_DECLARATION')
addImport(node.expression.token.processedValue);
});
proceedToTranslate(this, load, sourcePromise);
return p;
},
'import': function(name, options) {
if (this._modules[name]) {
ensureEvaluated(this._modules[name], this);
return Promise.resolve(this._modules[name].module);
}
var loader = this;
return (importPromises[name] || (importPromises[name] = loadModule(this, name, options)))
.then(function(load) {
delete importPromises[name];
return evaluateLoadedModule(loader, load);
});
},
eval: function(source) {
throw new TypeError('Eval not implemented in polyfill')
},
get: function(key) {
ensureEvaluated(this._modules[key], this);
return this._modules[key].module;
},
has: function(name) {
return !!this._modules[name];
},
set: function(name, module) {
if (!(module instanceof Module))
throw new TypeError('Set must be a module');
this._modules[name] = {
module: module
};
},
'delete': function(name) {
return this._modules[name] ? delete this._modules[name] : false;
},
// NB implement iterations
entries: function() {
throw new TypeError('Iteration not yet implemented in the polyfill');
},
keys: function() {
throw new TypeError('Iteration not yet implemented in the polyfill');
},
values: function() {
throw new TypeError('Iteration not yet implemented in the polyfill');
},
normalize: function(name, referrerName, referrerAddress) {
return name;
},
locate: function(load) {
return load.name;
},
fetch: function(load) {
throw new TypeError('Fetch not implemented');
},
translate: function(load) {
return load.source;
},
instantiate: function(load) {
return imports;
}
};
var anonCnt = 0;
// tree traversal, NB should use visitor pattern here
function traverse(object, iterator, parent, parentProperty) {
var key, child;
if (iterator(object, parent, parentProperty) === false)
return;
for (key in object) {
if (!object.hasOwnProperty(key))
continue;
if (key == 'location' || key == 'type')
continue;
child = object[key];
if (typeof child == 'object' && child !== null)
traverse(child, iterator, object, key);
}
}
// Module Object
function Module(obj) {
if (typeof obj != 'object')
throw new TypeError('Expected object');
// given a syntax tree, return the import list
function getImports(moduleTree) {
var imports = [];
if (!(this instanceof Module))
return new Module(obj);
function addImport(name) {
if (indexOf.call(imports, name) == -1)
imports.push(name);
var self = this;
for (var key in obj) {
(function (key, value) {
defineProperty(self, key, {
configurable: false,
enumerable: true,
get: function () {
return value;
}
});
})(key, obj[key]);
}
if (Object.preventExtensions)
Object.preventExtensions(this);
}
// Module.prototype = null;
traverse(moduleTree, function(node) {
// import {} from 'foo';
// export * from 'foo';
// export { ... } from 'foo';
// module x from 'foo';
if (node.type == 'EXPORT_DECLARATION') {
if (node.declaration.moduleSpecifier)
addImport(node.declaration.moduleSpecifier.token.processedValue);
}
else if (node.type == 'IMPORT_DECLARATION')
addImport(node.moduleSpecifier.token.processedValue);
else if (node.type == 'MODULE_DECLARATION')
addImport(node.expression.token.processedValue);
});
return imports;
}
var anonCnt = 0;
if (typeof exports === 'object')
module.exports = Loader;
global.Loader || (global.Loader = Loader);
global.LoaderPolyfill = Loader;
global.Module = Module;
})();
function __eval(__source, global, __sourceURL, __moduleName) {
try {
Function('global', 'var __moduleName = "' + (__moduleName || '').replace('"', '\"') + '"; with(global) { ' + __source + ' \n }'
eval('var __moduleName = "' + (__moduleName || '').replace('"', '\"') + '"; with(global) { (function() { ' + __source + ' \n }).call(global); }'
+ (__sourceURL && !__source.match(/\/\/[@#] ?(sourceURL|sourceMappingURL)=([^\n]+)/)
? '\n//# sourceURL=' + __sourceURL : '')).call(global, global);
? '\n//# sourceURL=' + __sourceURL : ''));
}

@@ -695,35 +727,2 @@ catch(e) {

// Module Object
function Module(obj) {
if (typeof obj != 'object')
throw new TypeError('Expected object');
if (!(this instanceof Module))
return new Module(obj);
var self = this;
for (var key in obj) {
(function (key, value) {
defineProperty(self, key, {
configurable: false,
enumerable: true,
get: function () {
return value;
}
});
})(key, obj[key]);
}
if (Object.preventExtensions)
Object.preventExtensions(this);
}
// Module.prototype = null;
if (typeof exports === 'object')
module.exports = Loader;
global.Loader || (global.Loader = Loader);
global.LoaderPolyfill = Loader;
global.Module = Module;
})(typeof global !== 'undefined' ? global : this);

@@ -1,145 +0,916 @@

(function (global) {
var isBrowser = typeof window != 'undefined';
var nextTick = isBrowser ? function(fn) { setTimeout(fn, 1); } : process.nextTick;
var Promise = global.Promise;
if (Promise) {
// check if native promises have what we need
if (Promise.all && Promise.resolve && Promise.reject) {
Promise = global.Promise;
var p = new Promise(function(r) {
if (typeof r != 'function')
Promise = null;
});
!function(){ return typeof Promise != 'undefined' && Promise.all && Promise.resolve && Promise.reject; }() &&
!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
/**
* ES6 global Promise shim
*/
var PromiseConstructor = module.exports = require('../lib/Promise');
var g = typeof global !== 'undefined' && global
|| typeof window !== 'undefined' && window
|| typeof self !== 'undefined' && self;
if(typeof g !== 'undefined' && typeof g.Promise === 'undefined') {
g.Promise = PromiseConstructor;
}
},{"../lib/Promise":2}],2:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
(function(define) { 'use strict';
define(function (require) {
var makePromise = require('./makePromise');
var Scheduler = require('./scheduler');
var async = require('./async');
return makePromise({
scheduler: new Scheduler(async),
monitor: typeof console !== 'undefined' ? console : void 0
});
});
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); });
},{"./async":4,"./makePromise":5,"./scheduler":6}],3:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
(function(define) { 'use strict';
define(function() {
/**
* Circular queue
* @param {number} capacityPow2 power of 2 to which this queue's capacity
* will be set initially. eg when capacityPow2 == 3, queue capacity
* will be 8.
* @constructor
*/
function Queue(capacityPow2) {
this.head = this.tail = this.length = 0;
this.buffer = new Array(1 << capacityPow2);
}
Queue.prototype.push = function(x) {
if(this.length === this.buffer.length) {
this._ensureCapacity(this.length * 2);
}
else
Promise = null;
this.buffer[this.tail] = x;
this.tail = (this.tail + 1) & (this.buffer.length - 1);
++this.length;
return this.length;
};
Queue.prototype.shift = function() {
var x = this.buffer[this.head];
this.buffer[this.head] = void 0;
this.head = (this.head + 1) & (this.buffer.length - 1);
--this.length;
return x;
};
Queue.prototype._ensureCapacity = function(capacity) {
var head = this.head;
var buffer = this.buffer;
var newBuffer = new Array(capacity);
var i = 0;
var len;
if(head === 0) {
len = this.length;
for(; i<len; ++i) {
newBuffer[i] = buffer[i];
}
} else {
capacity = buffer.length;
len = this.tail;
for(; head<capacity; ++i, ++head) {
newBuffer[i] = buffer[head];
}
for(head=0; head<len; ++i, ++head) {
newBuffer[i] = buffer[head];
}
}
this.buffer = newBuffer;
this.head = 0;
this.tail = this.length;
};
return Queue;
});
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
},{}],4:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
(function(define) { 'use strict';
define(function(require) {
// Sniff "best" async scheduling option
// Prefer process.nextTick or MutationObserver, then check for
// vertx and finally fall back to setTimeout
/*jshint maxcomplexity:6*/
/*global process,document,setTimeout,MutationObserver,WebKitMutationObserver*/
var nextTick, MutationObs;
if (typeof process !== 'undefined' && process !== null &&
typeof process.nextTick === 'function') {
nextTick = function(f) {
process.nextTick(f);
};
} else if (MutationObs =
(typeof MutationObserver === 'function' && MutationObserver) ||
(typeof WebKitMutationObserver === 'function' && WebKitMutationObserver)) {
nextTick = (function (document, MutationObserver) {
var scheduled;
var el = document.createElement('div');
var o = new MutationObserver(run);
o.observe(el, { attributes: true });
function run() {
var f = scheduled;
scheduled = void 0;
f();
}
return function (f) {
scheduled = f;
el.setAttribute('class', 'x');
};
}(document, MutationObs));
} else {
nextTick = (function(cjsRequire) {
try {
// vert.x 1.x || 2.x
return cjsRequire('vertx').runOnLoop || cjsRequire('vertx').runOnContext;
} catch (ignore) {}
// capture setTimeout to avoid being caught by fake timers
// used in time based tests
var capturedSetTimeout = setTimeout;
return function (t) {
capturedSetTimeout(t, 0);
};
}(require));
}
// export the promises polyfill
if (!Promise) {
global.Promise = (function(setImmediate, func, obj) {
// Type checking utility function
function is(type, item) { return (typeof item)[0] == type; }
// Creates a promise, calling callback(resolve, reject), ignoring other parameters.
function Promise(callback, handler) {
// The `handler` variable points to the function that will
// 1) handle a .then(resolved, rejected) call
// 2) handle a resolve or reject call (if the first argument === `is`)
// Before 2), `handler` holds a queue of callbacks.
// After 2), `handler` is a finalized .then handler.
handler = function pendingHandler(resolved, rejected, value, queue, then, i) {
queue = pendingHandler.q;
return nextTick;
});
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
// Case 1) handle a .then(resolved, rejected) call
if (resolved != is) {
return Promise(function(resolve, reject) {
queue.push({ p: this, r: resolve, j: reject, 1: resolved, 0: rejected });
});
},{}],5:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
(function(define) { 'use strict';
define(function() {
return function makePromise(environment) {
var foreverPendingPromise;
var tasks = environment.scheduler;
var objectCreate = Object.create ||
function(proto) {
function Child() {}
Child.prototype = proto;
return new Child();
};
/**
* Create a promise whose fate is determined by resolver
* @constructor
* @returns {Promise} promise
* @name Promise
*/
function Promise(resolver) {
var self = this;
this._handler = new DeferredHandler();
runResolver(resolver, promiseResolve, promiseReject, promiseNotify);
/**
* Transition from pre-resolution state to post-resolution state, notifying
* all listeners of the ultimate fulfillment or rejection
* @param {*} x resolution value
*/
function promiseResolve (x) {
self._handler.resolve(x);
}
/**
* Reject this promise with reason, which will be used verbatim
* @param {*} reason reason for the rejection, typically an Error
*/
function promiseReject (reason) {
self._handler.reject(reason);
}
/**
* Issue a progress event, notifying all progress listeners
* @param {*} x progress event payload to pass to all listeners
*/
function promiseNotify (x) {
self._handler.notify(x);
}
}
function runResolver(resolver, promiseResolve, promiseReject, promiseNotify) {
try {
resolver(promiseResolve, promiseReject, promiseNotify);
} catch (e) {
promiseReject(e);
}
}
// Creation
Promise.resolve = resolve;
Promise.reject = reject;
Promise.never = never;
Promise._defer = defer;
/**
* Returns a trusted promise. If x is already a trusted promise, it is
* returned, otherwise returns a new trusted Promise which follows x.
* @param {*} x
* @return {Promise} promise
*/
function resolve(x) {
return x instanceof Promise ? x
: new InternalPromise(new AsyncHandler(getHandler(x)));
}
/**
* Return a reject promise with x as its reason (x is used verbatim)
* @param {*} x
* @returns {Promise} rejected promise
*/
function reject(x) {
return new InternalPromise(new AsyncHandler(new RejectedHandler(x)));
}
/**
* Return a promise that remains pending forever
* @returns {Promise} forever-pending promise.
*/
function never() {
return foreverPendingPromise; // Should be frozen
}
/**
* Creates an internal {promise, resolver} pair
* @private
* @returns {{resolver: DeferredHandler, promise: InternalPromise}}
*/
function defer() {
return new InternalPromise(new DeferredHandler());
}
// Transformation and flow control
/**
* Transform this promise's fulfillment value, returning a new Promise
* for the transformed result. If the promise cannot be fulfilled, onRejected
* is called with the reason. onProgress *may* be called with updates toward
* this promise's fulfillment.
* @param [onFulfilled] {Function} fulfillment handler
* @param [onRejected] {Function} rejection handler
* @param [onProgress] {Function} progress handler
* @return {Promise} new promise
*/
Promise.prototype.then = function(onFulfilled, onRejected, onProgress) {
var from = this._handler;
var to = new DeferredHandler(from.receiver);
from.when(to.resolve, to.notify, to, from.receiver, onFulfilled, onRejected, onProgress);
return new InternalPromise(to);
};
/**
* If this promise cannot be fulfilled due to an error, call onRejected to
* handle the error. Shortcut for .then(undefined, onRejected)
* @param {function?} onRejected
* @return {Promise}
*/
Promise.prototype['catch'] = Promise.prototype.otherwise = function(onRejected) {
return this.then(void 0, onRejected);
};
/**
* Private function to bind a thisArg for this promise's handlers
* @private
* @param {object} thisArg `this` value for all handlers attached to
* the returned promise.
* @returns {Promise}
*/
Promise.prototype._bindContext = function(thisArg) {
return new InternalPromise(new BoundHandler(this._handler, thisArg));
};
// Array combinators
Promise.all = all;
Promise.race = race;
/**
* Return a promise that will fulfill when all promises in the
* input array have fulfilled, or will reject when one of the
* promises rejects.
* @param {array} promises array of promises
* @returns {Promise} promise for array of fulfillment values
*/
function all(promises) {
/*jshint maxcomplexity:6*/
var resolver = new DeferredHandler();
var len = promises.length >>> 0;
var pending = len;
var results = [];
var i, x;
for (i = 0; i < len; ++i) {
if (i in promises) {
x = promises[i];
if (maybeThenable(x)) {
resolveOne(resolver, results, getHandlerThenable(x), i);
} else {
results[i] = x;
--pending;
}
} else {
--pending;
}
}
// Case 2) handle a resolve or reject call
// (`resolved` === `is` acts as a sentinel)
// The actual function signature is
// .re[ject|solve](<is>, success, value)
if(pending === 0) {
resolver.resolve(results);
}
// Check if the value is a promise and try to obtain its `then` method
if (value && (is(func, value) | is(obj, value))) {
try { then = value.then; }
catch (reason) { rejected = 0; value = reason; }
return new InternalPromise(resolver);
function resolveOne(resolver, results, handler, i) {
handler.when(noop, noop, void 0, resolver, function(x) {
results[i] = x;
if(--pending === 0) {
this.resolve(results);
}
// If the value is a promise, take over its state
if (is(func, then)) {
function valueHandler(resolved) {
return function(value) { then && (then = 0, pendingHandler(is, resolved, value)); };
}
try { then.call(value, valueHandler(1), rejected = valueHandler(0)); }
catch (reason) { rejected(reason); }
}
// The value is not a promise; handle resolve/reject
else {
// Replace this handler with a finalized resolved/rejected handler
handler = createFinalizedThen(callback, value, rejected);
// Resolve/reject pending callbacks
i = 0;
while (i < queue.length) {
then = queue[i++];
// If no callback, just resolve/reject the promise
if (!is(func, resolved = then[rejected]))
(rejected ? then.r : then.j)(value);
// Otherwise, resolve/reject the promise with the result of the callback
else
finalize(then.p, then.r, then.j, value, resolved);
}
}
};
// The queue of pending callbacks; garbage-collected when handler is resolved/rejected
handler.q = [];
}, resolver.reject, resolver.notify);
}
}
// Create and return the promise (reusing the callback variable)
callback.call(callback = { then: function (resolved, rejected) { return handler(resolved, rejected); },
'catch': function (rejected) { return handler(0, rejected); } },
function(value) { handler(is, 1, value); },
function(reason) { handler(is, 0, reason); });
return callback;
/**
* Fulfill-reject competitive race. Return a promise that will settle
* to the same state as the earliest input promise to settle.
*
* WARNING: The ES6 Promise spec requires that race()ing an empty array
* must return a promise that is pending forever. This implementation
* returns a singleton forever-pending promise, the same singleton that is
* returned by Promise.never(), thus can be checked with ===
*
* @param {array} promises array of promises to race
* @returns {Promise} if input is non-empty, a promise that will settle
* to the same outcome as the earliest input promise to settle. if empty
* is empty, returns a promise that will never settle.
*/
function race(promises) {
// Sigh, race([]) is untestable unless we return *something*
// that is recognizable without calling .then() on it.
if(Object(promises) === promises && promises.length === 0) {
return never();
}
// Creates a resolved or rejected .then function
function createFinalizedThen(promise, value, success) {
return function(resolved, rejected) {
// If the resolved or rejected parameter is not a function, return the original promise
if (!is(func, (resolved = success ? resolved : rejected)))
return promise;
// Otherwise, return a finalized promise, transforming the value with the function
return Promise(function(resolve, reject) { finalize(this, resolve, reject, value, resolved); });
};
var h = new DeferredHandler();
for(var i=0; i<promises.length; ++i) {
getHandler(promises[i]).when(noop, noop, void 0, h, h.resolve, h.reject);
}
// Finalizes the promise by resolving/rejecting it with the transformed value
function finalize(promise, resolve, reject, value, transform) {
setImmediate(function() {
try {
// Transform the value through and check whether it's a promise
value = transform(value);
transform = value && (is(obj, value) | is(func, value)) && value.then;
// Return the result if it's not a promise
if (!is(func, transform))
resolve(value);
// If it's a promise, make sure it's not circular
else if (value == promise)
reject(new TypeError());
// Take over the promise's state
else
transform.call(value, resolve, reject);
}
catch (error) { reject(error); }
});
return new InternalPromise(h);
}
// Promise internals
/**
* InternalPromise represents a promise that is either already
* fulfilled or reject, or is following another promise, based
* on the provided handler.
* @private
* @param {object} handler
* @constructor
*/
function InternalPromise(handler) {
this._handler = handler;
}
InternalPromise.prototype = objectCreate(Promise.prototype);
/**
* Get an appropriate handler for x, checking for untrusted thenables
* and promise graph cycles.
* @private
* @param {*} x
* @param {object?} h optional handler to check for cycles
* @returns {object} handler
*/
function getHandler(x, h) {
if(x instanceof Promise) {
return getHandlerChecked(x, h);
}
return maybeThenable(x) ? getHandlerUntrusted(x) : new FulfilledHandler(x);
}
// Export the main module
Promise.resolve = function (value) { return Promise(function (resolve) { resolve(value) }); };
Promise.reject = function (reason) { return Promise(function (resolve, reject) { reject(reason) }); };
Promise.all = function(promises) {
return new Promise(function(resolve, reject) {
if (!promises.length)
return setImmediate(resolve);
/**
* Get an appropriate handler for x, which must be either a thenable
* @param {object} x
* @returns {object} handler
*/
function getHandlerThenable(x) {
return x instanceof Promise ? x._handler.join() : getHandlerUntrusted(x);
}
var outputs = [];
var resolved = 0;
for (var i = 0, l = promises.length; i < l; i++) (function(i) {
promises[i].then(function(resolvedVal) {
outputs[i] = resolvedVal;
resolved++;
if (resolved == promises.length)
resolve(outputs);
}, reject);
})(i);
});
/**
* Get x's handler, checking for cycles
* @param {Promise} x
* @param {object?} h handler to check for cycles
* @returns {object} handler
*/
function getHandlerChecked(x, h) {
var xh = x._handler.join();
return h === xh ? promiseCycleHandler() : xh;
}
/**
* Get a handler for potentially untrusted thenable x
* @param {*} x
* @returns {object} handler
*/
function getHandlerUntrusted(x) {
try {
var untrustedThen = x.then;
return typeof untrustedThen === 'function'
? new ThenableHandler(untrustedThen, x)
: new FulfilledHandler(x);
} catch(e) {
return new RejectedHandler(e);
}
return Promise;
})(nextTick, 'f', 'o');
}
/**
* Handler for a promise that is pending forever
* @private
* @constructor
*/
function Handler() {}
Handler.prototype.inspect = toPendingState;
Handler.prototype.when = noop;
Handler.prototype.resolve = noop;
Handler.prototype.reject = noop;
Handler.prototype.notify = noop;
Handler.prototype.join = function() { return this; };
Handler.prototype._env = environment.monitor || Promise;
Handler.prototype._addTrace = noop;
Handler.prototype._isMonitored = function() {
return typeof this._env.promiseMonitor !== 'undefined';
};
/**
* Abstract base for handler that delegates to another handler
* @private
* @param {object} handler
* @constructor
*/
function DelegateHandler(handler) {
this.handler = handler;
if(this._isMonitored()) {
var trace = this._env.promiseMonitor.captureStack();
this.trace = handler._addTrace(trace);
}
}
DelegateHandler.prototype = objectCreate(Handler.prototype);
DelegateHandler.prototype.join = function() {
return this.handler.join();
};
DelegateHandler.prototype.inspect = function() {
return this.handler.inspect();
};
DelegateHandler.prototype._addTrace = function(trace) {
return this.handler._addTrace(trace);
};
/**
* Handler that manages a queue of consumers waiting on a pending promise
* @private
* @constructor
*/
function DeferredHandler(receiver) {
this.consumers = [];
this.receiver = receiver;
this.handler = void 0;
this.resolved = false;
if(this._isMonitored()) {
this.trace = this._env.promiseMonitor.captureStack();
}
}
DeferredHandler.prototype = objectCreate(Handler.prototype);
DeferredHandler.prototype.inspect = function() {
return this.resolved ? this.handler.join().inspect() : toPendingState();
};
DeferredHandler.prototype.resolve = function(x) {
this._join(getHandler(x, this));
};
DeferredHandler.prototype.reject = function(x) {
this._join(new RejectedHandler(x));
};
DeferredHandler.prototype.join = function() {
return this.resolved ? this.handler.join() : this;
};
DeferredHandler.prototype.run = function() {
var q = this.consumers;
var handler = this.handler = this.handler.join();
this.consumers = void 0;
for (var i = 0; i < q.length; i+=7) {
handler.when(q[i], q[i+1], q[i+2], q[i+3], q[i+4], q[i+5], q[i+6]);
}
};
DeferredHandler.prototype._join = function(handler) {
if(this.resolved) {
return;
}
this.resolved = true;
this.handler = handler;
tasks.enqueue(this);
if(this._isMonitored()) {
this.trace = handler._addTrace(this.trace);
}
};
DeferredHandler.prototype.when = function(resolve, notify, t, receiver, f, r, u) {
if(this.resolved) {
tasks.enqueue(new RunHandlerTask(resolve, notify, t, receiver, f, r, u, this.handler.join()));
} else {
this.consumers.push(resolve, notify, t, receiver, f, r, u);
}
};
DeferredHandler.prototype.notify = function(x) {
if(!this.resolved) {
tasks.enqueue(new ProgressTask(this.consumers, x));
}
};
DeferredHandler.prototype._addTrace = function(trace) {
return this.resolved ? this.handler._addTrace(trace) : trace;
};
/**
* Wrap another handler and force it into a future stack
* @private
* @param {object} handler
* @constructor
*/
function AsyncHandler(handler) {
DelegateHandler.call(this, handler);
}
AsyncHandler.prototype = objectCreate(DelegateHandler.prototype);
AsyncHandler.prototype.when = function(resolve, notify, t, receiver, f, r, u) {
tasks.enqueue(new RunHandlerTask(resolve, notify, t, receiver, f, r, u, this.join()));
};
/**
* Handler that follows another handler, injecting a receiver
* @private
* @param {object} handler another handler to follow
* @param {object=undefined} receiver
* @constructor
*/
function BoundHandler(handler, receiver) {
DelegateHandler.call(this, handler);
this.receiver = receiver;
}
BoundHandler.prototype = objectCreate(DelegateHandler.prototype);
BoundHandler.prototype.when = function(resolve, notify, t, receiver, f, r, u) {
// Because handlers are allowed to be shared among promises,
// each of which possibly having a different receiver, we have
// to insert our own receiver into the chain if it has been set
// so that callbacks (f, r, u) will be called using our receiver
if(this.receiver !== void 0) {
receiver = this.receiver;
}
this.join().when(resolve, notify, t, receiver, f, r, u);
};
/**
* Handler that wraps an untrusted thenable and assimilates it in a future stack
* @private
* @param {function} then
* @param {{then: function}} thenable
* @constructor
*/
function ThenableHandler(then, thenable) {
DeferredHandler.call(this);
this.assimilated = false;
this.untrustedThen = then;
this.thenable = thenable;
}
ThenableHandler.prototype = objectCreate(DeferredHandler.prototype);
ThenableHandler.prototype.when = function(resolve, notify, t, receiver, f, r, u) {
if(!this.assimilated) {
this.assimilated = true;
this._assimilate();
}
DeferredHandler.prototype.when.call(this, resolve, notify, t, receiver, f, r, u);
};
ThenableHandler.prototype._assimilate = function() {
var h = this;
this._try(this.untrustedThen, this.thenable, _resolve, _reject, _notify);
function _resolve(x) { h.resolve(x); }
function _reject(x) { h.reject(x); }
function _notify(x) { h.notify(x); }
};
ThenableHandler.prototype._try = function(then, thenable, resolve, reject, notify) {
try {
then.call(thenable, resolve, reject, notify);
} catch (e) {
reject(e);
}
};
/**
* Handler for a fulfilled promise
* @private
* @param {*} x fulfillment value
* @constructor
*/
function FulfilledHandler(x) {
this.value = x;
}
FulfilledHandler.prototype = objectCreate(Handler.prototype);
FulfilledHandler.prototype.inspect = function() {
return toFulfilledState(this.value);
};
FulfilledHandler.prototype.when = function(resolve, notify, t, receiver, f) {
var x = typeof f === 'function'
? tryCatchReject(f, this.value, receiver)
: this.value;
resolve.call(t, x);
};
/**
* Handler for a rejected promise
* @private
* @param {*} x rejection reason
* @constructor
*/
function RejectedHandler(x) {
this.value = x;
this.observed = false;
if(this._isMonitored()) {
this.key = this._env.promiseMonitor.startTrace(x);
}
}
RejectedHandler.prototype = objectCreate(Handler.prototype);
RejectedHandler.prototype.inspect = function() {
return toRejectedState(this.value);
};
RejectedHandler.prototype.when = function(resolve, notify, t, receiver, f, r) {
if(this._isMonitored() && !this.observed) {
this._env.promiseMonitor.removeTrace(this.key);
}
this.observed = true;
var x = typeof r === 'function'
? tryCatchReject(r, this.value, receiver)
: reject(this.value);
resolve.call(t, x);
};
RejectedHandler.prototype._addTrace = function(trace) {
if(!this.observed) {
this._env.promiseMonitor.updateTrace(this.key, trace);
}
};
// Errors and singletons
foreverPendingPromise = new InternalPromise(new Handler());
function promiseCycleHandler() {
return new RejectedHandler(new TypeError('Promise cycle'));
}
// Snapshot states
/**
* Creates a fulfilled state snapshot
* @private
* @param {*} x any value
* @returns {{state:'fulfilled',value:*}}
*/
function toFulfilledState(x) {
return { state: 'fulfilled', value: x };
}
/**
* Creates a rejected state snapshot
* @private
* @param {*} x any reason
* @returns {{state:'rejected',reason:*}}
*/
function toRejectedState(x) {
return { state: 'rejected', reason: x };
}
/**
* Creates a pending state snapshot
* @private
* @returns {{state:'pending'}}
*/
function toPendingState() {
return { state: 'pending' };
}
// Task runners
/**
* Run a single consumer
* @private
* @constructor
*/
function RunHandlerTask(a, b, c, d, e, f, g, handler) {
this.a=a;this.b=b;this.c=c;this.d=d;this.e=e;this.f=f;this.g=g;
this.handler = handler;
}
RunHandlerTask.prototype.run = function() {
this.handler.when(this.a, this.b, this.c, this.d, this.e, this.f, this.g);
};
/**
* Run a queue of progress handlers
* @private
* @constructor
*/
function ProgressTask(q, value) {
this.q = q;
this.value = value;
}
ProgressTask.prototype.run = function() {
var q = this.q;
// First progress handler is at index 1
for (var i = 1; i < q.length; i+=7) {
this._notify(q[i], q[i+1], q[i+2], q[i+5]);
}
};
ProgressTask.prototype._notify = function(notify, t, receiver, u) {
var x = typeof u === 'function'
? tryCatchReturn(u, this.value, receiver)
: this.value;
notify.call(t, x);
};
/**
* @param {*} x
* @returns {boolean} false iff x is guaranteed not to be a thenable
*/
function maybeThenable(x) {
return (typeof x === 'object' || typeof x === 'function') && x !== null;
}
/**
* Return f.call(thisArg, x), or if it throws return a rejected promise for
* the thrown exception
* @private
*/
function tryCatchReject(f, x, thisArg) {
try {
return f.call(thisArg, x);
} catch(e) {
return reject(e);
}
}
/**
* Return f.call(thisArg, x), or if it throws, *return* the exception
* @private
*/
function tryCatchReturn(f, x, thisArg) {
try {
return f.call(thisArg, x);
} catch(e) {
return e;
}
}
function noop() {}
return Promise;
};
});
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
},{}],6:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
(function(define) { 'use strict';
define(function(require) {
var Queue = require('./Queue');
// Credit to Twisol (https://github.com/Twisol) for suggesting
// this type of extensible queue + trampoline approach for next-tick conflation.
function Scheduler(enqueue) {
this._enqueue = enqueue;
this._handlerQueue = new Queue(15);
var self = this;
this.drainQueue = function() {
self._drainQueue();
};
}
if (typeof exports === 'object')
module.exports = Promise;
/**
* Enqueue a task. If the queue is not currently scheduled to be
* drained, schedule it.
* @param {function} task
*/
Scheduler.prototype.enqueue = function(task) {
if(this._handlerQueue.push(task) === 1) {
this._enqueue(this.drainQueue);
}
};
})(typeof global !== 'undefined' ? global : this);
/**
* Drain the handler queue entirely, being careful to allow the
* queue to be extended while it is being processed, and to continue
* processing until it is truly empty.
*/
Scheduler.prototype._drainQueue = function() {
var q = this._handlerQueue;
while(q.length > 0) {
q.shift().run();
}
};
return Scheduler;
});
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
},{"./Queue":3}]},{},[1])
(1)
});
;

@@ -162,3 +162,3 @@ /*

normalizedParts = normalizedParts.concat(parentParts.splice(0, parentParts.length - 1 - dotdots));
normalizedParts = normalizedParts.concat(segments.splice(i));
normalizedParts = normalizedParts.concat(segments.splice(i, segments.length - i));

@@ -220,2 +220,5 @@ return normalizedParts.join('/');

if (global.System && global.traceur)
global.traceurSystem = global.System;
global.System = System;

@@ -222,0 +225,0 @@

{
"name": "es6-module-loader",
"description": "An ES6 Module Loader shim",
"version": "0.5.3",
"version": "0.5.4",
"homepage": "https://github.com/ModuleLoader/es6-module-loader",

@@ -44,4 +44,4 @@ "author": {

"dependencies": {
"traceur": "0.0.25"
"traceur": "0.0.32"
}
}

@@ -5,10 +5,11 @@ # ES6 Module Loader Polyfill

The complete combined polyfill comes to 15KB minified, making it suitable for production use, provided that modules are built into ES5 making them independent of Traceur. Build workflows are currently in progress.
* Implemented to the [Jan 20 ES6 Specification draft, rev 22](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-language-modules-and-scripts).
* Provides an asynchronous loader (`System.import`) to [dynamically load ES6 modules](#getting-started).
* Uses [Traceur](https://github.com/google/traceur-compiler) for compiling ES6 modules and syntax into ES5 in the browser with source map support.
* Polyfills ES6 Promises in the browser with a bundled [when.js](https://github.com/cujojs/when/blob/master/docs/es6-promise-shim.md) implementation.
* [Compatible with NodeJS](#nodejs-support) allowing for server-side module loading.
* Supports ES6 module loading in IE9+, and any other module formats in IE8+.
* The complete combined polyfill comes to 7.4KB minified and gzipped, making it suitable for production use, provided that modules are built into ES5 making them independent of Traceur.
For an overview of build workflows, [see the production guide](#moving-to-production).
* Provides an asynchronous loader (`System.import`) to [dynamically load ES6 modules](#getting-started) in all modern browsers including IE9+.
* Uses [Traceur](https://github.com/google/traceur-compiler) for compiling ES6 modules and syntax into ES5 in the browser with source map support
* Adds support for the `<script type="module">` tag allowing inline module loading.
* Loader hooks can be used to [extend the System loader with custom functionality](#creating-a-custom-loader)
* [Compatible with NodeJS](#nodejs-support) allowing for server-side module loading
See the [demo folder](https://github.com/ModuleLoader/es6-module-loader/blob/master/demo/index.html) in this repo for a working example demonstrating both module loading the module tag in the browser.

@@ -18,25 +19,14 @@

_Note that while the specification draft has been written, it is still subject to change._
_The current version is tested against **[Traceur 0.0.32](https://github.com/google/traceur-compiler/tree/traceur%400.0.32)**._
## Background
_Note the ES6 module specification is still in draft, and subject to change._
The new ES6 module specification defines a module system in JavaScript using `import` and `export` syntax. For dynamically loading modules, a dynamic module loader factory is also included in the specification (`new Loader`).
A separate browser specification defines a dynamic ES6 module loader loader for the browser, `window.System`, as well as a `<script type="module">` tag for using modules.
This polyfill implements the `Loader` and `Module` globals, exactly as specified in the [2013-12-02 ES6 Module Specification Draft](https://github.com/jorendorff/js-loaders/blob/e60d3651/specs/es6-modules-2013-12-02.pdf) and the `System` browser loader exactly as suggested in the [sample implementation](https://github.com/jorendorff/js-loaders/blob/964623c75d/browser-loader.js).
## Getting Started
Download both [es6-module-loader.js](https://raw.github.com/ModuleLoader/es6-module-loader/master/dist/es6-module-loader.js) and [traceur.js](https://raw.github.com/ModuleLoader/es6-module-loader/master/lib/traceur.js) into the same folder.
Download both [es6-module-loader.js](https://raw.githubusercontent.com/ModuleLoader/es6-module-loader/v0.5.4/dist/es6-module-loader.js) and [traceur.js](https://raw.githubusercontent.com/google/traceur-compiler/traceur@0.0.32/bin/traceur.js) into the same folder.
If using ES6 syntax (optional), include Traceur in the page first:
If using ES6 syntax (optional), include `traceur.js` in the page first then include `es6-module-loader.js`:
```html
<script src="traceur.js"></script>
```
Then include `es6-module-loader.js`:
```html
<script src="es6-module-loader.js"></script>

@@ -56,3 +46,3 @@ ```

We can then load this module with a module tag in the page:
Load this module with a module tag in the page:

@@ -90,4 +80,10 @@ ```html

## Terminology
## Background
### Specifications
The new ES6 module specification defines a module system in JavaScript using `import` and `export` syntax. For dynamically loading modules, a dynamic module loader factory is also included in the specification (`new Loader`).
A separate browser specification defines a dynamic ES6 module loader for the browser, `window.System`, as well as a `<module>` tag for using modules.
### Modules and Module Loaders

@@ -237,2 +233,3 @@

<a name="moving-to-production">
## Moving to Production

@@ -242,5 +239,5 @@

Also, suitable bundling would need to be used.
Additionally, suitable bundling would need to be used.
We are actively working on these workflows.
Traceur provides build outputs that can be loaded with extensions to the module loader including AMD, CommonJS and a System.register build.

@@ -360,6 +357,5 @@ ## Module Tag

// return a promise. Alternatively, just use the system fetch
// promise -return System.fetch(load)
var defer = MyPromiseLibrary.createDeferred();
myXhr.get(load.address, defer.resolve, defer.reject);
return defer.promise;
return new Promise(function(resolve, reject) {
myXhr.get(load.address, resolve, reject);
});
}

@@ -403,2 +399,4 @@

## Contributing

@@ -425,5 +423,5 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).

Promises Integration from [Promiscuous](https://github.com/RubenVerborgh/promiscuous/), Copyright (c) 2013-2014 Ruben Verborgh, MIT License
ES6 Promises integration from [when.js](https://github.com/cujojs/when/blob/master/docs/es6-promise-shim.md), Copyright (c) 2010-2014 Brian Cavalier, John Hann, MIT License
## License
Licensed under the MIT license.

@@ -61,2 +61,6 @@

process.on('uncaughtException', function(err) {
console.log('Caught: ' + err);
});
System = ml.System;

@@ -327,2 +331,5 @@ Loader = ml.Loader;

System['import']('syntax/es6-file').then(function(m) {
setTimeout(function() {
(new m.q()).foo();
});
assert(

@@ -329,0 +336,0 @@ [typeof m.q, 'function']

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc