Merge pull request #5736 from electron/missing-has-own-property

Support objects with no prototype over IPC
This commit is contained in:
Cheng Zhao 2016-05-28 13:42:30 +00:00
commit 747f910ce0
3 changed files with 14 additions and 1 deletions

View file

@ -6,6 +6,8 @@ const {ipcMain, isPromise} = electron
const objectsRegistry = require('./objects-registry') const objectsRegistry = require('./objects-registry')
const hasProp = {}.hasOwnProperty
// The internal properties of Function. // The internal properties of Function.
const FUNCTION_PROPERTIES = [ const FUNCTION_PROPERTIES = [
'length', 'name', 'arguments', 'caller', 'prototype' 'length', 'name', 'arguments', 'caller', 'prototype'
@ -67,7 +69,7 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) {
meta.type = 'date' meta.type = 'date'
} else if (isPromise(value)) { } else if (isPromise(value)) {
meta.type = 'promise' 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. // Treat the arguments object as array.
meta.type = 'array' meta.type = 'array'
} else if (optimizeSimpleObject && v8Util.getHiddenValue(value, 'simple')) { } else if (optimizeSimpleObject && v8Util.getHiddenValue(value, 'simple')) {

View file

@ -32,6 +32,13 @@ describe('ipc module', function () {
assert.equal(a.id, 1127) 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 () { 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.filename), path.resolve(__dirname, 'static', 'main.js'))
comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules')) comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules'))

4
spec/fixtures/module/no-prototype.js vendored Normal file
View file

@ -0,0 +1,4 @@
const foo = Object.create(null)
foo.bar = 'baz'
foo.baz = false
module.exports = {foo: foo, bar: 1234}