-
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(kernel): Return object literals as references
Use the javascript `Proxy` class to coalesce object literals to an interface type, allowing them to be returned by reference instead of by value. Introduces a test in the `jsii-kernel` to demonstrate the feature works as intended. Fixes #248 Fixes aws/aws-cdk#774
- Loading branch information
1 parent
b743a13
commit 471deda
Showing
13 changed files
with
340 additions
and
8 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
27 changes: 27 additions & 0 deletions
27
...rPackageId/Amazon/JSII/Tests/CalculatorNamespace/ClassWithMutableObjectLiteralProperty.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,27 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
[JsiiClass(typeof(ClassWithMutableObjectLiteralProperty), "jsii-calc.ClassWithMutableObjectLiteralProperty", "[]")] | ||
public class ClassWithMutableObjectLiteralProperty : DeputyBase | ||
{ | ||
public ClassWithMutableObjectLiteralProperty(): base(new DeputyProps(new object[]{})) | ||
{ | ||
} | ||
|
||
protected ClassWithMutableObjectLiteralProperty(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
protected ClassWithMutableObjectLiteralProperty(DeputyProps props): base(props) | ||
{ | ||
} | ||
|
||
[JsiiProperty("mutableObject", "{\"fqn\":\"jsii-calc.MutableObjectLiteral\"}")] | ||
public virtual IMutableObjectLiteral MutableObject | ||
{ | ||
get => GetInstanceProperty<IMutableObjectLiteral>(); | ||
set => SetInstanceProperty(value); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
....Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IMutableObjectLiteral.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,15 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
[JsiiInterface(typeof(IMutableObjectLiteral), "jsii-calc.MutableObjectLiteral")] | ||
public interface IMutableObjectLiteral | ||
{ | ||
[JsiiProperty("value", "{\"primitive\":\"string\"}")] | ||
string Value | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...I.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/MutableObjectLiteral.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,14 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
public class MutableObjectLiteral : DeputyBase, IMutableObjectLiteral | ||
{ | ||
[JsiiProperty("value", "{\"primitive\":\"string\"}", true)] | ||
public string Value | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ts.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/MutableObjectLiteralProxy.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,19 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
[JsiiTypeProxy(typeof(IMutableObjectLiteral), "jsii-calc.MutableObjectLiteral")] | ||
internal sealed class MutableObjectLiteralProxy : DeputyBase, IMutableObjectLiteral | ||
{ | ||
private MutableObjectLiteralProxy(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
[JsiiProperty("value", "{\"primitive\":\"string\"}")] | ||
public string Value | ||
{ | ||
get => GetInstanceProperty<string>(); | ||
set => SetInstanceProperty(value); | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...ain/java/software/amazon/jsii/tests/calculator/ClassWithMutableObjectLiteralProperty.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,21 @@ | ||
package software.amazon.jsii.tests.calculator; | ||
|
||
@javax.annotation.Generated(value = "jsii-pacmak") | ||
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.ClassWithMutableObjectLiteralProperty") | ||
public class ClassWithMutableObjectLiteralProperty extends software.amazon.jsii.JsiiObject { | ||
protected ClassWithMutableObjectLiteralProperty(final software.amazon.jsii.JsiiObject.InitializationMode mode) { | ||
super(mode); | ||
} | ||
public ClassWithMutableObjectLiteralProperty() { | ||
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii); | ||
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); | ||
} | ||
|
||
public software.amazon.jsii.tests.calculator.MutableObjectLiteral getMutableObject() { | ||
return this.jsiiGet("mutableObject", software.amazon.jsii.tests.calculator.MutableObjectLiteral.class); | ||
} | ||
|
||
public void setMutableObject(final software.amazon.jsii.tests.calculator.MutableObjectLiteral value) { | ||
this.jsiiSet("mutableObject", java.util.Objects.requireNonNull(value, "mutableObject is required")); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...i-calc/java/src/main/java/software/amazon/jsii/tests/calculator/MutableObjectLiteral.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,72 @@ | ||
package software.amazon.jsii.tests.calculator; | ||
|
||
@javax.annotation.Generated(value = "jsii-pacmak") | ||
public interface MutableObjectLiteral extends software.amazon.jsii.JsiiSerializable { | ||
java.lang.String getValue(); | ||
void setValue(final java.lang.String value); | ||
|
||
/** | ||
* @return a {@link Builder} of {@link MutableObjectLiteral} | ||
*/ | ||
static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* A builder for {@link MutableObjectLiteral} | ||
*/ | ||
final class Builder { | ||
private java.lang.String _value; | ||
|
||
/** | ||
* Sets the value of Value | ||
* @param value the value to be set | ||
* @return {@code this} | ||
*/ | ||
public Builder withValue(final java.lang.String value) { | ||
this._value = java.util.Objects.requireNonNull(value, "value is required"); | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the configured instance. | ||
* @return a new instance of {@link MutableObjectLiteral} | ||
* @throws NullPointerException if any required attribute was not provided | ||
*/ | ||
public MutableObjectLiteral build() { | ||
return new MutableObjectLiteral() { | ||
private java.lang.String $value = java.util.Objects.requireNonNull(_value, "value is required"); | ||
|
||
@Override | ||
public java.lang.String getValue() { | ||
return this.$value; | ||
} | ||
|
||
@Override | ||
public void setValue(final java.lang.String value) { | ||
this.$value = java.util.Objects.requireNonNull(value, "value is required"); | ||
} | ||
|
||
}; | ||
} | ||
} | ||
|
||
/** | ||
* A proxy class which represents a concrete javascript instance of this type. | ||
*/ | ||
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.MutableObjectLiteral { | ||
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) { | ||
super(mode); | ||
} | ||
|
||
@Override | ||
public java.lang.String getValue() { | ||
return this.jsiiGet("value", java.lang.String.class); | ||
} | ||
|
||
@Override | ||
public void setValue(final java.lang.String value) { | ||
this.jsiiSet("value", java.util.Objects.requireNonNull(value, "value is required")); | ||
} | ||
} | ||
} |
Oops, something went wrong.