-
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 (#3339)
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 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information
Romain Marcadier
committed
Jan 17, 2022
1 parent
309da85
commit d361c7b
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); | ||
}); |