-
Notifications
You must be signed in to change notification settings - Fork 246
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
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.
packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java
Outdated
Show resolved
Hide resolved
packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java
Outdated
Show resolved
Hide resolved
...atorPackageId/Amazon/JSII/Tests/CalculatorNamespace/PartiallyInitializedThisConsumerProxy.cs
Show resolved
Hide resolved
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 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.
…ctor-sends-this-out
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.
nothing interesting. looks awesome!
packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/CallbackExtensions.cs
Show resolved
Hide resolved
...sii-java-runtime/project/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
Show resolved
Hide resolved
I meant "nothing interesting to say". I love this change and that we are using Jackson like the Java gods intended |
In Javascript, a constructor is allowed to pass references to
this
tomethod calls (effectively passing a partially initialized instance).
When done, the kernel will assign an Object ID to
this
on the spot inorder to pass the reference through the JSII boundary. However, the
create
API 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.