concordancejs / concordance

Compare, format, diff and serialize any JavaScript value
ISC License
207 stars 15 forks source link

Consider function name support when comparing deserialized object ctors #28

Closed novemberborn closed 7 years ago

novemberborn commented 7 years ago

Whether an object's constructor name is available depends on whether the JavaScript engine could infer the name. Support for name inference is incomplete in Node.js releases up to 6.4.0.

Move the tracking of function name support from the complex Function value into the Object value. Compare deserialized object constructor names using the same algorithm as is used for comparing function names.

This is a breaking change in the serialization format, resulting in the serialization version being bumped to 2.

See #21 for background.


An easy way to reproduce the bug using concordance@1:

❯ node -v
v8.1.2
❯ node -pe "var c=require('concordance');var Foo=class {};c.serialize(c.describe(new Foo())).toString('hex')"
0100070000000000010700140106120103466f6f001201064f626a656374111111
❯ node --use_strict -pe "var c=require('concordance');var Foo=class {};c.compareDescriptors(c.deserialize(Buffer.from('0100070000000000010700140106120103466f6f001201064f626a656374111111','hex')), c.describe(new Foo()))"
true
❯ node -v
v4.8.3
❯ node --use_strict -pe "var c=require('concordance');var Foo=class {};c.compareDescriptors(c.deserialize(Buffer.from('0100070000000000010700140106120103466f6f001201064f626a656374111111','hex')), c.describe(new Foo()))"
false

With this PR:

❯ node -v
v8.1.2
❯ node -pe "var c=require('concordance');var Foo=class {};c.serialize(c.describe(new Foo())).toString('hex')"
0200070000000000010700140107120103466f6f001201064f626a65637411111102ff7f
❯ node --use_strict -pe "var c=require('concordance');var Foo=class {};c.compareDescriptors(c.deserialize(Buffer.from('0200070000000000010700140107120103466f6f001201064f626a65637411111102ff7f','hex')), c.describe(new Foo()))"
true
❯ node -v
v4.8.3
❯ node --use_strict -pe "var c=require('concordance');var Foo=class {};c.compareDescriptors(c.deserialize(Buffer.from('0200070000000000010700140107120103466f6f001201064f626a65637411111102ff7f','hex')), c.describe(new Foo()))"
true