diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index b5c9fe3a0e4..79fe41ed566 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -60,7 +60,7 @@ var wrapArgs = function (args, visited) { ret = { type: 'object', - name: value.constructor.name, + name: value.constructor != null ? value.constructor.name : '', members: [] } for (prop in value) { diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index 2bf5213cae3..0d9ba0ddeef 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -31,9 +31,13 @@ describe('ipc module', function () { it('should work when object has no prototype', function () { var a = remote.require(path.join(fixtures, 'module', 'no-prototype.js')) + assert.equal(a.foo.constructor.name, '') assert.equal(a.foo.bar, 'baz') assert.equal(a.foo.baz, false) assert.equal(a.bar, 1234) + assert.equal(a.anonymous.constructor.name, '') + assert.equal(a.getConstructorName(Object.create(null)), '') + assert.equal(a.getConstructorName(new (class {})), '') }) it('should search module from the user app', function () { diff --git a/spec/fixtures/module/no-prototype.js b/spec/fixtures/module/no-prototype.js index f298925b80f..46cc4fe8385 100644 --- a/spec/fixtures/module/no-prototype.js +++ b/spec/fixtures/module/no-prototype.js @@ -1,4 +1,11 @@ const foo = Object.create(null) foo.bar = 'baz' foo.baz = false -module.exports = {foo: foo, bar: 1234} +module.exports = { + foo: foo, + bar: 1234, + anonymous: new (class {}), + getConstructorName: function (value) { + return value.constructor.name + } +}