Merge pull request #5666 from electron/remote-promise-reject
Handle rejection of remote promises
This commit is contained in:
commit
cd444e82f9
4 changed files with 27 additions and 2 deletions
|
@ -91,7 +91,9 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) {
|
||||||
} else if (meta.type === 'buffer') {
|
} else if (meta.type === 'buffer') {
|
||||||
meta.value = Array.prototype.slice.call(value, 0)
|
meta.value = Array.prototype.slice.call(value, 0)
|
||||||
} else if (meta.type === 'promise') {
|
} else if (meta.type === 'promise') {
|
||||||
meta.then = valueToMeta(sender, function (v) { value.then(v) })
|
meta.then = valueToMeta(sender, function (onFulfilled, onRejected) {
|
||||||
|
value.then(onFulfilled, onRejected)
|
||||||
|
})
|
||||||
} else if (meta.type === 'error') {
|
} else if (meta.type === 'error') {
|
||||||
meta.members = plainObjectToMeta(value)
|
meta.members = plainObjectToMeta(value)
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,9 @@ var wrapArgs = function (args, visited) {
|
||||||
if (value.constructor != null && value.constructor.name === 'Promise') {
|
if (value.constructor != null && value.constructor.name === 'Promise') {
|
||||||
return {
|
return {
|
||||||
type: 'promise',
|
type: 'promise',
|
||||||
then: valueToMeta(function (v) { value.then(v) })
|
then: valueToMeta(function (onFulfilled, onRejected) {
|
||||||
|
value.then(onFulfilled, onRejected)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else if (v8Util.getHiddenValue(value, 'atomId')) {
|
} else if (v8Util.getHiddenValue(value, 'atomId')) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -106,6 +106,22 @@ describe('ipc module', function () {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('handles rejections via catch(onRejected)', function (done) {
|
||||||
|
var promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
|
||||||
|
promise.reject(Promise.resolve(1234)).catch(function (error) {
|
||||||
|
assert.equal(error.message, 'rejected')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles rejections via then(onFulfilled, onRejected)', function (done) {
|
||||||
|
var promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
|
||||||
|
promise.reject(Promise.resolve(1234)).then(function () {}, function (error) {
|
||||||
|
assert.equal(error.message, 'rejected')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote webContents', function () {
|
describe('remote webContents', function () {
|
||||||
|
|
5
spec/fixtures/module/rejected-promise.js
vendored
Normal file
5
spec/fixtures/module/rejected-promise.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
exports.reject = function (promise) {
|
||||||
|
return promise.then(function () {
|
||||||
|
throw Error('rejected')
|
||||||
|
})
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue