Merge pull request #1309 from sdougbrown/db/invalid-stream-guard
WIP - Prevent Infinite Loop in m.prop.combine
This commit is contained in:
commit
87b60d19dc
2 changed files with 16 additions and 0 deletions
|
|
@ -116,6 +116,7 @@ module.exports = function(log) {
|
|||
return initDependency(self, [stream], derive, recover)
|
||||
}
|
||||
function combine(fn, streams) {
|
||||
if (streams.length > streams.filter(valid).length) throw new Error("Ensure that each item passed to m.prop.combine/m.prop.merge is a stream")
|
||||
return initDependency(createStream(), streams, function() {
|
||||
var failed = streams.filter(errored)
|
||||
if (failed.length > 0) throw {__error: failed[0]._state.error}
|
||||
|
|
@ -177,6 +178,7 @@ module.exports = function(log) {
|
|||
function valueOf() {return this._state.value}
|
||||
function toJSON() {return this._state.value != null && typeof this._state.value.toJSON === "function" ? this._state.value.toJSON() : this._state.value}
|
||||
|
||||
function valid(stream) {return stream._state }
|
||||
function active(stream) {return stream._state.state === 1}
|
||||
function changed(stream) {return stream._state.changed}
|
||||
function notEnded(stream) {return stream._state.state !== 2}
|
||||
|
|
|
|||
|
|
@ -171,6 +171,20 @@ o.spec("stream", function() {
|
|||
|
||||
o(b()).equals(undefined)
|
||||
})
|
||||
o("combine will throw with a helpful error if given non-stream values", function () {
|
||||
var spy = o.spy()
|
||||
var a = Stream(1)
|
||||
var thrown = null;
|
||||
try {
|
||||
var b = Stream.combine(spy, [a, ''])
|
||||
} catch (e) {
|
||||
thrown = e
|
||||
}
|
||||
|
||||
o(thrown).notEquals(null)
|
||||
o(thrown.constructor === TypeError).equals(false)
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
})
|
||||
o.spec("merge", function() {
|
||||
o("transforms an array of streams to an array of values", function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue