提交 60056676 编写于 作者: D David Graham

Don't expose consumed function as public Body API.

上级 a7099768
......@@ -61,6 +61,13 @@
})
}
function consumed(body) {
if (body.bodyUsed) {
return new Promise.reject(new TypeError('Body already consumed'))
}
body.bodyUsed = true
}
function Body() {
this.body = null
this.bodyUsed = false
......@@ -70,7 +77,7 @@
}
this.blob = function() {
var error = this.consumed()
var error = consumed(this)
return error ? error : Promise.resolve(new Blob([this.body]))
}
......@@ -79,7 +86,7 @@
}
this.json = function() {
var error = this.consumed()
var error = consumed(this)
if (error) {
return error
}
......@@ -95,17 +102,10 @@
}
this.text = function() {
var error = this.consumed()
var error = consumed(this)
return error ? error : Promise.resolve(this.body)
}
this.consumed = function() {
if (this.bodyUsed) {
return new Promise.reject(new TypeError('Body already consumed'))
}
this.bodyUsed = true
}
return this
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册