-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(python): reference isomorphism is broken within __init__
Within the `__init__` of a class, reading `self` back from the JS process would result in a proxy object created for the parent type, instead of returning `self`. This is because the `JSIIMeta` metaclass only registered the instance in the rerefence map **after** the constructor had returned. This adds an additional registration point right after the `create` API returned from the kernel, making the reference available as early as it can possibly be known. Fixes aws/aws-cdk#8262
- Loading branch information
1 parent
61f8883
commit df12ec8
Showing
12 changed files
with
248 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
44 changes: 44 additions & 0 deletions
44
...mazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Isomorphism.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
#pragma warning disable CS0672,CS0809,CS1591 | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
/// <summary>Checks the "same instance" isomorphism is preserved within the constructor.</summary> | ||
/// <remarks> | ||
/// Create a subclass of this, and assert that <c>this.myself()</c> actually returns | ||
/// <c>this</c> from within the constructor. | ||
/// | ||
/// <strong>Stability</strong>: Experimental | ||
/// </remarks> | ||
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Isomorphism), fullyQualifiedName: "jsii-calc.Isomorphism")] | ||
public abstract class Isomorphism : DeputyBase | ||
{ | ||
protected Isomorphism(): base(new DeputyProps(new object[]{})) | ||
{ | ||
} | ||
|
||
/// <summary>Used by jsii to construct an instance of this class from a Javascript-owned object reference</summary> | ||
/// <param name="reference">The Javascript-owned object reference</param> | ||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] | ||
protected Isomorphism(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
/// <summary>Used by jsii to construct an instance of this class from DeputyProps</summary> | ||
/// <param name="props">The deputy props</param> | ||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] | ||
protected Isomorphism(DeputyProps props): base(props) | ||
{ | ||
} | ||
|
||
/// <remarks> | ||
/// <strong>Stability</strong>: Experimental | ||
/// </remarks> | ||
[JsiiMethod(name: "myself", returnsJson: "{\"type\":{\"fqn\":\"jsii-calc.Isomorphism\"}}")] | ||
public virtual Amazon.JSII.Tests.CalculatorNamespace.Isomorphism Myself() | ||
{ | ||
return InvokeInstanceMethod<Amazon.JSII.Tests.CalculatorNamespace.Isomorphism>(new System.Type[]{}, new object[]{}); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
....JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IsomorphismProxy.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
#pragma warning disable CS0672,CS0809,CS1591 | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
/// <summary>Checks the "same instance" isomorphism is preserved within the constructor.</summary> | ||
/// <remarks> | ||
/// Create a subclass of this, and assert that <c>this.myself()</c> actually returns | ||
/// <c>this</c> from within the constructor. | ||
/// | ||
/// <strong>Stability</strong>: Experimental | ||
/// </remarks> | ||
[JsiiTypeProxy(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Isomorphism), fullyQualifiedName: "jsii-calc.Isomorphism")] | ||
internal sealed class IsomorphismProxy : Amazon.JSII.Tests.CalculatorNamespace.Isomorphism | ||
{ | ||
private IsomorphismProxy(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/Isomorphism.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package software.amazon.jsii.tests.calculator; | ||
|
||
/** | ||
* Checks the "same instance" isomorphism is preserved within the constructor. | ||
* <p> | ||
* Create a subclass of this, and assert that <code>this.myself()</code> actually returns | ||
* <code>this</code> from within the constructor. | ||
* <p> | ||
* EXPERIMENTAL | ||
*/ | ||
@javax.annotation.Generated(value = "jsii-pacmak") | ||
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) | ||
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.Isomorphism") | ||
public abstract class Isomorphism extends software.amazon.jsii.JsiiObject { | ||
|
||
protected Isomorphism(final software.amazon.jsii.JsiiObjectRef objRef) { | ||
super(objRef); | ||
} | ||
|
||
protected Isomorphism(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { | ||
super(initializationMode); | ||
} | ||
|
||
protected Isomorphism() { | ||
super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); | ||
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); | ||
} | ||
|
||
/** | ||
* EXPERIMENTAL | ||
*/ | ||
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) | ||
public @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.Isomorphism myself() { | ||
return this.jsiiCall("myself", software.amazon.jsii.tests.calculator.Isomorphism.class); | ||
} | ||
|
||
/** | ||
* A proxy class which represents a concrete javascript instance of this type. | ||
*/ | ||
final static class Jsii$Proxy extends software.amazon.jsii.tests.calculator.Isomorphism { | ||
protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { | ||
super(objRef); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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