[Pkg-javascript-commits] [node-tap] 06/186: stdin so classy
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 1 16:40:38 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-tap.
commit 181df16acc0966ce3700f2aee266f8602ee4885a
Author: isaacs <i at izs.me>
Date: Thu Jul 6 15:20:43 2017 -0700
stdin so classy
---
lib/stdin.js | 51 ++++++++++++++++++++++++---------------------------
test/test/stdin.js | 2 +-
2 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/lib/stdin.js b/lib/stdin.js
index 07fc6f4..39e583d 100644
--- a/lib/stdin.js
+++ b/lib/stdin.js
@@ -1,37 +1,34 @@
'use strict'
const Base = require('./base.js')
-const util = require('util')
const ownOr = require('own-or')
const domain = require('domain')
-util.inherits(Stdin, Base)
+class Stdin extends Base {
+ constructor (options) {
+ options = options || {}
+ super(options)
+ options.name = ownOr(options, 'name', '/dev/stdin')
+ Base.call(this, options)
-module.exports = Stdin
-
-function Stdin (options) {
- options = options || {}
- if (!(this instanceof Stdin))
- return new Stdin(options)
-
- options.name = ownOr(options, 'name', '/dev/stdin')
- Base.call(this, options)
+ // This has to be here for node 0.10's wonky streams
+ this.stream = ownOr(options, 'tapStream', process.stdin)
+ this.stream.pause()
+ }
- // This has to be here for node 0.10's wonky streams
- this.stream = ownOr(options, 'tapStream', process.stdin)
- this.stream.pause()
-}
+ main (cb) {
+ this.domain.add(this.stream)
+ this.setTimeout(this.options.timeout)
+ this.stream.pipe(this.parser)
+ this.stream.resume()
+ this.once('end', cb)
+ }
-Stdin.prototype.main = function (cb) {
- this.domain.add(this.stream)
- this.setTimeout(this.options.timeout)
- this.stream.pipe(this.parser)
- this.stream.resume()
- this.once('end', cb)
+ threw (er, extra, proxy) {
+ extra = Base.prototype.threw.call(this, er, extra, proxy)
+ this.options = extra
+ this.parser.abort(er.message, extra)
+ this.parser.end()
+ }
}
-Stdin.prototype.threw = function (er, extra, proxy) {
- extra = Base.prototype.threw.call(this, er, extra, proxy)
- this.options = extra
- this.parser.abort(er.message, extra)
- this.parser.end()
-}
+module.exports = Stdin
diff --git a/test/test/stdin.js b/test/test/stdin.js
index 6147165..379f550 100644
--- a/test/test/stdin.js
+++ b/test/test/stdin.js
@@ -24,7 +24,7 @@ p.emit('end')
console.log('# between')
p = new PT()
-var s = Stdin({ tapStream: p, indent: '#### ' })
+var s = new Stdin({ tapStream: p, indent: '#### ' })
s.pipe(process.stdout)
s.main(function (e) { if (e) throw e })
p.write(
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git
More information about the Pkg-javascript-commits
mailing list