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(runtime): Passing 'this' to a callback from constructor #395

Merged
merged 10 commits into from
Mar 28, 2019

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Mar 20, 2019

In Javascript, a constructor is allowed to pass references to this to
method calls (effectively passing a partially initialized instance).
When done, the kernel will assign an Object ID to this on the spot in
order to pass the reference through the JSII boundary. However, the
create API before this change would have attempted to re-allocate an
Object ID to the object (which is illegal and causes a crash).

In addition, callbacks from at least Java and .NET runtimes could not
receive JSII object references, for they would not turn them into native
objects before passing them to the implementation, resulting in a class
conversion error.

Fixes #398


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

In Javascript, a constructor is allowed to pass references to `this` to
method calls (effectively passing a partially initialized instance).
When done, the kernel will assign an Object ID to `this` on the spot in
order to pass the reference through the JSII boundary. However, the
`create` API before this change would have attempted to re-allocate an
Object ID to the object (which is illegal and causes a crash).

In addition, callbacks from at least Java and .NET runtimes could not
receive JSII object references, for they would not turn them into native
objects before passing them to the implementation, resulting in a class
conversion error.
@RomainMuller RomainMuller requested review from costleya, dstufft and a team as code owners March 20, 2019 13:13
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what the change is supposed to do, but I trust you.

Rico Huijbers and others added 2 commits March 26, 2019 13:56
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.
@RomainMuller
Copy link
Contributor Author

I have a further change to improve the new compliance tests' feature coverage (include a date and an enum value), however this fell on a bug that @rix0rrr fixed in #401, so I will wait until that was merged before I update the PR with that.

@RomainMuller RomainMuller requested a review from eladb March 28, 2019 08:08
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.

nothing interesting. looks awesome!

@eladb
Copy link
Contributor

eladb commented Mar 28, 2019

I meant "nothing interesting to say". I love this change and that we are using Jackson like the Java gods intended

@RomainMuller RomainMuller merged commit 850f42b into master Mar 28, 2019
@RomainMuller RomainMuller deleted the rmuller/fix-constructor-sends-this-out branch March 28, 2019 10:51
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.

None yet

4 participants