Skip to content

Commit

Permalink
use isPrototypeOf from Object.prototype (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Aug 23, 2022
1 parent bc61fc2 commit e493d8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,14 @@ app.override = function (s, fn, opts) {

app.use(function first (s1, opts, cb) {
assert(s1 !== server)
assert(server.isPrototypeOf(s1))
assert(Object.prototype.isPrototypeOf.call(server, s1))
assert(s1.count === 1)
s1.use(second)
cb()

function second (s2, opts, cb) {
assert(s2 !== s1)
assert(s1.isPrototypeOf(s2))
assert(Object.prototype.isPrototypeOf.isPrototypeOf.call(s1, s2))
assert(s2.count === 2)
cb()
}
Expand Down
2 changes: 1 addition & 1 deletion test/async-await.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ test('skip override with promise', (t) => {
async function first () {
async function fn (s, opts) {
t.equal(s, server)
t.notOk(server.isPrototypeOf(s))
t.notOk(Object.prototype.isPrototypeOf.call(server, s))
}

fn[Symbol.for('skip-override')] = true
Expand Down
36 changes: 18 additions & 18 deletions test/override.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('custom inheritance', (t) => {

app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
})
})
Expand All @@ -42,15 +42,15 @@ test('custom inheritance multiple levels', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)

cb()

function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
Expand All @@ -72,7 +72,7 @@ test('custom inheritance multiple levels twice', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)
s1.use(third)
Expand All @@ -83,15 +83,15 @@ test('custom inheritance multiple levels twice', (t) => {
function second (s2, opts, cb) {
prev = s2
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}

function third (s3, opts, cb) {
t.not(s3, s1)
t.ok(s1.isPrototypeOf(s3))
t.notOk(prev.isPrototypeOf(s3))
t.ok(Object.prototype.isPrototypeOf.call(s1, s3))
t.notOk(Object.prototype.isPrototypeOf.call(prev, s3))
t.equal(s3.count, 2)
cb()
}
Expand All @@ -113,31 +113,31 @@ test('custom inheritance multiple levels with multiple heads', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)

cb()

function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
})

app.use(function third (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(fourth)

cb()

function fourth (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
Expand Down Expand Up @@ -176,7 +176,7 @@ test('fastify test case', (t) => {

instance.use((i, opts, cb) => {
t.not(i, instance)
t.ok(instance.isPrototypeOf(i))
t.ok(Object.prototype.isPrototypeOf.call(instance, i))

i.add('test', noop, (err) => {
t.error(err)
Expand Down Expand Up @@ -228,7 +228,7 @@ test('skip override - fastify test case', (t) => {

function first (s, opts, cb) {
t.equal(s, server)
t.notOk(server.isPrototypeOf(s))
t.notOk(Object.prototype.isPrototypeOf.call(server, s))
cb()
}
})
Expand All @@ -252,7 +252,7 @@ test('override can receive options object', (t) => {

app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
}, options)
})
Expand All @@ -279,15 +279,15 @@ test('override can receive options function', (t) => {

app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
s.foo = 'bar'
cb()
}, options)

app.use(function second (s, opts, cb) {
t.notOk(s.foo)
t.same(opts, { hello: 'world' })
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
}, p => ({ hello: p.bar }))
})
Expand Down Expand Up @@ -356,7 +356,7 @@ test('custom inheritance override in after', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.after(() => {
s1.use(second)
Expand All @@ -366,7 +366,7 @@ test('custom inheritance override in after', (t) => {

function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
Expand Down

0 comments on commit e493d8d

Please sign in to comment.