__proto__ and accessor descriptors

# Asen Bozhilov (13 years ago)

I would like to define custom getter and setter for __proto__ property:

var obj = Object.defineProperty({}, 'proto', { get : function () {return 'proto getter'}, set : function (){return 'proto setter'} });

console.log(obj.proto); //[object Object] console.log(obj.proto = {}); //[object Object]

I didn't find an engine which outputs the values in get and set. The idea behind my code is to reject the __proto__ ability to change the internal [[Prototype]].

Is the above behavior should be observed according ECMAScript 6?

Thank you.

# David Bruant (13 years ago)

Le 26/10/2012 22:56, Asen Bozhilov a écrit :

I would like to define custom getter and setter for __proto__ property:

var obj = Object.defineProperty({}, 'proto', { get : function () {return 'proto getter'}, set : function (){return 'proto setter'} });

console.log(obj.proto); //[object Object] console.log(obj.proto = {}); //[object Object]

I didn't find an engine which outputs the values in get and set.

On Firefox Aurora, I find: "proto getter" "[object Object]"

The idea behind my code is to reject the __proto__ ability to change the internal [[Prototype]]

In conforming engines, 'delete Object.prototype.proto' will do the job for all objects at the same time.

Is the above behavior should be observed according ECMAScript 6?

It is not, but it's likely that no implementation perfectly conforms. Take a look at strawman:magic_proto_property According to this strawman, the output should indeed be "__proto__getter" then "__proto__setter".

# Jeff Walden (13 years ago)

On 10/26/2012 02:30 PM, David Bruant wrote:> Le 26/10/2012 22:56, Asen Bozhilov a écrit :

var obj = Object.defineProperty({}, 'proto', { get : function () {return 'proto getter'}, set : function (){return 'proto setter'} });

console.log(obj.proto); //[object Object] console.log(obj.proto = {}); //[object Object]

On Firefox Aurora, I find: "proto getter" "[object Object]"

According to this strawman, the output should indeed be "__proto__getter" then "__proto__setter".

Given that the result of evaluating |obj.proto = {}| is the right-hand side (the return value of calling the setter is ignored), to the extent there's some determined-correct behavior here, it definitely wouldn't be to log "proto setter".

# Brendan Eich (13 years ago)

Jeff Walden wrote:

On 10/26/2012 02:30 PM, David Bruant wrote:> Le 26/10/2012 22:56, Asen Bozhilov a écrit :

var obj = Object.defineProperty({}, 'proto', { get : function () {return 'proto getter'}, set : function (){return 'proto setter'} });

console.log(obj.proto); //[object Object] console.log(obj.proto = {}); //[object Object]

On Firefox Aurora, I find: "proto getter" "[object Object]"

According to this strawman, the output should indeed be "__proto__getter" then "__proto__setter".

Given that the result of evaluating |obj.proto = {}| is the right-hand side (the return value of calling the setter is ignored), to the extent there's some determined-correct behavior here, it definitely wouldn't be to log "proto setter".

Score! Good point.

David, if the setter calls console.log you should see the desired results.

# David Bruant (13 years ago)

Le 09/11/2012 00:05, Jeff Walden a écrit :

On 10/26/2012 02:30 PM, David Bruant wrote:> Le 26/10/2012 22:56, Asen Bozhilov a écrit :

var obj = Object.defineProperty({}, 'proto', { get : function () {return 'proto getter'}, set : function (){return 'proto setter'} });

console.log(obj.proto); //[object Object] console.log(obj.proto = {}); //[object Object]

On Firefox Aurora, I find: "proto getter" "[object Object]"

According to this strawman, the output should indeed be "__proto__getter" then "__proto__setter". Given that the result of evaluating |obj.proto = {}| is the right-hand side (the return value of calling the setter is ignored), to the extent there's some determined-correct behavior here, it definitely wouldn't be to log "proto setter".

Jeff m'a tuer [1]

David

[1] Reference to "Omar m'a tuer", a case in France where the victim would have written the name of her murderer (Omar) with her own blood right before dying... but made an absurd typo (it should be "tuée" instead of "tuer"). A film has been made out of the case if anyone's interested en.wikipedia.org/wiki/Omar_Killed_Me