From d0ec7aca9b7f149f40db9a511820bef0cc46caec Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 7 Aug 2014 22:24:25 -0400 Subject: [PATCH 1/3] method.super references now ES3-compatible This is a bugfix; the bug was introduced in v0.2.3. In ECMAScript 5, reserved keywords can be used to reference the field of an object in dot notation (e.g. method.super), but in ES3 this is prohibited; in these cases, method['super'] must be used. To maintain ES3 compatiblity, GNU ease.js will use the latter within its code. Of course, if you are developing software that need not support ES3, then you can use the dot notation yourself in your own code. This does not sway my decision to use `super`---ES3 will soon (hopefully) become extinct, and would be already were it not for the terrible influence of Microsloth's outdated browsers. --- lib/MethodWrappers.js | 6 +++++- test/MethodWrappersTest.js | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/MethodWrappers.js b/lib/MethodWrappers.js index 2f88cca..e000a60 100644 --- a/lib/MethodWrappers.js +++ b/lib/MethodWrappers.js @@ -59,7 +59,11 @@ exports.standard = { return retval; }; - retf.super = super_method; + // `super` is reserved and, in ES3, this causes problems with the + // dot-notation; while `foo.super` will work fine in modern (ES5) + // browsers, we need to maintain our ES3 compatibility + retf['super'] = super_method; + return retf; }, diff --git a/test/MethodWrappersTest.js b/test/MethodWrappersTest.js index b3d740f..6f73e7b 100644 --- a/test/MethodWrappersTest.js +++ b/test/MethodWrappersTest.js @@ -229,8 +229,9 @@ require( 'common' ).testCase( ; // we should be able to invoke the super method by override.super, - // which is added atop of the wrapper - this.assertStrictEqual( override.super(), expected ); + // which is added atop of the wrapper (note that we quote it to avoid + // problems with ES3 engines) + this.assertStrictEqual( override['super'](), expected ); }, From 324ff5ddca27c6150946a371741284f35ddf8b94 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 7 Aug 2014 22:33:04 -0400 Subject: [PATCH 2/3] Global no longer uses root as alt object prototype This is a bugfix; the bug was introduced in v0.2.3. Initially, the implementation created a new object with the root object as its prototype, taking advantage of ECMAScript's native overrides/fallthroughs. Unfortunately, IE<=8 had a buggy implementation, effectively treating the prototype as an empty object. So, rather than alt.Array === root.Array, alt.Array === undefined. The fix is simply to reference discrete objects. --- lib/util/Global.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/util/Global.js b/lib/util/Global.js index 597d47e..914041c 100644 --- a/lib/util/Global.js +++ b/lib/util/Global.js @@ -45,9 +45,11 @@ function Global() return new Global(); } - // allows us to extend the global object without actually polluting the - // global scope - this._global = new _G(); + // do not pollute the global scope (previously, _the_global was used as + // the prototype for a new object to take advantage of native overrides, + // but unfortunately IE<=8 did not support this and always returned + // undefined values from the prototype). + this._alt = {}; } @@ -56,8 +58,9 @@ function Global() * versions, for any root variable name, and works with ES5 strict mode. * * As an example, Node.js exposes the variable `root` to represent global - * scope, but browsers expose `window`. Further, ES5 strict mode will provde - * an error when checking whether `typeof SomeGlobalVar === 'undefined'`. + * scope, but browsers expose `window`. Further, ES5 strict mode will + * provide an error when checking whether `typeof SomeGlobalVar === + * 'undefined'`. * * @return {Object} global object */ @@ -86,12 +89,14 @@ Global.prototype = { */ provideAlt: function( name, f ) { - if ( typeof this._global[ name ] !== 'undefined' ) + if ( ( _the_global[ name ] !== undefined ) + || ( this._alt[ name ] !== undefined ) + ) { return; } - this._global[ name ] = f(); + this._alt[ name ] = f(); return this; }, @@ -112,7 +117,9 @@ Global.prototype = { */ get: function( name ) { - return this._global[ name ]; + return ( this._alt[ name ] !== undefined ) + ? this._alt[ name ] + : _the_global[ name ]; }, }; From a5c89565fe6ceb7ebeef9794afb57415bd9bf099 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 7 Aug 2014 22:53:10 -0400 Subject: [PATCH 3/3] `undefined` is no longer applied to Trait.__mixin This is a bugfix; the bug was introduced in v0.2.3. Notably, this caused problems in IE<=8 for non-argument traits. The problem is that `fund.apply( x, undefined )` is not valid in ES3---we must apply an empty array (or argument list) instead. --- lib/Trait.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Trait.js b/lib/Trait.js index 0cca02f..b622586 100644 --- a/lib/Trait.js +++ b/lib/Trait.js @@ -176,6 +176,9 @@ Trait.extend = function( dfn ) return ''+name; }; + // we're not a param trait, but we want consistent data + Trait.___$$mixinargs = []; + // invoked to trigger mixin Trait.__mixin = function( dfn, tc, base ) {