This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28849 - Cloning steps for ES Map/Set should copy [[MapData]]/[[SetData]] list before recursing
Summary: Cloning steps for ES Map/Set should copy [[MapData]]/[[SetData]] list before ...
Status: RESOLVED MOVED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: https://html.spec.whatwg.org/#safe-pa...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-24 23:39 UTC by contributor
Modified: 2015-09-01 03:54 UTC (History)
3 users (show)

See Also:


Attachments

Description contributor 2015-06-24 23:39:41 UTC
Specification: https://html.spec.whatwg.org/multipage/infrastructure.html
Multipage: https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data
Complete: https://html.spec.whatwg.org/#safe-passing-of-structured-data
Referrer: https://html.spec.whatwg.org/multipage/

Comment:
Cloning steps for ES Map/Set should copy [[MapData]]/[[SetData]] list before
recursing

Posted from: 72.14.229.81
User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Comment 1 Adam Klein 2015-06-24 23:47:06 UTC
The spec as currently-written says:

"1. Let source be the List that is the value of input's [[SetData]] internal slot, if any."

Consider the following code:


var set = new Set;
var mutator = { get val() { set.add('mutator was here') } };
set.add(mutator);
onmessage = function(e) {
  console.log(e.data.size);
};
postMessage(set, '*')


What should be printed to the console? In Firefox, this example prints '1' (Chrome will print 1, soon, once it supports cloning Maps and Sets). But the spec suggests that it should print '2', since step 7.3.1 invokes the clone algorithm on |mutator| and thus adds another item to set's [[SetData]] List.

I'd recommend that the spec change to explicitly make a copy of [[SetData]] (and [[MapData]], for maps) before attempting to clone anything contained in those lists. This will match the existing implementation, and should be easier to implement in general.
Comment 2 Anne 2015-08-28 17:01:33 UTC
Adam, would you be willing to provide a pull request for https://github.com/whatwg/html?
Comment 3 Adam Klein 2015-08-31 21:50:22 UTC
(In reply to Anne from comment #2)
> Adam, would you be willing to provide a pull request for
> https://github.com/whatwg/html?

https://github.com/whatwg/html/pull/64
Comment 4 Anne 2015-09-01 03:54:54 UTC
Thank you!