-
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): Set
this
in static contexts (#460)
Javascript allows static members to refer to other static members through `this`, but the `jsii-kernel` passed `null` for the `this` context in `sinvoke`, making it impossible to invoke static methods that made use of this feature through the `jsii` runtimes. Fixes aws/aws-cdk#2304
- Loading branch information
1 parent
a5e8a93
commit c81b4c1
Showing
15 changed files
with
277 additions
and
6 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
31 changes: 31 additions & 0 deletions
31
...zon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StaticContext.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,31 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
/// <summary>This is used to validate the ability to use `this` from within a static context.</summary> | ||
/// <remarks>https://github.com/awslabs/aws-cdk/issues/2304</remarks> | ||
[JsiiClass(nativeType: typeof(StaticContext), fullyQualifiedName: "jsii-calc.StaticContext")] | ||
public class StaticContext : DeputyBase | ||
{ | ||
protected StaticContext(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
protected StaticContext(DeputyProps props): base(props) | ||
{ | ||
} | ||
|
||
[JsiiProperty(name: "staticVariable", typeJson: "{\"primitive\":\"boolean\"}")] | ||
public static bool StaticVariable | ||
{ | ||
get => GetStaticProperty<bool>(typeof(StaticContext)); | ||
set => SetStaticProperty(typeof(StaticContext), value); | ||
} | ||
|
||
[JsiiMethod(name: "canAccessStaticContext", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}")] | ||
public static bool CanAccessStaticContext() | ||
{ | ||
return InvokeStaticMethod<bool>(typeof(StaticContext), new object[]{}); | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...ted.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/StaticContext.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,26 @@ | ||
package software.amazon.jsii.tests.calculator; | ||
|
||
/** | ||
* This is used to validate the ability to use `this` from within a static context. | ||
* | ||
* https://github.com/awslabs/aws-cdk/issues/2304 | ||
*/ | ||
@javax.annotation.Generated(value = "jsii-pacmak") | ||
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.StaticContext") | ||
public class StaticContext extends software.amazon.jsii.JsiiObject { | ||
protected StaticContext(final software.amazon.jsii.JsiiObject.InitializationMode mode) { | ||
super(mode); | ||
} | ||
|
||
public static java.lang.Boolean canAccessStaticContext() { | ||
return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.jsii.tests.calculator.StaticContext.class, "canAccessStaticContext", java.lang.Boolean.class); | ||
} | ||
|
||
public static java.lang.Boolean getStaticVariable() { | ||
return software.amazon.jsii.JsiiObject.jsiiStaticGet(software.amazon.jsii.tests.calculator.StaticContext.class, "staticVariable", java.lang.Boolean.class); | ||
} | ||
|
||
public static void setStaticVariable(final java.lang.Boolean value) { | ||
software.amazon.jsii.JsiiObject.jsiiStaticSet(software.amazon.jsii.tests.calculator.StaticContext.class, "staticVariable", java.util.Objects.requireNonNull(value, "staticVariable is required")); | ||
} | ||
} |
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
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