-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(kernel): make type serialization explicit and recursive #401
Conversation
Serialize and deserialize types according to their declared static type, and add validation on the runtime types matching the declared types. This is in contrast to previously, when we mostly only used the runtime types to determine what to do, and harly any validation was done. The runtime types used to be able to freely disagree with the declared types, and we put a lot of burden on the JSII runtimes at the other end of the wire. Fix tests that used to exercise the API with invalid arguments. Remove Proxy objects since they only existed to prevent accidentally overwriting certain keys via the jsii interface, and Symbols serve the same purpose (but simpler). Fixes aws/aws-cdk#1981.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tat looks pretty good. I particularly like the improved typing, and the refactoring things around... Although it'll make my head go 🤯 when I'll have to resolve the merge conflicts this'll inevitably cause...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow is all I can say. Blessed be the fruit
* | ||
* Types will be serialized according to the following table: | ||
* | ||
* ┬───────────────────────────────────────────────────────────────────────────────────────────────┐ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool
// ---------------------------------------------------------------------- | ||
[SerializationClass.Enum]: { | ||
serialize(value, type, host): WireEnum | undefined { | ||
host.debug('hullo'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove (not really important).
}, | ||
|
||
// ---------------------------------------------------------------------- | ||
[SerializationClass.Struct]: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go structs
// This looks odd, but if an object was originally passed in as a by-ref | ||
// class, and it happens to conform to a datatype interface we say we're | ||
// returning, return the actual object instead of the serialized value. | ||
// NOTE: Not entirely sure yet whether this is a bug masquerading as a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay for the kernel to allow passing in structs by reference. It should Just Work I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it can be backwards-compatible.
Serialize and deserialize types according to their declared static type,
and add validation on the runtime types matching the declared types.
This is in contrast to previously, when we mostly only used the runtime
types to determine what to do, and hardly any validation was done. The
runtime types used to be able to freely disagree with the declared
types, and we put a lot of burden on the JSII runtimes at the other
end of the wire.
Fix tests that used to exercise the API with invalid arguments.
Remove Proxy objects since they only existed to prevent accidentally
overwriting certain keys via the jsii interface, and Symbols serve
the same purpose (but simpler).
Fixes aws/aws-cdk#1981.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.