Merge pull request #8890 from twolfson/dev/proxy.to.string.sqwished
🐛 Add toString support to remote functions
This commit is contained in:
commit
286f529968
3 changed files with 21 additions and 1 deletions
|
@ -179,7 +179,15 @@ const proxyFunctionProperties = function (remoteMemberFunction, metaId, name) {
|
|||
},
|
||||
get: (target, property, receiver) => {
|
||||
if (!target.hasOwnProperty(property)) loadRemoteProperties()
|
||||
return target[property]
|
||||
const value = target[property]
|
||||
|
||||
// Bind toString to target if it is a function to avoid
|
||||
// Function.prototype.toString is not generic errors
|
||||
if (property === 'toString' && typeof value === 'function') {
|
||||
return value.bind(target)
|
||||
}
|
||||
|
||||
return value
|
||||
},
|
||||
ownKeys: (target) => {
|
||||
loadRemoteProperties()
|
||||
|
|
|
@ -161,6 +161,14 @@ describe('ipc module', function () {
|
|||
assert.equal(typeof remote.clipboard.readText, 'function')
|
||||
assert.equal(typeof remote.shell.openExternal, 'function')
|
||||
})
|
||||
|
||||
it('returns toString() of original function via toString()', function () {
|
||||
const {readText} = remote.clipboard
|
||||
assert(readText.toString().startsWith('function'))
|
||||
|
||||
var {functionWithToStringProperty} = remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'))
|
||||
assert.equal(functionWithToStringProperty.toString, 'hello')
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote object in renderer', function () {
|
||||
|
|
4
spec/fixtures/module/to-string-non-function.js
vendored
Normal file
4
spec/fixtures/module/to-string-non-function.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
function hello () {
|
||||
}
|
||||
hello.toString = 'hello'
|
||||
module.exports = {functionWithToStringProperty: hello}
|
Loading…
Reference in a new issue