From 7cf6be07a613d3d51c5be54e57fb121955ced0d3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 27 May 2016 10:41:10 -0700 Subject: [PATCH 1/3] Add failing spec for remote property with no prototype --- spec/api-ipc-spec.js | 6 ++++++ spec/fixtures/module/no-prototype.js | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 spec/fixtures/module/no-prototype.js diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index 102b23ece567..41cc2488d87e 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -32,6 +32,12 @@ describe('ipc module', function () { assert.equal(a.id, 1127) }) + it('should work when object has no prototype', function () { + var a = remote.require(path.join(fixtures, 'module', 'no-prototype.js')) + assert.deepEqual(a.foo, {}) + 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')) diff --git a/spec/fixtures/module/no-prototype.js b/spec/fixtures/module/no-prototype.js new file mode 100644 index 000000000000..b6c9d7a4fcda --- /dev/null +++ b/spec/fixtures/module/no-prototype.js @@ -0,0 +1,4 @@ +module.exports = { + foo: Object.create(null), + bar: 1234 +} From 59dd7ca9df4fee4d12e7eae57e9046a1935edbc4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 27 May 2016 10:46:02 -0700 Subject: [PATCH 2/3] Guard against object with no hasOwnProperty --- lib/browser/rpc-server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index fe264cceeeff..fa9841aeecb0 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -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')) { From fc4b224dec39022ad79eda0e9c7d568f2caa41c2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 27 May 2016 10:52:56 -0700 Subject: [PATCH 3/3] Add asserts for properties --- spec/api-ipc-spec.js | 5 +++-- spec/fixtures/module/no-prototype.js | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index 41cc2488d87e..22c2edde08d0 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -32,9 +32,10 @@ describe('ipc module', function () { assert.equal(a.id, 1127) }) - it('should work when object has no prototype', function () { + it.only('should work when object has no prototype', function () { var a = remote.require(path.join(fixtures, 'module', 'no-prototype.js')) - assert.deepEqual(a.foo, {}) + assert.equal(a.foo.bar, 'baz') + assert.equal(a.foo.baz, false) assert.equal(a.bar, 1234) }) diff --git a/spec/fixtures/module/no-prototype.js b/spec/fixtures/module/no-prototype.js index b6c9d7a4fcda..f298925b80f2 100644 --- a/spec/fixtures/module/no-prototype.js +++ b/spec/fixtures/module/no-prototype.js @@ -1,4 +1,4 @@ -module.exports = { - foo: Object.create(null), - bar: 1234 -} +const foo = Object.create(null) +foo.bar = 'baz' +foo.baz = false +module.exports = {foo: foo, bar: 1234}