diff --git a/package.json b/package.json index b981d0d..0a12eb1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gawk", - "version": "4.6.5", + "version": "4.6.6", "description": "Observable JavaScript object model", "main": "./dist/index.js", "author": "Chris Barber (https://github.com/cb1kenobi)", diff --git a/src/index.js b/src/index.js index 44b84dd..07bb25b 100644 --- a/src/index.js +++ b/src/index.js @@ -421,7 +421,7 @@ function copyListeners(dest, src, compareFn) { return; } - for (const key of Object.getOwnPropertyNames(dest)) { + for (const key of [ ...Object.getOwnPropertySymbols(dest), ...Object.getOwnPropertyNames(dest) ]) { if (key === '__gawk__') { continue; } @@ -500,7 +500,7 @@ export function set(dest, src, compareFn) { const tmp = {}; - for (const key of Object.getOwnPropertyNames(src)) { + for (const key of [ ...Object.getOwnPropertySymbols(src), ...Object.getOwnPropertyNames(src) ]) { if (key === '__gawk__') { continue; } @@ -519,7 +519,7 @@ export function set(dest, src, compareFn) { } // prune the existing object, then copy all the properties from our temp object - for (const key of Object.getOwnPropertyNames(dest)) { + for (const key of [ ...Object.getOwnPropertySymbols(dest), ...Object.getOwnPropertyNames(dest) ]) { if (key !== '__gawk__') { delete dest[key]; } @@ -682,7 +682,7 @@ function mix(objs, deep) { * @param {Object} src - The source object to copy from. */ const mixer = (gobj, src) => { - for (const key of Object.getOwnPropertyNames(src)) { + for (const key of [ ...Object.getOwnPropertySymbols(src), ...Object.getOwnPropertyNames(src) ]) { if (key === '__gawk__') { continue; } diff --git a/test/test-object.js b/test/test-object.js index ab998fd..4ee9ef1 100644 --- a/test/test-object.js +++ b/test/test-object.js @@ -249,10 +249,12 @@ describe('set property', () => { const gobj = gawk({}); gobj[id] = 'foo'; - expect(gobj).to.deep.equal({ [id]: 'foo' }); + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('foo'); gobj[id] = 'bar'; - expect(gobj).to.deep.equal({ [id]: 'bar' }); + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('bar'); }); }); @@ -296,13 +298,22 @@ describe('Object.keys()', () => { }); describe('Object.getOwnPropertySymbols()', () => { - it('should return an array of symbol keys in the object', () => { + it('should return an array of symbol keys in empty object', () => { const id = Symbol(); - const gobj = gawk({ [id]: 'foo' }); - expect(gobj).to.deep.equal({ [id]: 'foo' }); + const gobj = gawk({}); + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([]); + + gobj[id] = 'foo'; + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + }); + it('should return an array of symbol keys from initialized object', () => { + const id = Symbol(); + + const gobj = gawk({ [id]: 'foo' }); expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('foo'); }); }); @@ -396,11 +407,14 @@ describe('gawk.merge()', () => { it('should merge an object with a symbol property', () => { const id = Symbol(); - const gobj = gawk({ [id]: 'foo' }); - expect(gobj).to.deep.equal({ [id]: 'foo' }); + const gobj = gawk({}); + gobj[id] = 'foo'; + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('foo'); gawk.merge(gobj, { [id]: 'bar' }); - expect(gobj).to.deep.equal({ [id]: 'bar' }); + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('bar'); }); }); diff --git a/test/test-set.js b/test/test-set.js index 33862ce..7f8ad71 100644 --- a/test/test-set.js +++ b/test/test-set.js @@ -391,13 +391,25 @@ describe('gawk.set()', () => { expect(counter).to.equal(2); }); - it('should set an object with a symbol property', () => { + it('should set an existing object with a symbol property', () => { + const id = Symbol(); + + const gobj = gawk({}); + + gawk.set(gobj, { [id]: 'foo' }); + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('foo'); + }); + + it('should set an existing object with a symbol property', () => { const id = Symbol(); const gobj = gawk({ [id]: 'foo' }); - expect(gobj).to.deep.equal({ [id]: 'foo' }); + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('foo'); gawk.set(gobj, { [id]: 'bar' }); - expect(gobj).to.deep.equal({ [id]: 'bar' }); + expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]); + expect(gobj[id]).to.equal('bar'); }); });