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

Use 'Reflect.defineProperty' instead of 'Object.defineProperty' #6832

Merged
merged 1 commit into from
Mar 26, 2018

Conversation

ooflorent
Copy link
Member

@ooflorent ooflorent commented Mar 22, 2018

What kind of change does this PR introduce?

refactoring

Did you add tests for your changes?

no

If relevant, link to documentation update:

n/a

Summary

Reflect.defineProperty is more meaningful than Object.defineProperty. Internally Reflect.dP performs less checks than Object.dP.

Use Object.defineProperty

Does this PR introduce a breaking change?

no

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

Copy link
Member

@Jessidhia Jessidhia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantically, Reflect is intended to be used from Proxy traps. You're supposed to return the result of Reflect.defineProperty from a default defineProperty Proxy trap.

I'm not sure you should be using it in non-Proxy-related code.

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed my mind on this one (thanks @Kovensky for pointing this out).

The difference between Reflect and Object.defineProperty is that Object.defineProperty throws if the operation fails. (Reflect.defineProperty returns false)

So what's the behavior we want here? In my opinion we want an error to be thrown if the property can't be defined. An error here indicates that something is wrong here. We don't want this to be silently ignored...

@webpack-bot
Copy link
Contributor

@ooflorent Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@sokra
Copy link
Member

sokra commented Mar 26, 2018

Thanks

@sokra sokra deleted the reflect branch March 26, 2018 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants