Improved error reporting when embedMachine() fails (eg, due to browser restrictions)

This commit is contained in:
Jeff Parsons 2014-10-30 09:54:09 -07:00 • committed by jeffpar
commit 29a3aceeb0
9 changed files with 15 additions and 14 deletions

View file

@ -119,11 +119,11 @@ w(function(){for(var a=I(window.document,"c1pjs","disk"),b=0;b<a.length;b++){var
$.prototype.stop=function(a,b){for(var c in this.I)if("cpu"!=c)for(var d=0;d<this.I[c].length;d++){var f=this.I[c][d];f&&f.stop&&f.stop(a,b)}};$.prototype.H=function(a,b,c,d){switch(c){case "reset":return this.o[c]=d,d.onclick=function(a){return function(){a.reset()}}(this),!0}return!1};function M(a,b){return a.I[b]?a.I[b][0]:null}
function Qa(a){var b=null,c;for(c in a.I)for(var d=0;d<a.I[c].length;d++){var f=a.I[c][d];if(f){if(!J(f)){J(f,function(a){return function(){Qa(a)}}(a));return}"cpu"==c?b=f:f.S&&f.S(!0,a)}}a.J();a.t("C1Pjs v1.15.7\nCopyright \u00a9 2012-2014 Jeff Parsons <Jeff@pcjs.org>");b&&b.S(!0,a)}
w(function(){for(var a=I(window.document,"c1pjs","computer"),b=0;b<a.length;b++){for(var c=a[b],d=G(c),f,g={},k,h=0,l=0,m=0;m<d.modules.length;m++){var n=d.modules[m];if(!m){if("cpu"!=n.type)break;h=n.start;l=n.end;k=Array(l+1-h);for(f=h;f<k.length;f++)k[f]=0}if(f=F(n.refID,d.id)){var A=n.type;void 0===g[A]&&(g[A]=[]);g[A].push(f);f.P&&void 0!==n.start&&f.P(k,n.start,n.end,g.cpu[0])}else{r('no component for <module refid="'+n.refID+'">');return}}if(void 0===k){r('<module type="cpu"> definition must appear first in the <computer> specification');
break}if(f=F("debugger",d.id))g["debugger"]=[f],f.P&&f.P(k,h,l,g.cpu[0]);h=new $(d,g);if(l=F("panel",d.id))if(g.panel=[l],l.jb){f=d.id;d=void 0;g=[];f&&(f=0<(d=f.indexOf("."))?f.substr(0,d+1):"");for(d=0;d<B.length;d++)m=B[d],f&&m.id.indexOf(f)||g.push(m);d=g;for(g=0;g<d.length;g++)f=d[g],f!=l&&(f.Ta=l.Ta,f.t=l.t,f.jb=l.jb)}H(h,c);Qa(h)}});var Ra=0;function Sa(a,b,c,d,f,g){f("Loading "+a+"...");q(a,null,function(k,h,l){l?g(h,null):Ta(h,a,b,c,d,f,g)})}
break}if(f=F("debugger",d.id))g["debugger"]=[f],f.P&&f.P(k,h,l,g.cpu[0]);h=new $(d,g);if(l=F("panel",d.id))if(g.panel=[l],l.jb){f=d.id;d=void 0;g=[];f&&(f=0<(d=f.indexOf("."))?f.substr(0,d+1):"");for(d=0;d<B.length;d++)m=B[d],f&&m.id.indexOf(f)||g.push(m);d=g;for(g=0;g<d.length;g++)f=d[g],f!=l&&(f.Ta=l.Ta,f.t=l.t,f.jb=l.jb)}H(h,c);Qa(h)}});var Ra=0;function Sa(a,b,c,d,f,g){f("Loading "+a+"...");q(a,null,function(k,h,l){l?(h||(h="unable to load "+a+" ("+l+")"),g(h,null)):Ta(h,a,b,c,d,f,g)})}
function Ta(a,b,c,d,f,g,k){function h(a,g){if(g)k(g,null);else{if(c){var h=b;h&&0>h.indexOf("/")&&(h=window.location.pathname+h);a=a.replace(/(<machine[^>]*\sid=)(['"]).*?\2/,"$1$2"+c+"$2"+(d?" state=$2"+d+"$2":"")+(h?" url=$2"+h+"$2":""))}h=null;if(0===a.indexOf("<"))try{window.ActiveXObject||"ActiveXObject"in window?(f||(a=a.replace(/<!DOCTYPE(.|[\r\n])*]>\s*/g,"")),h=new window.ActiveXObject("Microsoft.XMLDOM"),h.async=!1,h.loadXML(a)):h=(new window.DOMParser).parseFromString(a,"text/xml")}catch(A){h=
null,a=A.message}else a="unrecognized XML: "+(255<a.length?a.substr(0,255)+"...":a);k(a,h)}}a?f?Ua(a,g,h):h(a,null):k("no data"+(b?" for file: "+b:""),null)}
function Ua(a,b,c){var d;if(d=/<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g.exec(a)){var f=d[2];b("Loading "+f+"...");q(f,null,function(g,k,h){if(h||!k)c(a,"unable to resolve XML reference: "+d[0]+" ("+h+")");else{if(g=d[3])if(h=k.match(new RegExp("<"+d[1]+"[^>]*>"))){for(var l=h[0],m,n=/( [a-z]+=)(['"])(.*?)\2/g;m=n.exec(g);)l=0>l.indexOf(m[1])?l.replace(">",m[0]+">"):l.replace(new RegExp(m[1]+"(['\"])(.*?)\\1"),m[0]);h[0]!=l&&(k=k.replace(h[0],l))}else{c(a,"missing <"+d[1]+"> in "+f);return}k=k.replace(/<\?xml[^>]*>[\r\n]*/,
"");a=a.replace(d[0],k);Ua(a,b,c)}})}else c(a,null)}
function Va(a,b,c){function d(a){if(void 0===h){var b=k&&I(k,"machine-warning");h=b&&b[0]||null}h&&(h.innerHTML=ca(a))}function f(a){d("Error: "+a);l&&g();l=!1}function g(){0==--Ra&&y(!0)}var k,h,l=!0;Ra++;try{if(k=window.document.getElementById(a)){c||(c="/versions/c1pjs/1.15.7/components.xsl");var m=function(a,h){if(h){var l=function(a,l){if(l)if(l)if(d("Processing "+b+"..."),window.ActiveXObject||"ActiveXObject"in window){var m=h.transformNode(l);m?(k.outerHTML=m,g()):f("transformNodeToObject failed")}else window.document.implementation&&
function Va(a,b,c){function d(a){if(void 0===h){var b=k&&I(k,"machine-warning");h=b&&b[0]||k}h&&(h.innerHTML=ca(a))}function f(a){d("Error: "+a);l&&g();l=!1}function g(){0==--Ra&&y(!0)}var k,h,l=!0;Ra++;try{if(k=window.document.getElementById(a)){c||(c="/versions/c1pjs/1.15.7/components.xsl");var m=function(a,h){if(h){var l=function(a,l){if(l)if(l)if(d("Processing "+b+"..."),window.ActiveXObject||"ActiveXObject"in window){var m=h.transformNode(l);m?(k.outerHTML=m,g()):f("transformNodeToObject failed")}else window.document.implementation&&
window.document.implementation.createDocument?(m=new XSLTProcessor,m.importStylesheet(l),(m=m.transformToFragment(h,window.document))?(k.parentNode.replaceChild(m,k),g()):f("transformToFragment failed")):f("unable to transform XML: unsupported browser");else f("failed to load XSL file: "+c);else f(a)};h?Sa(c,null,null,!1,d,l):f("failed to load XML file: "+b)}else f(a)};"<"!=b.substr(0,1)?Sa(b,a,void 0,!0,d,m):Ta(b,null,a,void 0,!1,d,m)}else f("failed to find machine element: "+a)}catch(n){f(n.message)}return l}
window.embedC1P=function(a,b,c){return Va(a,b,c)};window.enableEvents=y;window.sendEvent=ea;y(!1);})();//@ sourceMappingURL=/tmp/c1pjs/1.15.7/c1p.map