Skip to content

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

Merged
sokra merged 1 commit intomasterfrom
reflect
Mar 26, 2018
Merged

Use 'Reflect.defineProperty' instead of 'Object.defineProperty'#6832
sokra merged 1 commit intomasterfrom
reflect

Conversation

@ooflorent
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

6 participants