Skip to content

Commit

Permalink
Export Iterator class.
Browse files Browse the repository at this point in the history
Make `instanceof Iterator` instead of `instanceof Iterator.Error`. That
was nonsense.

Closes #98.
  • Loading branch information
flatheadmill committed Oct 17, 2020
1 parent f08efe8 commit b5d7b27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions interrupt.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,32 @@ class Interrupt extends Error {
Object.defineProperty(this, property, { value: assign[property] })
}
}
}

exports.create = function (name, ...vargs) {
const prefix = typeof vargs[0] == 'string' ? vargs.shift() : name.toUpperCase()
const messages = vargs.length > 0 && typeof vargs[0] == 'object' ? vargs.shift() : {}
const superclass = typeof vargs[0] == 'function' ? vargs.shift() : Interrupt
assert(superclass == Interrupt || superclass.prototype instanceof Interrupt)
const interrupt = class extends superclass {
constructor (...vargs) {
if (superclass == Interrupt) {
super(messages, name, vargs)
} else {
super(...vargs)
static create (name, ...vargs) {
const prefix = typeof vargs[0] == 'string' ? vargs.shift() : name.toUpperCase()
const messages = vargs.length > 0 && typeof vargs[0] == 'object' ? vargs.shift() : {}
const superclass = typeof vargs[0] == 'function' ? vargs.shift() : Interrupt
assert(superclass == Interrupt || superclass.prototype instanceof Interrupt)
const interrupt = class extends superclass {
constructor (...vargs) {
if (superclass == Interrupt) {
super(messages, name, vargs)
} else {
super(...vargs)
}
}
}

static assert (condition, ...vargs) {
if (!condition) {
vargs.unshift(null)
vargs.push(interrupt.assert)
throw new (Function.prototype.bind.apply(interrupt, vargs))
static assert (condition, ...vargs) {
if (!condition) {
vargs.unshift(null)
vargs.push(interrupt.assert)
throw new (Function.prototype.bind.apply(interrupt, vargs))
}
}
}
Object.defineProperty(interrupt, "name", { value: name })
return interrupt
}
Object.defineProperty(interrupt, "name", { value: name })
return interrupt
}

exports.Error = Interrupt
module.exports = Interrupt
2 changes: 1 addition & 1 deletion test/interrupt.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require('proof')(35, okay => {
console.log(error.stack)
okay(error.name, 'Test.Error', 'error name')
okay(error instanceof Test.Error, 'is derived error')
okay(error instanceof Interrupt.Error, 'is interrupt error')
okay(error instanceof Interrupt, 'is interrupt error')
okay(error instanceof Error, 'is error')
okay(/^Test\.Error$/m.test(error.stack), 'no message stack header')
okay(error.message, '', 'no message')
Expand Down

0 comments on commit b5d7b27

Please sign in to comment.