New issue
Advanced search Search tips

Issue 806513 link

Starred by 3 users

Issue metadata

Status: WontFix
Owner:
Closed: Feb 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

Spread operator copies Symbol property from one to another object

Reported by konr...@gmail.com, Jan 27 2018

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

Steps to reproduce the problem:
1. Define object on which Symbol will be used as property name (e.g. obj[Symbol("secret property")] = "secret value")
2. Using spread operator copy all properties to another object (e.g. const newObj = {...obj})

What is the expected behavior?
Spread operator should copy only own `enumerable` (which is not relevant to the property named using Symbol as it's not enumerable) properties from a provided object onto a new object.

What went wrong?
All properties including property with name using Symbol are copied into new object.

Did this work before? N/A 

Chrome version: 63.0.3239.132  Channel: n/a
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version: 

working example: https://goo.gl/SkHd3H
 

Comment 1 by woxxom@gmail.com, Jan 27 2018

Object spread is not even standardized yet, the specification is just stage-3.
I'm not sure why the browsers implemented it at all.

As for the problem, I don't see any spec saying that Symbol keys should be created as non-enumerable.
The closest thing is that "for-in" enumeration skips Symbol keys so there's simply no need to set enumerable=false:
https://www.ecma-international.org/ecma-262/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-enumerate
Labels: Needs-Triage-M63

Comment 3 by konr...@gmail.com, Jan 28 2018

What I see here is inconsistency. 
On the one hand `spread operator` and `Object.assign` both do copy `Symbol` property. 
On the other hand, `Symbol` property doesn't appear in `for...in` loop and completely ignored by `JSON.stringify/JSON.parse`.

Comment 4 by kochi@chromium.org, Jan 31 2018

Components: -Blink Blink>JavaScript
Components: -Blink>JavaScript Blink>JavaScript>Language
Status: Available (was: Unconfirmed)

Comment 6 by adamk@chromium.org, Feb 6 2018

Owner: gsat...@chromium.org
Status: WontFix (was: Available)
Pretty sure this is working as intended per spec, but assigning to gsathya in case I've got that wrong.

Note that this spec is now stage 4, and will be part of ES2018. If you'd like to further discuss this issue, I recommend opening an issue at https://github.com/tc39/ecma262.

Sign in to add a comment