Skip to content
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

Merged
merged 3 commits into from
Mar 28, 2019

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Mar 26, 2019

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.

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.
@rix0rrr rix0rrr requested review from dstufft and a team as code owners March 26, 2019 12:56
Copy link
Contributor

@RomainMuller RomainMuller left a 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...

Copy link
Contributor

@eladb eladb left a 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:
*
* ┬───────────────────────────────────────────────────────────────────────────────────────────────┐
Copy link
Contributor

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');
Copy link
Contributor

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]: {
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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.

@rix0rrr rix0rrr merged commit 0a83d52 into master Mar 28, 2019
@rix0rrr rix0rrr deleted the huijbers/strict-kernel-types branch March 28, 2019 07:57
RomainMuller added a commit that referenced this pull request Mar 28, 2019
RomainMuller added a commit that referenced this pull request Mar 28, 2019
### Bug Fixes

* **kernel:** make type serialization explicit and recursive ([#401](#401)) ([0a83d52](0a83d52)), closes [aws/aws-cdk#1981](aws/aws-cdk#1981)
* **runtime:** Passing 'this' to a callback from constructor ([#395](#395)) ([850f42b](850f42b))
@RomainMuller RomainMuller mentioned this pull request Mar 28, 2019
RomainMuller added a commit that referenced this pull request Mar 28, 2019
### Bug Fixes

* **kernel:** make type serialization explicit and recursive ([#401](#401)) ([0a83d52](0a83d52)), closes [aws/aws-cdk#1981](aws/aws-cdk#1981)
* **runtime:** Passing 'this' to a callback from constructor ([#395](#395)) ([850f42b](850f42b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants