Merge pull request #5736 from electron/missing-has-own-property
Support objects with no prototype over IPC
This commit is contained in:
commit
747f910ce0
3 changed files with 14 additions and 1 deletions
|
@ -6,6 +6,8 @@ const {ipcMain, isPromise} = electron
|
|||
|
||||
const objectsRegistry = require('./objects-registry')
|
||||
|
||||
const hasProp = {}.hasOwnProperty
|
||||
|
||||
// The internal properties of Function.
|
||||
const FUNCTION_PROPERTIES = [
|
||||
'length', 'name', 'arguments', 'caller', 'prototype'
|
||||
|
@ -67,7 +69,7 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) {
|
|||
meta.type = 'date'
|
||||
} else if (isPromise(value)) {
|
||||
meta.type = 'promise'
|
||||
} else if (value.hasOwnProperty('callee') && value.length != null) {
|
||||
} else if (hasProp.call(value, 'callee') && value.length != null) {
|
||||
// Treat the arguments object as array.
|
||||
meta.type = 'array'
|
||||
} else if (optimizeSimpleObject && v8Util.getHiddenValue(value, 'simple')) {
|
||||
|
|
|
@ -32,6 +32,13 @@ describe('ipc module', function () {
|
|||
assert.equal(a.id, 1127)
|
||||
})
|
||||
|
||||
it.only('should work when object has no prototype', function () {
|
||||
var a = remote.require(path.join(fixtures, 'module', 'no-prototype.js'))
|
||||
assert.equal(a.foo.bar, 'baz')
|
||||
assert.equal(a.foo.baz, false)
|
||||
assert.equal(a.bar, 1234)
|
||||
})
|
||||
|
||||
it('should search module from the user app', function () {
|
||||
comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js'))
|
||||
comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules'))
|
||||
|
|
4
spec/fixtures/module/no-prototype.js
vendored
Normal file
4
spec/fixtures/module/no-prototype.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
const foo = Object.create(null)
|
||||
foo.bar = 'baz'
|
||||
foo.baz = false
|
||||
module.exports = {foo: foo, bar: 1234}
|
Loading…
Reference in a new issue