From 731767cfb2296240929e1008b169b44ff96f4d43 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 8 Feb 2016 16:32:13 -0800 Subject: [PATCH] test: remove unneeded common.indirectInstanceOf() PR-URL: https://github.com/nodejs/node/pull/5149 Reviewed-By: Ben Noordhuis --- test/common.js | 13 ------------ test/parallel/test-assert.js | 4 ++-- test/sequential/test-module-loading.js | 28 +++++++++++++------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/test/common.js b/test/common.js index ec223a1da6b950..187d26acce6056 100644 --- a/test/common.js +++ b/test/common.js @@ -188,19 +188,6 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) { }); }); -function protoCtrChain(o) { - var result = []; - for (; o; o = Object.getPrototypeOf(o)) { result.push(o.constructor); } - return result.join(); -} - -exports.indirectInstanceOf = function(obj, cls) { - if (obj instanceof cls) { return true; } - var clsChain = protoCtrChain(cls.prototype); - var objChain = protoCtrChain(obj); - return objChain.slice(-clsChain.length) === clsChain; -}; - exports.ddCommand = function(filename, kilobytes) { if (exports.isWindows) { diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index d779051d7f1d35..d37b179899ca70 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -1,5 +1,5 @@ 'use strict'; -var common = require('../common'); +require('../common'); var assert = require('assert'); var a = require('assert'); @@ -10,7 +10,7 @@ function makeBlock(f) { }; } -assert.ok(common.indirectInstanceOf(a.AssertionError.prototype, Error), +assert.ok(a.AssertionError.prototype instanceof Error, 'a.AssertionError instanceof Error'); assert.throws(makeBlock(a, false), a.AssertionError, 'ok(false)'); diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js index 2235a068ca23f0..8e7f641326e7c9 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -1,5 +1,5 @@ 'use strict'; -var common = require('../common'); +require('../common'); var assert = require('assert'); var path = require('path'); var fs = require('fs'); @@ -33,25 +33,25 @@ var d4 = require('../fixtures/b/d'); assert.equal(false, false, 'testing the test program.'); -assert.equal(true, common.indirectInstanceOf(a.A, Function)); +assert.ok(a.A instanceof Function); assert.equal('A', a.A()); -assert.equal(true, common.indirectInstanceOf(a.C, Function)); +assert.ok(a.C instanceof Function); assert.equal('C', a.C()); -assert.equal(true, common.indirectInstanceOf(a.D, Function)); +assert.ok(a.D instanceof Function); assert.equal('D', a.D()); -assert.equal(true, common.indirectInstanceOf(d.D, Function)); +assert.ok(d.D instanceof Function); assert.equal('D', d.D()); -assert.equal(true, common.indirectInstanceOf(d2.D, Function)); +assert.ok(d2.D instanceof Function); assert.equal('D', d2.D()); -assert.equal(true, common.indirectInstanceOf(d3.D, Function)); +assert.ok(d3.D instanceof Function); assert.equal('D', d3.D()); -assert.equal(true, common.indirectInstanceOf(d4.D, Function)); +assert.ok(d4.D instanceof Function); assert.equal('D', d4.D()); assert.ok((new a.SomeClass()) instanceof c.SomeClass); @@ -88,7 +88,7 @@ require('../fixtures/node_modules/foo'); console.error('test name clashes'); // this one exists and should import the local module var my_path = require('../fixtures/path'); -assert.ok(common.indirectInstanceOf(my_path.path_func, Function)); +assert.ok(my_path.path_func instanceof Function); // this one does not exist and should throw assert.throws(function() { require('./utils'); }); @@ -259,19 +259,19 @@ assert.throws(function() { }, 'missing path'); process.on('exit', function() { - assert.ok(common.indirectInstanceOf(a.A, Function)); + assert.ok(a.A instanceof Function); assert.equal('A done', a.A()); - assert.ok(common.indirectInstanceOf(a.C, Function)); + assert.ok(a.C instanceof Function); assert.equal('C done', a.C()); - assert.ok(common.indirectInstanceOf(a.D, Function)); + assert.ok(a.D instanceof Function); assert.equal('D done', a.D()); - assert.ok(common.indirectInstanceOf(d.D, Function)); + assert.ok(d.D instanceof Function); assert.equal('D done', d.D()); - assert.ok(common.indirectInstanceOf(d2.D, Function)); + assert.ok(d2.D instanceof Function); assert.equal('D done', d2.D()); assert.equal(true, errorThrown);