fix(kernel): calling super.property unexpectedly returns undefined
#1932
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.
When overriding a property, the
@jsii/kernel
creates a shadow propertyfor the previous implementation. In order to preserve the existing
implementation (whether the property is dynamic or not), the property
descriptor is retrieved and re-declared with the new name.
This process did not crawl up the prototype chain, and only looked at
the object itself. In many cases, this will never return anything (since
Object.getOwnPropertyDescriptor
will not return inherited descriptors)and in this case the
undefined
value was always used.This would break whenever attempting to override a property that was
inherited from a parent class, and appears to fail with certain
node
runtimes where the dynamic properties are set on the object's prototype
and not on the object itself.
This change adds the necessary logic to traverse the prototype chain all
the way up to
Object
(not included), to locate the property descriptorand upon failing to identify one, uses the current value of the property
instead of
undefined
.This was the cause of aws/aws-cdk#9822
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.