Closed Bug 1455179 Opened 2 years ago Closed 2 years ago

Don't warn about undefined properties when destructuring with default values

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla61
Tracking Status
firefox61 --- fixed

People

(Reporter: kmag, Assigned: kmag)

References

Details

Attachments

(1 file)

These warnings come up all the time in our test output. When we destructure with a default value for a missing property, e.g.:

  let obj = {};
  let {foo = 0} = obj;

We get an undefined property warning for `obj.foo`, even though we provide a default value for it. The NativeObject Detecting checks should handle this case, and treat that as a valid detection access.
Jason, do you think we should ignore the "undefined property" warnings when destructing objects?
Flags: needinfo?(jorendorff)
If this patch lands, bug 1300416 can be closed, too.
(In reply to Nicolas B. Pierron [:nbp] {backlog: ~36} from comment #2)
> Jason, do you think we should ignore the "undefined property" warnings when
> destructing objects?

To be clear, this only ignores properties that have default values. I.e.,

  let {foo = 0, bar} = {};

will warn for `bar` but not `foo`.
Comment on attachment 8969150 [details]
Bug 1455179: Support destructuring with default values in undefined property detection checks.

https://reviewboard.mozilla.org/r/237866/#review244164

Thanks for this patch, it does fix some missing corner cases implied by the original comments.
Attachment #8969150 - Flags: review?(nicolas.b.pierron) → review+
Flags: needinfo?(jorendorff)
https://hg.mozilla.org/integration/mozilla-inbound/rev/219afe052ae3a80b1da61d60ade56d73af0b0ca2
Bug 1455179: Support destructuring with default values in undefined property detection checks. r=nbp
https://hg.mozilla.org/mozilla-central/rev/219afe052ae3
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
Too late, but yes, this was the right call.
You need to log in before you can comment on or make changes to this bug.