From 07ee5497bcd5d1e47bc6276ea0fd1a3725843020 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 1 Oct 2016 14:37:02 -0700 Subject: [PATCH] Added some polyfills for old browsers --- docs/pcx86/examples/pcx86-dbg.js | 3 +- docs/pcx86/examples/pcx86.js | 3 +- modules/shared/lib/component.js | 44 ++++++++++++++++++++++++++++ versions/c1pjs/1.30.0/c1p-dbg.js | 3 +- versions/c1pjs/1.30.0/c1p.js | 5 ++-- versions/pc8080/1.30.0/pc8080-dbg.js | 2 ++ versions/pc8080/1.30.0/pc8080.js | 3 +- versions/pcx86/1.30.0/pcx86-dbg.js | 3 +- versions/pcx86/1.30.0/pcx86.js | 3 +- versions/pdp11/1.30.0/pdp11-dbg.js | 4 ++- versions/pdp11/1.30.0/pdp11.js | 9 +++--- 11 files changed, 69 insertions(+), 13 deletions(-) diff --git a/docs/pcx86/examples/pcx86-dbg.js b/docs/pcx86/examples/pcx86-dbg.js index 5a8c41ccb..d66cee40c 100644 --- a/docs/pcx86/examples/pcx86-dbg.js +++ b/docs/pcx86/examples/pcx86-dbg.js @@ -24,7 +24,8 @@ function tb(a,b,c){c&&(b+="-"+c+"-object");if(a.getElementsByClassName)return a. bb.prototype={constructor:bb,parent:null,toString:function(){return this.name?this.name:this.id||this.type},Pb:function(a,b,c){switch(b){case "clear":return this.qa[b]||(this.qa[b]=c,c.onclick=function(a){return function(){a.qa.print&&(a.qa.print.value="")}}(this)),!0;case "print":return this.qa[b]||(this.Gf=this.qa[b]=c,c.value="",this.O=function(a){return function(b,c){8192 support"). + * + * Perhaps we can implement a text-only faux video display for a fun retro-browser experience someday. + * + * TODO: Come up with a better place to put these polyfills. We will likely have more if we decide to + * make the leap from ES5.1 to ES6 features. + */ + +/* + * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf + */ +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(obj, start) { + for (var i = (start || 0), j = this.length; i < j; i++) { + if (this[i] === obj) { return i; } + } + return -1; + } +} + +/* + * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind + */ +if (!Function.prototype.bind) { + Function.prototype.bind = function(obj) { + if (typeof this != "function") { + // Closest thing possible to the ECMAScript 5 internal IsCallable function + throw new TypeError("Function.prototype.bind: non-callable object"); + } + var args = Array.prototype.slice.call(arguments, 1); + var fToBind = this; + var fnNOP = /** @constructor */ (function() {}); + var fnBound = function() { + return fToBind.apply(this instanceof fnNOP && obj? this : obj, args.concat(Array.prototype.slice.call(arguments))); + }; + fnNOP.prototype = this.prototype; + fnBound.prototype = new fnNOP(); + return fnBound; + }; +} + if (NODE) module.exports = Component; diff --git a/versions/c1pjs/1.30.0/c1p-dbg.js b/versions/c1pjs/1.30.0/c1p-dbg.js index a5cd2c61b..deacbb9fc 100644 --- a/versions/c1pjs/1.30.0/c1p-dbg.js +++ b/versions/c1pjs/1.30.0/c1p-dbg.js @@ -11,7 +11,8 @@ function E(a){var b=null;if(a=a.getAttribute("data-value"))try{b=eval("("+a+")") function G(a,b,c){c&&(b+="-"+c+"-object");if(a.getElementsByClassName)return a.getElementsByClassName(b);var d;c=[];a=a.getElementsByTagName("*");var e=new RegExp("(^| )"+b+"( |$)");b=0;for(d=a.length;b>1)+2;10>this.Z&&(this.Z=10);15>2;this.f=this.Ea-1;this.A=this.D/this.Ea|0;this.B=this.A-1;this.Ta=[];this.F=null;this.Mb=this.Kc;a=new H;zb(a,this.G);this.O=Array(this.A);for(b=0;b>>a.Z;0g&&(n=g);if(k&&k.size){if(k.type==d&&k.controller==f){if(e+g<=k.w)return k.Yb+=k.w-e,k.w=e,!0;if(e>=k.w+k.Yb){n=k.size-(e-m);n>g&&(n=g);k.Yb=e-k.w+n;e=m+a.Ea;g-=n;h++;continue}}return Gb(1,e,g)}e=new H(e,n,a.Ea,d,f);zb(e,a.G,k);a.O[h++]=e;e=m+a.Ea;g-=n}return 0>=g?(a.status(Math.floor(c/1024)+"Kb "+Hb[d]+" at "+t(b,8,!0)),!0):Gb(2,b,c)} l.sb=function(a){return this.O[(a&this.j)>>>this.Z].wb(a&this.f,a)};l.Ka=function(a){var b=a&this.f,c=(a&this.j)>>>this.Z;return b!=this.f?this.O[c].Rb(b,a):this.O[c++].wb(b,a)|this.O[c&this.B].wb(0,a+1)<<8};function Ib(a,b){var c=b&a.f,d=(b&a.j)>>>a.Z;return c!=a.f?a.O[d].oc(c,b):a.O[d++].Qb(c,b)|a.O[d&a.B].Qb(0,b+1)<<8}l.Vb=function(a,b){this.O[(a&this.j)>>>this.Z].Cb(a&this.f,b&255,a)}; l.pb=function(a,b){var c=a&this.f,d=(a&this.j)>>>this.Z;c!=this.f?this.O[d].Jc(c,b&65535,a):(this.O[d++].Cb(c,b&255,a),this.O[d&this.B].Cb(0,b>>8&255,a+1))};function Jb(a){for(var b=0,c=[],d=0;d>1)+2;10>this.f&&(this.f=10);15>2;this.i=this.g-1;this.m=this.s/this.g|0;this.H=this.m-1;this.qa=[];this.v=null;this.$a=this.L;a=new G;Ka(a,this.K);this.b=Array(this.m);for(b=0;b>8:d[2](b)&255}else if(b&1&&(d=c.qa[a&-2])&&d[2])return d[2](b&-2)>>8;c.M("warning: unconverted read access to byte @"+ba(b));return c.$a(b,-1,1)} function Ma(a,b,c){var d=this.controller,f=d.qa[a];if(f){if(f[1]){f[1](b,c);return}if(f[3]){a=f[2]?f[2](c):0;if(c&1)f[3](a&255|b<<8,c&-2);else f[3](a&-256|b,c);return}}else if(c&1&&(f=d.qa[a&-2])&&f[3]){c&=-2;a=f[2]?f[2](c):0;f[3](a&255|b<<8,c);return}d.M("warning: unconverted write access to byte @"+ba(c));d.$a(c,b,1)} function Na(a,b){var c=this.controller;if(a=c.qa[a]){if(a[2])return a[2](b);if(a[0])return a[0](b)|a[0](b+1)<<8}c.M("warning: unconverted read access to word @"+ba(b));return c.$a(b,-1,0)}function Oa(a,b,c){var d=this.controller;if(a=d.qa[a]){if(a[3]){a[3](b,c);return}if(a[1]){a[1](b&255,c);a[1](b>>8,c+1);return}}d.M("warning: unconverted write access to word @"+ba(c));d.$a(c,b,0)}F.prototype.reset=function(){this.v&&this.v()};F.prototype.L=function(){return 0}; F.prototype.za=function(a,b){b||this.reset();return!0};function Pa(a,b,c,d,f){for(var e=b,g=c,h=e>>>a.f;0g&&(q=g);if(k&&k.size){if(k.type==d&&k.controller==f){if(e+g<=k.Wa)return k.xb+=k.Wa-e,k.Wa=e,!0;if(e>=k.Wa+k.xb){q=k.size-(e-m);q>g&&(q=g);k.xb=e-k.Wa+q;e=m+a.g;g-=q;h++;continue}}return Ra(1,e,g)}e=new G(e,q,a.g,d,f);Ka(e,a.K,k);a.b[h++]=e;e=m+a.g;g-=q}return 0>=g?(a.status(Math.floor(c/1024)+"Kb "+Sa[d]+" at "+n(b,8,!0)),!0):Ra(2,b,c)} function Ta(a,b){return a.b[(b&a.l)>>>a.f].bb(b&a.i,b)}function Ua(a,b,c){var d=b&a.i,f=(b&a.l)>>>a.f;d!=a.i?a.b[f].Hc(d,c&65535,b):(a.b[f++].Va(d,c&255,b),a.b[f&a.H].Va(0,c>>8&255,b+1))}function Va(a){for(var b=0,c=[],d=0;d