Skip to content
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(kernel): calling super.property unexpectedly returns undefined #1932

Merged
merged 4 commits into from
Aug 24, 2020

Conversation

RomainMuller
Copy link
Contributor

When overriding a property, the @jsii/kernel creates a shadow property
for 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 descriptor
and 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.

When overriding a property, the `@jsii/kernel` creates a shadow property
for 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 descriptor
and upon failing to identify one, uses the current value of the property
instead of `undefined`.
@RomainMuller RomainMuller added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 module/kernel Issues affecting the `jsii-kernel` module contribution/core This is a PR that came from AWS. labels Aug 21, 2020
@RomainMuller RomainMuller added this to the August Release milestone Aug 21, 2020
@RomainMuller RomainMuller requested a review from a team August 21, 2020 09:34
@RomainMuller RomainMuller self-assigned this Aug 21, 2020
@mergify
Copy link
Contributor

mergify bot commented Aug 21, 2020

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Aug 21, 2020
@mergify
Copy link
Contributor

mergify bot commented Aug 21, 2020

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: f8d7481
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@RomainMuller RomainMuller merged commit 3b48778 into master Aug 24, 2020
@RomainMuller RomainMuller deleted the rmuller/fix-super-property-in-constructor branch August 24, 2020 15:12
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort module/kernel Issues affecting the `jsii-kernel` module p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants