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 28052 - Structured Clone algorithm should use ES primitives when specifying property setting
Summary: Structured Clone algorithm should use ES primitives when specifying property ...
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:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-18 20:22 UTC by Adam Klein
Modified: 2015-08-29 05:11 UTC (History)
4 users (show)

See Also:


Attachments

Description Adam Klein 2015-02-18 20:22:33 UTC
In particular, https://html.spec.whatwg.org/multipage/infrastructure.html#internal-structured-cloning-algorithm step 8.4 says:

"Add a new property to output having the name name, and having the value cloned value."

"Add a new property" has been interpreted differently in implementations: Chrome uses [[Set]] (thus invoking setters on the prototype), while Firefox appears to use [[DefineOwnProperty]].

[[DefineOwnProperty]] seems like a better idea to me, for what it's worth.
Comment 1 Ian 'Hixie' Hickson 2015-03-04 20:36:00 UTC
how can the prototype have anything interesting going on at this point?

To put it another way, how could you detect the difference?
Comment 2 Joshua Bell 2015-03-04 22:57:57 UTC
Example:

```js
onmessage = function(m) { console.log(m.data); };

Object.defineProperty(Object.prototype, 'foo', { 
  set: function(v) { console.log('in setter') } 
});

postMessage({foo: 1, bar: 2}, '*');
```

If [[Set]] is used, this would log 'in setter' then {bar: 2}

If [[DefineOwnProperty]] is used, this would log {foo: 1, bar: 2}

This assumes Object.prototype is used as the prototype for a "newly constructed empty Object object", which appears to be true of all implementations we had handy to test in, the same as e.g. var newEmptyObject = {}
Comment 3 Ian 'Hixie' Hickson 2015-03-30 20:33:55 UTC
It's suppose to just create the object without invoking any JS code at all. i.e. all you're supposed to do is add a new property. I suppose we can say that this uses [[DefineOwnProperty]] if there are implementations that are interpreting it as something more than that.
Comment 4 Joshua Bell 2015-03-30 20:54:53 UTC
(In reply to Ian 'Hixie' Hickson from comment #3)
> It's suppose to just create the object without invoking any JS code at all.
> i.e. all you're supposed to do is add a new property. I suppose we can say
> that this uses [[DefineOwnProperty]] if there are implementations that are
> interpreting it as something more than that.

SGTM. Given that the spec uses [[Get]] later on, precision here would be nice.

("Add a new property" certainly seems pretty clear that it should not trigger setters since that would not be adding a property, but Chrome got this wrong...)
Comment 5 Anne 2015-08-28 17:21:20 UTC
Adam or Joshua, either of you interested in fixing this by providing a pull request? https://github.com/whatwg/html
Comment 6 Joshua Bell 2015-08-28 18:31:04 UTC
(In reply to Anne from comment #5)
> Adam or Joshua, either of you interested in fixing this by providing a pull
> request? https://github.com/whatwg/html

Sure, let's try this out:

https://github.com/whatwg/html/pull/36