fix(runtime): Passing 'this' to a callback from constructor#395
Merged
RomainMuller merged 10 commits intomasterfrom Mar 28, 2019
Merged
fix(runtime): Passing 'this' to a callback from constructor#395RomainMuller merged 10 commits intomasterfrom
RomainMuller merged 10 commits intomasterfrom
Conversation
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.
eladb
suggested changes
Mar 20, 2019
rix0rrr
approved these changes
Mar 21, 2019
Collaborator
rix0rrr
left a comment
There was a problem hiding this comment.
I don't really understand what the change is supposed to do, but I trust you.
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.
This was referenced Mar 27, 2019
Contributor
Author
…ctor-sends-this-out
eladb
approved these changes
Mar 28, 2019
Contributor
eladb
left a comment
There was a problem hiding this comment.
nothing interesting. looks awesome!
Contributor
|
I meant "nothing interesting to say". I love this change and that we are using Jackson like the Java gods intended |
RomainMuller
added a commit
that referenced
this pull request
Mar 28, 2019
Merged
RomainMuller
added a commit
that referenced
this pull request
Mar 28, 2019
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Javascript, a constructor is allowed to pass references to
thistomethod calls (effectively passing a partially initialized instance).
When done, the kernel will assign an Object ID to
thison the spot inorder to pass the reference through the JSII boundary. However, the
createAPI before this change would have attempted to re-allocate anObject 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.