Merge pull request #5689 from cdaringe/master
Support non-native promises
This commit is contained in:
commit
8a4b7eb062
5 changed files with 24 additions and 4 deletions
|
@ -42,6 +42,7 @@
|
|||
'lib/common/api/crash-reporter.js',
|
||||
'lib/common/api/deprecate.js',
|
||||
'lib/common/api/deprecations.js',
|
||||
'lib/common/api/is-promise.js',
|
||||
'lib/common/api/exports/electron.js',
|
||||
'lib/common/api/native-image.js',
|
||||
'lib/common/api/shell.js',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const electron = require('electron')
|
||||
const v8Util = process.atomBinding('v8_util')
|
||||
const {ipcMain} = electron
|
||||
const {ipcMain, isPromise} = electron
|
||||
|
||||
const objectsRegistry = require('./objects-registry')
|
||||
|
||||
|
@ -65,7 +65,7 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) {
|
|||
meta.type = 'error'
|
||||
} else if (value instanceof Date) {
|
||||
meta.type = 'date'
|
||||
} else if (value.constructor != null && value.constructor.name === 'Promise') {
|
||||
} else if (isPromise(value)) {
|
||||
meta.type = 'promise'
|
||||
} else if (value.hasOwnProperty('callee') && value.length != null) {
|
||||
// Treat the arguments object as array.
|
||||
|
|
|
@ -43,6 +43,11 @@ exports.defineProperties = function (exports) {
|
|||
get: function () {
|
||||
return require('../deprecations')
|
||||
}
|
||||
},
|
||||
isPromise: {
|
||||
get: function () {
|
||||
return require('../is-promise')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
14
lib/common/api/is-promise.js
Normal file
14
lib/common/api/is-promise.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = function isPromise (val) {
|
||||
return (
|
||||
val &&
|
||||
val.then &&
|
||||
val.then instanceof Function &&
|
||||
val.constructor &&
|
||||
val.constructor.reject &&
|
||||
val.constructor.reject instanceof Function &&
|
||||
val.constructor.resolve &&
|
||||
val.constructor.resolve instanceof Function
|
||||
)
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const v8Util = process.atomBinding('v8_util')
|
||||
const {ipcRenderer, CallbacksRegistry} = require('electron')
|
||||
const {ipcRenderer, isPromise, CallbacksRegistry} = require('electron')
|
||||
|
||||
const callbacksRegistry = new CallbacksRegistry()
|
||||
|
||||
|
@ -44,7 +44,7 @@ var wrapArgs = function (args, visited) {
|
|||
value: value.getTime()
|
||||
}
|
||||
} else if ((value != null) && typeof value === 'object') {
|
||||
if (value.constructor != null && value.constructor.name === 'Promise') {
|
||||
if (isPromise(value)) {
|
||||
return {
|
||||
type: 'promise',
|
||||
then: valueToMeta(function (onFulfilled, onRejected) {
|
||||
|
|
Loading…
Reference in a new issue