-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kernel): kernel's private object annotations are enumerable
The jsii kernel needs to attach metadata to instances that are sent across the process boundary. While these properties use symbol names to eliminate the risk for collisions with user-defined properties, they were inadvertently set as `enumerable`, causing those to show in outputs of `JSON.stringify` and to be copied over as part of spat expressions (e.g: `{...obj}`), which resulted in the new value sharing the same identity as the previous one when sent over the wire. Caused: aws/aws-cdk#17876
- Loading branch information
1 parent
309da85
commit 3ce1374
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ObjectTable } from '../lib/objects'; | ||
|
||
const mockResolve = jest.fn(); | ||
|
||
test('can spread registered objects without consequences', () => { | ||
const subject = new ObjectTable(mockResolve); | ||
|
||
const obj = { foo: 'bar', baz: 1337 }; | ||
const objRef = subject.registerObject(obj, 'Object'); | ||
|
||
const copy = { ...obj, foo: undefined, baz: undefined }; | ||
const copyRef = subject.registerObject(copy, 'Object'); | ||
|
||
expect(objRef).not.toEqual(copyRef); | ||
}); | ||
|
||
test('registered objects have clean JSON.Stringify', () => { | ||
const subject = new ObjectTable(mockResolve); | ||
|
||
const obj = { foo: 'bar', baz: 1337 }; | ||
const expected = JSON.stringify(obj); | ||
|
||
subject.registerObject(obj, 'Object'); | ||
|
||
expect(JSON.stringify(obj)).toEqual(expected); | ||
}); |