From 8e079129f34aca4ce075f2090366d6e07aa4cb7d Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 15 Nov 2011 22:22:24 -0500 Subject: [PATCH] ClassBuilder.isInstanceOf() will no longer throw errors when given undefined for either argument - Yes, this is just quickly adding a test to a pre-existing, terrible format. This will be refactored with the rest of the test case. --- lib/ClassBuilder.js | 5 +++++ test/test-class.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index fb657c8..532b70f 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -230,6 +230,11 @@ exports.isInstanceOf = function( type, instance ) { var meta, implemented, i; + if ( !( type && instance ) ) + { + return false; + } + try { // check prototype chain (will throw an error if type is not a diff --git a/test/test-class.js b/test/test-class.js index 5c76b4f..b8a4a07 100644 --- a/test/test-class.js +++ b/test/test-class.js @@ -102,6 +102,16 @@ assert.ok( "Class instance is recognized by Class.isInstanceOf()" ); +assert.ok( + Class.isInstanceOf( Foo, undefined ) === false, + "Checking instance of undefined will not throw an error" +); + +assert.ok( + Class.isInstanceOf( undefined, {} ) === false, + "Checking for instance of undefined will not throw an error" +); + assert.ok( !( Class.isInstanceOf( Foo, Foo ) ), "Class is not an instance of itself when uninstantiated"