From 887d5ef0a3d28449ecab3138c0fa25f0fd983158 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 4 May 2014 22:17:23 -0400 Subject: [PATCH] GNU ease.js and test cases now compile in strict mode During its initial development, no environments (e.g. Node.js, Chromium, Firefox) supported strict mode; this has since changed, and node has a --use-strict option, which is used in the test runner to ensure conformance. --- lib/ClassBuilder.js | 22 +++++++++++++++------- lib/MethodWrappers.js | 5 ++++- lib/Trait.js | 2 +- lib/interface.js | 5 +++-- test/ClassBuilder/InstanceTest.js | 3 ++- test/MethodWrappersTest.js | 2 +- test/Trait/DefinitionTest.js | 8 +++++--- test/Util/CopyTest.js | 4 ++-- test/Util/PropParseTest.js | 4 +++- test/WarnHandlersTest.js | 10 ++++++---- 10 files changed, 42 insertions(+), 23 deletions(-) diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index 59d9a10..bb413d0 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -321,7 +321,7 @@ exports.prototype.build = function extend( _, __ ) abstract_methods = util.clone( exports.getMeta( base ).abstractMethods ) - || { __length: 0 } + || { __length: 0 }, virtual_members = util.clone( exports.getMeta( base ).virtualMembers ) @@ -411,10 +411,12 @@ exports.prototype.build = function extend( _, __ ) var new_class = this.createCtor( cname, abstract_methods, members ); // closure to hold static initialization to be used later by subtypes - initStaticVisibilityObj( new_class ); + this.initStaticVisibilityObj( new_class ); + + var _self = this; var staticInit = function( ctor, inheriting ) { - attachStatic( ctor, static_members, base, inheriting ); + _self.attachStatic( ctor, static_members, base, inheriting ); } staticInit( new_class, false ); @@ -578,7 +580,8 @@ exports.prototype.buildMembers = function buildMembers( var parser = props.___$$parser$$; delete props.___$$parser$$; - function hjoin( name, orig ) + // TODO: this is recreated every call! + var hjoin = function( name, orig ) { handlers[ name ] = function() { @@ -593,7 +596,7 @@ exports.prototype.buildMembers = function buildMembers( args.push( orig ); parser[ name ].apply( context, args ); }; - } + }; // this avoids a performance penalty unless the above property is // set @@ -1044,7 +1047,7 @@ function keywordStatic( keywords ) * * @return {undefined} */ -function initStaticVisibilityObj( ctor ) +exports.prototype.initStaticVisibilityObj = function( ctor ) { var _self = this; @@ -1096,7 +1099,7 @@ function initStaticVisibilityObj( ctor ) * * @return {undefined} */ -function attachStatic( ctor, members, base, inheriting ) +exports.prototype.attachStatic = function( ctor, members, base, inheriting ) { var methods = members.methods, props = members.props, @@ -1341,6 +1344,11 @@ function attachInstanceOf( instance ) */ exports.getMethodInstance = function( inst, cid ) { + if ( inst === undefined ) + { + return null; + } + var iid = inst.__iid, data = inst.___$$vis$$; diff --git a/lib/MethodWrappers.js b/lib/MethodWrappers.js index 6f7d198..2f88cca 100644 --- a/lib/MethodWrappers.js +++ b/lib/MethodWrappers.js @@ -28,7 +28,10 @@ exports.standard = { { var retf = function() { - var context = getInst( this, cid ) || this, + // we need some sort of context in order to set __super; it may + // be undefined per strict mode requirements depending on how + // the method was invoked + var context = getInst( this, cid ) || this || {}, retval = undefined ; diff --git a/lib/Trait.js b/lib/Trait.js index 3825454..febefb9 100644 --- a/lib/Trait.js +++ b/lib/Trait.js @@ -96,7 +96,7 @@ function _createStaging( name ) Trait.extend = function( dfn ) { // we may have been passed some additional metadata - var meta = this.__$$meta || {}; + var meta = ( this || {} ).__$$meta || {}; // store any provided name, since we'll be clobbering it (the definition // object will be used to define the hidden abstract class) diff --git a/lib/interface.js b/lib/interface.js index 28fd3bc..e7a7dff 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -494,13 +494,14 @@ function _isInstanceOf( type, instance ) { // if no metadata are available, then our remaining checks cannot be // performed + var meta; if ( !instance.__cid || !( meta = ClassBuilder.getMeta( instance ) ) ) { return false; } - implemented = meta.implemented; - i = implemented.length; + var implemented = meta.implemented, + i = implemented.length; // check implemented interfaces et. al. (other systems may make use of // this meta-attribute to provide references to types) diff --git a/test/ClassBuilder/InstanceTest.js b/test/ClassBuilder/InstanceTest.js index fd2ac78..ad3b8f2 100644 --- a/test/ClassBuilder/InstanceTest.js +++ b/test/ClassBuilder/InstanceTest.js @@ -38,7 +38,8 @@ require( 'common' ).testCase( var _self = this; // object to assert against - var obj = {}; + var obj = {}, + called = false; // mock type var type = { __isInstanceOf: function( givent, giveno ) diff --git a/test/MethodWrappersTest.js b/test/MethodWrappersTest.js index 00fa6e3..b3d740f 100644 --- a/test/MethodWrappersTest.js +++ b/test/MethodWrappersTest.js @@ -402,7 +402,7 @@ require( 'common' ).testCase( }; }, - keywords = { 'static': true }; + keywords = { 'static': true }, val = [ 'value' ], s = { diff --git a/test/Trait/DefinitionTest.js b/test/Trait/DefinitionTest.js index 5849e52..5f14802 100644 --- a/test/Trait/DefinitionTest.js +++ b/test/Trait/DefinitionTest.js @@ -127,8 +127,8 @@ require( 'common' ).testCase( '@each(ctor) Supertype definition is applied when using traits': function( T ) { - var expected = 'bar'; - expected2 = 'baz'; + var expected = 'bar', + expected2 = 'baz', Foo = this.Class( { foo: expected } ), SubFoo = this.Class.use( T( {} ) ) .extend( Foo, { bar: expected2 } ); @@ -210,7 +210,9 @@ require( 'common' ).testCase( return; } - this.fail( "Traits should not be able to define __construct" ); + this.fail( false, true, + "Traits should not be able to define __construct" + ); }, diff --git a/test/Util/CopyTest.js b/test/Util/CopyTest.js index 2cb0eb7..76dd9fb 100644 --- a/test/Util/CopyTest.js +++ b/test/Util/CopyTest.js @@ -41,8 +41,8 @@ require( 'common' ).testCase( c: true, d: false, e: undefined, - d: null, - f: function() {}, + f: null, + g: function() {}, }, dest = {} ; diff --git a/test/Util/PropParseTest.js b/test/Util/PropParseTest.js index e4049e9..aa3a471 100644 --- a/test/Util/PropParseTest.js +++ b/test/Util/PropParseTest.js @@ -219,7 +219,7 @@ require( 'common' ).testCase( */ 'Supports dynamic context to handlers': function() { - var _self = this; + var _self = this, context = {}; // should trigger all of the handlers @@ -228,6 +228,8 @@ require( 'common' ).testCase( method: function() {}, }; + var get, set; + // run test on getters/setters only if supported by the environment if ( this.hasGetSet ) { diff --git a/test/WarnHandlersTest.js b/test/WarnHandlersTest.js index abc243b..ea0b09a 100644 --- a/test/WarnHandlersTest.js +++ b/test/WarnHandlersTest.js @@ -85,10 +85,11 @@ require( 'common' ).testCase( Sut.setConsole( undefined ); // attempt to log + var _self = this; this.assertDoesNotThrow( function() { - Sut.handlers.log( this.warnstub ); - }, Error ); + Sut.handlers.log( _self.warnstub ); + } ); // restore console Sut.setConsole( console ); @@ -163,10 +164,11 @@ require( 'common' ).testCase( Sut.setConsole( undefined ); // no errors should occur because it should not do anything. + var _self = this; this.assertDoesNotThrow( function() { - Sut.handlers.dismiss( this.warnstub ); - }, Error ); + Sut.handlers.dismiss( _self.warnstub ); + } ); // restore console Sut.setConsole( console );